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
250 changes: 247 additions & 3 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ public function testShowGrantsFor() {
$result,
array(
(object) array(
'Grants for root@localhost' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION',
'Grants for root@%' => 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `root`@`localhost` WITH GRANT OPTION',
),
)
);
Expand Down Expand Up @@ -4204,7 +4204,7 @@ public function getReservedPrefixTestData(): array {
public function testInformationSchemaIsReadonly( string $query ): void {
$this->assertQuery( 'CREATE TABLE tables (id INT)' );
$this->expectException( WP_SQLite_Driver_Exception::class );
$this->expectExceptionMessage( "Access denied for user 'sqlite'@'%' to database 'information_schema'" );
$this->expectExceptionMessage( "Access denied for user 'root'@'%' to database 'information_schema'" );
$this->assertQuery( $query );
}

Expand Down Expand Up @@ -4236,7 +4236,7 @@ public function getInformationSchemaIsReadonlyTestData(): array {
public function testInformationSchemaIsReadonlyWithUse( string $query ): void {
$this->assertQuery( 'CREATE TABLE tables (id INT)' );
$this->expectException( WP_SQLite_Driver_Exception::class );
$this->expectExceptionMessage( "Access denied for user 'sqlite'@'%' to database 'information_schema'" );
$this->expectExceptionMessage( "Access denied for user 'root'@'%' to database 'information_schema'" );
$this->assertQuery( 'USE information_schema' );
$this->assertQuery( $query );
}
Expand Down Expand Up @@ -9809,4 +9809,248 @@ public function testWriteWithUsageOfInformationSchemaTables(): void {
$result
);
}

public function testNonEmptyColumnMeta(): void {
$this->assertQuery( 'CREATE TABLE t (id INT PRIMARY KEY)' );
$this->assertQuery( 'INSERT INTO t VALUES (1)' );

// SELECT
$this->assertQuery( 'SELECT * FROM t' );
$this->assertSame( 1, $this->engine->get_last_column_count() );
$this->assertSame( 'id', $this->engine->get_last_column_meta()[0]['name'] );

// SHOW COLLATION
$this->assertQuery( 'SHOW COLLATION' );
$this->assertSame( 7, $this->engine->get_last_column_count() );
$this->assertSame( 'Collation', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Charset', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Id', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Default', $this->engine->get_last_column_meta()[3]['name'] );
$this->assertSame( 'Compiled', $this->engine->get_last_column_meta()[4]['name'] );
$this->assertSame( 'Sortlen', $this->engine->get_last_column_meta()[5]['name'] );
$this->assertSame( 'Pad_attribute', $this->engine->get_last_column_meta()[6]['name'] );

// SHOW DATABASES
$this->assertQuery( 'SHOW DATABASES' );
$this->assertSame( 1, $this->engine->get_last_column_count() );
$this->assertSame( 'Database', $this->engine->get_last_column_meta()[0]['name'] );

// SHOW CREATE TABLE
$this->assertQuery( 'SHOW CREATE TABLE t' );
$this->assertSame( 2, $this->engine->get_last_column_count() );
$this->assertSame( 'Table', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Create Table', $this->engine->get_last_column_meta()[1]['name'] );

// SHOW TABLE STATUS
$this->assertQuery( 'SHOW TABLE STATUS' );
$this->assertSame( 18, $this->engine->get_last_column_count() );
$this->assertSame( 'Name', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Engine', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Version', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Row_format', $this->engine->get_last_column_meta()[3]['name'] );
$this->assertSame( 'Rows', $this->engine->get_last_column_meta()[4]['name'] );
$this->assertSame( 'Avg_row_length', $this->engine->get_last_column_meta()[5]['name'] );
$this->assertSame( 'Data_length', $this->engine->get_last_column_meta()[6]['name'] );
$this->assertSame( 'Max_data_length', $this->engine->get_last_column_meta()[7]['name'] );
$this->assertSame( 'Index_length', $this->engine->get_last_column_meta()[8]['name'] );
$this->assertSame( 'Data_free', $this->engine->get_last_column_meta()[9]['name'] );
$this->assertSame( 'Auto_increment', $this->engine->get_last_column_meta()[10]['name'] );
$this->assertSame( 'Create_time', $this->engine->get_last_column_meta()[11]['name'] );
$this->assertSame( 'Update_time', $this->engine->get_last_column_meta()[12]['name'] );
$this->assertSame( 'Check_time', $this->engine->get_last_column_meta()[13]['name'] );
$this->assertSame( 'Collation', $this->engine->get_last_column_meta()[14]['name'] );
$this->assertSame( 'Checksum', $this->engine->get_last_column_meta()[15]['name'] );
$this->assertSame( 'Create_options', $this->engine->get_last_column_meta()[16]['name'] );
$this->assertSame( 'Comment', $this->engine->get_last_column_meta()[17]['name'] );

// SHOW TABLES
$this->assertQuery( 'SHOW TABLES' );
$this->assertSame( 1, $this->engine->get_last_column_count() );
$this->assertSame( 'Tables_in_wp', $this->engine->get_last_column_meta()[0]['name'] );

// SHOW FULL TABLES
$this->assertQuery( 'SHOW FULL TABLES' );
$this->assertSame( 2, $this->engine->get_last_column_count() );
$this->assertSame( 'Tables_in_wp', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Table_type', $this->engine->get_last_column_meta()[1]['name'] );

// SHOW COLUMNS
$this->assertQuery( 'SHOW COLUMNS FROM t' );
$this->assertSame( 6, $this->engine->get_last_column_count() );
$this->assertSame( 'Field', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Type', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Null', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Key', $this->engine->get_last_column_meta()[3]['name'] );
$this->assertSame( 'Default', $this->engine->get_last_column_meta()[4]['name'] );
$this->assertSame( 'Extra', $this->engine->get_last_column_meta()[5]['name'] );

// SHOW INDEX
$this->assertQuery( 'SHOW INDEX FROM t' );
$this->assertSame( 15, $this->engine->get_last_column_count() );
$this->assertSame( 'Table', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Non_unique', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Key_name', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Seq_in_index', $this->engine->get_last_column_meta()[3]['name'] );
$this->assertSame( 'Column_name', $this->engine->get_last_column_meta()[4]['name'] );
$this->assertSame( 'Collation', $this->engine->get_last_column_meta()[5]['name'] );
$this->assertSame( 'Cardinality', $this->engine->get_last_column_meta()[6]['name'] );
$this->assertSame( 'Sub_part', $this->engine->get_last_column_meta()[7]['name'] );
$this->assertSame( 'Packed', $this->engine->get_last_column_meta()[8]['name'] );
$this->assertSame( 'Null', $this->engine->get_last_column_meta()[9]['name'] );
$this->assertSame( 'Index_type', $this->engine->get_last_column_meta()[10]['name'] );
$this->assertSame( 'Comment', $this->engine->get_last_column_meta()[11]['name'] );
$this->assertSame( 'Index_comment', $this->engine->get_last_column_meta()[12]['name'] );
$this->assertSame( 'Visible', $this->engine->get_last_column_meta()[13]['name'] );
$this->assertSame( 'Expression', $this->engine->get_last_column_meta()[14]['name'] );

// SHOW GRANTS
$this->assertQuery( 'SHOW GRANTS' );
$this->assertSame( 1, $this->engine->get_last_column_count() );
$this->assertSame( 'Grants for root@%', $this->engine->get_last_column_meta()[0]['name'] );

// SHOW VARIABLES
$this->assertQuery( 'SHOW VARIABLES' );
$this->assertSame( 2, $this->engine->get_last_column_count() );
$this->assertSame( 'Variable_name', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Value', $this->engine->get_last_column_meta()[1]['name'] );

// DESCRIBE/EXPLAIN
$this->assertQuery( 'DESCRIBE t' );
$this->assertSame( 6, $this->engine->get_last_column_count() );
$this->assertSame( 'Field', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Type', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Null', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Key', $this->engine->get_last_column_meta()[3]['name'] );
$this->assertSame( 'Default', $this->engine->get_last_column_meta()[4]['name'] );
$this->assertSame( 'Extra', $this->engine->get_last_column_meta()[5]['name'] );

// ANALYZE TABLE
$this->assertQuery( 'ANALYZE TABLE t' );
$this->assertSame( 4, $this->engine->get_last_column_count() );
$this->assertSame( 'Table', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Op', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Msg_type', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Msg_text', $this->engine->get_last_column_meta()[3]['name'] );

// CHECK TABLE
$this->assertQuery( 'CHECK TABLE t' );
$this->assertSame( 4, $this->engine->get_last_column_count() );
$this->assertSame( 'Table', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Op', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Msg_type', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Msg_text', $this->engine->get_last_column_meta()[3]['name'] );

// OPTIMIZE TABLE
$this->assertQuery( 'OPTIMIZE TABLE t' );
$this->assertSame( 4, $this->engine->get_last_column_count() );
$this->assertSame( 'Table', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Op', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Msg_type', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Msg_text', $this->engine->get_last_column_meta()[3]['name'] );

// REPAIR TABLE
$this->assertQuery( 'REPAIR TABLE t' );
$this->assertSame( 4, $this->engine->get_last_column_count() );
$this->assertSame( 'Table', $this->engine->get_last_column_meta()[0]['name'] );
$this->assertSame( 'Op', $this->engine->get_last_column_meta()[1]['name'] );
$this->assertSame( 'Msg_type', $this->engine->get_last_column_meta()[2]['name'] );
$this->assertSame( 'Msg_text', $this->engine->get_last_column_meta()[3]['name'] );
}

public function testEmptyColumnMeta(): void {
// CREATE TABLE
$this->assertQuery( 'CREATE TABLE t (id INT)' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// INSERT
$this->assertQuery( 'INSERT INTO t (id) VALUES (1)' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// REPLACE
$this->assertQuery( 'UPDATE t SET id = 1' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// DELETE
$this->assertQuery( 'DELETE FROM t' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// TRUNCATE TABLE
$this->assertQuery( 'TRUNCATE TABLE t' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// START TRANSACTION
$this->assertQuery( 'START TRANSACTION' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// COMMIT
$this->assertQuery( 'COMMIT' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// ROLLBACK
$this->assertQuery( 'ROLLBACK' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// SAVEPOINT
$this->assertQuery( 'SAVEPOINT s1' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// ROLLBACK TO SAVEPOINT
$this->assertQuery( 'ROLLBACK TO SAVEPOINT s1' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// RELEASE SAVEPOINT
$this->assertQuery( 'RELEASE SAVEPOINT s1' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// LOCK TABLE
$this->assertQuery( 'LOCK TABLES t READ' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// UNLOCK TABLE
$this->assertQuery( 'UNLOCK TABLES' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// ALTER TABLE
$this->assertQuery( 'ALTER TABLE t ADD COLUMN name VARCHAR(255)' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// CREATE INDEX
$this->assertQuery( 'CREATE INDEX idx_name ON t (name)' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// DROP INDEX
$this->assertQuery( 'DROP INDEX idx_name ON t' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// DROP TABLE
$this->assertQuery( 'DROP TABLE t' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// USE
$this->assertQuery( 'USE wp' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );

// SET
$this->assertQuery( 'SET @my_var = 1' );
$this->assertSame( 0, $this->engine->get_last_column_count() );
$this->assertSame( array(), $this->engine->get_last_column_meta() );
}
}
Loading
Loading