@@ -102,6 +102,7 @@ type SQLiteStmt struct {
102
102
s * C.sqlite3_stmt
103
103
t string
104
104
closed bool
105
+ cls bool
105
106
}
106
107
107
108
// Result struct.
@@ -116,6 +117,7 @@ type SQLiteRows struct {
116
117
nc int
117
118
cols []string
118
119
decltype []string
120
+ cls bool
119
121
}
120
122
121
123
// Commit transaction.
@@ -165,10 +167,10 @@ func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, err
165
167
args = args [na :]
166
168
}
167
169
tail := s .(* SQLiteStmt ).t
170
+ s .Close ()
168
171
if tail == "" {
169
172
return res , nil
170
173
}
171
- s .Close ()
172
174
query = tail
173
175
}
174
176
}
@@ -180,6 +182,7 @@ func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, erro
180
182
if err != nil {
181
183
return nil , err
182
184
}
185
+ s .(* SQLiteStmt ).cls = true
183
186
na := s .NumInput ()
184
187
rows , err := s .Query (args [:na ])
185
188
if err != nil && err != driver .ErrSkip {
@@ -389,7 +392,7 @@ func (s *SQLiteStmt) Query(args []driver.Value) (driver.Rows, error) {
389
392
if err := s .bind (args ); err != nil {
390
393
return nil , err
391
394
}
392
- return & SQLiteRows {s , int (C .sqlite3_column_count (s .s )), nil , nil }, nil
395
+ return & SQLiteRows {s , int (C .sqlite3_column_count (s .s )), nil , nil , s . cls }, nil
393
396
}
394
397
395
398
// Return last inserted ID.
@@ -424,6 +427,9 @@ func (rc *SQLiteRows) Close() error {
424
427
if rc .s .closed {
425
428
return nil
426
429
}
430
+ if rc .cls {
431
+ return rc .s .Close ()
432
+ }
427
433
rv := C .sqlite3_reset (rc .s .s )
428
434
if rv != C .SQLITE_OK {
429
435
return rc .s .c .lastError ()
0 commit comments