formatting
This commit is contained in:
17
pg4wp/db.php
17
pg4wp/db.php
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: PostgreSQL for WordPress (PG4WP)
|
||||
Plugin URI: http://www.hawkix.net
|
||||
Description: PG4WP is a special 'plugin' enabling WordPress to use a PostgreSQL database.
|
||||
Version: 1.3.1+
|
||||
Author: Hawk__
|
||||
Author URI: http://www.hawkix.net
|
||||
Plugin URI: https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress
|
||||
Description: PG4WP is a special plugin enabling WordPress to use a PostgreSQL database.
|
||||
Version: v2.2
|
||||
Author: PostgreSQL-For-Wordpress
|
||||
Author URI: https://github.com/PostgreSQL-For-Wordpress
|
||||
License: GPLv2 or newer.
|
||||
*/
|
||||
|
||||
@@ -47,14 +47,11 @@ if(!defined('PG4WP_ROOT')) {
|
||||
}
|
||||
|
||||
// Logs are put in the pg4wp directory
|
||||
if (!defined('PG4WP_LOG'))
|
||||
{
|
||||
if (!defined('PG4WP_LOG')) {
|
||||
define('PG4WP_LOG', PG4WP_ROOT . '/logs/');
|
||||
}
|
||||
// Check if the logs directory is needed and exists or create it if possible
|
||||
if((PG4WP_DEBUG || PG4WP_LOG_ERRORS) &&
|
||||
!file_exists(PG4WP_LOG) &&
|
||||
is_writable(dirname(PG4WP_LOG))) {
|
||||
if((PG4WP_DEBUG || PG4WP_LOG_ERRORS) && !file_exists(PG4WP_LOG) && is_writable(dirname(PG4WP_LOG))) {
|
||||
mkdir(PG4WP_LOG);
|
||||
}
|
||||
|
||||
|
@@ -9,43 +9,83 @@
|
||||
* Provides a driver for MySQL
|
||||
* This file remaps all wpsql_* calls to mysql_* original name
|
||||
*/
|
||||
function wpsql_num_rows($result)
|
||||
{ return mysql_num_rows($result); }
|
||||
function wpsql_numrows($result)
|
||||
{ return mysql_num_rows($result); }
|
||||
function wpsql_num_fields($result)
|
||||
{ return mysql_num_fields($result); }
|
||||
function wpsql_fetch_field($result)
|
||||
{ return mysql_fetch_field($result); }
|
||||
function wpsql_fetch_object($result)
|
||||
{ return mysql_fetch_object($result); }
|
||||
function wpsql_free_result($result)
|
||||
{ return mysql_free_result($result); }
|
||||
function wpsql_affected_rows()
|
||||
{ return mysql_affected_rows(); }
|
||||
function wpsql_fetch_row($result)
|
||||
{ return mysql_fetch_row($result); }
|
||||
function wpsql_data_seek($result, $offset)
|
||||
{ return mysql_data_seek( $result, $offset ); }
|
||||
function wpsql_error()
|
||||
{ return mysql_error();}
|
||||
function wpsql_fetch_assoc($result)
|
||||
{ return mysql_fetch_assoc($result); }
|
||||
function wpsql_escape_string($s)
|
||||
{ return mysql_real_escape_string($s); }
|
||||
function wpsql_real_escape_string($s,$c=NULL)
|
||||
{ return mysql_real_escape_string($s,$c); }
|
||||
function wpsql_get_server_info()
|
||||
{ return mysql_get_server_info(); }
|
||||
function wpsql_result($result, $i, $fieldname)
|
||||
{ return mysql_result($result, $i, $fieldname); }
|
||||
function wpsql_connect($dbserver, $dbuser, $dbpass)
|
||||
{ return mysql_connect($dbserver, $dbuser, $dbpass); }
|
||||
function wpsql_fetch_array($result)
|
||||
{ return mysql_fetch_array($result); }
|
||||
function wpsql_select_db($dbname, $connection_id)
|
||||
{ return mysql_select_db($dbname, $connection_id); }
|
||||
function wpsql_query($sql)
|
||||
{ return mysql_query($sql); }
|
||||
function wpsql_insert_id($table)
|
||||
{ return mysql_insert_id($table); }
|
||||
function wpsql_num_rows($result)
|
||||
{
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
function wpsql_numrows($result)
|
||||
{
|
||||
return mysql_num_rows($result);
|
||||
}
|
||||
function wpsql_num_fields($result)
|
||||
{
|
||||
return mysql_num_fields($result);
|
||||
}
|
||||
function wpsql_fetch_field($result)
|
||||
{
|
||||
return mysql_fetch_field($result);
|
||||
}
|
||||
function wpsql_fetch_object($result)
|
||||
{
|
||||
return mysql_fetch_object($result);
|
||||
}
|
||||
function wpsql_free_result($result)
|
||||
{
|
||||
return mysql_free_result($result);
|
||||
}
|
||||
function wpsql_affected_rows()
|
||||
{
|
||||
return mysql_affected_rows();
|
||||
}
|
||||
function wpsql_fetch_row($result)
|
||||
{
|
||||
return mysql_fetch_row($result);
|
||||
}
|
||||
function wpsql_data_seek($result, $offset)
|
||||
{
|
||||
return mysql_data_seek($result, $offset);
|
||||
}
|
||||
function wpsql_error()
|
||||
{
|
||||
return mysql_error();
|
||||
}
|
||||
function wpsql_fetch_assoc($result)
|
||||
{
|
||||
return mysql_fetch_assoc($result);
|
||||
}
|
||||
function wpsql_escape_string($s)
|
||||
{
|
||||
return mysql_real_escape_string($s);
|
||||
}
|
||||
function wpsql_real_escape_string($s, $c = null)
|
||||
{
|
||||
return mysql_real_escape_string($s, $c);
|
||||
}
|
||||
function wpsql_get_server_info()
|
||||
{
|
||||
return mysql_get_server_info();
|
||||
}
|
||||
function wpsql_result($result, $i, $fieldname)
|
||||
{
|
||||
return mysql_result($result, $i, $fieldname);
|
||||
}
|
||||
function wpsql_connect($dbserver, $dbuser, $dbpass)
|
||||
{
|
||||
return mysql_connect($dbserver, $dbuser, $dbpass);
|
||||
}
|
||||
function wpsql_fetch_array($result)
|
||||
{
|
||||
return mysql_fetch_array($result);
|
||||
}
|
||||
function wpsql_select_db($dbname, $connection_id)
|
||||
{
|
||||
return mysql_select_db($dbname, $connection_id);
|
||||
}
|
||||
function wpsql_query($sql)
|
||||
{
|
||||
return mysql_query($sql);
|
||||
}
|
||||
function wpsql_insert_id($table)
|
||||
{
|
||||
return mysql_insert_id($table);
|
||||
}
|
||||
|
@@ -558,4 +558,4 @@ function wpsql_get_server_info()
|
||||
function wpsql_get_client_info()
|
||||
{
|
||||
return '8.0.35'; // Just want to fool wordpress ...
|
||||
}
|
||||
}
|
||||
|
@@ -122,5 +122,3 @@ class AlterTableSQLRewriter extends AbstractSQLRewriter
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -15,7 +15,8 @@ class DescribeSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $sql The SQL statement
|
||||
* @return string|null The table name if found, or null otherwise
|
||||
*/
|
||||
protected function extractTableName($sql) {
|
||||
protected function extractTableName($sql)
|
||||
{
|
||||
$pattern = "/DESCRIBE ['\"`]?([^'\"`]+)['\"`]?/i";
|
||||
if (preg_match($pattern, $sql, $matches)) {
|
||||
return $matches[1];
|
||||
@@ -29,7 +30,8 @@ class DescribeSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $tableName The table name
|
||||
* @return string The generated SQL query
|
||||
*/
|
||||
function generatePostgresDescribeTable($tableName) {
|
||||
public function generatePostgresDescribeTable($tableName)
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT
|
||||
f.attnum AS number,
|
||||
|
@@ -15,7 +15,8 @@ class ShowFullColumnsSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $sql The SQL statement
|
||||
* @return string|null The table name if found, or null otherwise
|
||||
*/
|
||||
protected function extractTableNameFromShowColumns($sql) {
|
||||
protected function extractTableNameFromShowColumns($sql)
|
||||
{
|
||||
$pattern = "/SHOW FULL COLUMNS FROM ['\"`]?([^'\"`]+)['\"`]?/i";
|
||||
if (preg_match($pattern, $sql, $matches)) {
|
||||
return $matches[1];
|
||||
@@ -29,7 +30,8 @@ class ShowFullColumnsSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $tableName The table name
|
||||
* @return string The generated SQL query
|
||||
*/
|
||||
function generatePostgresShowColumns($tableName) {
|
||||
public function generatePostgresShowColumns($tableName)
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT
|
||||
a.attname AS "Field",
|
||||
|
@@ -15,7 +15,8 @@ class ShowIndexSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $sql The SQL statement
|
||||
* @return string|null The table name if found, or null otherwise
|
||||
*/
|
||||
protected function extractVariableName($sql) {
|
||||
protected function extractVariableName($sql)
|
||||
{
|
||||
$pattern = "/SHOW INDEX FROM ['\"`]?([^'\"`]+)['\"`]?/i";
|
||||
if (preg_match($pattern, $sql, $matches)) {
|
||||
return $matches[1];
|
||||
@@ -29,7 +30,8 @@ class ShowIndexSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $tableName The table name
|
||||
* @return string The generated SQL query
|
||||
*/
|
||||
function generatePostgresShowIndexFrom($tableName) {
|
||||
public function generatePostgresShowIndexFrom($tableName)
|
||||
{
|
||||
$sql = <<<SQL
|
||||
SELECT bc.relname AS "Table",
|
||||
CASE WHEN i.indisunique THEN '0' ELSE '1' END AS "Non_unique",
|
||||
|
@@ -15,7 +15,8 @@ class ShowVariablesSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $sql The SQL statement
|
||||
* @return string|null The table name if found, or null otherwise
|
||||
*/
|
||||
protected function extractVariableName($sql) {
|
||||
protected function extractVariableName($sql)
|
||||
{
|
||||
$pattern = "/SHOW VARIABLES LIKE ['\"`]?([^'\"`]+)['\"`]?/i";
|
||||
if (preg_match($pattern, $sql, $matches)) {
|
||||
return $matches[1];
|
||||
@@ -29,7 +30,8 @@ class ShowVariablesSQLRewriter extends AbstractSQLRewriter
|
||||
* @param string $tableName The table name
|
||||
* @return string The generated SQL query
|
||||
*/
|
||||
function generatePostgres($sql, $variableName) {
|
||||
public function generatePostgres($sql, $variableName)
|
||||
{
|
||||
if ($variableName == "sql_mode") {
|
||||
// Act like MySQL default configuration, where sql_mode is ""
|
||||
return "SELECT '$variableName' AS \"Variable_name\", '' AS \"Value\";";
|
||||
|
Reference in New Issue
Block a user