Skip to content

Commit b01deee

Browse files
fix: Add proper identifier quoting for SQLite3 non-English characters
- Wrap identifiers in double quotes in EscapeSpecificIdentifier - Use proper escaping for table names in COUNT queries - Escape table and column names in CREATE TABLE statements - Fixes "near '-': syntax error" with Chinese characters and special chars Fixes #502 Co-authored-by: Anguel <modelorona@users.noreply.github.com>
1 parent d59f602 commit b01deee

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

core/src/plugins/sqlite3/add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (p *Sqlite3Plugin) GetCreateTableQuery(schema string, storageUnit string, c
2626
var columnDefs []string
2727

2828
for _, column := range columns {
29-
parts := []string{column.Key}
29+
parts := []string{p.EscapeIdentifier(column.Key)}
3030

3131
// Handle primary key with INTEGER type for auto-increment
3232
if primary, ok := column.Extra["primary"]; ok && primary == "true" {
@@ -47,5 +47,5 @@ func (p *Sqlite3Plugin) GetCreateTableQuery(schema string, storageUnit string, c
4747
columnDefs = append(columnDefs, strings.Join(parts, " "))
4848
}
4949

50-
return fmt.Sprintf("CREATE TABLE %s (%s)", storageUnit, strings.Join(columnDefs, ", "))
50+
return fmt.Sprintf("CREATE TABLE %s (%s)", p.EscapeIdentifier(storageUnit), strings.Join(columnDefs, ", "))
5151
}

core/src/plugins/sqlite3/sqlite3.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func (p *Sqlite3Plugin) GetTableNameAndAttributes(rows *sql.Rows, db *gorm.DB) (
9090
}
9191

9292
var rowCount int64
93-
rowCountRow := db.Raw(fmt.Sprintf("SELECT COUNT(*) FROM '%s'", tableName)).Row()
93+
escapedTableName := p.EscapeIdentifier(tableName)
94+
rowCountRow := db.Raw(fmt.Sprintf("SELECT COUNT(*) FROM %s", escapedTableName)).Row()
9495
err := rowCountRow.Scan(&rowCount)
9596
if err != nil {
9697
return "", nil

core/src/plugins/sqlite3/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ func (p *Sqlite3Plugin) GetColTypeQuery() string {
4949

5050
func (p *Sqlite3Plugin) EscapeSpecificIdentifier(identifier string) string {
5151
identifier = strings.Replace(identifier, "\"", "\"\"", -1)
52-
return identifier
52+
return "\"" + identifier + "\""
5353
}

0 commit comments

Comments
 (0)