Skip to content

Commit 98f9427

Browse files
committed
fix(canal): fix "Index of range error" for unsigned columns
1 parent 046188b commit 98f9427

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

canal/rows.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package canal
22

33
import (
44
"fmt"
5+
56
"github.com/siddontang/go-mysql/replication"
67
"github.com/siddontang/go-mysql/schema"
78
)
@@ -58,15 +59,14 @@ func (r *RowsEvent) handleUnsigned() {
5859
case int16:
5960
r.Rows[i][index] = uint16(t)
6061
case int32:
61-
if r.Table.Columns[i].Type == schema.TYPE_MEDIUM_INT {
62+
if r.Table.Columns[index].Type == schema.TYPE_MEDIUM_INT {
6263
// problem with mediumint is that it's a 3-byte type. There is no compatible golang type to match that.
6364
// So to convert from negative to positive we'd need to convert the value manually
64-
if i >= 0 {
65+
if t >= 0 {
6566
r.Rows[i][index] = uint32(t)
6667
} else {
6768
r.Rows[i][index] = uint32(maxMediumintUnsigned + t + 1)
6869
}
69-
return
7070
} else {
7171
r.Rows[i][index] = uint32(t)
7272
}

0 commit comments

Comments
 (0)