Skip to content

Commit

Permalink
Merge pull request #935 from redHJ/sqlFix
Browse files Browse the repository at this point in the history
fix sql panic
  • Loading branch information
wonderflow authored Feb 26, 2019
2 parents 8fbf290 + fbcf5fd commit 5a40879
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion reader/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (r *MssqlReader) sendError(err error) {
}

func (r *MssqlReader) checkExit(idx int, db *sql.DB) (bool, int64) {
if len(r.offsetKey) <= 0 {
if idx >= len(r.offsets) || len(r.offsetKey) <= 0 {
return true, -1
}
rawSQL := strings.TrimSuffix(strings.TrimSpace(r.syncSQLs[idx]), ";")
Expand Down
4 changes: 2 additions & 2 deletions reader/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (r *MysqlReader) getSQL(idx int, rawSQL string) string {
}

func (r *MysqlReader) checkExit(idx int, db *sql.DB) (bool, int64) {
if len(r.offsetKey) <= 0 {
if len(r.offsetKey) <= 0 || idx >= len(r.offsets) {
return true, -1
}
rawSQL := r.syncSQLs[idx]
Expand Down Expand Up @@ -971,7 +971,7 @@ func (r *MysqlReader) execReadSql(curDB string, idx int, execSQL string, db *sql
if maxOffset > 0 {
r.offsets[idx] = maxOffset + 1
}
if exit {
if exit && !r.historyAll {
var newOffsetIdx int64
exit, newOffsetIdx = r.checkExit(idx, db)
if !exit {
Expand Down
2 changes: 1 addition & 1 deletion reader/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (r *PostgresReader) getSQL(idx int, rawSQL string) string {
}

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

0 comments on commit 5a40879

Please sign in to comment.