Skip to content

Commit b142e59

Browse files
authored
Emulate the VERSION() function in the SQLite driver (#281)
Emulate the `VERSION()` function in the SQLite driver This replaces the old implementation from the legacy SQLite translator that's defined in `WP_SQLite_PDO_User_Defined_Functions` and returns `5.5`. Emulating it directly in the driver should also be faster than calling a PHP function from SQLite. This function is used in WordPress core and causes outdated database warning on the Site Health screen.
1 parent def2400 commit b142e59

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11134,4 +11134,9 @@ public function testUpdateErrorsInNonStrictMode(): void {
1113411134
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'missing_column' in 'field list'"
1113511135
);
1113611136
}
11137+
11138+
public function testVersionFunction(): void {
11139+
$result = $this->engine->query( 'SELECT VERSION()' );
11140+
$this->assertSame( '8.0.38', $result[0]->{'VERSION()'} );
11141+
}
1113711142
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,15 @@ private function translate_function_call( WP_Parser_Node $node ): string {
39633963
$found_rows = count( $this->last_result );
39643964
}
39653965
return $found_rows;
3966+
case 'VERSION':
3967+
$version = (string) $this->mysql_version;
3968+
$value = sprintf(
3969+
'%d.%d.%d',
3970+
$version[0],
3971+
substr( $version, 1, 2 ),
3972+
substr( $version, 3, 2 )
3973+
);
3974+
return $this->connection->quote( $value );
39663975
default:
39673976
return $this->translate_sequence( $node->get_children() );
39683977
}

0 commit comments

Comments
 (0)