Commit 6394bba8 authored by gwenn's avatar gwenn

Add Stmt#Busy method.

parent e7464b51
...@@ -68,7 +68,7 @@ func (e *ConnError) Filename() string { ...@@ -68,7 +68,7 @@ func (e *ConnError) Filename() string {
return e.c.Filename return e.c.Filename
} }
func (e *ConnError) Error() string { func (e *ConnError) Error() string { // FIXME code.Error() & e.msg are often redundant...
if len(e.details) > 0 { if len(e.details) > 0 {
return fmt.Sprintf("%s: %s (%s)", e.code.Error(), e.msg, e.details) return fmt.Sprintf("%s: %s (%s)", e.code.Error(), e.msg, e.details)
} else if len(e.msg) > 0 { } else if len(e.msg) > 0 {
...@@ -126,7 +126,7 @@ var ( ...@@ -126,7 +126,7 @@ var (
ErrNotDB error = Errno(C.SQLITE_NOTADB) /* File opened that is not a database file */ ErrNotDB error = Errno(C.SQLITE_NOTADB) /* File opened that is not a database file */
Row = Errno(C.SQLITE_ROW) /* sqlite3_step() has another row ready */ Row = Errno(C.SQLITE_ROW) /* sqlite3_step() has another row ready */
Done = Errno(C.SQLITE_DONE) /* sqlite3_step() has finished executing */ Done = Errno(C.SQLITE_DONE) /* sqlite3_step() has finished executing */
ErrSpecific = Errno(-1) /* Gosqlite specific error */ ErrSpecific = Errno(-1) /* Wrapper specific error */
) )
var errText = map[Errno]string{ var errText = map[Errno]string{
...@@ -158,7 +158,7 @@ var errText = map[Errno]string{ ...@@ -158,7 +158,7 @@ var errText = map[Errno]string{
C.SQLITE_NOTADB: "File opened that is not a database file", C.SQLITE_NOTADB: "File opened that is not a database file",
Row: "sqlite3_step() has another row ready", Row: "sqlite3_step() has another row ready",
Done: "sqlite3_step() has finished executing", Done: "sqlite3_step() has finished executing",
ErrSpecific: "Gosqlite specific error", ErrSpecific: "Wrapper specific error",
} }
func (c *Conn) error(rv C.int, details ...string) error { func (c *Conn) error(rv C.int, details ...string) error {
...@@ -587,6 +587,7 @@ func (s *Stmt) BindParameterCount() int { ...@@ -587,6 +587,7 @@ func (s *Stmt) BindParameterCount() int {
} }
// Index of a parameter with a given name (cached) // Index of a parameter with a given name (cached)
// The first host parameter has an index of 1, not 0.
// (See http://sqlite.org/c3ref/bind_parameter_index.html) // (See http://sqlite.org/c3ref/bind_parameter_index.html)
func (s *Stmt) BindParameterIndex(name string) (int, error) { func (s *Stmt) BindParameterIndex(name string) (int, error) {
if s.params == nil { if s.params == nil {
...@@ -601,7 +602,7 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) { ...@@ -601,7 +602,7 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) {
defer C.free(unsafe.Pointer(cname)) defer C.free(unsafe.Pointer(cname))
index = int(C.sqlite3_bind_parameter_index(s.stmt, cname)) index = int(C.sqlite3_bind_parameter_index(s.stmt, cname))
if index == 0 { if index == 0 {
return -1, s.specificError("invalid parameter name: %s", name) return index, s.specificError("invalid parameter name: %s", name)
} }
s.params[name] = index s.params[name] = index
return index, nil return index, nil
...@@ -883,6 +884,7 @@ func (s *Stmt) SQL() string { ...@@ -883,6 +884,7 @@ func (s *Stmt) SQL() string {
} }
// Column index in a result set for a given column name // Column index in a result set for a given column name
// The leftmost column is number 0.
// Must scan all columns (but result is cached). // Must scan all columns (but result is cached).
// (See http://sqlite.org/c3ref/column_name.html) // (See http://sqlite.org/c3ref/column_name.html)
func (s *Stmt) ColumnIndex(name string) (int, error) { func (s *Stmt) ColumnIndex(name string) (int, error) {
...@@ -897,7 +899,7 @@ func (s *Stmt) ColumnIndex(name string) (int, error) { ...@@ -897,7 +899,7 @@ func (s *Stmt) ColumnIndex(name string) (int, error) {
if ok { if ok {
return index, nil return index, nil
} }
return 0, s.specificError("invalid column name: %s", name) return -1, s.specificError("invalid column name: %s", name)
} }
// Returns true when column is null and Stmt.CheckNull is activated. // Returns true when column is null and Stmt.CheckNull is activated.
...@@ -1206,9 +1208,9 @@ func (s *Stmt) checkTypeMismatch(source, target Type) error { ...@@ -1206,9 +1208,9 @@ func (s *Stmt) checkTypeMismatch(source, target Type) error {
// Determine if a prepared statement has been reset // Determine if a prepared statement has been reset
// (See http://sqlite.org/c3ref/stmt_busy.html) // (See http://sqlite.org/c3ref/stmt_busy.html)
/*func (s *Stmt) Busy() bool { func (s *Stmt) Busy() bool {
return C.sqlite3_stmt_busy(s.stmt) != 0 return C.sqlite3_stmt_busy(s.stmt) != 0
}*/ }
// Destroy a prepared statement // Destroy a prepared statement
// (See http://sqlite.org/c3ref/finalize.html) // (See http://sqlite.org/c3ref/finalize.html)
......
...@@ -129,6 +129,12 @@ func TestInsert(t *testing.T) { ...@@ -129,6 +129,12 @@ func TestInsert(t *testing.T) {
if i != 1000 { if i != 1000 {
t.Errorf("count should be 1000, but it is %d", i) t.Errorf("count should be 1000, but it is %d", i)
} }
if Must(cs.Next()) {
t.Fatal("Only one row expected")
}
if cs.Busy() {
t.Error("Statement not reset")
}
} }
func TestInsertWithStatement(t *testing.T) { func TestInsertWithStatement(t *testing.T) {
...@@ -166,6 +172,9 @@ func TestInsertWithStatement(t *testing.T) { ...@@ -166,6 +172,9 @@ func TestInsertWithStatement(t *testing.T) {
if c != 1 { if c != 1 {
t.Errorf("insert error: %d but got 1", c) t.Errorf("insert error: %d but got 1", c)
} }
if s.Busy() {
t.Errorf("Statement not reset")
}
} }
checkNoError(t, db.Commit(), "Error: %s") checkNoError(t, db.Commit(), "Error: %s")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment