Skip to content

Commit 36a415e

Browse files
authored
fix: cannot parse SQLite upsert statement (#1732)
1 parent 200af70 commit 36a415e

File tree

14 files changed

+5476
-2656
lines changed

14 files changed

+5476
-2656
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/kyleconroy/sqlc
33
go 1.18
44

55
require (
6-
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9
6+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e
77
github.com/bytecodealliance/wasmtime-go v0.38.1
88
github.com/davecgh/go-spew v1.1.1
99
github.com/go-sql-driver/mysql v1.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
4-
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9 h1:zvkJv+9Pxm1nnEMcKnShREt4qtduHKz4iw4AB4ul0Ao=
5-
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220209173558-ad29539cd2e9/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
4+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e h1:bt6SW1eSSvdmmsG0KqyxYXorcTnFBTX7hfVR1+68+jg=
5+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220626175859-9abda183db8e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
66
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
77
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
88
github.com/bytecodealliance/wasmtime-go v0.38.1 h1:eqrJmy1nR/uyxZC4OydXWpvGeEHzprW1Fao6eXvNnEE=

internal/endtoend/testdata/upsert/sqlite/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/upsert/sqlite/go/models.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/upsert/sqlite/go/query.sql.go

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- https://github.com/kyleconroy/sqlc/issues/1728
2+
3+
CREATE TABLE IF NOT EXISTS locations (
4+
id INTEGER PRIMARY KEY,
5+
name TEXT NOT NULL,
6+
address TEXT NOT NULL,
7+
zip_code INT NOT NULL,
8+
latitude REAL NOT NULL,
9+
longitude REAL NOT NULL,
10+
UNIQUE(name)
11+
);
12+
13+
/* name: UpsertLocation :exec */
14+
INSERT INTO locations (
15+
name,
16+
address,
17+
zip_code,
18+
latitude,
19+
longitude
20+
)
21+
VALUES (?, ?, ?, ?, ?)
22+
ON CONFLICT(name) DO UPDATE SET
23+
name = excluded.name,
24+
address = excluded.address,
25+
zip_code = excluded.zip_code,
26+
latitude = excluded.latitude,
27+
longitude = excluded.longitude;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"engine": "sqlite",
6+
"path": "go",
7+
"name": "querytest",
8+
"schema": "query.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

internal/engine/sqlite/parser/SQLiteLexer.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

internal/engine/sqlite/parser/SQLiteParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ upsert_clause:
355355
)? DO_ (
356356
NOTHING_
357357
| UPDATE_ SET_ (
358-
(column_name | column_name_list) EQ expr (
359-
COMMA (column_name | column_name_list) EQ expr
358+
(column_name | column_name_list) ASSIGN expr (
359+
COMMA (column_name | column_name_list) ASSIGN expr
360360
)* (WHERE_ expr)?
361361
)
362362
)

internal/engine/sqlite/parser/SQLiteParser.interp

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)