tx_lock mode set regardless of read or write tx?
Hi! From my understanding, BEGIN IMMEDIATE/EXCLUSIVE should only ever be set for write transactions and BEGIN DEFERRED should always be used for read only transactions. But from the code, it looks like if a connection sets the tx_lock=immedate
option then BEGIN IMMEDIATE is always set regardless of if the caller has marked a transaction as ReadOnly (using driver.TxOptions). Should there maybe be a switch on ReadOnly
here?
Something like this:
diff --git a/sqlite.go b/sqlite.go
index 1d2a6ea..ade5647 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -657,14 +657,14 @@ type tx struct {
c *conn
}
-func newTx(c *conn) (*tx, error) {
+func newTx(c *conn, opts driver.TxOptions) (*tx, error) {
r := &tx{c: c}
- var sql string
- if c.beginMode != "" {
+
+ sql := "begin"
+ if !opts.ReadOnly && c.beginMode != "" {
sql = "begin " + c.beginMode
- } else {
- sql = "begin"
}
+
if err := r.exec(context.Background(), sql); err != nil {
return nil, err
}
@@ -1325,7 +1325,7 @@ func (c *conn) Begin() (driver.Tx, error) {
}
func (c *conn) begin(ctx context.Context, opts driver.TxOptions) (t driver.Tx, err error) {
- return newTx(c)
+ return newTx(c, opts)
}
// Close invalidates and potentially stops any current prepared statements and