This commit is contained in:
Nuno Cruces
2025-11-19 11:27:42 +00:00
parent 9bbbab77f6
commit ce0da893b4

View File

@@ -263,10 +263,8 @@ func (n *connector) Connect(ctx context.Context) (ret driver.Conn, err error) {
return nil, err return nil, err
} }
defer s.Close() defer s.Close()
if s.Step() && s.ColumnBool(0) { if s.Step() {
c.readOnly = '1' c.readOnly = s.ColumnBool(0)
} else {
c.readOnly = '0'
} }
err = s.Close() err = s.Close()
if err != nil { if err != nil {
@@ -322,7 +320,7 @@ type conn struct {
txReset string txReset string
tmRead sqlite3.TimeFormat tmRead sqlite3.TimeFormat
tmWrite sqlite3.TimeFormat tmWrite sqlite3.TimeFormat
readOnly byte readOnly bool
} }
var ( var (
@@ -358,9 +356,9 @@ func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e
c.txReset = `` c.txReset = ``
txBegin := `BEGIN ` + txLock txBegin := `BEGIN ` + txLock
if opts.ReadOnly { if opts.ReadOnly && !c.readOnly {
txBegin += ` ; PRAGMA query_only=on` txBegin += ` ; PRAGMA query_only=on`
c.txReset = `; PRAGMA query_only=` + string(c.readOnly) c.txReset = `; PRAGMA query_only=off`
} }
if old := c.Conn.SetInterrupt(ctx); old != ctx { if old := c.Conn.SetInterrupt(ctx); old != ctx {