Skip to content

Commit 371a560

Browse files
committed
add ErrReadOnlyTxNotSupported error
1 parent 316c7f3 commit 371a560

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

connection_go18.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ func (mc *mysqlConn) beginReadOnly() (driver.Tx, error) {
7878
}
7979
err := mc.exec("START TRANSACTION READ ONLY")
8080
if err != nil {
81+
if _, ok := err.(*MySQLError); ok {
82+
return nil, ErrReadOnlyTxNotSupported
83+
}
8184
return nil, err
8285
}
8386

driver_go18_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func TestContextBeginReadOnly(t *testing.T) {
478478
tx, err := dbt.db.BeginTx(ctx, &sql.TxOptions{
479479
ReadOnly: true,
480480
})
481-
if _, ok := err.(*MySQLError); ok {
481+
if err == ErrReadOnlyTxNotSupported {
482482
dbt.Skip("It seems that your MySQL does not support READ ONLY transactions")
483483
return
484484
} else if err != nil {

errors.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ import (
1919

2020
// Various errors the driver might return. Can change between driver versions.
2121
var (
22-
ErrInvalidConn = errors.New("invalid connection")
23-
ErrMalformPkt = errors.New("malformed packet")
24-
ErrNoTLS = errors.New("TLS requested but server does not support TLS")
25-
ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN")
26-
ErrNativePassword = errors.New("this user requires mysql native password authentication.")
27-
ErrOldPassword = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
28-
ErrUnknownPlugin = errors.New("this authentication plugin is not supported")
29-
ErrOldProtocol = errors.New("MySQL server does not support required protocol 41+")
30-
ErrPktSync = errors.New("commands out of sync. You can't run this command now")
31-
ErrPktSyncMul = errors.New("commands out of sync. Did you run multiple statements at once?")
32-
ErrPktTooLarge = errors.New("packet for query is too large. Try adjusting the 'max_allowed_packet' variable on the server")
33-
ErrBusyBuffer = errors.New("busy buffer")
22+
ErrInvalidConn = errors.New("invalid connection")
23+
ErrMalformPkt = errors.New("malformed packet")
24+
ErrNoTLS = errors.New("TLS requested but server does not support TLS")
25+
ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN")
26+
ErrNativePassword = errors.New("this user requires mysql native password authentication.")
27+
ErrOldPassword = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
28+
ErrUnknownPlugin = errors.New("this authentication plugin is not supported")
29+
ErrOldProtocol = errors.New("MySQL server does not support required protocol 41+")
30+
ErrPktSync = errors.New("commands out of sync. You can't run this command now")
31+
ErrPktSyncMul = errors.New("commands out of sync. Did you run multiple statements at once?")
32+
ErrPktTooLarge = errors.New("packet for query is too large. Try adjusting the 'max_allowed_packet' variable on the server")
33+
ErrBusyBuffer = errors.New("busy buffer")
34+
ErrReadOnlyTxNotSupported = errors.New("read-only transactions not supported")
3435
)
3536

3637
var errLog = Logger(log.New(os.Stderr, "[mysql] ", log.Ldate|log.Ltime|log.Lshortfile))

0 commit comments

Comments
 (0)