Skip to content

Commit

Permalink
Handle untyped sqlite columns without crashing. Fixes #2279
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmbenton committed May 16, 2023
1 parent c13b156 commit 9495460
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/untyped_columns/sqlite/stdlib/db/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.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- original table name in sqlite schema was sqlite_sequence, rest of def is identical
create table repro(id, name, seq);

-- name: GetRepro :one
select * from repro where id = ? limit 1;
16 changes: 16 additions & 0 deletions internal/endtoend/testdata/untyped_columns/sqlite/stdlib/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "2",
"sql": [
{
"engine": "sqlite",
"schema": "query.sql",
"queries": "query.sql",
"gen": {
"go": {
"package": "db",
"out": "db"
}
}
}
]
}
6 changes: 5 additions & 1 deletion internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ func (c *cc) convertCreate_table_stmtContext(n *parser.Create_table_stmtContext)
}
for _, idef := range n.AllColumn_def() {
if def, ok := idef.(*parser.Column_defContext); ok {
typeName := "any"
if def.Type_name() != nil {
typeName = def.Type_name().GetText()
}
stmt.Cols = append(stmt.Cols, &ast.ColumnDef{
Colname: identifier(def.Column_name().GetText()),
IsNotNull: hasNotNullConstraint(def.AllColumn_constraint()),
TypeName: &ast.TypeName{Name: def.Type_name().GetText()},
TypeName: &ast.TypeName{Name: typeName},
})
}
}
Expand Down

0 comments on commit 9495460

Please sign in to comment.