Skip to content

Commit 5d9b653

Browse files
committed
More.
1 parent 7a209df commit 5d9b653

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

conn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ func (c *Conn) Exec(sql string) error {
182182
if c.interrupt.Err() != nil {
183183
return INTERRUPT
184184
}
185+
return c.exec(sql)
186+
}
187+
188+
func (c *Conn) exec(sql string) error {
185189
defer c.arena.mark()()
186190
textPtr := c.arena.string(sql)
187191
rc := res_t(c.call("sqlite3_exec", stk_t(c.handle), stk_t(textPtr), 0, 0, 0))

txn.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sqlite3
22

33
import (
44
"context"
5-
"errors"
65
"math/rand"
76
"runtime"
87
"strconv"
@@ -25,7 +24,7 @@ type Txn struct {
2524
// https://sqlite.org/lang_transaction.html
2625
func (c *Conn) Begin() Txn {
2726
// BEGIN even if interrupted.
28-
err := c.txnExecInterrupted(`BEGIN DEFERRED`)
27+
err := c.exec(`BEGIN DEFERRED`)
2928
if err != nil {
3029
panic(err)
3130
}
@@ -120,7 +119,7 @@ func (tx Txn) Commit() error {
120119
//
121120
// https://sqlite.org/lang_transaction.html
122121
func (tx Txn) Rollback() error {
123-
return tx.c.txnExecInterrupted(`ROLLBACK`)
122+
return tx.c.exec(`ROLLBACK`)
124123
}
125124

126125
// Savepoint is a marker within a transaction
@@ -143,7 +142,7 @@ func (c *Conn) Savepoint() Savepoint {
143142
// Names can be reused, but this makes catching bugs more likely.
144143
name = QuoteIdentifier(name + "_" + strconv.Itoa(int(rand.Int31())))
145144

146-
err := c.txnExecInterrupted(`SAVEPOINT ` + name)
145+
err := c.exec(`SAVEPOINT ` + name)
147146
if err != nil {
148147
panic(err)
149148
}
@@ -199,7 +198,7 @@ func (s Savepoint) Release(errp *error) {
199198
return
200199
}
201200
// ROLLBACK and RELEASE even if interrupted.
202-
err := s.c.txnExecInterrupted(`ROLLBACK TO ` + s.name + `; RELEASE ` + s.name)
201+
err := s.c.exec(`ROLLBACK TO ` + s.name + `; RELEASE ` + s.name)
203202
if err != nil {
204203
panic(err)
205204
}
@@ -212,17 +211,7 @@ func (s Savepoint) Release(errp *error) {
212211
// https://sqlite.org/lang_transaction.html
213212
func (s Savepoint) Rollback() error {
214213
// ROLLBACK even if interrupted.
215-
return s.c.txnExecInterrupted(`ROLLBACK TO ` + s.name)
216-
}
217-
218-
func (c *Conn) txnExecInterrupted(sql string) error {
219-
err := c.Exec(sql)
220-
if errors.Is(err, INTERRUPT) {
221-
old := c.SetInterrupt(context.Background())
222-
defer c.SetInterrupt(old)
223-
err = c.Exec(sql)
224-
}
225-
return err
214+
return s.c.exec(`ROLLBACK TO ` + s.name)
226215
}
227216

228217
// TxnState determines the transaction state of a database.

0 commit comments

Comments
 (0)