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