Skip to content

Commit 24d1fad

Browse files
committed
Add missing schema fields
1 parent 2478ce4 commit 24d1fad

2 files changed

Lines changed: 69 additions & 48 deletions

File tree

tests/WP_SQLite_Metadata_Tests.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,39 @@ public function testInformationSchemaTables() {
7777
$result = $this->assertQuery( "SELECT * FROM information_schema.tables WHERE TABLE_NAME = 'wp_options'" );
7878
$this->assertEquals(
7979
array(
80-
'TABLE_NAME' => 'wp_options',
81-
'TABLE_TYPE' => 'BASE TABLE',
82-
'TABLE_SCHEMA' => 'database',
83-
'ENGINE' => 'InnoDB',
80+
'TABLE_CATALOG' => 'def',
81+
'TABLE_SCHEMA' => 'database',
82+
'TABLE_NAME' => 'wp_options',
83+
'TABLE_TYPE' => 'BASE TABLE',
84+
'ENGINE' => 'InnoDB',
85+
'ROW_FORMAT' => 'Dynamic',
8486
'TABLE_COLLATION' => 'utf8mb4_general_ci',
85-
'TABLE_COMMENT' => '',
86-
'CREATE_TABLE' => 'CREATE TABLE "wp_options"(
87+
'TABLE_COMMENT' => '',
88+
'CREATE_TABLE' => 'CREATE TABLE "wp_options"(
8789
"option_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
8890
"option_name" text NOT NULL DEFAULT \'\' COLLATE NOCASE,
8991
"option_value" text NOT NULL COLLATE NOCASE,
9092
"autoload" text NOT NULL DEFAULT \'yes\' COLLATE NOCASE
9193
)',
92-
'AUTO_INCREMENT' => null,
93-
'CREATE_TIME' => null,
94-
'UPDATE_TIME' => null,
95-
'CHECK_TIME' => null,
96-
'TABLE_ROWS' => '0',
97-
'DATA_LENGTH' => '0',
98-
'INDEX_LENGTH' => '0',
99-
'DATA_FREE' => '0',
100-
'VERSION' => '10',
94+
'AUTO_INCREMENT' => null,
95+
'CREATE_TIME' => null,
96+
'UPDATE_TIME' => null,
97+
'CHECK_TIME' => null,
98+
'TABLE_ROWS' => '0',
99+
'AVG_ROW_LENGTH' => '0',
100+
'DATA_LENGTH' => '0',
101+
'MAX_DATA_LENGTH' => '0',
102+
'INDEX_LENGTH' => '0',
103+
'DATA_FREE' => '0',
104+
'CHECKSUM' => null,
105+
'CREATE_OPTIONS' => '',
106+
'VERSION' => '10',
101107
),
102108
(array) $result[0]
103109
);
104110

105-
$result = $this->assertQuery( "SELECT
111+
$result = $this->assertQuery(
112+
"SELECT
106113
table_name as 'name',
107114
engine AS 'engine',
108115
round( ( data_length / 1024 / 1024 ), 2 ) 'data'
@@ -113,9 +120,9 @@ public function testInformationSchemaTables() {
113120

114121
$this->assertEquals(
115122
array(
116-
'name' => 'wp_posts',
123+
'name' => 'wp_posts',
117124
'engine' => 'InnoDB',
118-
'data' => '0',
125+
'data' => '0',
119126
),
120127
(array) $result[0]
121128
);

wp-includes/sqlite/class-wp-sqlite-translator.php

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,29 +1509,35 @@ private function execute_select() {
15091509

15101510
if ( $table_name && str_starts_with( strtolower( $table_name ), 'information_schema' ) ) {
15111511
$this->is_information_schema_query = true;
1512-
$updated_query = preg_replace(
1513-
'/'.$table_name.'\.tables/i',
1512+
$updated_query = preg_replace(
1513+
'/' . $table_name . '\.tables/i',
15141514
"(SELECT
1515-
name as TABLE_NAME,
1515+
'def' as TABLE_CATALOG, /* Standard value for TABLE_CATALOG */
15161516
'database' as TABLE_SCHEMA,
1517+
name as TABLE_NAME,
15171518
CASE type
15181519
WHEN 'table' THEN 'BASE TABLE'
15191520
WHEN 'view' THEN 'VIEW'
15201521
ELSE type
15211522
END as TABLE_TYPE,
15221523
'InnoDB' as ENGINE,
1523-
'utf8mb4_general_ci' as TABLE_COLLATION,
1524-
'' as TABLE_COMMENT,
1525-
sql as CREATE_TABLE,
1526-
NULL as AUTO_INCREMENT,
1527-
NULL as CREATE_TIME,
1528-
NULL as UPDATE_TIME,
1529-
NULL as CHECK_TIME,
1524+
'Dynamic' as ROW_FORMAT, /* Standard InnoDB row format */
15301525
0 as TABLE_ROWS,
1526+
0 as AVG_ROW_LENGTH,
15311527
0 as DATA_LENGTH,
1528+
0 as MAX_DATA_LENGTH,
15321529
0 as INDEX_LENGTH,
15331530
0 as DATA_FREE,
1534-
10 as VERSION
1531+
NULL as AUTO_INCREMENT,
1532+
NULL as CREATE_TIME,
1533+
NULL as UPDATE_TIME,
1534+
NULL as CHECK_TIME,
1535+
'utf8mb4_general_ci' as TABLE_COLLATION,
1536+
NULL as CHECKSUM,
1537+
'' as CREATE_OPTIONS,
1538+
'' as TABLE_COMMENT,
1539+
10 as VERSION,
1540+
sql as CREATE_TABLE
15351541
FROM sqlite_master
15361542
WHERE type IN ('table', 'view'))",
15371543
$updated_query
@@ -2805,7 +2811,7 @@ function ( $table ) {
28052811
* for the name/table_name column, the table would be removed.
28062812
*/
28072813
$table_name = true;
2808-
$table = (array) $table;
2814+
$table = (array) $table;
28092815
if ( isset( $table['Name'] ) ) {
28102816
$table_name = $table['Name'];
28112817
} elseif ( isset( $table['table_name'] ) ) {
@@ -3536,24 +3542,32 @@ private function execute_show() {
35363542
$database_expression = $this->rewriter->skip();
35373543
$stmt = $this->execute_sqlite_query(
35383544
"SELECT
3539-
name as `Name`,
3540-
'myisam' as `Engine`,
3541-
10 as `Version`,
3542-
'Fixed' as `Row_format`,
3543-
0 as `Rows`,
3544-
0 as `Avg_row_length`,
3545-
0 as `Data_length`,
3546-
0 as `Max_data_length`,
3547-
0 as `Index_length`,
3548-
0 as `Data_free` ,
3549-
0 as `Auto_increment`,
3550-
'2024-03-20 15:33:20' as `Create_time`,
3551-
'2024-03-20 15:33:20' as `Update_time`,
3552-
null as `Check_time`,
3553-
null as `Collation`,
3554-
null as `Checksum`,
3555-
'' as `Create_options`,
3556-
'' as `Comment`
3545+
'def' as TABLE_CATALOG, /* Standard value for TABLE_CATALOG */
3546+
'database' as TABLE_SCHEMA,
3547+
name as TABLE_NAME,
3548+
CASE type
3549+
WHEN 'table' THEN 'BASE TABLE'
3550+
WHEN 'view' THEN 'VIEW'
3551+
ELSE type
3552+
END as TABLE_TYPE,
3553+
'InnoDB' as ENGINE,
3554+
'Dynamic' as ROW_FORMAT, /* Standard InnoDB row format */
3555+
0 as TABLE_ROWS,
3556+
0 as AVG_ROW_LENGTH, /* Added missing column */
3557+
0 as DATA_LENGTH,
3558+
0 as MAX_DATA_LENGTH, /* Added missing column */
3559+
0 as INDEX_LENGTH,
3560+
0 as DATA_FREE,
3561+
NULL as AUTO_INCREMENT,
3562+
NULL as CREATE_TIME,
3563+
NULL as UPDATE_TIME,
3564+
NULL as CHECK_TIME,
3565+
'utf8mb4_general_ci' as TABLE_COLLATION,
3566+
NULL as CHECKSUM, /* Added missing column */
3567+
'' as CREATE_OPTIONS, /* Added missing column */
3568+
'' as TABLE_COMMENT,
3569+
10 as VERSION,
3570+
sql as CREATE_TABLE
35573571
FROM sqlite_master
35583572
WHERE
35593573
type='table'

0 commit comments

Comments
 (0)