Skip to content

named parameters do not work with sqlite #1961

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

Closed
jreut opened this issue Nov 20, 2022 · 2 comments
Closed

named parameters do not work with sqlite #1961

jreut opened this issue Nov 20, 2022 · 2 comments

Comments

@jreut
Copy link
Contributor

jreut commented Nov 20, 2022

Howdy, I've really enjoyed using this software so far. Thank you for writing it! I think I found a problem in SQLite, and I think I have a vague understanding of the cause.

When I write a test like this on top of the latest main:

diff --git a/internal/endtoend/testdata/sqlc_arg/sqlite/catalog.sql b/internal/endtoend/testdata/sqlc_arg/sqlite/catalog.sql
new file mode 100644
index 00000000..2d02dc78
--- /dev/null
+++ b/internal/endtoend/testdata/sqlc_arg/sqlite/catalog.sql
@@ -0,0 +1 @@
+CREATE TABLE t (a INTEGER);
diff --git a/internal/endtoend/testdata/sqlc_arg/sqlite/query.sql b/internal/endtoend/testdata/sqlc_arg/sqlite/query.sql
new file mode 100644
index 00000000..386bf906
--- /dev/null
+++ b/internal/endtoend/testdata/sqlc_arg/sqlite/query.sql
@@ -0,0 +1,5 @@
+-- name: FuncParamIdent :many
+SELECT a FROM t WHERE a = sqlc.arg(b);
+
+-- name: FuncParamString :many
+SELECT a FROM t WHERE a = sqlc.arg('b');
diff --git a/internal/endtoend/testdata/sqlc_arg/sqlite/sqlc.yaml b/internal/endtoend/testdata/sqlc_arg/sqlite/sqlc.yaml
new file mode 100644
index 00000000..f16dc833
--- /dev/null
+++ b/internal/endtoend/testdata/sqlc_arg/sqlite/sqlc.yaml
@@ -0,0 +1,8 @@
+version: "2"
+sql:
+- schema: catalog.sql
+  queries: query.sql
+  engine: sqlite
+  gen:
+    go:
+      out: db
-- 
2.37.1

I get an error like this:

$ go test -run=TestReplay/testdata/sqlc_arg/sqlite ./internal/endtoend
line 2:34 extraneous input '(' expecting {<EOF>, ';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
line 5:34 extraneous input '(' expecting {<EOF>, ';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
line 6:0 extraneous input '<EOF>' expecting {';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
--- FAIL: TestReplay (0.05s)
    --- FAIL: TestReplay/testdata/sqlc_arg/sqlite (0.01s)
        endtoend_test.go:100: sqlc generate failed: # package db
            query.sql:1:1: extraneous input '<EOF>' expecting {';', ALTER_, ANALYZE_, ATTACH_, BEGIN_, COMMIT_, CREATE_, DEFAULT_, DELETE_, DETACH_, DROP_, END_, EXPLAIN_, INSERT_, PRAGMA_, REINDEX_, RELEASE_, REPLACE_, ROLLBACK_, SAVEPOINT_, SELECT_, UPDATE_, VACUUM_, VALUES_, WITH_}
FAIL
FAIL    github.com/kyleconroy/sqlc/internal/endtoend    0.469s
FAIL

I believe this error comes from ./internal/engine/sqlite.Parser.Parse(), which make sense. SQLite doesn't have namespaces, so it cannot parse sqlc.arg(ident). It can parse sqlc_arg(ident), but then of course the rewrite rule doesn't do its job.

What should we do? Perhaps move the rewriting before the engine parse step? Or extend the syntax of named parameters? I'm more than happy to write some code, ask more questions, or hear more opinions.

@jreut
Copy link
Contributor Author

jreut commented Nov 20, 2022

Huh, it seems gh issue new doesn't use issue templates. I'll open a new one there!

@jreut jreut closed this as completed Nov 20, 2022
@jreut
Copy link
Contributor Author

jreut commented Nov 20, 2022

See #1962

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant