Skip to content

Commit b437c9d

Browse files
committed
check error number.
1 parent 371a560 commit b437c9d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

connection_go18.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +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 {
81+
if err, ok := err.(*MySQLError); ok && err.Number == 1064 {
82+
// Error 1064 ER_PARSE_ERROR
83+
// It seems that your MySQL does not support READ ONLY transactions.
8284
return nil, ErrReadOnlyTxNotSupported
8385
}
8486
return nil, err

driver_go18_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ func TestContextBeginReadOnly(t *testing.T) {
487487

488488
// INSERT queries fail in a READ ONLY transaction.
489489
_, err = tx.ExecContext(ctx, "INSERT INTO test VALUES (1)")
490-
if _, ok := err.(*MySQLError); !ok {
490+
// Error 1792 ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
491+
// https://dev.mysql.com/doc/refman/5.6/en/innodb-performance-ro-txn.html
492+
if err, ok := err.(*MySQLError); !ok || err.Number != 1792 {
491493
dbt.Errorf("expected MySQLError, got %v", err)
492494
}
493495

0 commit comments

Comments
 (0)