Generic hack to avoid duplicate index names
REGEXP gets replaced with '~' Added a hack to handle "ON DUPLICATE KEY" Moved handling field names with CAPITALS near the end Added support for "INTERVAL 15 DAY" found in Akismet 2.2.7 git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@194346 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
@@ -124,25 +124,6 @@
|
|||||||
// Remove illegal characters
|
// Remove illegal characters
|
||||||
$sql = str_replace('`', '', $sql);
|
$sql = str_replace('`', '', $sql);
|
||||||
|
|
||||||
// Field names with CAPITALS need special handling
|
|
||||||
if( false !== strpos($sql, 'ID'))
|
|
||||||
{
|
|
||||||
$pattern = '/ID([^ ])/';
|
|
||||||
$sql = preg_replace($pattern, 'ID $1', $sql);
|
|
||||||
$pattern = '/ID$/';
|
|
||||||
$sql = preg_replace($pattern, 'ID ', $sql);
|
|
||||||
$pattern = '/\(ID/';
|
|
||||||
$sql = preg_replace($pattern, '( ID', $sql);
|
|
||||||
$pattern = '/,ID/';
|
|
||||||
$sql = preg_replace($pattern, ', ID', $sql);
|
|
||||||
$pattern = '/[a-zA-Z_]+ID/';
|
|
||||||
$sql = preg_replace($pattern, '"$0"', $sql);
|
|
||||||
$pattern = '/\.ID/';
|
|
||||||
$sql = preg_replace($pattern, '."ID"', $sql);
|
|
||||||
$pattern = '/[\s]ID /';
|
|
||||||
$sql = preg_replace($pattern, ' "ID" ', $sql);
|
|
||||||
} // CAPITALS
|
|
||||||
|
|
||||||
if( 0 === strpos($sql, 'SELECT'))
|
if( 0 === strpos($sql, 'SELECT'))
|
||||||
{
|
{
|
||||||
$logto = 'SELECT';
|
$logto = 'SELECT';
|
||||||
@@ -251,6 +232,18 @@
|
|||||||
$sql = str_replace( '), (', ');'.$insert.'(', $sql);
|
$sql = str_replace( '), (', ');'.$insert.'(', $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Support for "INSERT ... ON DUPLICATE KEY UPDATE ..." is a dirty hack
|
||||||
|
// consisting in deleting the row before inserting it
|
||||||
|
if( false !== $pos = strpos( $sql, 'ON DUPLICATE KEY'))
|
||||||
|
{
|
||||||
|
// Remove 'ON DUPLICATE KEY UPDATE...' and following
|
||||||
|
$sql = substr( $sql, 0, $pos);
|
||||||
|
// Get the elements we need (table name, first field, value)
|
||||||
|
$pattern = '/INSERT INTO (\w+)\s+\(([^,]+).+VALUES\s+\(([^,]+)/';
|
||||||
|
preg_match($pattern, $sql, $matches);
|
||||||
|
$sql = 'DELETE FROM '.$matches[1].' WHERE '.$matches[2].' = '.$matches[3].';'.$sql;
|
||||||
|
}
|
||||||
|
|
||||||
// To avoid Encoding errors when inserting data coming from outside
|
// To avoid Encoding errors when inserting data coming from outside
|
||||||
if( preg_match('/^.{1}/us',$sql,$ar) != 1)
|
if( preg_match('/^.{1}/us',$sql,$ar) != 1)
|
||||||
$sql = utf8_encode($sql);
|
$sql = utf8_encode($sql);
|
||||||
@@ -261,6 +254,7 @@
|
|||||||
$logto = 'DELETE';
|
$logto = 'DELETE';
|
||||||
// LIMIT is not allowed in DELETE queries
|
// LIMIT is not allowed in DELETE queries
|
||||||
$sql = str_replace( 'LIMIT 1', '', $sql);
|
$sql = str_replace( 'LIMIT 1', '', $sql);
|
||||||
|
$sql = str_replace( ' REGEXP ', ' ~ ', $sql);
|
||||||
}
|
}
|
||||||
// Fix tables listing
|
// Fix tables listing
|
||||||
elseif( 0 === strpos($sql, 'SHOW TABLES'))
|
elseif( 0 === strpos($sql, 'SHOW TABLES'))
|
||||||
@@ -324,8 +318,7 @@ WHERE bc.oid = i.indrelid
|
|||||||
$index = $matches[3];
|
$index = $matches[3];
|
||||||
$columns = $matches[4];
|
$columns = $matches[4];
|
||||||
// Workaround for index name duplicate
|
// Workaround for index name duplicate
|
||||||
if( $table == $table_prefix.'usermeta' && $index == 'meta_key')
|
$index = $table.'_'.$index;
|
||||||
$index = 'umeta_key';
|
|
||||||
$sql = "CREATE {$unique}INDEX $index ON $table ($columns)";
|
$sql = "CREATE {$unique}INDEX $index ON $table ($columns)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,14 +389,34 @@ WHERE pg_class.relname='$table_name' AND pg_attribute.attnum>=1 AND NOT pg_attri
|
|||||||
$index = $match[2];
|
$index = $match[2];
|
||||||
$columns = $match[3];
|
$columns = $match[3];
|
||||||
// Workaround for index name duplicate
|
// Workaround for index name duplicate
|
||||||
if( $table == $table_prefix.'usermeta' && $index == 'meta_key')
|
$index = $table.'_'.$index;
|
||||||
$index = 'umeta_key';
|
|
||||||
$sql .= "\nCREATE {$unique}INDEX $index ON $table ($columns);";
|
$sql .= "\nCREATE {$unique}INDEX $index ON $table ($columns);";
|
||||||
}
|
}
|
||||||
// Now remove handled indexes
|
// Now remove handled indexes
|
||||||
$sql = preg_replace( $pattern, '', $sql);
|
$sql = preg_replace( $pattern, '', $sql);
|
||||||
}// CREATE TABLE
|
}// CREATE TABLE
|
||||||
|
|
||||||
|
// Field names with CAPITALS need special handling
|
||||||
|
if( false !== strpos($sql, 'ID'))
|
||||||
|
{
|
||||||
|
$pattern = '/ID([^ ])/';
|
||||||
|
$sql = preg_replace($pattern, 'ID $1', $sql);
|
||||||
|
$pattern = '/ID$/';
|
||||||
|
$sql = preg_replace($pattern, 'ID ', $sql);
|
||||||
|
$pattern = '/\(ID/';
|
||||||
|
$sql = preg_replace($pattern, '( ID', $sql);
|
||||||
|
$pattern = '/,ID/';
|
||||||
|
$sql = preg_replace($pattern, ', ID', $sql);
|
||||||
|
$pattern = '/[a-zA-Z_]+ID/';
|
||||||
|
$sql = preg_replace($pattern, '"$0"', $sql);
|
||||||
|
$pattern = '/\.ID/';
|
||||||
|
$sql = preg_replace($pattern, '."ID"', $sql);
|
||||||
|
$pattern = '/[\s]ID /';
|
||||||
|
$sql = preg_replace($pattern, ' "ID" ', $sql);
|
||||||
|
$pattern = '/"ID "/';
|
||||||
|
$sql = preg_replace($pattern, ' "ID" ', $sql);
|
||||||
|
} // CAPITALS
|
||||||
|
|
||||||
// Empty "IN" statements are erroneous
|
// Empty "IN" statements are erroneous
|
||||||
$sql = str_replace( 'IN (\'\')', 'IN (NULL)', $sql);
|
$sql = str_replace( 'IN (\'\')', 'IN (NULL)', $sql);
|
||||||
$sql = str_replace( 'IN ( \'\' )', 'IN (NULL)', $sql);
|
$sql = str_replace( 'IN ( \'\' )', 'IN (NULL)', $sql);
|
||||||
|
16
readme.txt
16
readme.txt
@@ -38,7 +38,7 @@ This is because the database needs to be up and running before any plugin can be
|
|||||||
You can modify this file to configure the database driver you wish to use
|
You can modify this file to configure the database driver you wish to use
|
||||||
Currently you can set 'DB_DRIVER' to 'pgsql' or 'mysql'
|
Currently you can set 'DB_DRIVER' to 'pgsql' or 'mysql'
|
||||||
|
|
||||||
You can also activate DEBUG logs
|
You can also activate DEBUG or ERROR logs
|
||||||
|
|
||||||
1. Point your Web Browser to your wordpress installation and go through the traditional WordPress installation routine.
|
1. Point your Web Browser to your wordpress installation and go through the traditional WordPress installation routine.
|
||||||
|
|
||||||
@@ -50,6 +50,12 @@ There is no screenshot for this plugin
|
|||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
* Upgrading from WP 2.8.6 to WP 2.9.1 works with errors
|
||||||
|
* Installing WP 2.9.1 works smoothly
|
||||||
|
* Generic hack to avoid duplicate index names
|
||||||
|
* REGEXP gets replaced with '~'
|
||||||
|
* Added a hack to handle "ON DUPLICATE KEY"
|
||||||
|
* Moved handling field names with CAPITALS near the end
|
||||||
* Added support for "INTERVAL 15 DAY" found in Akismet 2.2.7
|
* Added support for "INTERVAL 15 DAY" found in Akismet 2.2.7
|
||||||
|
|
||||||
= 1.0.2 =
|
= 1.0.2 =
|
||||||
@@ -63,7 +69,6 @@ There is no screenshot for this plugin
|
|||||||
* Changed the fake server version to 4.1.3
|
* Changed the fake server version to 4.1.3
|
||||||
* Added support for Unix socket connections (just leave the "host" field empty when installing)
|
* Added support for Unix socket connections (just leave the "host" field empty when installing)
|
||||||
|
|
||||||
|
|
||||||
= 1.0.0 =
|
= 1.0.0 =
|
||||||
* Initial stable release.
|
* Initial stable release.
|
||||||
* Code optimisation and reorganisation.
|
* Code optimisation and reorganisation.
|
||||||
@@ -97,7 +102,12 @@ There is no screenshot for this plugin
|
|||||||
* Case insensitivity of MySQL 'LIKE' restored
|
* Case insensitivity of MySQL 'LIKE' restored
|
||||||
* Importing WordPress eXtended RSS tested and seems to work
|
* Importing WordPress eXtended RSS tested and seems to work
|
||||||
|
|
||||||
|
== Upgrade Notice ==
|
||||||
|
|
||||||
|
= 1.0 =
|
||||||
|
Initial stable release, you should upgrade to this version if you have installed any older release
|
||||||
|
|
||||||
== Licence ==
|
== Licence ==
|
||||||
PG4WP is provided "as-is" with no warranty.
|
PG4WP is provided "as-is" with no warranty in the hope it can be useful.
|
||||||
|
|
||||||
PG4WP is licensed under the [GNU GPL](http://www.gnu.org/licenses/gpl.html "GNU GPL") v2 or any newer version at your choice.
|
PG4WP is licensed under the [GNU GPL](http://www.gnu.org/licenses/gpl.html "GNU GPL") v2 or any newer version at your choice.
|
||||||
|
Reference in New Issue
Block a user