Commit eb98c92c authored by gwenn's avatar gwenn
parent e8065407
...@@ -374,6 +374,24 @@ func TestOpenSameMemoryDb(t *testing.T) { ...@@ -374,6 +374,24 @@ func TestOpenSameMemoryDb(t *testing.T) {
checkNoError(t, err, "exists error: %s") checkNoError(t, err, "exists error: %s")
} }
func TestStmtWithClosedDb(t *testing.T) {
db := open(t)
defer db.Close()
db.SetCacheSize(0)
s, err := db.Prepare("select 1")
checkNoError(t, err, "prepare error: %s")
defer s.Finalize()
err = db.Close()
checkNoError(t, err, "close error: %s")
err = s.Finalize()
assert(t, "error expected", err != nil)
//println(err.Error())
}
func assertEquals(t *testing.T, format string, expected, actual interface{}) { func assertEquals(t *testing.T, format string, expected, actual interface{}) {
if expected != actual { if expected != actual {
t.Errorf(format, expected, actual) t.Errorf(format, expected, actual)
......
...@@ -910,7 +910,7 @@ func (s *Stmt) Finalize() error { ...@@ -910,7 +910,7 @@ func (s *Stmt) Finalize() error {
if s == nil { if s == nil {
return errors.New("nil sqlite statement") return errors.New("nil sqlite statement")
} }
if s.Cacheable { if s.Cacheable && s.c != nil && s.c.db != nil {
return s.c.stmtCache.release(s) return s.c.stmtCache.release(s)
} }
return s.finalize() return s.finalize()
...@@ -919,6 +919,9 @@ func (s *Stmt) finalize() error { ...@@ -919,6 +919,9 @@ func (s *Stmt) finalize() error {
if s == nil { if s == nil {
return errors.New("nil sqlite statement") return errors.New("nil sqlite statement")
} }
if s.stmt == nil {
return nil
}
if s.c == nil || s.c.db == nil { if s.c == nil || s.c.db == nil {
return errors.New("sqlite statement with already closed database connection") return errors.New("sqlite statement with already closed database connection")
} }
......
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