Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,27 +436,29 @@ func isSafeIdentifier(s string) bool {

func (c *Canal) GenerateCharsetQuery() (string, error) {
query := `
SELECT
c.ORDINAL_POSITION,
CASE
WHEN c.CHARACTER_SET_NAME IS NOT NULL THEN c.CHARACTER_SET_NAME
WHEN c.DATA_TYPE IN ('binary','varbinary','tinyblob','blob','mediumblob','longblob') THEN col.CHARACTER_SET_NAME
END AS CHARACTER_SET_NAME,
c.COLUMN_NAME
FROM
information_schema.COLUMNS c
LEFT JOIN information_schema.TABLES t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
LEFT JOIN information_schema.COLLATIONS col
ON col.COLLATION_NAME = t.TABLE_COLLATION
WHERE
c.TABLE_SCHEMA = ?
AND c.TABLE_NAME = ?
AND (c.CHARACTER_SET_NAME IS NOT NULL OR c.DATA_TYPE IN ('binary','varbinary','tinyblob','blob','mediumblob','longblob'));
`
SELECT
c.ORDINAL_POSITION,
CASE
WHEN c.CHARACTER_SET_NAME IS NOT NULL THEN c.CHARACTER_SET_NAME
WHEN c.DATA_TYPE IN ('binary','varbinary','tinyblob','blob','mediumblob','longblob') THEN col.CHARACTER_SET_NAME
ELSE t.CHARACTER_SET_NAME
END AS CHARACTER_SET_NAME,
c.COLUMN_NAME
FROM
information_schema.COLUMNS c
LEFT JOIN information_schema.TABLES t
ON t.TABLE_SCHEMA = c.TABLE_SCHEMA AND t.TABLE_NAME = c.TABLE_NAME
LEFT JOIN information_schema.COLLATIONS col
ON col.COLLATION_NAME = t.TABLE_COLLATION
WHERE
c.TABLE_SCHEMA = ?
AND c.TABLE_NAME = ?
AND (c.CHARACTER_SET_NAME IS NOT NULL
OR c.DATA_TYPE IN ('binary','varbinary','tinyblob','blob','mediumblob','longblob')
OR c.DATA_TYPE IN ('varchar','char','text','tinytext','mediumtext','longtext'));
`

return query, nil

}

func (c *Canal) setColumnsCharsetFromRows(tableRegex string, rows *sql.Rows) error {
Expand Down
4 changes: 3 additions & 1 deletion replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,6 @@ func (e *RowsEvent) parseFracTime(t interface{}) interface{} {
// see mysql sql/log_event.cc log_event_print_value
func (e *RowsEvent) decodeValue(data []byte, tp byte, charset string, meta uint16) (v interface{}, n int, err error) {
var length int = 0

if tp == MYSQL_TYPE_STRING {
if meta >= 256 {
b0 := uint8(meta >> 8)
Expand Down Expand Up @@ -1203,6 +1202,9 @@ func convertToString(s interface{}) (string, bool) {
}

func decodeStringByCharSet(data []byte, charset string, length int) (v string, n int) {
if len(data) == 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decodeValue function has some unit tests. Please add this case also to unit tests

return "", 0
}
enc, err := getDecoderByCharsetName(charset)
if err != nil {
log.Errorf(err.Error())
Expand Down
Loading