(b encoding2.BinaryWriter)
| 505 | } |
| 506 | |
| 507 | func (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 | |
| 533 | func (s String) encodeAscii(b encoding2.BinaryWriter) { |
| 534 | writebyte(b, '\'') |
nothing calls this directly
no test coverage detected