-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathShowTableStatusSQLRewriter.php
More file actions
54 lines (50 loc) · 1.54 KB
/
ShowTableStatusSQLRewriter.php
File metadata and controls
54 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class ShowTableStatusSQLRewriter extends AbstractSQLRewriter
{
public function rewrite(): string
{
$sql = $this->original();
return $this->generatePostgresShowTableStatus(DB_SCHEMA);
}
/**
* Generates a PostgreSQL-compatible SQL query to mimic MySQL's "SHOW TABLE STATUS".
*
* @return string The generated SQL query
*/
public function generatePostgresShowTableStatus($schema)
{
$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;
}
}