orangy / squash

SQL access DSL for Kotlin
265 stars 16 forks source link

Default value in TableDefinition causes `no parameter $1` when creating table #20

Open janvladimirmostert opened 5 years ago

janvladimirmostert commented 5 years ago

This happens on Postgres, haven't tried it on other databases.

I create a test table, notice the .default("TEST123") on the name-column:

    object TestEntity : TableDefinition(name = "test") {
        val id = integer("id").autoIncrement().primaryKey()
        val name = varchar("name", 50).default("TEST123")
    }

Now when I try and use this TableDefinition to generate a scema:

val trans = DatabaseHandler.createTransaction()
trans.databaseSchema().create(listOf(TestEntity))

I get the following error:

Exception in thread "main" org.postgresql.util.PSQLException: ERROR: there is no parameter $1
CREATE TABLE IF NOT EXISTS test (id SERIAL NOT NULL, name VARCHAR(50) NOT NULL DEFAULT ?, CONSTRAINT PK_test PRIMARY KEY (id))
Arguments: [SQLArgument(index=0, value=TEST123)]

    at org.jetbrains.squash.drivers.JDBCTransaction.executeStatement(JDBCTransaction.kt:87)
    at org.jetbrains.squash.schema.DatabaseSchemaBase.create(DatabaseSchemaBase.kt:12)
    at Tables.main(Tables.kt:14)
Caused by: org.postgresql.util.PSQLException: ERROR: there is no parameter $1
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
    at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132)
    at org.jetbrains.squash.drivers.JDBCTransaction.executeStatement(JDBCTransaction.kt:75)
    ... 2 more