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
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]

with:
os: ${{ matrix.os }}
Expand Down
3 changes: 2 additions & 1 deletion packages/wp-mysql-proxy/tests/WP_MySQL_Proxy_PDO_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class WP_MySQL_Proxy_PDO_Test extends WP_MySQL_Proxy_Test {
public function setUp(): void {
parent::setUp();

$this->pdo = new PDO(
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->pdo = new $pdo_class(
sprintf( 'mysql:host=127.0.0.1;port=%d', $this->port ),
'user',
'password'
Expand Down
3 changes: 2 additions & 1 deletion tests/WP_SQLite_Driver_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class WP_SQLite_Driver_Metadata_Tests extends TestCase {

// Before each test, we create a new database
public function setUp(): void {
$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
$this->engine = new WP_SQLite_Driver(
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
'wp'
Expand Down
3 changes: 2 additions & 1 deletion tests/WP_SQLite_Driver_Query_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function setUp(): void {
global $tables;
$queries = explode( ';', $tables );

$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
$this->engine = new WP_SQLite_Driver(
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
'wp'
Expand Down
6 changes: 4 additions & 2 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class WP_SQLite_Driver_Tests extends TestCase {

// Before each test, we create a new database
public function setUp(): void {
$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );

$this->engine = new WP_SQLite_Driver(
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
Expand Down Expand Up @@ -6059,7 +6060,8 @@ public function testComplexInformationSchemaQueries(): void {
}

public function testDatabaseNameEmpty(): void {
$pdo = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$pdo = new $pdo_class( 'sqlite::memory:' );
$connection = new WP_SQLite_Connection( array( 'pdo' => $pdo ) );

$this->expectException( WP_SQLite_Driver_Exception::class );
Expand Down
3 changes: 2 additions & 1 deletion tests/WP_SQLite_Information_Schema_Reconstructor_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function wp_get_db_schema() {

// Before each test, we create a new database
public function setUp(): void {
$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
$this->engine = new WP_SQLite_Driver(
new WP_SQLite_Connection( array( 'pdo' => $this->sqlite ) ),
'wp'
Expand Down
3 changes: 2 additions & 1 deletion tests/WP_SQLite_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public function setUp(): void {
global $blog_tables;
$queries = explode( ';', $blog_tables );

$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
$this->engine = new WP_SQLite_Translator( $this->sqlite );

$translator = $this->engine;
Expand Down
5 changes: 3 additions & 2 deletions tests/WP_SQLite_PDO_User_Defined_Functions_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class WP_SQLite_PDO_User_Defined_Functions_Tests extends TestCase {
* @dataProvider dataProviderForTestFieldFunction
*/
public function testFieldFunction( $expected, $args ) {
$pdo = new PDO( 'sqlite::memory:' );
$fns = WP_SQLite_PDO_User_Defined_Functions::register_for( $pdo );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$pdo = new $pdo_class( 'sqlite::memory:' );
$fns = WP_SQLite_PDO_User_Defined_Functions::register_for( $pdo );

$this->assertEquals(
$expected,
Expand Down
3 changes: 2 additions & 1 deletion tests/WP_SQLite_Query_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function setUp(): void {
global $blog_tables;
$queries = explode( ';', $blog_tables );

$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );
$this->engine = new WP_SQLite_Translator( $this->sqlite );

$translator = $this->engine;
Expand Down
3 changes: 2 additions & 1 deletion tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class WP_SQLite_Translator_Tests extends TestCase {

// Before each test, we create a new database
public function setUp(): void {
$this->sqlite = new PDO( 'sqlite::memory:' );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->sqlite = new $pdo_class( 'sqlite::memory:' );

$this->engine = new WP_SQLite_Translator( $this->sqlite );
$this->engine->query(
Expand Down
6 changes: 3 additions & 3 deletions wp-includes/mysql/class-wp-mysql-lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2615,15 +2615,15 @@ private function read_identifier(): ?int {
// If it can't, bail out early to avoid unnecessary UTF-8 decoding.
// Identifiers are usually ASCII-only, so we can optimize for that.
$byte_1 = ord(
$this->sql[ $this->bytes_already_read ] ?? ''
$this->sql[ $this->bytes_already_read ] ?? "\0"
);
if ( $byte_1 < 0xC2 || $byte_1 > 0xEF ) {
break;
}

// Look for a valid 2-byte UTF-8 symbol. Covers range U+0080 - U+07FF.
$byte_2 = ord(
$this->sql[ $this->bytes_already_read + 1 ] ?? ''
$this->sql[ $this->bytes_already_read + 1 ] ?? "\0"
);
if (
$byte_1 <= 0xDF
Expand All @@ -2635,7 +2635,7 @@ private function read_identifier(): ?int {

// Look for a valid 3-byte UTF-8 symbol in range U+0800 - U+FFFF.
$byte_3 = ord(
$this->sql[ $this->bytes_already_read + 2 ] ?? ''
$this->sql[ $this->bytes_already_read + 2 ] ?? "\0"
);
if (
$byte_1 <= 0xEF
Expand Down
3 changes: 2 additions & 1 deletion wp-includes/sqlite-ast/class-wp-sqlite-connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function __construct( array $options ) {
if ( ! isset( $options['path'] ) || ! is_string( $options['path'] ) ) {
throw new InvalidArgumentException( 'Option "path" is required when "connection" is not provided.' );
}
$this->pdo = new PDO( 'sqlite:' . $options['path'] );
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$this->pdo = new $pdo_class( 'sqlite:' . $options['path'] );
}

// Throw exceptions on error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ class WP_SQLite_PDO_User_Defined_Functions {
* Registers the user defined functions for SQLite to a PDO instance.
* The functions are registered using PDO::sqliteCreateFunction().
*
* @param PDO $pdo The PDO object.
* @param PDO|PDO\SQLite $pdo The PDO object.
*/
public static function register_for( PDO $pdo ): self {
public static function register_for( $pdo ): self {
$instance = new self();
foreach ( $instance->functions as $f => $t ) {
$pdo->sqliteCreateFunction( $f, array( $instance, $t ) );
if ( $pdo instanceof PDO\SQLite ) {
$pdo->createFunction( $f, array( $instance, $t ) );
} else {
$pdo->sqliteCreateFunction( $f, array( $instance, $t ) );
}
}
return $instance;
}
Expand Down
5 changes: 3 additions & 2 deletions wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ public function __construct( $pdo = null ) {
PDO::ATTR_TIMEOUT => 5,
);

$dsn = 'sqlite:' . FQDB;
$pdo = new PDO( $dsn, null, null, $options ); // phpcs:ignore WordPress.DB.RestrictedClasses
$dsn = 'sqlite:' . FQDB;
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class;
$pdo = new $pdo_class( $dsn, null, null, $options );
} catch ( PDOException $ex ) {
$status = $ex->getCode();
if ( self::SQLITE_BUSY === $status || self::SQLITE_LOCKED === $status ) {
Expand Down
6 changes: 4 additions & 2 deletions wp-includes/sqlite/install-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function sqlite_make_db_sqlite() {
$table_schemas = wp_get_db_schema();
$queries = explode( ';', $table_schemas );
try {
$pdo = new PDO( 'sqlite:' . FQDB, null, null, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\SQLite::class : PDO::class; // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
$pdo = new $pdo_class( 'sqlite:' . FQDB, null, null, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses
} catch ( PDOException $err ) {
$err_data = $err->errorInfo; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$message = 'Database connection error!<br />';
Expand Down Expand Up @@ -84,7 +85,8 @@ function sqlite_make_db_sqlite() {
$port = $host_parts[1];
}
$dsn = 'mysql:host=' . $host . '; port=' . $port . '; dbname=' . DB_NAME;
$pdo_mysql = new PDO( $dsn, DB_USER, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
$pdo_class = PHP_VERSION_ID >= 80400 ? PDO\MySQL::class : PDO::class; // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
$pdo_mysql = new $pdo_class( $dsn, DB_USER, DB_PASSWORD, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); // phpcs:ignore WordPress.DB.RestrictedClasses.mysql__PDO
$pdo_mysql->query( 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' );
$pdo_mysql->query( 'SET time_zone = "+00:00";' );
foreach ( $queries as $query ) {
Expand Down
Loading