-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from PostgreSQL-For-Wordpress/site-health
add rewrite logic for SHOW TABLE STATUS and a catch for calls to information_schema
- Loading branch information
Showing
6 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
class ShowTableStatusSQLRewriter extends AbstractSQLRewriter | ||
{ | ||
public function rewrite(): string | ||
{ | ||
$sql = $this->original(); | ||
return $this->generatePostgresShowTableStatus(); | ||
} | ||
|
||
|
||
/** | ||
* Generates a PostgreSQL-compatible SQL query to mimic MySQL's "SHOW TABLE STATUS". | ||
* | ||
* @return string The generated SQL query | ||
*/ | ||
public function generatePostgresShowTableStatus($schema = "public") | ||
{ | ||
$sql = <<<SQL | ||
SELECT | ||
'Postgres' AS Engine, | ||
cls.relname AS TableName, | ||
NULL AS Version, | ||
NULL AS Row_format, | ||
cls.reltuples AS Rows, | ||
NULL AS Avg_row_length, | ||
pg_size_pretty(pg_relation_size(cls.oid)) AS Data_length, | ||
NULL AS Max_data_length, | ||
pg_size_pretty(pg_indexes_size(cls.oid)) AS Index_length, | ||
NULL AS Data_free, | ||
NULL AS Auto_increment, | ||
NULL AS Create_time, | ||
NULL AS Update_time, | ||
NULL AS Check_time, | ||
'UTF8' AS Table_collation, | ||
NULL AS Checksum, | ||
NULL AS Create_options, | ||
obj_description(cls.oid) AS Comment | ||
FROM | ||
pg_class cls | ||
JOIN | ||
pg_namespace nsp ON cls.relnamespace = nsp.oid | ||
WHERE | ||
cls.relkind = 'r' | ||
AND nsp.nspname NOT LIKE 'pg_%' | ||
AND nsp.nspname != 'information_schema' | ||
AND nsp.nspname = '$schema' | ||
ORDER BY | ||
cls.relname ASC; | ||
SQL; | ||
|
||
return $sql; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters