[MediaWiki-commits] [Gerrit] sql queries reformatted - change (mediawiki...WikiLexicalData)

2013-05-30 Thread Kipcool (Code Review)
Kipcool has uploaded a new change for review.

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


Change subject: sql queries reformatted
..

sql queries reformatted

Change-Id: I67493f7d832bd4c4bcb165a89f09f8b6140e0dde
---
M OmegaWiki/OmegaWikiRecordSets.php
1 file changed, 52 insertions(+), 61 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiLexicalData 
refs/changes/96/66096/1

diff --git a/OmegaWiki/OmegaWikiRecordSets.php 
b/OmegaWiki/OmegaWikiRecordSets.php
index cbc4030..b20c40f 100644
--- a/OmegaWiki/OmegaWikiRecordSets.php
+++ b/OmegaWiki/OmegaWikiRecordSets.php
@@ -127,26 +127,21 @@
$o = OmegaWikiAttributes::getInstance();
$dc = wdGetDataSetContext();
$dbr = wfGetDB( DB_SLAVE );
-   
-   # Query building
-   $frontQuery = SELECT {$dc}_defined_meaning.defined_meaning_id AS 
defined_meaning_id, {$dc}_expression.spelling .
-FROM {$dc}_defined_meaning, {$dc}_expression  .
-WHERE 
{$dc}_defined_meaning.expression_id={$dc}_expression.expression_id  .
-AND {$dc}_defined_meaning.remove_transaction_id IS NULL  .
-AND {$dc}_expression.remove_transaction_id IS NULL  .
-AND {$dc}_defined_meaning.defined_meaning_id = ;
 
-   // copy the definedMeaningIds array to create one query for each DM id
-   $definedMeaningQueries = $definedMeaningIds;
-   unset( $value );
-   foreach ( $definedMeaningQueries as $value ) {
-   $value = $frontQuery . $value;
-   }
-   unset( $value );
-   # Union of the atoms
-   $finalQuery = implode( ' UNION ', $definedMeaningQueries );
-   
-   $queryResult = $dbr-query( $finalQuery );
+   $queryResult = $dbr-select(
+   array(
+   'dm' = {$dc}_defined_meaning,
+   'exp' = {$dc}_expression
+   ), array( /* fields to select */
+   'defined_meaning_id' = dm.defined_meaning_id,
+   'spelling' = exp.spelling
+   ), array( /* where */
+   'exp.expression_id = dm.expression_id', // getting 
defining expression
+   'dm.defined_meaning_id' = $definedMeaningIds,
+   'exp.remove_transaction_id' = null,
+   'dm.remove_transaction_id' = null
+   ), __METHOD__
+   );
 
foreach ( $queryResult as $row ) {
if ( isset( 
$definedMeaningReferenceRecords[$row-defined_meaning_id] ) ) {
@@ -252,15 +247,21 @@
// an array of records
$result = array();
 
-   // find the spelling of a syntrans (of all syntrans from array 
syntransIds)
-   $sql = SELECT /* getSyntransReferenceRecords */ syntrans_sid, spelling
-   .  FROM {$dc}_syntrans, {$dc}_expression 
-   .  WHERE syntrans_sid IN ( . implode( , , $syntransIds ) . 
)
-   .  AND 
{$dc}_expression.expression_id={$dc}_syntrans.expression_id ;
-
-   $queryResult = $dbr-query( $sql );
$structure = new Structure( WLD_SYNONYMS_TRANSLATIONS, $o-syntransId, 
$o-spelling );
$structure-setStructureType( $usedAs );
+
+   $queryResult = $dbr-select(
+   array(
+   'synt' = {$dc}_syntrans,
+   'exp' = {$dc}_expression
+   ), array (
+   'syntrans_sid',
+   'spelling'
+   ), array (
+   'syntrans_sid' = $syntransIds,
+   'exp.expression_id = synt.expression_id'
+   ), __METHOD__
+   );
 
foreach ( $queryResult as $row ) {
$record = new ArrayRecord( $structure );
@@ -313,20 +314,14 @@
if ( count( $expressionIds )  0 ) {
$dbr = wfGetDB( DB_SLAVE );

-   # Prepare steady components
-   $frontQuery = SELECT expression_id, spelling FROM 
{$dc}_expression WHERE expression_id =;
-   $queueQuery =  AND {$dc}_expression.remove_transaction_id 
IS NULL ;
-   # Build atomic queries
-   foreach ( $expressionIds as $value ) {
-   $value = $frontQuery . $value . $queueQuery;
-   }
-   unset( $value );
-   # Union of the atoms
-   $finalQuery = implode( ' UNION ', $expressionIds );
-   
-   $queryResult = $dbr-query( $finalQuery );
-   
-   $result = array();
+   $queryResult = $dbr-select(
+   {$dc}_expression,
+   array( 'expression_id', 'spelling' ),
+   array( /* where */
+   'expression_id' = $expressionIds,
+   'remove_transaction_id' = null
+   ), 

[MediaWiki-commits] [Gerrit] sql queries reformatted - change (mediawiki...WikiLexicalData)

2013-05-30 Thread Kipcool (Code Review)
Kipcool has submitted this change and it was merged.

Change subject: sql queries reformatted
..


sql queries reformatted

Change-Id: I67493f7d832bd4c4bcb165a89f09f8b6140e0dde
---
M OmegaWiki/OmegaWikiRecordSets.php
1 file changed, 52 insertions(+), 61 deletions(-)

Approvals:
  Kipcool: Verified; Looks good to me, approved



diff --git a/OmegaWiki/OmegaWikiRecordSets.php 
b/OmegaWiki/OmegaWikiRecordSets.php
index cbc4030..b20c40f 100644
--- a/OmegaWiki/OmegaWikiRecordSets.php
+++ b/OmegaWiki/OmegaWikiRecordSets.php
@@ -127,26 +127,21 @@
$o = OmegaWikiAttributes::getInstance();
$dc = wdGetDataSetContext();
$dbr = wfGetDB( DB_SLAVE );
-   
-   # Query building
-   $frontQuery = SELECT {$dc}_defined_meaning.defined_meaning_id AS 
defined_meaning_id, {$dc}_expression.spelling .
-FROM {$dc}_defined_meaning, {$dc}_expression  .
-WHERE 
{$dc}_defined_meaning.expression_id={$dc}_expression.expression_id  .
-AND {$dc}_defined_meaning.remove_transaction_id IS NULL  .
-AND {$dc}_expression.remove_transaction_id IS NULL  .
-AND {$dc}_defined_meaning.defined_meaning_id = ;
 
-   // copy the definedMeaningIds array to create one query for each DM id
-   $definedMeaningQueries = $definedMeaningIds;
-   unset( $value );
-   foreach ( $definedMeaningQueries as $value ) {
-   $value = $frontQuery . $value;
-   }
-   unset( $value );
-   # Union of the atoms
-   $finalQuery = implode( ' UNION ', $definedMeaningQueries );
-   
-   $queryResult = $dbr-query( $finalQuery );
+   $queryResult = $dbr-select(
+   array(
+   'dm' = {$dc}_defined_meaning,
+   'exp' = {$dc}_expression
+   ), array( /* fields to select */
+   'defined_meaning_id' = dm.defined_meaning_id,
+   'spelling' = exp.spelling
+   ), array( /* where */
+   'exp.expression_id = dm.expression_id', // getting 
defining expression
+   'dm.defined_meaning_id' = $definedMeaningIds,
+   'exp.remove_transaction_id' = null,
+   'dm.remove_transaction_id' = null
+   ), __METHOD__
+   );
 
foreach ( $queryResult as $row ) {
if ( isset( 
$definedMeaningReferenceRecords[$row-defined_meaning_id] ) ) {
@@ -252,15 +247,21 @@
// an array of records
$result = array();
 
-   // find the spelling of a syntrans (of all syntrans from array 
syntransIds)
-   $sql = SELECT /* getSyntransReferenceRecords */ syntrans_sid, spelling
-   .  FROM {$dc}_syntrans, {$dc}_expression 
-   .  WHERE syntrans_sid IN ( . implode( , , $syntransIds ) . 
)
-   .  AND 
{$dc}_expression.expression_id={$dc}_syntrans.expression_id ;
-
-   $queryResult = $dbr-query( $sql );
$structure = new Structure( WLD_SYNONYMS_TRANSLATIONS, $o-syntransId, 
$o-spelling );
$structure-setStructureType( $usedAs );
+
+   $queryResult = $dbr-select(
+   array(
+   'synt' = {$dc}_syntrans,
+   'exp' = {$dc}_expression
+   ), array (
+   'syntrans_sid',
+   'spelling'
+   ), array (
+   'syntrans_sid' = $syntransIds,
+   'exp.expression_id = synt.expression_id'
+   ), __METHOD__
+   );
 
foreach ( $queryResult as $row ) {
$record = new ArrayRecord( $structure );
@@ -313,20 +314,14 @@
if ( count( $expressionIds )  0 ) {
$dbr = wfGetDB( DB_SLAVE );

-   # Prepare steady components
-   $frontQuery = SELECT expression_id, spelling FROM 
{$dc}_expression WHERE expression_id =;
-   $queueQuery =  AND {$dc}_expression.remove_transaction_id 
IS NULL ;
-   # Build atomic queries
-   foreach ( $expressionIds as $value ) {
-   $value = $frontQuery . $value . $queueQuery;
-   }
-   unset( $value );
-   # Union of the atoms
-   $finalQuery = implode( ' UNION ', $expressionIds );
-   
-   $queryResult = $dbr-query( $finalQuery );
-   
-   $result = array();
+   $queryResult = $dbr-select(
+   {$dc}_expression,
+   array( 'expression_id', 'spelling' ),
+   array( /* where */
+   'expression_id' = $expressionIds,
+   'remove_transaction_id' = null
+   ), __METHOD__
+   );
 
foreach ( $queryResult as $row ) {