@@ -948,7 +948,7 @@ func (c *SQLiteConn) exec(ctx context.Context, query string, args []driver.Named
948948
949949 start := 0
950950 for {
951- s , err := c .prepareWithCache (ctx , query , true )
951+ s , err := c .prepareWithCache (ctx , query )
952952 if err != nil {
953953 return nil , err
954954 }
@@ -1013,7 +1013,7 @@ func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, erro
10131013func (c * SQLiteConn ) query (ctx context.Context , query string , args []driver.NamedValue ) (driver.Rows , error ) {
10141014 start := 0
10151015 for {
1016- s , err := c .prepareWithCache (ctx , query , true )
1016+ s , err := c .prepareWithCache (ctx , query )
10171017 if err != nil {
10181018 return nil , err
10191019 }
@@ -1969,16 +1969,6 @@ func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
19691969}
19701970
19711971func (c * SQLiteConn ) prepare (ctx context.Context , query string ) (driver.Stmt , error ) {
1972- return c .prepareWithCache (ctx , query , false )
1973- }
1974-
1975- func (c * SQLiteConn ) prepareWithCache (ctx context.Context , query string , useCache bool ) (driver.Stmt , error ) {
1976- if useCache {
1977- if stmt := c .takeCachedStmt (query ); stmt != nil {
1978- return stmt , nil
1979- }
1980- }
1981-
19821972 pquery := C .CString (query )
19831973 defer C .free (unsafe .Pointer (pquery ))
19841974 var s * C.sqlite3_stmt
@@ -1992,10 +1982,22 @@ func (c *SQLiteConn) prepareWithCache(ctx context.Context, query string, useCach
19921982 t = strings .TrimSpace (C .GoString (tail ))
19931983 }
19941984 ss := & SQLiteStmt {c : c , s : s , t : t }
1995- if useCache && t == "" {
1985+ runtime .SetFinalizer (ss , (* SQLiteStmt ).Close )
1986+ return ss , nil
1987+ }
1988+
1989+ func (c * SQLiteConn ) prepareWithCache (ctx context.Context , query string ) (driver.Stmt , error ) {
1990+ if stmt := c .takeCachedStmt (query ); stmt != nil {
1991+ return stmt , nil
1992+ }
1993+ stmt , err := c .prepare (ctx , query )
1994+ if err != nil {
1995+ return nil , err
1996+ }
1997+ ss := stmt .(* SQLiteStmt )
1998+ if ss .t == "" {
19961999 ss .cacheKey = query
19972000 }
1998- runtime .SetFinalizer (ss , (* SQLiteStmt ).Close )
19992001 return ss , nil
20002002}
20012003
0 commit comments