@@ -42,14 +42,14 @@ type RowData []interface{}
4242// https://github.com/Shopify/ghostferry/issues/165.
4343//
4444// In summary:
45- // - This code receives values from both go-sql-driver/mysql and
46- // go-mysql-org/go-mysql.
47- // - go-sql-driver/mysql gives us int64 for signed integer, and uint64 in a byte
48- // slice for unsigned integer.
49- // - go-mysql-org/go-mysql gives us int64 for signed integer, and uint64 for
50- // unsigned integer.
51- // - We currently make this function deal with both cases. In the future we can
52- // investigate alternative solutions.
45+ // - This code receives values from both go-sql-driver/mysql and
46+ // go-mysql-org/go-mysql.
47+ // - go-sql-driver/mysql gives us int64 for signed integer, and uint64 in a byte
48+ // slice for unsigned integer.
49+ // - go-mysql-org/go-mysql gives us int64 for signed integer, and uint64 for
50+ // unsigned integer.
51+ // - We currently make this function deal with both cases. In the future we can
52+ // investigate alternative solutions.
5353func (r RowData ) GetUint64 (colIdx int ) (uint64 , error ) {
5454 u64 , ok := Uint64Value (r [colIdx ])
5555 if ok {
@@ -174,8 +174,8 @@ func (e *BinlogInsertEvent) AsSQLString(schemaName, tableName string) (string, e
174174
175175 query := "INSERT IGNORE INTO " +
176176 QuotedTableNameFromString (schemaName , tableName ) +
177- " (" + strings .Join (quotedColumnNamesForInsert (e .table ), "," ) + ")" +
178- " VALUES (" + buildStringListForInsertValues (e .table , e .newValues ) + ")"
177+ " (" + strings .Join (quotedColumnNames (e .table ), "," ) + ")" +
178+ " VALUES (" + buildStringListForValues (e .table . Columns , e .newValues ) + ")"
179179
180180 return query , nil
181181}
@@ -323,14 +323,10 @@ func NewBinlogDMLEvents(table *TableSchema, ev *replication.BinlogEvent, pos, re
323323 }
324324}
325325
326- func quotedColumnNamesForInsert (table * TableSchema ) []string {
327- cols := []string {}
328-
329- for _ , c := range table .Columns {
330- if c .IsVirtual {
331- continue
332- }
333- cols = append (cols , QuoteField (c .Name ))
326+ func quotedColumnNames (table * TableSchema ) []string {
327+ cols := make ([]string , len (table .Columns ))
328+ for i , column := range table .Columns {
329+ cols [i ] = QuoteField (column .Name )
334330 }
335331
336332 return cols
@@ -351,18 +347,15 @@ func verifyValuesHasTheSameLengthAsColumns(table *TableSchema, values ...RowData
351347 return nil
352348}
353349
354- func buildStringListForInsertValues ( table * TableSchema , values []interface {}) string {
350+ func buildStringListForValues ( columns []schema. TableColumn , values []interface {}) string {
355351 var buffer []byte
356352
357353 for i , value := range values {
358- if table .Columns [i ].IsVirtual {
359- continue
360- }
361-
362- if len (buffer ) != 0 {
354+ if i > 0 {
363355 buffer = append (buffer , ',' )
364356 }
365- buffer = appendEscapedValue (buffer , value , table .Columns [i ])
357+
358+ buffer = appendEscapedValue (buffer , value , columns [i ])
366359 }
367360
368361 return string (buffer )
@@ -511,10 +504,10 @@ func Int64Value(value interface{}) (int64, bool) {
511504//
512505// This is specifically mentioned in the the below link:
513506//
514- // When BINARY values are stored, they are right-padded with the pad value
515- // to the specified length. The pad value is 0x00 (the zero byte). Values
516- // are right-padded with 0x00 for inserts, and no trailing bytes are removed
517- // for retrievals.
507+ // When BINARY values are stored, they are right-padded with the pad value
508+ // to the specified length. The pad value is 0x00 (the zero byte). Values
509+ // are right-padded with 0x00 for inserts, and no trailing bytes are removed
510+ // for retrievals.
518511//
519512// ref: https://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html
520513func appendEscapedString (buffer []byte , value string , rightPadToLengthWithZeroBytes int ) []byte {
0 commit comments