diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index fb29f4e..46275bb 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -124,25 +124,6 @@ // Remove illegal characters $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')) { $logto = 'SELECT'; @@ -251,6 +232,18 @@ $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 if( preg_match('/^.{1}/us',$sql,$ar) != 1) $sql = utf8_encode($sql); @@ -261,6 +254,7 @@ $logto = 'DELETE'; // LIMIT is not allowed in DELETE queries $sql = str_replace( 'LIMIT 1', '', $sql); + $sql = str_replace( ' REGEXP ', ' ~ ', $sql); } // Fix tables listing elseif( 0 === strpos($sql, 'SHOW TABLES')) @@ -324,8 +318,7 @@ WHERE bc.oid = i.indrelid $index = $matches[3]; $columns = $matches[4]; // Workaround for index name duplicate - if( $table == $table_prefix.'usermeta' && $index == 'meta_key') - $index = 'umeta_key'; + $index = $table.'_'.$index; $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]; $columns = $match[3]; // Workaround for index name duplicate - if( $table == $table_prefix.'usermeta' && $index == 'meta_key') - $index = 'umeta_key'; + $index = $table.'_'.$index; $sql .= "\nCREATE {$unique}INDEX $index ON $table ($columns);"; } // Now remove handled indexes $sql = preg_replace( $pattern, '', $sql); }// 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 $sql = str_replace( 'IN (\'\')', 'IN (NULL)', $sql); $sql = str_replace( 'IN ( \'\' )', 'IN (NULL)', $sql); diff --git a/readme.txt b/readme.txt index c0b8335..a6f88c6 100644 --- a/readme.txt +++ b/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 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. @@ -50,6 +50,12 @@ There is no screenshot for this plugin == 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 = 1.0.2 = @@ -63,7 +69,6 @@ There is no screenshot for this plugin * Changed the fake server version to 4.1.3 * Added support for Unix socket connections (just leave the "host" field empty when installing) - = 1.0.0 = * Initial stable release. * Code optimisation and reorganisation. @@ -97,7 +102,12 @@ There is no screenshot for this plugin * Case insensitivity of MySQL 'LIKE' restored * 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 == -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.