Skip to content
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

Fix AS #3370

Merged
merged 5 commits into from Jul 15, 2022
Merged

Fix AS #3370

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,6 +25,7 @@
parserImports=[
// If you want to use a token from the core grammar it must be statically imported.
"static com.alecstrong.sql.psi.core.psi.SqlTypes.DEFAULT"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.AS"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.LOCK"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.VALUE"
"static com.alecstrong.sql.psi.core.psi.SqlTypes.VALUES"
Expand All @@ -49,7 +50,7 @@ stmt_clojure_stmt_list ::= {stmt} ';' ( {stmt} ';' ) * {
extends="app.cash.sqldelight.core.lang.psi.ClojureStmtListMixin"
pin(".*") = 1
}
column_type ::= {type_name} [ 'AS' ( VALUE | LOCK | ('@' annotation) * java_type_name ) ] {
column_type ::= {type_name} [ AS ( VALUE | LOCK | ('@' annotation) * java_type_name ) ] {
implements=[
"com.alecstrong.sql.psi.core.psi.SqlColumnType";
"app.cash.sqldelight.core.lang.psi.TypedColumn"
Expand Down
Expand Up @@ -62,8 +62,7 @@ class SyntaxErrors {
)

assertThat(result.errors).containsExactly(
"Test.sq: (2, 8): Reserved keyword in sqlite",
"Test.sq: (2, 16): Expected 'AS', got 'as'",
"Test.sq: (2, 16): ')', ',', <column constraint real> or AS expected, got 'as'",
)
}
}
@@ -1,13 +1,15 @@
CREATE TABLE dog (
name VARCHAR(8) NOT NULL,
breed VARCHAR(40) NOT NULL,
is_good BOOLEAN DEFAULT TRUE NOT NULL
is_good BOOLEAN DEFAULT TRUE NOT NULL,
id INTEGER NOT NULL,
id_bigger_than_ten BOOLEAN AS kotlin.Boolean GENERATED ALWAYS AS (id > 10) NOT NULL
);

insertDog:
INSERT INTO dog
VALUES (?, ?, ?);
VALUES (?, ?, ?, ?);
Copy link
Collaborator Author

@hfhbd hfhbd Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs new release of sql-psi, I added two new columns, one id and one generated. With the current release of sql-psi, the compiler needs 5 parameters, but Hsql expect only 4, you can't update a generated one (workaround use DEFAULT).

Update: DEFAULT does not work, so I added the columns explicitly


selectDogs:
SELECT *
FROM dog;
FROM dog;
Expand Up @@ -29,13 +29,15 @@ class HsqlTest {
}

@Test fun simpleSelect() {
database.dogQueries.insertDog("Tilda", "Pomeranian", true)
database.dogQueries.insertDog("Tilda", "Pomeranian", true, 1, null)
assertThat(database.dogQueries.selectDogs().executeAsOne())
.isEqualTo(
Dog(
name = "Tilda",
breed = "Pomeranian",
is_good = true,
id = 1,
id_bigger_than_ten = false,
),
)
}
Expand Down