Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 0690f44

Browse files
committed
Check for auto increment edge case, add test
1 parent 4dae813 commit 0690f44

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,4 +3885,12 @@ public function testTimestampColumnNamedTimestamp() {
38853885
$results
38863886
);
38873887
}
3888+
3889+
public function testCompoundPrimaryKeyAndAutoincrementNotSupported(): void {
3890+
$this->expectException( WP_SQLite_Driver_Exception::class );
3891+
$this->expectExceptionMessage( 'Cannot combine AUTOINCREMENT and multiple primary keys in SQLite' );
3892+
$this->assertQuery(
3893+
'CREATE TABLE t1 (id1 INT AUTO_INCREMENT, id2 INT, PRIMARY KEY(id1, id2))'
3894+
);
3895+
}
38883896
}

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,11 @@ private function get_sqlite_create_table_statement( string $table_name, ?string
26412641

26422642
if ( 'PRIMARY' === $info['INDEX_NAME'] ) {
26432643
if ( $has_autoincrement ) {
2644+
if ( count( $constraint ) > 1 ) {
2645+
throw $this->new_driver_exception(
2646+
'Cannot combine AUTOINCREMENT and multiple primary keys in SQLite'
2647+
);
2648+
}
26442649
continue;
26452650
}
26462651
$query = ' PRIMARY KEY (';

0 commit comments

Comments
 (0)