Skip to content

Commit 07e383d

Browse files
committed
Support MySQL savepoint rollback variants
1 parent 19f1702 commit 07e383d

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/mysql-on-sqlite/src/postgresql/class-wp-postgresql-driver.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,11 +2583,7 @@ private function get_mysql_savepoint_query( string $query ): ?string {
25832583
if ( WP_MySQL_Lexer::ROLLBACK_SYMBOL === $tokens[0]->id ) {
25842584
$position = 1;
25852585
if ( isset( $tokens[ $position ] ) && WP_MySQL_Lexer::WORK_SYMBOL === $tokens[ $position ]->id ) {
2586-
if ( isset( $tokens[ $position + 1 ] ) && WP_MySQL_Lexer::TO_SYMBOL === $tokens[ $position + 1 ]->id ) {
2587-
throw new InvalidArgumentException( 'Unsupported SAVEPOINT statement.' );
2588-
}
2589-
2590-
return null;
2586+
++$position;
25912587
}
25922588

25932589
if ( isset( $tokens[ $position ] ) && WP_MySQL_Lexer::SAVEPOINT_SYMBOL === $tokens[ $position ]->id ) {

packages/mysql-on-sqlite/tests/WP_PostgreSQL_Driver_Tests.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19309,6 +19309,18 @@ public function test_mysql_savepoint_statements_use_public_query_path(): void {
1930919309
$this->assertSame( array(), $driver->get_last_column_meta() );
1931019310
$this->assertSame( 'ROLLBACK TO SAVEPOINT "s1"', $this->get_last_single_postgresql_sql( $driver ) );
1931119311

19312+
$this->assertSame( 0, $driver->query( 'SAVEPOINT s2' ) );
19313+
$driver->query( 'INSERT INTO savepoint_public VALUES (2)' );
19314+
$this->assertSame( 0, $driver->query( 'ROLLBACK WORK TO s2' ) );
19315+
$this->assertSame( 'ROLLBACK TO SAVEPOINT "s2"', $this->get_last_single_postgresql_sql( $driver ) );
19316+
$this->assertSame( 0, $driver->query( 'RELEASE SAVEPOINT s2' ) );
19317+
19318+
$this->assertSame( 0, $driver->query( 'SAVEPOINT s3' ) );
19319+
$driver->query( 'INSERT INTO savepoint_public VALUES (3)' );
19320+
$this->assertSame( 0, $driver->query( 'ROLLBACK WORK TO SAVEPOINT s3' ) );
19321+
$this->assertSame( 'ROLLBACK TO SAVEPOINT "s3"', $this->get_last_single_postgresql_sql( $driver ) );
19322+
$this->assertSame( 0, $driver->query( 'RELEASE SAVEPOINT s3' ) );
19323+
1931219324
$this->assertSame( 0, $driver->query( 'RELEASE SAVEPOINT s1' ) );
1931319325
$this->assertSame( 0, $driver->get_last_column_count() );
1931419326
$this->assertSame( array(), $driver->get_last_column_meta() );
@@ -19325,8 +19337,7 @@ public function test_mysql_savepoint_statements_use_public_query_path(): void {
1932519337
public function test_unsupported_mysql_savepoint_statements_fail_closed_without_backend_execution(): void {
1932619338
$cases = array(
1932719339
'RELEASE s',
19328-
'ROLLBACK WORK TO SAVEPOINT s',
19329-
'ROLLBACK WORK TO s',
19340+
'ROLLBACK SAVEPOINT s',
1933019341
);
1933119342

1933219343
foreach ( $cases as $query ) {

0 commit comments

Comments
 (0)