-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0787f87
commit 9d2ce53
Showing
11 changed files
with
345 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Tests basic CREATE TABLE functionality. | ||
|
||
# The result contains the table name. The table is written to storage. | ||
[result,ops]> CREATE TABLE test (id INTEGER PRIMARY KEY) | ||
--- | ||
CreateTable { name: "test" } | ||
storage set mvcc:NextVersion → 2 ["\x00" → "\x02"] | ||
storage set mvcc:TxnActive(1) → "" ["\x01\x00\x00\x00\x00\x00\x00\x00\x01" → ""] | ||
storage set mvcc:TxnWrite(1, sql:Table("test")) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\xfftest\x00\xff\x00\xff\x00\x00" → ""] | ||
storage set mvcc:Version(sql:Table("test"), 1) → CREATE TABLE test ( id INTEGER PRIMARY KEY ) ["\x04\x00\xfftest\x00\xff\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" → "\x01\x10\x04test\x00\x01\x02id\x01\x00\x00\x01\x00\x00"] | ||
storage delete mvcc:TxnWrite(1, sql:Table("test")) ["\x03\x00\x00\x00\x00\x00\x00\x00\x01\x00\xfftest\x00\xff\x00\xff\x00\x00"] | ||
storage delete mvcc:TxnActive(1) ["\x01\x00\x00\x00\x00\x00\x00\x00\x01"] | ||
|
||
# Creating a table with multiple columns, indexes and foreign keys | ||
# still only results in a single stored schema entry. | ||
[ops]> CREATE TABLE indexed (id INTEGER PRIMARY KEY, "index" INTEGER INDEX, "unique" INTEGER UNIQUE, test_id INTEGER REFERENCES test) | ||
--- | ||
storage set mvcc:NextVersion → 3 ["\x00" → "\x03"] | ||
storage set mvcc:TxnActive(2) → "" ["\x01\x00\x00\x00\x00\x00\x00\x00\x02" → ""] | ||
storage set mvcc:TxnWrite(2, sql:Table("indexed")) → "" ["\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\xffindexed\x00\xff\x00\xff\x00\x00" → ""] | ||
storage set mvcc:Version(sql:Table("indexed"), 2) → CREATE TABLE indexed ( id INTEGER PRIMARY KEY, "index" INTEGER DEFAULT NULL INDEX, "unique" INTEGER DEFAULT NULL UNIQUE INDEX, test_id INTEGER DEFAULT NULL INDEX REFERENCES test ) ["\x04\x00\xffindexed\x00\xff\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02" → "\x01B\x07indexed\x00\x04\x02id\x01\x00\x00\x01\x00\x00\x05index\x01\x01\x01\x00\x00\x01\x00\x06unique\x01\x01\x01\x00\x01\x01\x00\x07test_id\x01\x01\x01\x00\x00\x01\x01\x04test"] | ||
storage delete mvcc:TxnWrite(2, sql:Table("indexed")) ["\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\xffindexed\x00\xff\x00\xff\x00\x00"] | ||
storage delete mvcc:TxnActive(2) ["\x01\x00\x00\x00\x00\x00\x00\x00\x02"] | ||
|
||
dump | ||
--- | ||
mvcc:NextVersion → 3 ["\x00" → "\x03"] | ||
mvcc:Version(sql:Table("indexed"), 2) → CREATE TABLE indexed ( id INTEGER PRIMARY KEY, "index" INTEGER DEFAULT NULL INDEX, "unique" INTEGER DEFAULT NULL UNIQUE INDEX, test_id INTEGER DEFAULT NULL INDEX REFERENCES test ) ["\x04\x00\xffindexed\x00\xff\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02" → "\x01B\x07indexed\x00\x04\x02id\x01\x00\x00\x01\x00\x00\x05index\x01\x01\x01\x00\x00\x01\x00\x06unique\x01\x01\x01\x00\x01\x01\x00\x07test_id\x01\x01\x01\x00\x00\x01\x01\x04test"] | ||
mvcc:Version(sql:Table("test"), 1) → CREATE TABLE test ( id INTEGER PRIMARY KEY ) ["\x04\x00\xfftest\x00\xff\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" → "\x01\x10\x04test\x00\x01\x02id\x01\x00\x00\x01\x00\x00"] | ||
|
||
schema | ||
--- | ||
CREATE TABLE indexed ( | ||
id INTEGER PRIMARY KEY, | ||
"index" INTEGER DEFAULT NULL INDEX, | ||
"unique" INTEGER DEFAULT NULL UNIQUE INDEX, | ||
test_id INTEGER DEFAULT NULL INDEX REFERENCES test | ||
) | ||
CREATE TABLE test ( | ||
id INTEGER PRIMARY KEY | ||
) | ||
|
||
# Errors if table already exists. | ||
!> CREATE TABLE test (id INTEGER PRIMARY KEY) | ||
--- | ||
Error: invalid input: table test already exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Tests CREATE TABLE datatypes. | ||
|
||
# Create columns with all datatypes. | ||
> CREATE TABLE datatypes ( \ | ||
id INTEGER PRIMARY KEY, \ | ||
"bool" BOOL, \ | ||
"boolean" BOOLEAN, \ | ||
"double" DOUBLE, \ | ||
"float" FLOAT, \ | ||
"int" INT, \ | ||
"integer" INTEGER, \ | ||
"string" STRING, \ | ||
"text" TEXT, \ | ||
"varchar" VARCHAR \ | ||
) | ||
schema | ||
--- | ||
CREATE TABLE datatypes ( | ||
id INTEGER PRIMARY KEY, | ||
"bool" BOOLEAN DEFAULT NULL, | ||
"boolean" BOOLEAN DEFAULT NULL, | ||
"double" FLOAT DEFAULT NULL, | ||
"float" FLOAT DEFAULT NULL, | ||
"int" INTEGER DEFAULT NULL, | ||
"integer" INTEGER DEFAULT NULL, | ||
"string" STRING DEFAULT NULL, | ||
"text" STRING DEFAULT NULL, | ||
"varchar" STRING DEFAULT NULL | ||
) | ||
|
||
# Missing datatype errors. | ||
!> CREATE TABLE test (id INTEGER PRIMARY KEY, value) | ||
--- | ||
Error: invalid input: unexpected token ) | ||
|
||
# Unknown datatype errors. | ||
!> CREATE TABLE test (id INTEGER PRIMARY KEY, value FOO) | ||
!> CREATE TABLE test (id INTEGER PRIMARY KEY, value INDEX) | ||
--- | ||
Error: invalid input: unexpected token foo | ||
Error: invalid input: unexpected token INDEX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Tests CREATE TABLE table and column name validation. | ||
|
||
# A couple of valid names. | ||
> CREATE TABLE a_123 (a_123 INTEGER PRIMARY KEY) | ||
> CREATE TABLE 表 (身元 INTEGER PRIMARY KEY, 名前 STRING) | ||
schema | ||
--- | ||
CREATE TABLE a_123 ( | ||
a_123 INTEGER PRIMARY KEY | ||
) | ||
CREATE TABLE 表 ( | ||
身元 INTEGER PRIMARY KEY, | ||
名前 STRING DEFAULT NULL | ||
) | ||
|
||
# Mixed case is valid, but interpreted as lower case. Quoted identifiers retain | ||
# their case. | ||
> CREATE TABLE mIxEd_cAsE (ÄÅÆ STRING PRIMARY KEY) | ||
> CREATE TABLE "mIxEd_cAsE" ("ÄÅÆ" STRING PRIMARY KEY) | ||
schema mixed_case | ||
schema mIxEd_cAsE | ||
--- | ||
CREATE TABLE mixed_case ( | ||
äåæ STRING PRIMARY KEY | ||
) | ||
CREATE TABLE mIxEd_cAsE ( | ||
ÄÅÆ STRING PRIMARY KEY | ||
) | ||
|
||
# Unquoted _, number, keyword, and emoji errors. | ||
!> CREATE TABLE _name (id INTEGER PRIMARY KEY) | ||
!> CREATE TABLE 123 (1 INTEGER PRIMARY KEY) | ||
!> CREATE TABLE table (primary INTEGER PRIMARY KEY) | ||
!> CREATE TABLE 👋 (🆔 INTEGER PRIMARY KEY) | ||
--- | ||
Error: invalid input: unexpected character _ | ||
Error: invalid input: expected identifier, got 123 | ||
Error: invalid input: expected identifier, got TABLE | ||
Error: invalid input: unexpected character 👋 | ||
|
||
# Double quotes allow them. | ||
> CREATE TABLE "_name" (id INTEGER PRIMARY KEY) | ||
> CREATE TABLE "123" ("1" INTEGER PRIMARY KEY) | ||
> CREATE TABLE "table" ("primary" INTEGER PRIMARY KEY) | ||
> CREATE TABLE "👋" ("🆔" INTEGER PRIMARY KEY) | ||
schema _name 123 table "👋" | ||
--- | ||
CREATE TABLE "_name" ( | ||
id INTEGER PRIMARY KEY | ||
) | ||
CREATE TABLE "123" ( | ||
"1" INTEGER PRIMARY KEY | ||
) | ||
CREATE TABLE "table" ( | ||
"primary" INTEGER PRIMARY KEY | ||
) | ||
CREATE TABLE "👋" ( | ||
"🆔" INTEGER PRIMARY KEY | ||
) | ||
|
||
# "" escapes " in identifiers. | ||
> CREATE TABLE "name with ""quotes""" (id INTEGER PRIMARY KEY); | ||
schema 'name with "quotes"' | ||
--- | ||
CREATE TABLE "name with ""quotes""" ( | ||
id INTEGER PRIMARY KEY | ||
) | ||
|
||
# ' are for string literals, not identifiers. | ||
!> CREATE TABLE 'name' (id INTEGER PRIMARY KEY) | ||
--- | ||
Error: invalid input: expected identifier, got name |
Oops, something went wrong.