MCPcopy
hub / github.com/dropbox/godropbox / encodeSql

Method encodeSql

database/sqltypes/sqltypes.go:507–531  ·  view source on GitHub ↗
(b encoding2.BinaryWriter)

Source from the content-addressed store, hash-verified

505}
506
507func (s String) encodeSql(b encoding2.BinaryWriter) {
508 if s.isUtf8 {
509 writebyte(b, '\'')
510 rawBytes := s.raw()
511 for i, ch := range rawBytes {
512 if encodedChar := SqlEncodeMap[ch]; encodedChar == DONTESCAPE {
513 writebyte(b, ch)
514 } else if i < len(rawBytes)-1 && '\\' == ch && ('%' == rawBytes[i+1] || '_' == rawBytes[i+1]) {
515 // Don't escape '\' specifically in the constructions '\%' or
516 // '\_', because those are special to how the RHS of LIKE
517 // clauses are escaped. See the notes following table 9.1 in
518 // http://dev.mysql.com/doc/refman/5.7/en/string-literals.html
519 writebyte(b, ch)
520 } else {
521 writebyte(b, '\\')
522 writebyte(b, encodedChar)
523 }
524 }
525 writebyte(b, '\'')
526 } else {
527 b.Write([]byte("X'"))
528 encoding2.HexEncodeToWriter(b, s.raw())
529 writebyte(b, '\'')
530 }
531}
532
533func (s String) encodeAscii(b encoding2.BinaryWriter) {
534 writebyte(b, '\'')

Callers

nothing calls this directly

Calls 4

rawMethod · 0.95
HexEncodeToWriterFunction · 0.92
writebyteFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected