Skip to content

Commit 0d0349e

Browse files
committed
Explicitly disable CREATE TABLE ... [AS] SELECT statements
1 parent bdc12f3 commit 0d0349e

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

tests/WP_SQLite_Driver_Translation_Tests.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ public function testCreateTableWithStandaloneUniqueIndexes(): void {
480480
);
481481
}
482482

483-
public function testCreateTableFromSelectQuery(): void {
483+
// @TODO: Implement information schema support for CREATE TABLE ... AS SELECT.
484+
/*public function testCreateTableFromSelectQuery(): void {
484485
// CREATE TABLE AS SELECT ...
485486
$this->assertQuery(
486487
'CREATE TABLE `t1` AS SELECT * FROM `t2` STRICT',
@@ -493,7 +494,7 @@ public function testCreateTableFromSelectQuery(): void {
493494
'CREATE TABLE `t1` AS SELECT * FROM `t2` STRICT',
494495
'CREATE TABLE t1 SELECT * FROM t2'
495496
);
496-
}
497+
}*/
497498

498499
// TODO: IF NOT EXISTS
499500
/*public function testCreateTemporaryTable(): void {

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,14 +1086,22 @@ private function execute_delete_statement( WP_Parser_Node $node ): void {
10861086
private function execute_create_table_statement( WP_Parser_Node $node ): void {
10871087
$subnode = $node->get_first_child_node();
10881088

1089-
// Handle TEMPORARY and CREATE TABLE ... SELECT.
1089+
// Handle TEMPORARY keyword.
10901090
$table_is_temporary = $subnode->has_child_token( WP_MySQL_Lexer::TEMPORARY_SYMBOL );
1091-
$element_list = $subnode->get_first_child_node( 'tableElementList' );
1091+
1092+
// Handle CREATE TABLE ... [AS] SELECT.
1093+
$element_list = $subnode->get_first_child_node( 'tableElementList' );
10921094
if ( null === $element_list ) {
1093-
$query = $this->translate( $node ) . ' STRICT';
1094-
$this->execute_sqlite_query( $query );
1095-
$this->set_result_from_affected_rows();
1096-
return;
1095+
/*
1096+
* While SQLite supports CREATE TABLE ... AS SELECT statements,
1097+
* we need to somehow implement information schema support for
1098+
* the tables created in this way.
1099+
*
1100+
* TODO: Implement information schema support for CREATE TABLE ... AS SELECT.
1101+
*/
1102+
throw $this->new_not_supported_exception(
1103+
'CREATE TABLE ... [AS] SELECT is currently not supported'
1104+
);
10971105
}
10981106

10991107
// Get table name.

0 commit comments

Comments
 (0)