numeric rewriting should be case insensitive

This commit is contained in:
Matthew Bucci
2024-10-17 01:18:11 -07:00
parent d8b83c88e2
commit d46dba6148
2 changed files with 26 additions and 3 deletions

View File

@ -96,7 +96,7 @@ class CreateTableSQLRewriter extends AbstractSQLRewriter
$numeric_types_imploded = implode('|', $numeric_types);
// Prepare regex pattern to match 'type(x)'
$pattern = "/(" . $numeric_types_imploded . ")\(\d+\)/";
$pattern = "/(" . $numeric_types_imploded . ")\(\d+\)/i";
// Execute type find & replace
$sql = preg_replace_callback($pattern, function ($matches) {

View File

@ -96,6 +96,29 @@ final class rewriteTest extends TestCase
$this->assertSame(trim($expected), trim($postgresql));
}
public function test_it_handles_numerics_without_auto_incrment_case_insensitively()
{
$sql = <<<SQL
CREATE TABLE IF NOT EXISTS stars_votes (
voter_ip VARCHAR(150) NOT NULL,
post_id BIGINT(20) UNSIGNED NOT NULL,
rating INT(1) UNSIGNED NOT NULL,
PRIMARY KEY (voter_ip, post_id)
)
SQL;
$expected = <<<SQL
CREATE TABLE IF NOT EXISTS stars_votes (
voter_ip VARCHAR(150) NOT NULL,
post_id BIGINT NOT NULL,
rating INT NOT NULL,
PRIMARY KEY (voter_ip, post_id)
);
SQL;
$postgresql = pg4wp_rewrite($sql);
$this->assertSame(trim($expected), trim($postgresql));
}
public function test_it_handles_keys()
{
@ -229,8 +252,8 @@ final class rewriteTest extends TestCase
platform varchar(255),
version varchar(255),
location varchar(10),
user_id BIGINT(48) NOT NULL,
page_id BIGINT(48) NOT NULL,
user_id BIGINT NOT NULL,
page_id BIGINT NOT NULL,
type VARCHAR(100) NOT NULL,
PRIMARY KEY ( "ID" )
);