erosenfield
Forum Replies Created
-
Forum: Plugins
In reply to: [WP Db Abstraction] [Plugin: WP Db Abstraction] doesnt work fullyNOOOOOO…. that code causes problems with session and login for some reason…. ugh…. back to drawing board… ignore my last post (but it might have been close)
Forum: Plugins
In reply to: [WP Db Abstraction] [Plugin: WP Db Abstraction] doesnt work fullyI experienced the same issue, and have resolved it.
So I thought I would post to help others.
I tracked the issue to the same place.
The troublesome file is:
/wp-content/mu-plugins/wp-db-abstraction/translations/sqlsrv/translations.php
The problematic code is inside the function called “translate_limit”
The issue seems to be the result of “count($limit_matches).”
Querys against the user table seem to match five times, and queries against the post table seem to match six times.
Bottom line:
Below is my present solution.
Simply replace the CONTENTS (not the outmost braces) of the “translate_limit” function with the code below.
Hope this works for others.
if ( (stripos($query,'SELECT') !== 0 && stripos($query,'SELECT') !== FALSE) && (stripos($query,'UPDATE') !== 0 && stripos($query,'UPDATE') !== FALSE) ) { return $query; } $pattern = '/LIMIT\s*(\d+)((\s*,?\s*)(\d+)*)(;{0,1})$/is'; $matched = preg_match($pattern, $query, $limit_matches); if ( $matched == 0 ) { return $query; } // Remove the LIMIT statement $true_offset = false; $query = preg_replace($pattern, '', $query); if ( $this->delete_query ) { return $query; } // Check for true offset // needed to add new code here: // The pages showing posts need count($limit_matches) == 6 // The pages showing users need count($limit_matches) == 5 // so I will check if the query includes the name of the user table, and then respond accordingly // check for user table $userTablePos = strpos($query,"ASPPR_users"); if ($userTablePos == true) { // the query is addressing the user table if ( count($limit_matches) == 5 && $limit_matches[1] != '0' ) { $true_offset = true; } elseif ( count($limit_matches) == 5 && $limit_matches[1] == '0' ) { $limit_matches[1] = $limit_matches[4]; } } else { // the query is not addressing the user table if ( count($limit_matches) == 6 && $limit_matches[1] != '0' ) { $true_offset = true; } elseif ( count($limit_matches) == 6 && $limit_matches[1] == '0' ) { $limit_matches[1] = $limit_matches[4]; } } // Rewrite the query. if ( $true_offset === false ) { if ( stripos($query, 'DISTINCT') > 0 ) { $query = str_ireplace('DISTINCT', 'DISTINCT TOP ' . $limit_matches[1] . ' ', $query); } else { $query = str_ireplace('DELETE ', 'DELETE TOP ' . $limit_matches[1] . ' ', $query); $query = str_ireplace('SELECT ', 'SELECT TOP ' . $limit_matches[1] . ' ', $query); } } else { $limit_matches[1] = (int) $limit_matches[1]; $limit_matches[4] = (int) $limit_matches[4]; $this->limit = array( 'from' => $limit_matches[1], 'to' => $limit_matches[4] ); } return $query;