[MediaWiki-commits] [Gerrit] mediawiki/core[master]: DB: Add join conditions to selectField, selectFieldValues, a...

2017-06-13 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/358054 )

Change subject: DB: Add join conditions to selectField, selectFieldValues, and 
insertSelect
..


DB: Add join conditions to selectField, selectFieldValues, and insertSelect

selectField() and selectFieldValues() are trivial, they just need to
pass it through to select(). In fact, selectFieldValues() was already
doing it, just no one ever updated IDatabase.

insertSelect() is a little more work. nativeInsertSelect() was
originally written as largely a copy-paste of select() and has since
gotten well out of sync. Now that we have selectSQLText(), we should be
able to just use that. DatabasePostgres's implementation can wrap the
parent implementation instead of being another copy-paste, but
DatabaseOracle seems to still need to be special.

Change-Id: I0e6a9e6daa510639d3212641606047a5db96c500
---
M includes/db/DatabaseOracle.php
M includes/libs/rdbms/database/DBConnRef.php
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/database/DatabaseMssql.php
M includes/libs/rdbms/database/DatabasePostgres.php
M includes/libs/rdbms/database/IDatabase.php
M tests/phpunit/includes/db/DatabaseSQLTest.php
7 files changed, 78 insertions(+), 86 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php
index b728786..556fe75 100644
--- a/includes/db/DatabaseOracle.php
+++ b/includes/db/DatabaseOracle.php
@@ -558,19 +558,9 @@
}
 
function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, 
$fname = __METHOD__,
-   $insertOptions = [], $selectOptions = []
+   $insertOptions = [], $selectOptions = [], $selectJoinConds = []
) {
$destTable = $this->tableName( $destTable );
-   if ( !is_array( $selectOptions ) ) {
-   $selectOptions = [ $selectOptions ];
-   }
-   list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) =
-   $this->makeSelectOptions( $selectOptions );
-   if ( is_array( $srcTable ) ) {
-   $srcTable = implode( ',', array_map( [ $this, 
'tableName' ], $srcTable ) );
-   } else {
-   $srcTable = $this->tableName( $srcTable );
-   }
 
$sequenceData = $this->getSequenceData( $destTable );
if ( $sequenceData !== false &&
@@ -585,13 +575,16 @@
$val = $val . ' field' . ( $i++ );
}
 
-   $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( 
$varMap ) ) . ')' .
-   " SELECT $startOpts " . implode( ',', $varMap ) .
-   " FROM $srcTable $useIndex $ignoreIndex ";
-   if ( $conds != '*' ) {
-   $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
-   }
-   $sql .= " $tailOpts";
+   $selectSql = $this->selectSQLText(
+   $srcTable,
+   array_values( $varMap ),
+   $conds,
+   $fname,
+   $selectOptions,
+   $selectJoinConds
+   );
+
+   $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( 
$varMap ) ) . ') ' . $selectSql;
 
if ( in_array( 'IGNORE', $insertOptions ) ) {
$this->ignoreDupValOnIndex = true;
diff --git a/includes/libs/rdbms/database/DBConnRef.php 
b/includes/libs/rdbms/database/DBConnRef.php
index 5b59d2a..fb4122d 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -247,13 +247,13 @@
}
 
public function selectField(
-   $table, $var, $cond = '', $fname = __METHOD__, $options = []
+   $table, $var, $cond = '', $fname = __METHOD__, $options = [], 
$join_conds = []
) {
return $this->__call( __FUNCTION__, func_get_args() );
}
 
public function selectFieldValues(
-   $table, $var, $cond = '', $fname = __METHOD__, $options = []
+   $table, $var, $cond = '', $fname = __METHOD__, $options = [], 
$join_conds = []
) {
return $this->__call( __FUNCTION__, func_get_args() );
}
@@ -411,7 +411,7 @@
 
public function insertSelect(
$destTable, $srcTable, $varMap, $conds,
-   $fname = __METHOD__, $insertOptions = [], $selectOptions = []
+   $fname = __METHOD__, $insertOptions = [], $selectOptions = [], 
$selectJoinConds = []
) {
return $this->__call( __FUNCTION__, func_get_args() );
}
diff --git a/includes/libs/rdbms/database/Database.php 

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: DB: Add join conditions to selectField, selectFieldValues, a...

2017-06-09 Thread Anomie (Code Review)
Anomie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358054 )

Change subject: DB: Add join conditions to selectField, selectFieldValues, and 
insertSelect
..

DB: Add join conditions to selectField, selectFieldValues, and insertSelect

selectField() and selectFieldValues() are trivial, they just need to
pass it through to select(). In fact, selectFieldValues() was already
doing it, just no one ever updated IDatabase.

insertSelect() is a little more work. nativeInsertSelect() was
originally written as largely a copy-paste of select() and has since
gotten well out of sync. Now that we have selectSQLText(), we should be
able to just use that. DatabasePostgres's implementation can wrap the
parent implementation instead of being another copy-paste, but
DatabaseOracle seems to still need to be special.

Change-Id: I0e6a9e6daa510639d3212641606047a5db96c500
---
M includes/db/DatabaseOracle.php
M includes/libs/rdbms/database/DBConnRef.php
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/database/DatabaseMssql.php
M includes/libs/rdbms/database/DatabasePostgres.php
M includes/libs/rdbms/database/IDatabase.php
6 files changed, 48 insertions(+), 80 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/54/358054/1

diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php
index b728786..556fe75 100644
--- a/includes/db/DatabaseOracle.php
+++ b/includes/db/DatabaseOracle.php
@@ -558,19 +558,9 @@
}
 
function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, 
$fname = __METHOD__,
-   $insertOptions = [], $selectOptions = []
+   $insertOptions = [], $selectOptions = [], $selectJoinConds = []
) {
$destTable = $this->tableName( $destTable );
-   if ( !is_array( $selectOptions ) ) {
-   $selectOptions = [ $selectOptions ];
-   }
-   list( $startOpts, $useIndex, $tailOpts, $ignoreIndex ) =
-   $this->makeSelectOptions( $selectOptions );
-   if ( is_array( $srcTable ) ) {
-   $srcTable = implode( ',', array_map( [ $this, 
'tableName' ], $srcTable ) );
-   } else {
-   $srcTable = $this->tableName( $srcTable );
-   }
 
$sequenceData = $this->getSequenceData( $destTable );
if ( $sequenceData !== false &&
@@ -585,13 +575,16 @@
$val = $val . ' field' . ( $i++ );
}
 
-   $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( 
$varMap ) ) . ')' .
-   " SELECT $startOpts " . implode( ',', $varMap ) .
-   " FROM $srcTable $useIndex $ignoreIndex ";
-   if ( $conds != '*' ) {
-   $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
-   }
-   $sql .= " $tailOpts";
+   $selectSql = $this->selectSQLText(
+   $srcTable,
+   array_values( $varMap ),
+   $conds,
+   $fname,
+   $selectOptions,
+   $selectJoinConds
+   );
+
+   $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( 
$varMap ) ) . ') ' . $selectSql;
 
if ( in_array( 'IGNORE', $insertOptions ) ) {
$this->ignoreDupValOnIndex = true;
diff --git a/includes/libs/rdbms/database/DBConnRef.php 
b/includes/libs/rdbms/database/DBConnRef.php
index b6167aa..c4aeab7 100644
--- a/includes/libs/rdbms/database/DBConnRef.php
+++ b/includes/libs/rdbms/database/DBConnRef.php
@@ -243,13 +243,13 @@
}
 
public function selectField(
-   $table, $var, $cond = '', $fname = __METHOD__, $options = []
+   $table, $var, $cond = '', $fname = __METHOD__, $options = [], 
$join_conds = []
) {
return $this->__call( __FUNCTION__, func_get_args() );
}
 
public function selectFieldValues(
-   $table, $var, $cond = '', $fname = __METHOD__, $options = []
+   $table, $var, $cond = '', $fname = __METHOD__, $options = [], 
$join_conds = []
) {
return $this->__call( __FUNCTION__, func_get_args() );
}
@@ -407,7 +407,7 @@
 
public function insertSelect(
$destTable, $srcTable, $varMap, $conds,
-   $fname = __METHOD__, $insertOptions = [], $selectOptions = []
+   $fname = __METHOD__, $insertOptions = [], $selectOptions = [], 
$selectJoinConds = []
) {
return $this->__call( __FUNCTION__, func_get_args() );
}
diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index ee7644f..2021c86 100644
---