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] fixing a bug in creating table with autoInc column and custom primarykey #755

Merged
merged 1 commit into from
Jan 7, 2020

Conversation

hfazai
Copy link
Contributor

@hfazai hfazai commented Jan 4, 2020

Creating a table that has an autoIncrement column and a custom primarykey (that contains single column) causes an error in SQLite dialect. Here is an example :

object Test : Table("Test") {
        val id = integer("id").autoIncrement()

        // Rest of columns

        override val primaryKey = PrimaryKey(id, name = "PKConstraintName")
    }

SQL generated :

CREATE TABLE IF NOT EXISTS Test(id INTEGER PRIMARY KEY AUTOINCREMENT, CONSTRAINT PKConstraintName PRIMARY KEY (id))

Error : SQL error or missing database (table "Test" has more than one primary key)

.

=> So in this PR I did a little change to consider this case.

Comment on lines -70 to 71
isSQLiteAutoIncColumn && !isOneColumnPK() && table.primaryKey != null -> append(currentDialect.dataTypeProvider.integerType())
isSQLiteAutoIncColumn && (!isOneColumnPK() || table.isCustomPKNameDefined()) && table.primaryKey != null -> append(currentDialect.dataTypeProvider.integerType())
else -> append(colType.sqlType())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When using SQLite : If isOneColumnPK() = true and the column type is integerAutoincType, then colType.sqlType() returns : "INTEGER PRIMARY KEY AUTOINCREMENT" at the same time when defining a costom primaryKey name, a primary key constraint is generated too. That's why we get the error.
Here I added a condition to prevent defining primary key multiple times.

@hfazai hfazai changed the title [SQLite] fixing a bug that happens when creating table with autoInc c… [SQLite] fixing a bug in creating table with autoInc column and custom primarykey Jan 4, 2020
@Tapac Tapac merged commit 3af6614 into JetBrains:master Jan 7, 2020
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

Successfully merging this pull request may close these issues.

2 participants