From dfacc9d5c009e2a728310133b2fef327965602c5 Mon Sep 17 00:00:00 2001 From: Philip Wedemann <22521688+hfhbd@users.noreply.github.com> Date: Fri, 15 Jul 2022 19:38:25 +0200 Subject: [PATCH] Fix AS (#3370) * Fix AS * Fix AS in IntelliJ test * Workaround for not working DEFAULT usage Co-authored-by: hfhbd --- .../kotlin/app/cash/sqldelight/core/sqldelight.bnf | 3 ++- .../cash/sqldelight/core/errors/SyntaxErrors.kt | 3 +-- .../app/cash/sqldelight/hsql/integration/Dog.sq | 10 ++++++---- .../cash/sqldelight/hsql/integration/HsqlTest.kt | 4 +++- .../testData/import-inspection/src/CreateTable.sq | 14 +++++++------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/sqldelight.bnf b/sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/sqldelight.bnf index f7e9d2aee7b..bdcef067dbd 100644 --- a/sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/sqldelight.bnf +++ b/sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/sqldelight.bnf @@ -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" @@ -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" diff --git a/sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/errors/SyntaxErrors.kt b/sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/errors/SyntaxErrors.kt index 0997ba443fe..ff2edc7587a 100644 --- a/sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/errors/SyntaxErrors.kt +++ b/sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/errors/SyntaxErrors.kt @@ -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): ')', ',', or AS expected, got 'as'", ) } } diff --git a/sqldelight-gradle-plugin/src/test/integration-hsql/src/main/sqldelight/app/cash/sqldelight/hsql/integration/Dog.sq b/sqldelight-gradle-plugin/src/test/integration-hsql/src/main/sqldelight/app/cash/sqldelight/hsql/integration/Dog.sq index 0419a00beb1..f1d41860df4 100644 --- a/sqldelight-gradle-plugin/src/test/integration-hsql/src/main/sqldelight/app/cash/sqldelight/hsql/integration/Dog.sq +++ b/sqldelight-gradle-plugin/src/test/integration-hsql/src/main/sqldelight/app/cash/sqldelight/hsql/integration/Dog.sq @@ -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 (?, ?, ?); +INSERT INTO dog (name, breed, is_good, id) +VALUES (?, ?, ?, ?); selectDogs: SELECT * -FROM dog; \ No newline at end of file +FROM dog; diff --git a/sqldelight-gradle-plugin/src/test/integration-hsql/src/test/kotlin/app/cash/sqldelight/hsql/integration/HsqlTest.kt b/sqldelight-gradle-plugin/src/test/integration-hsql/src/test/kotlin/app/cash/sqldelight/hsql/integration/HsqlTest.kt index c7f83c53dcd..94cd092ee67 100644 --- a/sqldelight-gradle-plugin/src/test/integration-hsql/src/test/kotlin/app/cash/sqldelight/hsql/integration/HsqlTest.kt +++ b/sqldelight-gradle-plugin/src/test/integration-hsql/src/test/kotlin/app/cash/sqldelight/hsql/integration/HsqlTest.kt @@ -29,13 +29,15 @@ class HsqlTest { } @Test fun simpleSelect() { - database.dogQueries.insertDog("Tilda", "Pomeranian", true) + database.dogQueries.insertDog("Tilda", "Pomeranian", true, 1) assertThat(database.dogQueries.selectDogs().executeAsOne()) .isEqualTo( Dog( name = "Tilda", breed = "Pomeranian", is_good = true, + id = 1, + id_bigger_than_ten = false, ), ) } diff --git a/sqldelight-idea-plugin/testData/import-inspection/src/CreateTable.sq b/sqldelight-idea-plugin/testData/import-inspection/src/CreateTable.sq index d01ecd010d7..964cb21a28e 100644 --- a/sqldelight-idea-plugin/testData/import-inspection/src/CreateTable.sq +++ b/sqldelight-idea-plugin/testData/import-inspection/src/CreateTable.sq @@ -9,10 +9,10 @@ import kotlin.collections.Set; import org.jetbrains.annotations.Nullable; CREATE TABLE hockeyPlayer( - column1 TEXT as @Nullable String NOT NULL, - column2 TEXT as OffsetDateTime NOT NULL, - column3 TEXT as List NOT NULL, - column4 TEXT as Integer NOT NULL, - column5 TEXT as Map NOT NULL, - column6 TEXT as List NOT NULL -); \ No newline at end of file + column1 TEXT AS @Nullable String NOT NULL, + column2 TEXT AS OffsetDateTime NOT NULL, + column3 TEXT AS List NOT NULL, + column4 TEXT AS Integer NOT NULL, + column5 TEXT AS Map NOT NULL, + column6 TEXT AS List NOT NULL +);