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

engine/sqlite: Handle untyped sqlite columns without crashing #2281

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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