Skip to content

Commit

Permalink
fix (engine/sqlite): normalize table names (#3162) (#3657)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvns authored Nov 25, 2024
1 parent 0b952b4 commit 58b08ae
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 4 deletions.
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/quoted_tablename/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions internal/endtoend/testdata/quoted_tablename/sqlite/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/endtoend/testdata/quoted_tablename/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: TestList :many
SELECT * FROM users;
6 changes: 6 additions & 0 deletions internal/endtoend/testdata/quoted_tablename/sqlite/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Example queries for sqlc
CREATE TABLE "users"
(
id TEXT NOT NULL
);

12 changes: 12 additions & 0 deletions internal/endtoend/testdata/quoted_tablename/sqlite/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "sqlite",
"schema": "schema.sql",
"queries": "query.sql",
"name": "querytest"
}
]
}
6 changes: 3 additions & 3 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type Delete_stmt interface {
func (c *cc) convertDelete_stmtContext(n Delete_stmt) ast.Node {
if qualifiedName, ok := n.Qualified_table_name().(*parser.Qualified_table_nameContext); ok {

tableName := qualifiedName.Table_name().GetText()
tableName := identifier(qualifiedName.Table_name().GetText())
relation := &ast.RangeVar{
Relname: &tableName,
}
Expand Down Expand Up @@ -854,7 +854,7 @@ func (c *cc) convertReturning_caluseContext(n parser.IReturning_clauseContext) *
}

func (c *cc) convertInsert_stmtContext(n *parser.Insert_stmtContext) ast.Node {
tableName := n.Table_name().GetText()
tableName := identifier(n.Table_name().GetText())
rel := &ast.RangeVar{
Relname: &tableName,
}
Expand Down Expand Up @@ -936,7 +936,7 @@ func (c *cc) convertTablesOrSubquery(n []parser.ITable_or_subqueryContext) []ast
}

if from.Table_name() != nil {
rel := from.Table_name().GetText()
rel := identifier(from.Table_name().GetText())
rv := &ast.RangeVar{
Relname: &rel,
Location: from.GetStart().GetStart(),
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type tableNamer interface {

func parseTableName(c tableNamer) *ast.TableName {
name := ast.TableName{
Name: c.Table_name().GetText(),
Name: identifier(c.Table_name().GetText()),
}
if c.Schema_name() != nil {
name.Schema = c.Schema_name().GetText()
Expand Down

0 comments on commit 58b08ae

Please sign in to comment.