Skip to content

Commit 72c4918

Browse files
odaysecngjaying
andauthored
fix(kv): prepare ts query (#3767)
Signed-off-by: Zeroday BYTE <[email protected]> Signed-off-by: Jiyong Huang <[email protected]> Co-authored-by: Jiyong Huang <[email protected]>
1 parent a1e08fd commit 72c4918

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/pkg/store/sql/sqlTs.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func createSqlTs(database Database, table string) (*ts, error) {
3939
last: getLast(database, table),
4040
}
4141
err := store.database.Apply(func(db *sql.DB) error {
42-
query := fmt.Sprintf("CREATE TABLE IF NOT EXISTS '%s'('key' INTEGER PRIMARY KEY, 'val' BLOB);", table)
42+
query := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s ('key' INTEGER PRIMARY KEY, 'val' BLOB);", table)
4343
stmt, err := db.Prepare(query)
4444
if err != nil {
4545
return err
4646
}
47-
_, err = stmt.Exec(query)
47+
_, err = stmt.Exec()
4848
return err
4949
})
5050
if err != nil {
@@ -158,13 +158,16 @@ func (t ts) Drop() error {
158158

159159
func getLast(d Database, table string) int64 {
160160
var last int64 = 0
161+
if !isValidTableName(table) {
162+
return 0 // or handle the error appropriately
163+
}
161164
_ = d.Apply(func(db *sql.DB) error {
162-
query := fmt.Sprintf("SELECT key FROM %s Order by key DESC Limit 1;", table)
165+
query := fmt.Sprintf("SELECT key FROM %s ORDER BY key DESC LIMIT 1;", table)
163166
stmt, err := db.Prepare(query)
164167
if err != nil {
165168
return err
166169
}
167-
row := stmt.QueryRow(query)
170+
row := stmt.QueryRow()
168171
return row.Scan(&last)
169172
})
170173
return last

0 commit comments

Comments
 (0)