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

Complex insert statement does not compile #262

Open
melbic opened this issue May 10, 2021 · 2 comments
Open

Complex insert statement does not compile #262

melbic opened this issue May 10, 2021 · 2 comments
Labels

Comments

@melbic
Copy link

melbic commented May 10, 2021

Dialect: SQLite

failing sql:

WITH new(number, modificationDate, firstName, lastName, languageId, telephoneNumber1, email1, street, city, zipCode, countryId) AS ( VALUES (?,?,?,?,?,?,?,?,?,?,?) )
 INSERT OR REPLACE INTO customer (localId, number, modificationDate, firstName, lastName, languageId, telephoneNumber1, email1, street, city, zipCode, countryId)
 SELECT old.localId, new.number, new.modificationDate, new.firstName, new.lastName, new.languageId, new.telephoneNumber1, new.email1, new.street, new.city, new.zipCode, new.countryId
 FROM new LEFT JOIN customer AS old ON new.number = old.number;

The above statements doe not compile in sqldelight with the error: Cannot bind unknown types or null. Running it as a SQL statement works fine.

Scheme:

import java.time.LocalDateTime;
import ch.dreipol.app.database.extensions.CustomerID;


CREATE TABLE customer (
localId INTEGER AS CustomerID NOT NULL PRIMARY KEY AUTOINCREMENT,
number TEXT,
modificationDate TEXT AS LocalDateTime,
firstName TEXT,
lastName TEXT,
languageId TEXT,
telephoneNumber1 TEXT,
email1 TEXT,

street TEXT,
city TEXT,
zipCode TEXT,
countryId TEXT
);

CREATE INDEX customer_number ON customer(number);
CREATE INDEX customer_lastName ON customer(lastName);

Helper classes:

import com.squareup.sqldelight.ColumnAdapter
import java.time.LocalDateTime

class LocalDateTimeAdapter : ColumnAdapter<LocalDateTime, String> {
    override fun decode(databaseValue: String): LocalDateTime {
        return LocalDateTime.parse(databaseValue)
    }

    override fun encode(value: LocalDateTime): String {
        return value.toString()
    }
}

typealias CustomerID = Long
@veyndan veyndan added the sqlite label May 10, 2021
@AlecKazakova
Copy link
Collaborator

AlecKazakova commented May 10, 2021 via email

@melbic
Copy link
Author

melbic commented May 10, 2021

Sure. I added the scheme and the used helper classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants