Implemented a generic "INTERVAL xx DAY|HOUR|MINUTE|SECOND" handler
Prepare workaround for undesirable effects (works with new content for now) git-svn-id: https://plugins.svn.wordpress.org/postgresql-for-wordpress/trunk@226893 b8457f37-d9ea-0310-8a92-e5e31aec5664
This commit is contained in:
@@ -96,13 +96,12 @@
|
|||||||
$logto = 'queries';
|
$logto = 'queries';
|
||||||
// This is used to catch the number of rows returned by the last "SELECT" REQUEST
|
// This is used to catch the number of rows returned by the last "SELECT" REQUEST
|
||||||
$catchnumrows = false;
|
$catchnumrows = false;
|
||||||
|
// The end of the query may be protected against changes
|
||||||
|
$end = '';
|
||||||
|
|
||||||
// Remove unusefull spaces
|
// Remove unusefull spaces
|
||||||
$initial = $sql = trim($sql);
|
$initial = $sql = trim($sql);
|
||||||
|
|
||||||
// Remove illegal characters
|
|
||||||
$sql = str_replace('`', '', $sql);
|
|
||||||
|
|
||||||
if( 0 === strpos($sql, 'SELECT'))
|
if( 0 === strpos($sql, 'SELECT'))
|
||||||
{
|
{
|
||||||
$logto = 'SELECT';
|
$logto = 'SELECT';
|
||||||
@@ -126,8 +125,6 @@
|
|||||||
$pattern = '/LIMIT[ ]+(\d+),[ ]*(\d+)/';
|
$pattern = '/LIMIT[ ]+(\d+),[ ]*(\d+)/';
|
||||||
$sql = preg_replace($pattern, 'LIMIT $2 OFFSET $1', $sql);
|
$sql = preg_replace($pattern, 'LIMIT $2 OFFSET $1', $sql);
|
||||||
|
|
||||||
$sql = str_replace('INTERVAL 120 MINUTE', "'120 minutes'::interval", $sql);
|
|
||||||
|
|
||||||
$pattern = '/DATE_ADD[ ]*\(([^,]+),([^\)]+)\)/';
|
$pattern = '/DATE_ADD[ ]*\(([^,]+),([^\)]+)\)/';
|
||||||
$sql = preg_replace( $pattern, '($1 + $2)', $sql);
|
$sql = preg_replace( $pattern, '($1 + $2)', $sql);
|
||||||
|
|
||||||
@@ -229,6 +226,8 @@
|
|||||||
{
|
{
|
||||||
// Remove 'ON DUPLICATE KEY UPDATE...' and following
|
// Remove 'ON DUPLICATE KEY UPDATE...' and following
|
||||||
$sql = substr( $sql, 0, $pos);
|
$sql = substr( $sql, 0, $pos);
|
||||||
|
// Remove illegal characters
|
||||||
|
$sql = str_replace('`', '', $sql);
|
||||||
// Get the elements we need (table name, first field, value)
|
// Get the elements we need (table name, first field, value)
|
||||||
$pattern = '/INSERT INTO (\w+)\s+\(([^,]+).+VALUES\s+\(([^,]+)/';
|
$pattern = '/INSERT INTO (\w+)\s+\(([^,]+).+VALUES\s+\(([^,]+)/';
|
||||||
preg_match($pattern, $sql, $matches);
|
preg_match($pattern, $sql, $matches);
|
||||||
@@ -239,6 +238,9 @@
|
|||||||
if( preg_match('/^.{1}/us',$sql,$ar) != 1)
|
if( preg_match('/^.{1}/us',$sql,$ar) != 1)
|
||||||
$sql = utf8_encode($sql);
|
$sql = utf8_encode($sql);
|
||||||
|
|
||||||
|
// This will avoid modifications to anything following 'VALUES('
|
||||||
|
list($sql,$end) = explode( ' VALUES(', $sql, 2);
|
||||||
|
$end = ' VALUES('.$end;
|
||||||
} // INSERT
|
} // INSERT
|
||||||
elseif( 0 === strpos( $sql, 'DELETE' ))
|
elseif( 0 === strpos( $sql, 'DELETE' ))
|
||||||
{
|
{
|
||||||
@@ -267,11 +269,15 @@
|
|||||||
$pattern = '/AND meta_value = (-?\d+)/';
|
$pattern = '/AND meta_value = (-?\d+)/';
|
||||||
$sql = preg_replace( $pattern, 'AND meta_value = \'$1\'', $sql);
|
$sql = preg_replace( $pattern, 'AND meta_value = \'$1\'', $sql);
|
||||||
|
|
||||||
// The following handles a new "INTERVAL" call in Akismet 2.2.7
|
// Generic "INTERVAL xx DAY|HOUR|MINUTE|SECOND" handle
|
||||||
$sql = str_replace('INTERVAL 15 DAY', "'15 days'::interval", $sql);
|
$pattern = '/INTERVAL[ ]+(\d+)[ ]+(DAY|HOUR|MINUTE|SECOND)/';
|
||||||
|
$sql = preg_replace( $pattern, "'\$1 \$2'::interval", $sql);
|
||||||
$pattern = '/DATE_SUB[ ]*\(([^,]+),([^\)]+)\)/';
|
$pattern = '/DATE_SUB[ ]*\(([^,]+),([^\)]+)\)/';
|
||||||
$sql = preg_replace( $pattern, '($1::timestamp - $2)', $sql);
|
$sql = preg_replace( $pattern, '($1::timestamp - $2)', $sql);
|
||||||
|
|
||||||
|
// Remove illegal characters
|
||||||
|
$sql = str_replace('`', '', $sql);
|
||||||
|
|
||||||
// Field names with CAPITALS need special handling
|
// Field names with CAPITALS need special handling
|
||||||
if( false !== strpos($sql, 'ID'))
|
if( false !== strpos($sql, 'ID'))
|
||||||
{
|
{
|
||||||
@@ -313,6 +319,9 @@
|
|||||||
$sql = str_replace( array_keys($zdml_conv), array_values($zdml_conv), $sql);
|
$sql = str_replace( array_keys($zdml_conv), array_values($zdml_conv), $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put back the end of the query if it was separated
|
||||||
|
$sql .= $end;
|
||||||
|
|
||||||
if( PG4WP_DEBUG)
|
if( PG4WP_DEBUG)
|
||||||
{
|
{
|
||||||
if( $initial != $sql)
|
if( $initial != $sql)
|
||||||
|
@@ -50,6 +50,8 @@ There is no screenshot for this plugin
|
|||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
|
||||||
|
* Implemented a generic "INTERVAL xx DAY|HOUR|MINUTE|SECOND" handler
|
||||||
|
* Prepare workaround for undesirable effects (works with new content for now)
|
||||||
* Improved db.php to remove notices and possible fatal errors
|
* Improved db.php to remove notices and possible fatal errors
|
||||||
* Preliminary support for Wordpress 3.0
|
* Preliminary support for Wordpress 3.0
|
||||||
* Improved dates functions handling
|
* Improved dates functions handling
|
||||||
|
Reference in New Issue
Block a user