Open
Description
Version
1.15.0
What happened?
I'm using sqlc with MySQL. In a query, if I use bogus field names in JOIN
, WHERE
or ORDER BY
clauses, the code generator will not complain. It seems that field names in the SELECT
clause are validated, but not anywhere else.
Relevant log output
No response
Database schema
create table t1 (
id int(11) not null,
s varchar(128) not null,
primary key (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
create table t2 (
id int(11) not null,
t1_id int(11) not null,
primary key (id),
key t1_id (t1_id),
foreign key (t1_id) references t1 (id)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL queries
-- name: Broken :many
SELECT
t1.*
FROM
t1 LEFT JOIN t2 on t1.id = t2.t1_id
WHERE
t1.bar = 'x' AND t2.baz = 'y'
ORDER BY
t1.xyz > t2.abc
Configuration
No response
Playground URL
https://play.sqlc.dev/p/bf880aa2e19616101663a8bf3e1a4c02a99e234d1aac598c65541e5e11823488
What operating system are you using?
Linux
What database engines are you using?
MySQL
What type of code are you generating?
Go