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

SQLite autoincrement table is not created correctly #328

Closed
xgouchet opened this issue Jun 26, 2018 · 4 comments
Closed

SQLite autoincrement table is not created correctly #328

xgouchet opened this issue Jun 26, 2018 · 4 comments

Comments

@xgouchet
Copy link

xgouchet commented Jun 26, 2018

I'm testing exposed with a SQLite driver (https://github.com/xerial/sqlite-jdbc). I use the following table definition :

object Polls : Table() {
    val id = integer("id").primaryKey().autoIncrement()
    val question = varchar("question", 255)
}

And my insert method is doing this :

fun createNewPoll(question : String) : Int?{
        return Polls.insert({ p ->
            p[question] = poll.question
        }) get Polls.id
}

But when I try to insert a new entry, leaving the id empty to let the autoincrement do its job, I get the following error :

Caused by: org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_NOTNULL]  A NOT NULL constraint failed (NOT NULL constraint failed: Polls.id)
	at org.sqlite.core.DB.newSQLException(DB.java:909)
	at org.sqlite.core.DB.newSQLException(DB.java:921)
	at org.sqlite.core.DB.execute(DB.java:825)
	at org.sqlite.core.DB.executeUpdate(DB.java:863)
	at org.sqlite.jdbc3.JDBC3PreparedStatement.executeUpdate(JDBC3PreparedStatement.java:102)
	at org.jetbrains.exposed.sql.statements.InsertStatement.execInsertFunction(InsertStatement.kt:86)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:95)
	at org.jetbrains.exposed.sql.statements.InsertStatement.executeInternal(InsertStatement.kt:12)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed(Statement.kt:59)
	... 24 common frames omitted

When looking into the created file, here's what it looks like :

CREATE TABLE Polls (
    id INTEGER AUTO_INCREMENT NOT NULL, 
    question VARCHAR(255) NOT NULL, 
    CONSTRAINT pk_Polls PRIMARY KEY (id)
)

which uses AUTO_INCREMENT instead of AUTOINCREMENT

@Tapac
Copy link
Contributor

Tapac commented Jun 26, 2018

Thank you for a report, strange that none of the unit-tests hit that problem.
Possibly that if there is not AUTO_INCREMENT column then PreparedStatatement.generatedKeys() returns ROW_ID.

Release with the fix for that issue will be available on the next week.

@Tapac Tapac closed this as completed Jun 26, 2018
@tapanrgohil
Copy link

@Tapac
Please merge this commit to master branch as still it is failing in current version.

tapanrgohil added a commit to tapanrgohil/Exposed that referenced this issue Jan 18, 2019
JetBrains#328
AUTO_INCREMENT changed to AUTOINCREMENT for sqllite
@Tapac
Copy link
Contributor

Tapac commented Jan 18, 2019

@tapanrgohil , oh thank you for your attention, I've just noticed that the fix was committed to non-master branch. I'll cherry-pick it and reject your PR.

Release is planned on today-tomorrow.

@tapanrgohil
Copy link

tapanrgohil commented Jan 18, 2019

@Tapac actually this pr is from current master branch . I think you can merge it

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

No branches or pull requests

3 participants