Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/280806

Change subject: Added quotes around field names, to avoid Postgres lowercasing
......................................................................

Added quotes around field names, to avoid Postgres lowercasing

Change-Id: I1cdce214a08b6f9cbf9d6bd02cccd041f254fd11
---
M CargoSQLQuery.php
M CargoUtils.php
2 files changed, 18 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/06/280806/1

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 51ebfc5..27995eb 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -1101,7 +1101,14 @@
                // call the DB query.
                $realAliasedFieldNames = array();
                foreach ( $this->mAliasedFieldNames as $alias => $fieldName ) {
-                       $realAliasedFieldNames['"' . $alias . '"'] = $fieldName;
+                       $alias = $cdb->addIdentifierQuotes( $alias );
+                       // If it's really a field name, add quotes around it.
+                       // (The quotes are mostly needed for Postgres, which
+                       // lowercases all unquoted fields.)
+                       if ( strpos( $fieldName, '(' ) === false ) {
+                               $fieldName = $cdb->addIdentifierQuotes( 
$fieldName );
+                       }
+                       $realAliasedFieldNames[$alias] = $fieldName;
                }
 
                $res = $cdb->select( $this->mTableNames, 
$realAliasedFieldNames, $this->mWhereStr, __METHOD__,
diff --git a/CargoUtils.php b/CargoUtils.php
index 3cc4f7a..ce212df 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -536,11 +536,11 @@
 
                $createSQL = "CREATE TABLE " .
                        $cdb->tableName( $tableName ) . ' ( ' .
-                       "_ID $intTypeString NOT NULL UNIQUE, " .
-                       "_pageName $stringTypeString NOT NULL, " .
-                       "_pageTitle $stringTypeString NOT NULL, " .
-                       "_pageNamespace $intTypeString NOT NULL, " .
-                       "_pageID $intTypeString NOT NULL";
+                       $cdb->addIdentifierQuotes( '_ID' ) . " $intTypeString 
NOT NULL UNIQUE, " .
+                       $cdb->addIdentifierQuotes( '_pageName' ) . " 
$stringTypeString NOT NULL, " .
+                       $cdb->addIdentifierQuotes( '_pageTitle' ) . " 
$stringTypeString NOT NULL, " .
+                       $cdb->addIdentifierQuotes( '_pageNamespace' ) . " 
$intTypeString NOT NULL, " .
+                       $cdb->addIdentifierQuotes( '_pageID' ) . " 
$intTypeString NOT NULL";
 
                foreach ( $tableSchema->mFieldDescriptions as $fieldName => 
$fieldDescription ) {
                        $size = $fieldDescription->mSize;
@@ -552,7 +552,7 @@
                                // instead, we'll have one called
                                // fieldName + '__full', and a separate table
                                // for holding each value.
-                               $createSQL .= ', ' . $fieldName . '__full ';
+                               $createSQL .= ', ' . $cdb->addIdentifierQuotes( 
$fieldName . '__full' ) . ' ';
                                // The field holding the full list will always
                                // just be text
                                $createSQL .= $stringTypeString;
@@ -563,16 +563,16 @@
 
                        if ( !$isList && $fieldType == 'Coordinates' ) {
                                $floatTypeString = self::fieldTypeToSQLType( 
'Float', $dbType );
-                               $createSQL .= ', ' . $fieldName . '__lat ';
+                               $createSQL .= ', ' . $cdb->addIdentifierQuotes( 
$fieldName . '__lat' ) . ' ';
                                $createSQL .= $floatTypeString;
-                               $createSQL .= ', ' . $fieldName . '__lon ';
+                               $createSQL .= ', ' . $cdb->addIdentifierQuotes( 
$fieldName . '__lon' ) . ' ';
                                $createSQL .= $floatTypeString;
                        } elseif ( $fieldType == 'Date' || $fieldType == 
'Datetime' ) {
                                $integerTypeString = self::fieldTypeToSQLType( 
'Integer', $dbType );
-                               $createSQL .= ', ' . $fieldName . '__precision 
';
+                               $createSQL .= ", " . $cdb->addIdentifierQuotes( 
$fieldName . '__precision' ) . ' ';
                                $createSQL .= $integerTypeString;
                        } elseif ( $fieldType == 'Searchtext' ) {
-                               $createSQL .= ", FULLTEXT KEY $fieldName 
($fieldName)";
+                               $createSQL .= ", FULLTEXT KEY $fieldName (" . 
$cdb->addIdentifierQuotes( $fieldName ) . ')';
                        }
                }
                $createSQL .= ' )';

-- 
To view, visit https://gerrit.wikimedia.org/r/280806
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1cdce214a08b6f9cbf9d6bd02cccd041f254fd11
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to