Yaron Koren has uploaded a new change for review.

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

Change subject: Yet more quoting of field names
......................................................................

Yet more quoting of field names

Change-Id: Ie1f276ce9bf3c5554397caa24c0cd2500d8c28f7
---
M CargoSQLQuery.php
M parserfunctions/CargoStore.php
2 files changed, 14 insertions(+), 14 deletions(-)


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

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 936af93..e042d3e 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -57,7 +57,7 @@
                $sqlQuery->mGroupByStr = $groupByStr;
                $sqlQuery->mHavingStr = $havingStr;
                $sqlQuery->setDescriptionsForFields();
-               $sqlQuery->handleVirtualFields();
+               $sqlQuery->handleVirtualFields( $cdb );
                $sqlQuery->handleVirtualCoordinateFields();
                $sqlQuery->handleDateFields();
                $sqlQuery->handleSearchTextFields();
@@ -577,7 +577,7 @@
                }
        }
 
-       function handleVirtualFields() {
+       function handleVirtualFields( $cdb ) {
                // The array-field alias can be found in a number of different
                // clauses. Handling depends on which clause it is:
                // "where" - make sure that "HOLDS" or "HOlDS LIKE" is
@@ -666,9 +666,9 @@
                                $this->mCargoJoinConds[] = array(
                                        'joinType' => 'LEFT OUTER JOIN',
                                        'table1' => $tableName,
-                                       'field1' => '_ID',
+                                       'field1' => $cdb->addIdentifierQuotes( 
'_ID' ),
                                        'table2' => $fieldTableName,
-                                       'field2' => '_rowID'
+                                       'field2' => $cdb->addIdentifierQuotes( 
'_rowID' )
                                );
                        }
                }
@@ -693,9 +693,9 @@
                                $newJoinCond = array(
                                        'joinType' => 'LEFT OUTER JOIN',
                                        'table1' => $tableName,
-                                       'field1' => '_ID',
+                                       'field1' => $cdb->addIdentifierQuotes( 
'_ID' ),
                                        'table2' => $fieldTableName,
-                                       'field2' => '_rowID'
+                                       'field2' => $cdb->addIdentifierQuotes( 
'_rowID' )
                                );
                                $newCargoJoinConds[] = $newJoinCond;
                                $newJoinCond2 = array(
@@ -737,9 +737,9 @@
                                        $this->mCargoJoinConds[] = array(
                                                'joinType' => 'LEFT OUTER JOIN',
                                                'table1' => $tableName,
-                                               'field1' => '_ID',
+                                               'field1' => 
$cdb->addIdentifierQuotes( '_ID' ),
                                                'table2' => $fieldTableName,
-                                               'field2' => '_rowID'
+                                               'field2' => 
$cdb->addIdentifierQuotes( '_rowID' )
                                        );
                                }
                                $replacement = "$fieldTableName._value";
@@ -784,7 +784,7 @@
                        // whether or not that field has been "joined" on.
                        $fieldTableName = $tableName . '__' . $fieldName;
                        if ( $this->fieldTableIsIncluded( $fieldTableName ) ) {
-                               $fieldName = $fieldTableName . '._value';
+                               $fieldName = $fieldTableName . '.' . 
$cdb->addIdentifierQuotes( '_value' );
                        } else {
                                $fieldName .= '__full';
                        }
@@ -1106,7 +1106,7 @@
                        // 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 ) {
+                       if ( strpos( $fieldName, '(' ) === false && 
!$cdb->isQuotedIdentifier( $fieldName ) ) {
                                $fieldName = $cdb->addIdentifierQuotes( 
$fieldName );
                        }
                        $realAliasedFieldNames[$alias] = $fieldName;
diff --git a/parserfunctions/CargoStore.php b/parserfunctions/CargoStore.php
index 7471428..2ceb96e 100644
--- a/parserfunctions/CargoStore.php
+++ b/parserfunctions/CargoStore.php
@@ -277,7 +277,8 @@
 
                $cdb = CargoUtils::getDB();
 
-               $res = $cdb->select( $tableName, 'MAX(_ID) AS "ID"' );
+               $res = $cdb->select( $tableName, 'MAX(' .
+                       $cdb->addIdentifierQuotes( '_ID' ) . ') AS "ID"' );
                $row = $cdb->fetchRow( $res );
                $curRowID = $row['ID'] + 1;
                $tableFieldValues['_ID'] = $curRowID;
@@ -323,9 +324,8 @@
                        }
                }
 
-               // Put quotes around everything - this doesn't help with
-               // anything, but it might in the future, if Cargo becomes
-               // more permissive about field naming.
+               // Put quotes around everything - needed for Postgres,
+               // which otherwise lowercases all field names.
                $quotedFieldValues = array();
                foreach( $tableFieldValues as $fieldName => $fieldValue ) {
                        $quotedFieldName = $cdb->addIdentifierQuotes( 
$fieldName );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1f276ce9bf3c5554397caa24c0cd2500d8c28f7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <yaro...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to