File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ import (
113
113
"runtime"
114
114
"strconv"
115
115
"strings"
116
+ "sync"
116
117
"time"
117
118
"unsafe"
118
119
@@ -157,6 +158,7 @@ type SQLiteDriver struct {
157
158
158
159
// SQLiteConn implement sql.Conn.
159
160
type SQLiteConn struct {
161
+ dbMu sync.Mutex
160
162
db * C.sqlite3
161
163
loc * time.Location
162
164
txlock string
@@ -679,11 +681,22 @@ func (c *SQLiteConn) Close() error {
679
681
return c .lastError ()
680
682
}
681
683
deleteHandles (c )
684
+ c .dbMu .Lock ()
682
685
c .db = nil
686
+ c .dbMu .Unlock ()
683
687
runtime .SetFinalizer (c , nil )
684
688
return nil
685
689
}
686
690
691
+ func (c * SQLiteConn ) dbConnOpen () bool {
692
+ if c == nil {
693
+ return false
694
+ }
695
+ c .dbMu .Lock ()
696
+ defer c .dbMu .Unlock ()
697
+ return c .db != nil
698
+ }
699
+
687
700
// Prepare the query string. Return a new statement.
688
701
func (c * SQLiteConn ) Prepare (query string ) (driver.Stmt , error ) {
689
702
return c .prepare (context .Background (), query )
@@ -713,7 +726,7 @@ func (s *SQLiteStmt) Close() error {
713
726
return nil
714
727
}
715
728
s .closed = true
716
- if s .c == nil || s . c . db == nil {
729
+ if ! s .c . dbConnOpen () {
717
730
return errors .New ("sqlite statement with already closed database connection" )
718
731
}
719
732
rv := C .sqlite3_finalize (s .s )
You can’t perform that action at this time.
0 commit comments