correctly emulate Show Variables command in postgres by using the pg_settings table

This commit is contained in:
Matthew Bucci
2024-01-16 21:38:24 -08:00
parent a389cc7adc
commit 487657a642

View File

@@ -5,12 +5,12 @@ class ShowVariablesSQLRewriter extends AbstractSQLRewriter
public function rewrite(): string public function rewrite(): string
{ {
$sql = $this->original(); $sql = $this->original();
$table = $this->extractVariableName($sql); $variableName = $this->extractVariableName($sql);
return $this->generatePostgres($sql, $variableName); return $this->generatePostgres($sql, $variableName);
} }
/** /**
* Extracts table name from a "SHOW FULL COLUMNS" SQL statement. * Extracts Variable name from a "SHOW VARIABLES LIKE " SQL statement.
* *
* @param string $sql The SQL statement * @param string $sql The SQL statement
* @return string|null The table name if found, or null otherwise * @return string|null The table name if found, or null otherwise
@@ -37,7 +37,11 @@ class ShowVariablesSQLRewriter extends AbstractSQLRewriter
return "SELECT '$variableName' AS \"Variable_name\", '' AS \"Value\";"; return "SELECT '$variableName' AS \"Variable_name\", '' AS \"Value\";";
} }
// return untransformed sql if ($variableName == "max_allowed_packet") {
return $sql; // Act like 1GB packet size, in practice this limit doesn't actually exist for postgres, we just want to fool WP
return "SELECT '$variableName' AS \"Variable_name\", '1073741824' AS \"Value\";";
}
return "SELECT name as \"Variable_name\", setting as \"Value\" FROM pg_settings WHERE name = '$variableName';";
} }
} }