@@ -40,8 +40,6 @@ type Conn struct {
4040 busylst time.Time
4141 arena arena
4242 handle ptr_t
43- pending ptr_t
44- stepped bool
4543 gosched uint8
4644}
4745
@@ -167,9 +165,6 @@ func (c *Conn) Close() error {
167165 return nil
168166 }
169167
170- c .call ("sqlite3_finalize" , stk_t (c .pending ))
171- c .pending = 0
172-
173168 rc := res_t (c .call ("sqlite3_close" , stk_t (c .handle )))
174169 if err := c .error (rc ); err != nil {
175170 return err
@@ -184,10 +179,15 @@ func (c *Conn) Close() error {
184179//
185180// https://sqlite.org/c3ref/exec.html
186181func (c * Conn ) Exec (sql string ) error {
182+ if c .interrupt .Err () != nil {
183+ return INTERRUPT
184+ }
185+ return c .exec (sql )
186+ }
187+
188+ func (c * Conn ) exec (sql string ) error {
187189 defer c .arena .mark ()()
188190 textPtr := c .arena .string (sql )
189-
190- c .checkInterrupt ()
191191 rc := res_t (c .call ("sqlite3_exec" , stk_t (c .handle ), stk_t (textPtr ), 0 , 0 , 0 ))
192192 return c .error (rc , sql )
193193}
@@ -207,13 +207,15 @@ func (c *Conn) PrepareFlags(sql string, flags PrepareFlag) (stmt *Stmt, tail str
207207 if len (sql ) > _MAX_SQL_LENGTH {
208208 return nil , "" , TOOBIG
209209 }
210+ if c .interrupt .Err () != nil {
211+ return nil , "" , INTERRUPT
212+ }
210213
211214 defer c .arena .mark ()()
212215 stmtPtr := c .arena .new (ptrlen )
213216 tailPtr := c .arena .new (ptrlen )
214217 textPtr := c .arena .string (sql )
215218
216- c .checkInterrupt ()
217219 rc := res_t (c .call ("sqlite3_prepare_v3" , stk_t (c .handle ),
218220 stk_t (textPtr ), stk_t (len (sql )+ 1 ), stk_t (flags ),
219221 stk_t (stmtPtr ), stk_t (tailPtr )))
@@ -343,42 +345,9 @@ func (c *Conn) GetInterrupt() context.Context {
343345func (c * Conn ) SetInterrupt (ctx context.Context ) (old context.Context ) {
344346 old = c .interrupt
345347 c .interrupt = ctx
346-
347- if ctx == old {
348- return old
349- }
350-
351- // An active SQL statement prevents SQLite from ignoring an interrupt
352- // that comes before any other statements are started.
353- if c .pending == 0 {
354- defer c .arena .mark ()()
355- stmtPtr := c .arena .new (ptrlen )
356- textPtr := c .arena .string (`SELECT 0 UNION ALL SELECT 0` )
357- c .call ("sqlite3_prepare_v3" , stk_t (c .handle ), stk_t (textPtr ), math .MaxUint64 ,
358- stk_t (PREPARE_PERSISTENT ), stk_t (stmtPtr ), 0 )
359- c .pending = util .Read32 [ptr_t ](c .mod , stmtPtr )
360- }
361-
362- if c .stepped && ctx .Err () == nil {
363- c .call ("sqlite3_reset" , stk_t (c .pending ))
364- c .stepped = false
365- } else {
366- c .checkInterrupt ()
367- }
368348 return old
369349}
370350
371- func (c * Conn ) checkInterrupt () {
372- if c .interrupt .Err () == nil {
373- return
374- }
375- if ! c .stepped {
376- c .call ("sqlite3_step" , stk_t (c .pending ))
377- c .stepped = true
378- }
379- c .call ("sqlite3_interrupt" , stk_t (c .handle ))
380- }
381-
382351func progressCallback (ctx context.Context , mod api.Module , _ ptr_t ) (interrupt int32 ) {
383352 if c , ok := ctx .Value (connKey {}).(* Conn ); ok {
384353 if c .gosched ++ ; c .gosched % 16 == 0 {
0 commit comments