Skip to content

Commit 5a40879

Browse files
authored
Merge pull request #935 from redHJ/sqlFix
fix sql panic
2 parents 8fbf290 + fbcf5fd commit 5a40879

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

reader/mssql/mssql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func (r *MssqlReader) sendError(err error) {
469469
}
470470

471471
func (r *MssqlReader) checkExit(idx int, db *sql.DB) (bool, int64) {
472-
if len(r.offsetKey) <= 0 {
472+
if idx >= len(r.offsets) || len(r.offsetKey) <= 0 {
473473
return true, -1
474474
}
475475
rawSQL := strings.TrimSuffix(strings.TrimSpace(r.syncSQLs[idx]), ";")

reader/mysql/mysql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func (r *MysqlReader) getSQL(idx int, rawSQL string) string {
681681
}
682682

683683
func (r *MysqlReader) checkExit(idx int, db *sql.DB) (bool, int64) {
684-
if len(r.offsetKey) <= 0 {
684+
if len(r.offsetKey) <= 0 || idx >= len(r.offsets) {
685685
return true, -1
686686
}
687687
rawSQL := r.syncSQLs[idx]
@@ -971,7 +971,7 @@ func (r *MysqlReader) execReadSql(curDB string, idx int, execSQL string, db *sql
971971
if maxOffset > 0 {
972972
r.offsets[idx] = maxOffset + 1
973973
}
974-
if exit {
974+
if exit && !r.historyAll {
975975
var newOffsetIdx int64
976976
exit, newOffsetIdx = r.checkExit(idx, db)
977977
if !exit {

reader/postgres/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func (r *PostgresReader) getSQL(idx int, rawSQL string) string {
644644
}
645645

646646
func (r *PostgresReader) checkExit(idx int, db *sql.DB) (bool, int64) {
647-
if len(r.offsetKey) <= 0 && len(r.timestampKey) <= 0 {
647+
if idx >= len(r.offsets) || (len(r.offsetKey) <= 0 && len(r.timestampKey) <= 0) {
648648
return true, -1
649649
}
650650
rawSQL := r.syncSQLs[idx]

0 commit comments

Comments
 (0)