-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
allow creating PRIMARY KEY AUTOINCREMENT fields for sqlite (unit tests) #3141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,4 +232,29 @@ public function getDiffListIntegerAutoincrementTableColumnsData() | |
array('bigint', true, true), | ||
); | ||
} | ||
|
||
/** | ||
* @group DBAL-2921 | ||
*/ | ||
public function testPrimaryKeyNoAutoIncrement() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to cover this case with a test? Is it something DBAL users could/would want to rely on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test was added by the original author to check that the default behavior of SQLite wasn't altered in cases it shouldn't. |
||
{ | ||
$table = new Schema\Table('test_pk_auto_increment'); | ||
$table->addColumn('id', 'integer'); | ||
$table->addColumn('text', 'text'); | ||
$table->setPrimaryKey(['id']); | ||
$this->_sm->dropAndCreateTable($table); | ||
|
||
$this->_conn->insert('test_pk_auto_increment', ['text' => '1']); | ||
|
||
$this->_conn->query('DELETE FROM test_pk_auto_increment'); | ||
|
||
$this->_conn->insert('test_pk_auto_increment', ['text' => '2']); | ||
|
||
$query = $this->_conn->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"'); | ||
$query->execute(); | ||
$lastUsedIdAfterDelete = (int) $query->fetchColumn(); | ||
|
||
// with an empty table, non autoincrement rowid is always 1 | ||
$this->assertEquals(1, $lastUsedIdAfterDelete); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you check if it's technically possible to have a PK which consists of multiple columns one or more of which has
AUTOINCREMENT
? If yes, then it would be a breaking change since in this case, the PK will consist only declared for the autoincremented column.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's currently not possible. It will result in a
MappingException
while generating the scheme:"Single id is not allowed on composite primary key in entity...."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking about SQLite itself, not the ORM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can read online it's either a composite key, or a single autoincrement key. The combination seems not possible in SQLite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we're not breaking anything. Sounds good.