Test if inserted data is correctly retrieved after being escaped
(t *testing.T)
| 2130 | |
| 2131 | // Test if inserted data is correctly retrieved after being escaped |
| 2132 | func TestInsertRetrieveEscapedData(t *testing.T) { |
| 2133 | testData := func(dbt *DBTest) { |
| 2134 | dbt.mustExec("CREATE TABLE test (v VARCHAR(255))") |
| 2135 | |
| 2136 | // All sequences that are escaped by escapeQuotes and escapeBackslash |
| 2137 | v := "foo \x00\n\r\x1a\"'\\" |
| 2138 | dbt.mustExec("INSERT INTO test VALUES (?)", v) |
| 2139 | |
| 2140 | var out string |
| 2141 | err := dbt.db.QueryRow("SELECT v FROM test").Scan(&out) |
| 2142 | if err != nil { |
| 2143 | dbt.Fatalf("%s", err.Error()) |
| 2144 | } |
| 2145 | |
| 2146 | if out != v { |
| 2147 | dbt.Errorf("%q != %q", out, v) |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | dsns := []string{ |
| 2152 | dsn, |
| 2153 | dsn + "&sql_mode='NO_BACKSLASH_ESCAPES'", |
| 2154 | } |
| 2155 | for _, testdsn := range dsns { |
| 2156 | runTests(t, testdsn, testData) |
| 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | func TestUnixSocketAuthFail(t *testing.T) { |
| 2161 | runTests(t, dsn, func(dbt *DBTest) { |