Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always use a sql safe table name in failed events manager #2664

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions router/failed-events-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (*FailedEventsManagerT) SaveFailedRecordIDs(taskRunIDFailedEventsMap map[st
}

for taskRunID, failedEvents := range taskRunIDFailedEventsMap {
table := `"` + strings.ReplaceAll(fmt.Sprintf(`%s_%s`, failedKeysTablePrefix, taskRunID), `"`, `""`) + `"`
table := getSqlSafeTablename(taskRunID)
sqlStatement := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s (
destination_id TEXT NOT NULL,
record_id JSONB NOT NULL,
Expand Down Expand Up @@ -94,7 +94,7 @@ func (fem *FailedEventsManagerT) DropFailedRecordIDs(taskRunID string) {
}

// Drop table
table := fmt.Sprintf(`%s_%s`, failedKeysTablePrefix, taskRunID)
table := getSqlSafeTablename(taskRunID)
sqlStatement := fmt.Sprintf(`DROP TABLE IF EXISTS %s`, table)
_, err := fem.dbHandle.Exec(sqlStatement)
if err != nil {
Expand All @@ -111,7 +111,7 @@ func (fem *FailedEventsManagerT) FetchFailedRecordIDs(taskRunID string) []*Faile

var rows *sql.Rows
var err error
table := `"` + strings.ReplaceAll(fmt.Sprintf(`%s_%s`, failedKeysTablePrefix, taskRunID), `"`, `""`) + `"`
table := getSqlSafeTablename(taskRunID)
sqlStatement := fmt.Sprintf(`SELECT %[1]s.destination_id, %[1]s.record_id
FROM %[1]s `, table)
rows, err = fem.dbHandle.Query(sqlStatement)
Expand Down Expand Up @@ -188,3 +188,7 @@ func CleanFailedRecordsTableProcess(ctx context.Context) {
func (fem *FailedEventsManagerT) GetDBHandle() *sql.DB {
return fem.dbHandle
}

func getSqlSafeTablename(taskRunID string) string {
return `"` + strings.ReplaceAll(fmt.Sprintf(`%s_%s`, failedKeysTablePrefix, taskRunID), `"`, `""`) + `"`
Copy link
Member

Choose a reason for hiding this comment

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

pq.QuoteIdentifier can be used as well.

}