func (s String) encodeSql(b encoding2.BinaryWriter) { if s.isUtf8 { writebyte(b, '\'') rawBytes := s.raw() for i, ch := range rawBytes { if encodedChar := SqlEncodeMap[ch]; encodedChar == DONTESCAPE { writebyte(b, ch) } else if i < len(rawBytes)-1 && '\\' == ch && ('%' == rawBytes[i+1] || '_' == rawBytes[i+1]) { // Don't escape '\' specifically in the constructions '\%' or // '\_', because those are special to how the RHS of LIKE // clauses are escaped. See the notes following table 9.1 in // http://dev.mysql.com/doc/refman/5.7/en/string-literals.html writebyte(b, ch) } else { writebyte(b, '\\') writebyte(b, encodedChar) } } writebyte(b, '\'') } else { b.Write([]byte("X'")) encoding2.HexEncodeToWriter(b, s.raw()) writebyte(b, '\'') } }
// EncodeSql encodes the value into an SQL statement. Can be binary. func (v Value) EncodeSql(b encoding2.BinaryWriter) { if v.Inner == nil { if _, err := b.Write(nullstr); err != nil { panic(err) } } else { v.Inner.encodeSql(b) } }
func (s String) encodeSql(b encoding2.BinaryWriter) { if s.isUtf8 { writebyte(b, '\'') for _, ch := range s.raw() { if encodedChar := SqlEncodeMap[ch]; encodedChar == DONTESCAPE { writebyte(b, ch) } else { writebyte(b, '\\') writebyte(b, encodedChar) } } writebyte(b, '\'') } else { b.Write([]byte("X'")) encoding2.HexEncodeToWriter(b, s.raw()) writebyte(b, '\'') } }
func (f Fractional) encodeAscii(b encoding2.BinaryWriter) { if _, err := b.Write(f.raw()); err != nil { panic(err) } }
func (n Numeric) encodeAscii(b encoding2.BinaryWriter) { if _, err := b.Write(n.raw()); err != nil { panic(err) } }