Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1820,9 +1820,10 @@ private function extract_referential_constraint_data( WP_Parser_Node $node, stri
continue;
}

// Column names are case-insensitive in MySQL.
$is_prefix = true;
foreach ( $reference_parts as $i => $reference_part ) {
if ( $index_columns[ $i ] !== $this->get_value( $reference_part ) ) {
if ( 0 !== strcasecmp( $index_columns[ $i ], $this->get_value( $reference_part ) ) ) {
$is_prefix = false;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,53 @@ public function testInformationSchemaForeignKeysReferencingShorterUniqueKey(): v
);
}

public function testInformationSchemaForeignKeysReferencingColumnsInDifferentLetterCase(): void {
$this->assertQuery(
'CREATE TABLE t1 (
id INT PRIMARY KEY,
code INT,
a INT NOT NULL,
b INT NOT NULL,
UNIQUE KEY u_code (code),
UNIQUE KEY u_a_b (a, b)
)'
);
$this->assertQuery(
'CREATE TABLE t2 (
t1_id INT,
x INT,
y INT,
FOREIGN KEY (t1_id) REFERENCES t1 (ID),
FOREIGN KEY (x, y) REFERENCES t1 (A, b)
)'
);
$this->assertQuery( 'ALTER TABLE t2 ADD COLUMN z INT, ADD CONSTRAINT fk_z FOREIGN KEY (z) REFERENCES t1 (CoDe)' );

$result = $this->assertQuery(
"SELECT constraint_name, unique_constraint_name
FROM information_schema.referential_constraints
WHERE table_name = 't2'
ORDER BY constraint_name"
);
$this->assertEquals(
array(
(object) array(
'CONSTRAINT_NAME' => 'fk_z',
'UNIQUE_CONSTRAINT_NAME' => 'u_code',
),
(object) array(
'CONSTRAINT_NAME' => 't2_ibfk_1',
'UNIQUE_CONSTRAINT_NAME' => 'PRIMARY',
),
(object) array(
'CONSTRAINT_NAME' => 't2_ibfk_2',
'UNIQUE_CONSTRAINT_NAME' => 'u_a_b',
),
),
$result
);
}

public function testInformationSchemaAlterTableAddForeignKeys(): void {
$this->assertQuery( 'CREATE TABLE t1 (id INT PRIMARY KEY, name VARCHAR(255))' );
$this->assertQuery( 'CREATE TABLE t2 (id INT)' );
Expand Down
Loading