Skip to content

Commit

Permalink
sqlite: Add support for CREATE TABLE ... STRICT (sqlc-dev#2175)
Browse files Browse the repository at this point in the history
Switch to v4 of ANTLR (which we were already kind of using)
  • Loading branch information
kyleconroy authored Mar 30, 2023
1 parent 73d9290 commit bfc48c7
Show file tree
Hide file tree
Showing 22 changed files with 4,488 additions and 3,145 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/kyleconroy/sqlc
go 1.20

require (
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1
github.com/bytecodealliance/wasmtime-go/v5 v5.0.0
github.com/cubicdaiya/gonp v1.0.4
github.com/davecgh/go-spew v1.1.1
Expand All @@ -25,7 +25,7 @@ require (
require (
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
)

require (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 h1:yL7+Jz0jTC6yykIK/Wh74gnTJnrGr5AyrNMXuA0gves=
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1 h1:X8MJ0fnN5FPdcGF5Ij2/OW+HgiJrRg3AfHAx1PJtIzM=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230321174746-8dcc6526cfb1/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bytecodealliance/wasmtime-go/v5 v5.0.0 h1:Ue3eBDElMrdzWoUtr7uPr7NeDZriuR5oIivp5EHknQU=
Expand Down Expand Up @@ -201,8 +201,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4=
golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
Expand Down
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/ddl_create_table_strict/sqlite/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- name: Placeholder :exec
SELECT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE venues (name text) STRICT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "sqlite",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
2 changes: 1 addition & 1 deletion internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
"strings"

"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"

"github.com/kyleconroy/sqlc/internal/debug"
"github.com/kyleconroy/sqlc/internal/engine/sqlite/parser"
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/sqlite/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"io"

"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"

"github.com/kyleconroy/sqlc/internal/engine/sqlite/parser"
"github.com/kyleconroy/sqlc/internal/metadata"
Expand Down
2 changes: 2 additions & 0 deletions internal/engine/sqlite/parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

antlr-4.12.0-complete.jar
9 changes: 7 additions & 2 deletions internal/engine/sqlite/parser/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
sqlite_parser.go: SQLiteLexer.g4 SQLiteParser.g4
antlr -Dlanguage=Go SQLiteLexer.g4 SQLiteParser.g4
sqlite_parser.go: SQLiteLexer.g4 SQLiteParser.g4 antlr-4.12.0-complete.jar
java -jar antlr-4.12.0-complete.jar -Dlanguage=Go SQLiteLexer.g4 SQLiteParser.g4

antlr-4.12.0-complete.jar:
curl -O https://www.antlr.org/download/antlr-4.12.0-complete.jar


1 change: 1 addition & 0 deletions internal/engine/sqlite/parser/SQLiteLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ ROWS_: R O W S;
SAVEPOINT_: S A V E P O I N T;
SELECT_: S E L E C T;
SET_: S E T;
STRICT_: S T R I C T;
TABLE_: T A B L E;
TEMP_: T E M P;
TEMPORARY_: T E M P O R A R Y;
Expand Down
5 changes: 4 additions & 1 deletion internal/engine/sqlite/parser/SQLiteLexer.interp

Large diffs are not rendered by default.

125 changes: 63 additions & 62 deletions internal/engine/sqlite/parser/SQLiteLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -129,68 +129,69 @@ ROWS_=128
SAVEPOINT_=129
SELECT_=130
SET_=131
TABLE_=132
TEMP_=133
TEMPORARY_=134
THEN_=135
TO_=136
TRANSACTION_=137
TRIGGER_=138
UNION_=139
UNIQUE_=140
UPDATE_=141
USING_=142
VACUUM_=143
VALUES_=144
VIEW_=145
VIRTUAL_=146
WHEN_=147
WHERE_=148
WITH_=149
WITHOUT_=150
FIRST_VALUE_=151
OVER_=152
PARTITION_=153
RANGE_=154
PRECEDING_=155
UNBOUNDED_=156
CURRENT_=157
FOLLOWING_=158
CUME_DIST_=159
DENSE_RANK_=160
LAG_=161
LAST_VALUE_=162
LEAD_=163
NTH_VALUE_=164
NTILE_=165
PERCENT_RANK_=166
RANK_=167
ROW_NUMBER_=168
GENERATED_=169
ALWAYS_=170
STORED_=171
TRUE_=172
FALSE_=173
WINDOW_=174
NULLS_=175
FIRST_=176
LAST_=177
FILTER_=178
GROUPS_=179
EXCLUDE_=180
TIES_=181
OTHERS_=182
DO_=183
NOTHING_=184
IDENTIFIER=185
NUMERIC_LITERAL=186
BIND_PARAMETER=187
STRING_LITERAL=188
BLOB_LITERAL=189
SINGLE_LINE_COMMENT=190
MULTILINE_COMMENT=191
SPACES=192
UNEXPECTED_CHAR=193
STRICT_=132
TABLE_=133
TEMP_=134
TEMPORARY_=135
THEN_=136
TO_=137
TRANSACTION_=138
TRIGGER_=139
UNION_=140
UNIQUE_=141
UPDATE_=142
USING_=143
VACUUM_=144
VALUES_=145
VIEW_=146
VIRTUAL_=147
WHEN_=148
WHERE_=149
WITH_=150
WITHOUT_=151
FIRST_VALUE_=152
OVER_=153
PARTITION_=154
RANGE_=155
PRECEDING_=156
UNBOUNDED_=157
CURRENT_=158
FOLLOWING_=159
CUME_DIST_=160
DENSE_RANK_=161
LAG_=162
LAST_VALUE_=163
LEAD_=164
NTH_VALUE_=165
NTILE_=166
PERCENT_RANK_=167
RANK_=168
ROW_NUMBER_=169
GENERATED_=170
ALWAYS_=171
STORED_=172
TRUE_=173
FALSE_=174
WINDOW_=175
NULLS_=176
FIRST_=177
LAST_=178
FILTER_=179
GROUPS_=180
EXCLUDE_=181
TIES_=182
OTHERS_=183
DO_=184
NOTHING_=185
IDENTIFIER=186
NUMERIC_LITERAL=187
BIND_PARAMETER=188
STRING_LITERAL=189
BLOB_LITERAL=190
SINGLE_LINE_COMMENT=191
MULTILINE_COMMENT=192
SPACES=193
UNEXPECTED_CHAR=194
';'=1
'.'=2
'('=3
Expand Down
3 changes: 2 additions & 1 deletion internal/engine/sqlite/parser/SQLiteParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ create_table_stmt:
schema_name DOT
)? table_name (
OPEN_PAR column_def (COMMA column_def)*? (COMMA table_constraint)* CLOSE_PAR (
WITHOUT_ row_ROW_ID = IDENTIFIER
(WITHOUT_ row_ROW_ID = IDENTIFIER) | (STRICT_)
)?
| AS_ select_stmt
)
Expand Down Expand Up @@ -756,6 +756,7 @@ keyword:
| SAVEPOINT_
| SELECT_
| SET_
| STRICT_
| TABLE_
| TEMP_
| TEMPORARY_
Expand Down
4 changes: 3 additions & 1 deletion internal/engine/sqlite/parser/SQLiteParser.interp

Large diffs are not rendered by default.

Loading

0 comments on commit bfc48c7

Please sign in to comment.