mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
fix: factually correct escpaing in sqlite
This commit is contained in:
+49
-17
@@ -785,36 +785,68 @@ func quoteStringValue(buf []byte, s string, flavor Flavor) []byte {
|
||||
for ; sz != 0; r, sz = utf8.DecodeRuneInString(s) {
|
||||
switch r {
|
||||
case '\x00':
|
||||
buf = append(buf, "\\0"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't support \0
|
||||
buf = append(buf, `'||char(0)||'`...)
|
||||
default:
|
||||
buf = append(buf, `\0`...)
|
||||
}
|
||||
case '\b':
|
||||
buf = append(buf, "\\b"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
|
||||
buf = append(buf, '\b')
|
||||
default:
|
||||
buf = append(buf, `\b`...)
|
||||
}
|
||||
case '\n':
|
||||
buf = append(buf, "\\n"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
|
||||
buf = append(buf, '\n')
|
||||
default:
|
||||
buf = append(buf, `\n`...)
|
||||
}
|
||||
case '\r':
|
||||
buf = append(buf, "\\r"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
|
||||
buf = append(buf, '\r')
|
||||
default:
|
||||
buf = append(buf, `\r`...)
|
||||
}
|
||||
case '\t':
|
||||
buf = append(buf, "\\t"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
|
||||
buf = append(buf, '\t')
|
||||
default:
|
||||
buf = append(buf, `\t`...)
|
||||
}
|
||||
case '\x1a':
|
||||
buf = append(buf, "\\Z"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
|
||||
buf = append(buf, '\x1a')
|
||||
default:
|
||||
buf = append(buf, `\Z`...)
|
||||
}
|
||||
case '\'':
|
||||
switch flavor {
|
||||
case SQLite, CQL:
|
||||
buf = append(buf, "''"...)
|
||||
default:
|
||||
buf = append(buf, "\\'"...)
|
||||
buf = append(buf, `\'`...)
|
||||
}
|
||||
case '"':
|
||||
buf = append(buf, "\\\""...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite Supports direct use of " inside strings
|
||||
buf = append(buf, '"')
|
||||
default:
|
||||
buf = append(buf, `\"`...)
|
||||
}
|
||||
case '\\':
|
||||
buf = append(buf, "\\\\"...)
|
||||
|
||||
switch flavor {
|
||||
case SQLite: // SQLite doesn't have any special meaning for back slashes "\"
|
||||
buf = append(buf, '\\')
|
||||
default:
|
||||
buf = append(buf, `\\`...)
|
||||
}
|
||||
default:
|
||||
buf = append(buf, s[:sz]...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user