Closed
Description
Version
Other
What happened?
With sqlc 1.18.0.
While importing a Django schema by running sqlite3
and dumping the schema with .schema
, I found a crasher in sqlc's sqlite parser: defining a table with no column types (which is allowed in sqlite, although obviously impossible for sqlc to generate good APIs), sqlc generate
crashes with a nil pointer dereference.
Relevant log output
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xd8 pc=0xeac741]
goroutine 19 [running]:
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertCreate_table_stmtContext(0x3e669dfae640?, 0xc00021f3e0)
/home/runner/work/release-sqlc/release-sqlc/internal/engine/sqlite/convert.go:115 +0x241
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0xc0004ec400?, {0x20f6900?, 0xc00021f3e0?})
/home/runner/work/release-sqlc/release-sqlc/internal/engine/sqlite/convert.go:794 +0x7b
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertSql_stmtContext(0x2?, 0xc00041e648)
/home/runner/work/release-sqlc/release-sqlc/internal/engine/sqlite/convert.go:445 +0x8fd
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0xc000138ce8?, {0x20f6b40?, 0xc00041e648?})
/home/runner/work/release-sqlc/release-sqlc/internal/engine/sqlite/convert.go:849 +0x2ef
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*Parser).Parse(0xc00015a460?, {0x20fe3c0?, 0xc0003f20c0?})
/home/runner/work/release-sqlc/release-sqlc/internal/engine/sqlite/parse.go:71 +0x59a
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseCatalog(0xc0003d2700, {0xc0002c7540?, 0xc0002c7540?, 0x1?})
/home/runner/work/release-sqlc/release-sqlc/internal/compiler/compile.go:69 +0x1a6
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseCatalog(...)
/home/runner/work/release-sqlc/release-sqlc/internal/compiler/engine.go:45
github.com/kyleconroy/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0xc00023f840, 0x6}, {0xc0002c7540, 0x1, ...}, ...}, ...)
/home/runner/work/release-sqlc/release-sqlc/internal/cmd/generate.go:336 +0x14a
github.com/kyleconroy/sqlc/internal/cmd.Generate.func1()
/home/runner/work/release-sqlc/release-sqlc/internal/cmd/generate.go:224 +0x805
golang.org/x/sync/errgroup.(*Group).Go.func1()
/home/runner/go/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:75 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
/home/runner/go/pkg/mod/golang.org/x/sync@v0.1.0/errgroup/errgroup.go:72 +0xa5
Database schema
-- original table name in sqlite schema was sqlite_sequence, rest of def is identical
create table repro(name, seq);
SQL queries
-- name: GetRepro :one
select * from repro where id = ? limit 1;
Configuration
{
"version": "2",
"sql": [
{
"engine": "sqlite",
"schema": "query.sql",
"queries": "query.sql",
"gen": {
"go": {
"package": "db",
"out": "db"
}
}
}
]
}
Playground URL
https://play.sqlc.dev/p/d95f42ce7ad6a4b861181b57e72e3abe2efdf41d97924a51cd7ee4f6c7447add
What operating system are you using?
Linux
What database engines are you using?
No response
What type of code are you generating?
Go