Skip to content

Commit

Permalink
end to end test for reserved connection in autocommit mode
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Sep 21, 2020
1 parent 2ae1bc0 commit 7b075b6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions go/test/endtoend/vtgate/setstatement/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,36 @@ func TestSetSystemVariableAndThenSuccessfulTx(t *testing.T) {
assertMatches(t, conn, "select @@sql_safe_updates", "[[INT64(1)]]")
}

func TestSetSystemVariableAndThenSuccessfulAutocommitDML(t *testing.T) {
vtParams := mysql.ConnParams{
Host: "localhost",
Port: clusterInstance.VtgateMySQLPort,
}

conn, err := mysql.Connect(context.Background(), &vtParams)
require.NoError(t, err)
defer conn.Close()
checkedExec(t, conn, `delete from test`)

checkedExec(t, conn, `set sql_safe_updates = 1`)

checkedExec(t, conn, `insert into test (id, val1) values (80, null)`)
assertMatches(t, conn, `select id, val1 from test`, `[[INT64(80) NULL]]`)
assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`)

checkedExec(t, conn, `update test set val2 = 2 where val1 is null`)
assertMatches(t, conn, `select id, val1, val2 from test`, `[[INT64(80) NULL INT64(2)]]`)
assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`)

checkedExec(t, conn, `update test set val1 = 'text' where val1 is null`)
assertMatches(t, conn, `select id, val1, val2 from test`, `[[INT64(80) VARCHAR("text") INT64(2)]]`)
assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`)

checkedExec(t, conn, `delete from test where val1 = 'text'`)
assertMatches(t, conn, `select id, val1, val2 from test`, `[]`)
assertMatches(t, conn, `select @@sql_safe_updates`, `[[INT64(1)]]`)
}

func TestStartTxAndSetSystemVariableAndThenSuccessfulCommit(t *testing.T) {
vtParams := mysql.ConnParams{
Host: "localhost",
Expand Down

0 comments on commit 7b075b6

Please sign in to comment.