Vincenzo Laudizio has uploaded a new change for review.
https://gerrit.wikimedia.org/r/114763
Change subject: Fixed SemanticDrillDown generated sql queries for working with
Postgres
......................................................................
Fixed SemanticDrillDown generated sql queries for working with Postgres
1) Revomed blank string check
2) Special character quote is replaced with a double quote sequence when
postgres is the database
Bug: 61751
Change-Id: Ibce4f16821810475649512dccf4ade0f0cc10572
---
M includes/SD_AppliedFilter.php
M includes/SD_Filter.php
2 files changed, 14 insertions(+), 5 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticDrilldown
refs/changes/63/114763/1
diff --git a/includes/SD_AppliedFilter.php b/includes/SD_AppliedFilter.php
index b05a24d..99e4b1e 100644
--- a/includes/SD_AppliedFilter.php
+++ b/includes/SD_AppliedFilter.php
@@ -42,10 +42,12 @@
* combination to an SQL "WHERE" clause.
*/
function checkSQL( $value_field ) {
+ global $wgDBtype;
$sql = "(";
$dbr = wfGetDB( DB_SLAVE );
if ( $this->search_term != null ) {
- $search_term = str_replace( "'", "\'",
$this->search_term );
+ $quoteReplace = ( $wgDBtype == 'postgres' ? "''" :
"\'");
+ $search_term = str_replace( "'", $quoteReplace,
$this->search_term );
if ( $this->filter->property_type === 'page' ) {
// FIXME: 'LIKE' is supposed to be
// case-insensitive, but it's not acting
@@ -72,14 +74,17 @@
foreach ( $this->values as $i => $fv ) {
if ( $i > 0 ) { $sql .= " OR "; }
if ( $fv->is_other ) {
- $sql .= "(! ($value_field IS NULL OR
$value_field = '' ";
+ $checkNullOrEmptySql = "$value_field IS NULL "
. ( $wgDBtype == 'postgres' ? '' : "OR $value_field = '' ");
+ $notOperatorSql = ( $wgDBtype == 'postgres' ?
"not" : "!" );
+ $sql .= "($notOperatorSql ($checkNullOrEmptySql
";
foreach (
$this->filter->possible_applied_filters as $paf ) {
$sql .= " OR ";
$sql .= $paf->checkSQL( $value_field );
}
$sql .= "))";
} elseif ( $fv->is_none ) {
- $sql .= "($value_field = '' OR $value_field IS
NULL) ";
+ $checkNullOrEmptySql = ( $wgDBtype ==
'postgres' ? '' : "$value_field = '' OR ") . "$value_field IS NULL";
+ $sql .= "($checkNullOrEmptySql) ";
} elseif ( $fv->is_numeric ) {
if ( $fv->lower_limit && $fv->upper_limit )
$sql .= "($value_field >=
{$fv->lower_limit} AND $value_field <= {$fv->upper_limit}) ";
diff --git a/includes/SD_Filter.php b/includes/SD_Filter.php
index 0780780..ef8225a 100644
--- a/includes/SD_Filter.php
+++ b/includes/SD_Filter.php
@@ -20,6 +20,8 @@
var $db_date_field;
static function loadAllFromPageSchema( $psSchemaObj ){
+ global $wgDBtype;
+ $quoteReplace = ( $wgDBtype == 'postgres' ? "''" : "\'");
$filters_ps = array();
$template_all = $psSchemaObj->getTemplates();
foreach ( $template_all as $template ) {
@@ -41,7 +43,7 @@
} else {
$f->property = $f->name;
}
- $f->escaped_property = str_replace( array( ' ',
"'" ), array( '_', "\'" ), $f->property );
+ $f->escaped_property = str_replace( array( ' ',
"'" ), array( '_', $quoteReplace ), $f->property );
if ( array_key_exists( 'Type', $prop_array ) ) {
// Thankfully, the property type names
// assigned by SMW/Page Schemas, and the
@@ -73,12 +75,14 @@
}
static function load( $filter_name ) {
+ global $wgDBtype;
+ $quoteReplace = ( $wgDBtype == 'postgres' ? "''" : "\'");
$f = new SDFilter();
$f->name = $filter_name;
$properties_used = SDUtils::getValuesForProperty( $filter_name,
SD_NS_FILTER, '_SD_CP', SD_SP_COVERS_PROPERTY, SMW_NS_PROPERTY );
if ( count( $properties_used ) > 0 ) {
$f->property = $properties_used[0];
- $f->escaped_property = str_replace( array( ' ', "'" ),
array( '_', "\'" ), $f->property );
+ $f->escaped_property = str_replace( array( ' ', "'" ),
array( '_', $quoteReplace ), $f->property );
// This may not be necessary, or useful.
$f->property_type = 'page';
}
--
To view, visit https://gerrit.wikimedia.org/r/114763
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibce4f16821810475649512dccf4ade0f0cc10572
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticDrilldown
Gerrit-Branch: master
Gerrit-Owner: Vincenzo Laudizio <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits