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

fix (engine/sqlite): normalize table names (#3162) #3657

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

jvns
Copy link
Contributor

@jvns jvns commented Oct 16, 2024

This aims to fix #3162, where in SQLite if schema.sql contained CREATE TABLE "users" and query.sql contained SELECT * from users, it would complain relation "users" does not exist, because the quotes don't match.

I think this was happening because the identifier function (which removes quotes from table names) wasn't consistently being called everywhere in the parser. I went through and replaced all instances of n.Table_name().GetText() with identifier(n.Table_name().GetText()) and that seems to have fixed the issue.

I've also added a test which previously failed and now passes. Here's what the output was previously:

$ cd internal/endtoend/testdata/quoted_tablename/sqlite/
$ sqlc generate
# package querytest
query.sql:1:1: relation "users" does not exist

@kyleconroy
Copy link
Collaborator

hey! long time

I've been a bit underwater with pull requests. Appreciate the added tests.

Do you mind rebasing on main? The tests didn't run in CI

@kyleconroy kyleconroy force-pushed the normalize-sqlite-table-names branch from abee542 to 186bce6 Compare November 25, 2024 06:36
@kyleconroy kyleconroy merged commit 58b08ae into sqlc-dev:main Nov 25, 2024
8 checks passed
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

Successfully merging this pull request may close these issues.

warn when using quotes or parse the SQL
2 participants