Skip to content

Commit 49e482f

Browse files
committed
Avoid using the IIF() function due to lack of support on old SQLite versions
1 parent e083f95 commit 49e482f

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,7 +2630,9 @@ private function execute_show_databases_statement( WP_Parser_Node $node ): void
26302630
sprintf(
26312631
'SELECT SCHEMA_NAME AS Database
26322632
FROM (
2633-
SELECT IIF(SCHEMA_NAME = ?, ?, SCHEMA_NAME) AS SCHEMA_NAME FROM %s ORDER BY SCHEMA_NAME
2633+
SELECT CASE WHEN SCHEMA_NAME = ? THEN ? ELSE SCHEMA_NAME END AS SCHEMA_NAME
2634+
FROM %s
2635+
ORDER BY SCHEMA_NAME
26342636
)%s',
26352637
$this->quote_sqlite_identifier( $schemata_table ),
26362638
isset( $condition ) ? ( ' WHERE TRUE ' . $condition ) : ''
@@ -4372,7 +4374,7 @@ public function translate_select_item( WP_Parser_Node $node ): string {
43724374
* SELECT *, `t`.*, `t`.`table_schema` FROM (
43734375
* SELECT
43744376
* `TABLE_CATALOG`,
4375-
* IIF(`TABLE_SCHEMA` = 'information_schema', `TABLE_SCHEMA`, 'database_name') AS `TABLE_SCHEMA`,
4377+
* CASE WHEN `TABLE_SCHEMA` = 'information_schema' THEN `TABLE_SCHEMA` ELSE 'database_name' END AS `TABLE_SCHEMA`,
43764378
* `TABLE_NAME`,
43774379
* ...
43784380
* FROM `_wp_sqlite_mysql_information_schema_tables` AS `tables`
@@ -4442,7 +4444,7 @@ public function translate_table_ref( WP_Parser_Node $node ): string {
44424444
$quoted_column = $this->quote_sqlite_identifier( $column );
44434445
if ( isset( $information_schema_db_column_map[ strtoupper( $column ) ] ) ) {
44444446
$expanded_list[] = sprintf(
4445-
"IIF(%s = 'information_schema', %s, %s) AS %s",
4447+
"CASE WHEN %s = 'information_schema' THEN %s ELSE %s END AS %s",
44464448
$quoted_column,
44474449
$quoted_column,
44484450
$this->connection->quote( $this->main_db_name ),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function ensure_database_data(): void {
231231
SET
232232
TABLE_SCHEMA = ?,
233233
CONSTRAINT_SCHEMA = ?,
234-
REFERENCED_TABLE_SCHEMA = IIF(REFERENCED_TABLE_SCHEMA IS NULL, NULL, ?)
234+
REFERENCED_TABLE_SCHEMA = CASE WHEN REFERENCED_TABLE_SCHEMA IS NULL THEN NULL ELSE ? END
235235
WHERE TABLE_SCHEMA != 'information_schema'",
236236
$this->driver->get_connection()->quote_identifier( $key_column_usage_table )
237237
),

0 commit comments

Comments
 (0)