Skip to content

Sqlite engine creates wrong number of arguments in case of several JOINS with parameters #2368

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
leodeim opened this issue Jun 26, 2023 · 2 comments · Fixed by #2428
Closed

Comments

@leodeim
Copy link

leodeim commented Jun 26, 2023

Version

1.18.0

What happened?

If you have a query with two JOINs which have parameters sqlite engine skips parameter in one of the JOINs.
If you change sqlite to mysql generation works correctly.
Schema, query and playground link are provided.

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   integer PRIMARY KEY,
  name text      NOT NULL,
  age  integer
);

CREATE TABLE translators (
  id   integer PRIMARY KEY,
  name text      NOT NULL,
  age  integer
);

CREATE TABLE books (
  id   integer PRIMARY KEY,
  author text      NOT NULL,
  translator text      NOT NULL,
  year  integer
);

SQL queries

DELETE FROM
  books AS b
WHERE
  b.author NOT IN (
    SELECT
      a.name
    FROM
      authors a
    WHERE
      a.age >= ?
  )
  AND b.translator NOT IN (
    SELECT
      t.name
    FROM
      translators t
    WHERE
      t.age >= ?
  )
  AND b.year <= ?;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "sqlite",
      "schema": "query.sql",
      "queries": "query.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/b46d0f5491464a5698aeb56d290764f8a38daa6f59d2a5f89f3ab707a9b2b078

What operating system are you using?

Windows

What database engines are you using?

SQLite

What type of code are you generating?

Go

@leodeim leodeim added bug Something isn't working triage New issues that hasn't been reviewed labels Jun 26, 2023
@leodeim
Copy link
Author

leodeim commented Jun 26, 2023

sqlite generates:

type DeleteAuthorParams struct {
	Age  sql.NullInt64
	Year sql.NullInt64
}

mysql generates:

type DeleteAuthorParams struct {
	Age   sql.NullInt32
	Age_2 sql.NullInt32
	Year  sql.NullInt32
}

@tape3093
Copy link

Same problem, please help.

@kyleconroy kyleconroy added 🔧 golang 💻 windows 📚 sqlite and removed triage New issues that hasn't been reviewed labels Jul 6, 2023
orisano added a commit to orisano/sqlc that referenced this issue Jul 10, 2023
orisano added a commit to orisano/sqlc that referenced this issue Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants