Commit 62d699a6 authored by gwenn's avatar gwenn

Fix dangling statements.

parent fa0708e4
......@@ -5,6 +5,7 @@ Yet another SQLite binding based on:
Open supports flags.
Conn#Exec handles multiple statements (separated by semicolons) properly.
Conn#Prepare can optionnaly #Bind as well.
Conn#Close ensures that all dangling statements are finalized.
Stmt#Exec is renamed in Stmt#Bind and a new Stmt#Exec method is introduced to #Bind and #Step.
Stmt#Bind uses native sqlite3_bind_x methods and failed if unsupported type.
Stmt#Next returns a (bool, os.Error) couple like Reader#Read.
......
......@@ -28,6 +28,7 @@ func (c *Conn) Tables() ([]string, os.Error) {
if err != nil {
return nil, err
}
defer s.Finalize()
var tables []string = make([]string, 0, 20)
var ok bool
var name string
......@@ -57,6 +58,7 @@ func (c *Conn) Columns(table string) ([]Column, os.Error) {
if err != nil {
return nil, err
}
defer s.Finalize()
var columns []Column = make([]Column, 0, 20)
var ok bool
for ok, err = s.Next(); ok; ok, err = s.Next() {
......@@ -86,6 +88,7 @@ func (c *Conn) ForeignKeys(table string) (map[int]*ForeignKey, os.Error) {
if err != nil {
return nil, err
}
defer s.Finalize()
var fks = make(map[int]*ForeignKey)
var ok bool
var id, seq int
......
......@@ -263,6 +263,7 @@ func (c *Conn) Exists(query string, args ...interface{}) (bool, os.Error) {
if err != nil {
return false, err
}
defer s.Finalize()
return s.Next()
}
......@@ -702,7 +703,14 @@ func (c *Conn) Close() os.Error {
if c == nil {
return os.NewError("nil sqlite database")
}
// TODO sqlite3_next_stmt & dangling statements?
// Dangling statements
stmt := C.sqlite3_next_stmt(c.db, nil)
for stmt != nil {
//Log(1, "Dangling statement")
C.sqlite3_finalize(stmt)
stmt = C.sqlite3_next_stmt(c.db, stmt)
}
rv := C.sqlite3_close(c.db)
if rv != C.SQLITE_OK {
return c.error(rv)
......
......@@ -200,7 +200,7 @@ func TestInsertWithStatement(t *testing.T) {
t.Errorf("insert error: %d <> 1", c)
}
}
s.Finalize()
if err := db.Commit(); err != nil {
t.Fatalf("Error: %s", err)
}
......@@ -220,6 +220,7 @@ func TestInsertWithStatement(t *testing.T) {
}
rs, _ := db.Prepare("SELECT float_num, int_num, a_string FROM test where a_string like ? ORDER BY int_num LIMIT 2", "hel%")
defer rs.Finalize()
columnCount := rs.ColumnCount()
if columnCount != 3 {
t.Errorf("column count error: %d <> 3", columnCount)
......
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