MCPcopy
hub / github.com/go-sql-driver/mysql / TestInsertRetrieveEscapedData

Function TestInsertRetrieveEscapedData

driver_test.go:2132–2158  ·  view source on GitHub ↗

Test if inserted data is correctly retrieved after being escaped

(t *testing.T)

Source from the content-addressed store, hash-verified

2130
2131// Test if inserted data is correctly retrieved after being escaped
2132func 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
2160func TestUnixSocketAuthFail(t *testing.T) {
2161 runTests(t, dsn, func(dbt *DBTest) {

Callers

nothing calls this directly

Calls 4

runTestsFunction · 0.85
mustExecMethod · 0.80
ScanMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected