Add support for sql_mode variable

This appears as both "SELECT @@SESSION.sql_mode" checked from wp-db.php
in Wordpress core during startup and as "SHOW VARIABLES LIKE 'sql_mode'"
in several extensions (all-in-one-seo-pack, flash-album-gallery, and
nextgen-gallery on my system).  Support both by returning the empty
string, which reports the default MySQL behavior (and avoids attempts to
change the mode, since all current code expects this).

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
Kevin Locke
2015-06-03 01:12:12 -06:00
parent 6aea521bf2
commit 83e5074461
2 changed files with 12 additions and 1 deletions

View File

@@ -271,6 +271,10 @@
$pattern = '/ (?<!NULL)IF[ ]*\(([^,]+),([^,]+),([^\)]+)\)/';
$sql = preg_replace( $pattern, ' CASE WHEN $1 THEN $2 ELSE $3 END', $sql);
// Act like MySQL default configuration, where sql_mode is ""
$pattern = '/@@SESSION.sql_mode/';
$sql = preg_replace( $pattern, "''", $sql);
$sql = str_replace('GROUP BY '.$wpdb->prefix.'posts.ID', '' , $sql);
$sql = str_replace("!= ''", '<> 0', $sql);

View File

@@ -41,8 +41,15 @@
// Emulate SHOW commands
if( 0 === strpos( $sql, 'SHOW') || 0 === strpos( $sql, 'show'))
{
// SHOW VARIABLES LIKE emulation for sql_mode
// Used by nextgen-gallery plugin
if( 0 === strpos( $sql, "SHOW VARIABLES LIKE 'sql_mode'"))
{
// Act like MySQL default configuration, where sql_mode is ""
$sql = 'SELECT \'sql_mode\' AS "Variable_name", \'\' AS "Value";';
}
// SHOW COLUMNS emulation
if( preg_match('/SHOW\s+(FULL\s+)?COLUMNS\s+(?:FROM\s+|IN\s+)`?(\w+)`?(?:\s+LIKE\s+(.+)|\s+WHERE\s+(.+))?/i', $sql, $matches))
elseif( preg_match('/SHOW\s+(FULL\s+)?COLUMNS\s+(?:FROM\s+|IN\s+)`?(\w+)`?(?:\s+LIKE\s+(.+)|\s+WHERE\s+(.+))?/i', $sql, $matches))
{
$logto = 'SHOWCOLUMN';
$full = $matches[1];