aboutsummaryrefslogtreecommitdiffstats
path: root/includes/libs
diff options
context:
space:
mode:
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>2022-06-28 02:28:10 +0000
committerGerrit Code Review <gerrit@wikimedia.org>2022-06-28 02:28:10 +0000
commit4075ba2bab0a52baf6c3af8a0dbc1baf2f2efc7c (patch)
treeab237c814a567d36475b4edcab44f7cb731d273e /includes/libs
parent2a26bcc0fe80322fd33fddb9446728ecf9618f4b (diff)
parent0f32376bf68020ec762c2130a9be8db7c7b899bc (diff)
downloadmediawikicore-4075ba2bab0a52baf6c3af8a0dbc1baf2f2efc7c.tar.gz
mediawikicore-4075ba2bab0a52baf6c3af8a0dbc1baf2f2efc7c.zip
Merge "rdbms: Migrate buildGroupConcatField and buildSelectSubquery to platform"
Diffstat (limited to 'includes/libs')
-rw-r--r--includes/libs/rdbms/database/Database.php34
-rw-r--r--includes/libs/rdbms/database/DatabasePostgres.php8
-rw-r--r--includes/libs/rdbms/database/DatabaseSqlite.php8
-rw-r--r--includes/libs/rdbms/database/IDatabase.php43
-rw-r--r--includes/libs/rdbms/platform/ISQLPlatform.php43
-rw-r--r--includes/libs/rdbms/platform/PostgresPlatform.php7
-rw-r--r--includes/libs/rdbms/platform/SQLPlatform.php21
-rw-r--r--includes/libs/rdbms/platform/SqlitePlatform.php8
8 files changed, 92 insertions, 80 deletions
diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php
index 4e349e2f7b9c..ea9eb97aa6f2 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -2535,18 +2535,6 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
}
/**
- * @inheritDoc
- * @stable to override
- */
- public function buildGroupConcatField(
- $delim, $table, $field, $conds = '', $join_conds = []
- ) {
- $fld = "GROUP_CONCAT($field SEPARATOR " . $this->addQuotes( $delim ) . ')';
-
- return '(' . $this->selectSQLText( $table, $fld, $conds, __METHOD__, [], $join_conds ) . ')';
- }
-
- /**
* Check type and bounds conditions parameters for update
*
* In order to prevent possible performance or replication issues,
@@ -2570,15 +2558,6 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
}
}
- public function buildSelectSubquery(
- $table, $vars, $conds = '', $fname = __METHOD__,
- $options = [], $join_conds = []
- ) {
- return new Subquery(
- $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds )
- );
- }
-
public function buildExcludedValue( $column ) {
/* @see Database::doUpsert() */
// This can be treated like a single value since __VALS is a single row table
@@ -4939,6 +4918,19 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
$this->platform->setIndexAliases( $aliases );
}
+ public function buildGroupConcatField(
+ $delim, $table, $field, $conds = '', $join_conds = []
+ ) {
+ return $this->platform->buildGroupConcatField( $delim, $table, $field, $conds, $join_conds );
+ }
+
+ public function buildSelectSubquery(
+ $table, $vars, $conds = '', $fname = __METHOD__,
+ $options = [], $join_conds = []
+ ) {
+ return $this->platform->buildSelectSubquery( $table, $vars, $conds, $fname, $options, $join_conds );
+ }
+
/* End of methods delegated to SQLPlatform. */
}
diff --git a/includes/libs/rdbms/database/DatabasePostgres.php b/includes/libs/rdbms/database/DatabasePostgres.php
index 97489387f0ef..5243274697ac 100644
--- a/includes/libs/rdbms/database/DatabasePostgres.php
+++ b/includes/libs/rdbms/database/DatabasePostgres.php
@@ -1220,14 +1220,6 @@ SQL;
return "'" . pg_escape_string( $conn, (string)$s ) . "'";
}
- public function buildGroupConcatField(
- $delim, $table, $field, $conds = '', $join_conds = []
- ) {
- $fld = "array_to_string(array_agg($field)," . $this->addQuotes( $delim ) . ')';
-
- return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
- }
-
public function streamStatementEnd( &$sql, &$newLine ) {
# Allow dollar quoting for function declarations
if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php b/includes/libs/rdbms/database/DatabaseSqlite.php
index 9d90eed6c462..2b90d25d91f3 100644
--- a/includes/libs/rdbms/database/DatabaseSqlite.php
+++ b/includes/libs/rdbms/database/DatabaseSqlite.php
@@ -832,14 +832,6 @@ class DatabaseSqlite extends Database {
return $this->lockMgr->unlock( [ $lockName ], LockManager::LOCK_EX )->isGood();
}
- public function buildGroupConcatField(
- $delim, $table, $field, $conds = '', $join_conds = []
- ) {
- $fld = "group_concat($field," . $this->addQuotes( $delim ) . ')';
-
- return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
- }
-
/**
* @param string $oldName
* @param string $newName
diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php
index 5ecb29de16a6..793786fd6356 100644
--- a/includes/libs/rdbms/database/IDatabase.php
+++ b/includes/libs/rdbms/database/IDatabase.php
@@ -884,26 +884,6 @@ interface IDatabase extends ISQLPlatform, DbQuoter {
public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
/**
- * Build a GROUP_CONCAT or equivalent statement for a query.
- *
- * This is useful for combining a field for several rows into a single string.
- * NULL values will not appear in the output, duplicated values will appear,
- * and the resulting delimiter-separated values have no defined sort order.
- * Code using the results may need to use the PHP unique() or sort() methods.
- *
- * @param string $delim Glue to bind the results together
- * @param string|array $table Table name
- * @param string $field Field name
- * @param string|array $conds Conditions
- * @param string|array $join_conds Join conditions
- * @return string SQL text
- * @since 1.23
- */
- public function buildGroupConcatField(
- $delim, $table, $field, $conds = '', $join_conds = []
- );
-
- /**
* Build a reference to a column value from the conflicting proposed upsert() row.
*
* The reference comes in the form of an alias, function, or parenthesized SQL expression.
@@ -923,29 +903,6 @@ interface IDatabase extends ISQLPlatform, DbQuoter {
public function buildExcludedValue( $column );
/**
- * Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery
- *
- * @see IDatabase::selectSQLText()
- *
- * @param string|array $table Table name
- * @param string|array $vars Field names
- * @param string|array $conds Conditions
- * @param string $fname Caller function name
- * @param string|array $options Query options
- * @param string|array $join_conds Join conditions
- * @return Subquery
- * @since 1.31
- */
- public function buildSelectSubquery(
- $table,
- $vars,
- $conds = '',
- $fname = __METHOD__,
- $options = [],
- $join_conds = []
- );
-
- /**
* Returns true if DBs are assumed to be on potentially different servers
*
* In systems like mysql/mariadb, different databases can easily be referenced on a single
diff --git a/includes/libs/rdbms/platform/ISQLPlatform.php b/includes/libs/rdbms/platform/ISQLPlatform.php
index b8edd15bf57b..8e7242f099a0 100644
--- a/includes/libs/rdbms/platform/ISQLPlatform.php
+++ b/includes/libs/rdbms/platform/ISQLPlatform.php
@@ -21,6 +21,7 @@ namespace Wikimedia\Rdbms\Platform;
use Wikimedia\Rdbms\DBError;
use Wikimedia\Rdbms\LikeMatch;
+use Wikimedia\Rdbms\Subquery;
/**
* Interface for query language.
@@ -520,4 +521,46 @@ interface ISQLPlatform {
$join_conds = []
);
+ /**
+ * Build a GROUP_CONCAT or equivalent statement for a query.
+ *
+ * This is useful for combining a field for several rows into a single string.
+ * NULL values will not appear in the output, duplicated values will appear,
+ * and the resulting delimiter-separated values have no defined sort order.
+ * Code using the results may need to use the PHP unique() or sort() methods.
+ *
+ * @param string $delim Glue to bind the results together
+ * @param string|array $table Table name
+ * @param string $field Field name
+ * @param string|array $conds Conditions
+ * @param string|array $join_conds Join conditions
+ * @return string SQL text
+ * @since 1.23
+ */
+ public function buildGroupConcatField(
+ $delim, $table, $field, $conds = '', $join_conds = []
+ );
+
+ /**
+ * Equivalent to IDatabase::selectSQLText() except wraps the result in Subquery
+ *
+ * @see IDatabase::selectSQLText()
+ *
+ * @param string|array $table Table name
+ * @param string|array $vars Field names
+ * @param string|array $conds Conditions
+ * @param string $fname Caller function name
+ * @param string|array $options Query options
+ * @param string|array $join_conds Join conditions
+ * @return Subquery
+ * @since 1.31
+ */
+ public function buildSelectSubquery(
+ $table,
+ $vars,
+ $conds = '',
+ $fname = __METHOD__,
+ $options = [],
+ $join_conds = []
+ );
}
diff --git a/includes/libs/rdbms/platform/PostgresPlatform.php b/includes/libs/rdbms/platform/PostgresPlatform.php
index 8359d64bfa91..7d557bcb50b0 100644
--- a/includes/libs/rdbms/platform/PostgresPlatform.php
+++ b/includes/libs/rdbms/platform/PostgresPlatform.php
@@ -98,4 +98,11 @@ class PostgresPlatform extends SQLPlatform {
return parent::relationSchemaQualifier();
}
+ public function buildGroupConcatField(
+ $delim, $table, $field, $conds = '', $join_conds = []
+ ) {
+ $fld = "array_to_string(array_agg($field)," . $this->quoter->addQuotes( $delim ) . ')';
+
+ return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
+ }
}
diff --git a/includes/libs/rdbms/platform/SQLPlatform.php b/includes/libs/rdbms/platform/SQLPlatform.php
index 9409b44c3076..0344fe24b102 100644
--- a/includes/libs/rdbms/platform/SQLPlatform.php
+++ b/includes/libs/rdbms/platform/SQLPlatform.php
@@ -1301,4 +1301,25 @@ class SQLPlatform implements ISQLPlatform {
return $sql;
}
+
+ /**
+ * @inheritDoc
+ * @stable to override
+ */
+ public function buildGroupConcatField(
+ $delim, $table, $field, $conds = '', $join_conds = []
+ ) {
+ $fld = "GROUP_CONCAT($field SEPARATOR " . $this->quoter->addQuotes( $delim ) . ')';
+
+ return '(' . $this->selectSQLText( $table, $fld, $conds, __METHOD__, [], $join_conds ) . ')';
+ }
+
+ public function buildSelectSubquery(
+ $table, $vars, $conds = '', $fname = __METHOD__,
+ $options = [], $join_conds = []
+ ) {
+ return new Subquery(
+ $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds )
+ );
+ }
}
diff --git a/includes/libs/rdbms/platform/SqlitePlatform.php b/includes/libs/rdbms/platform/SqlitePlatform.php
index 771bb66e62e7..a323b8766729 100644
--- a/includes/libs/rdbms/platform/SqlitePlatform.php
+++ b/includes/libs/rdbms/platform/SqlitePlatform.php
@@ -105,4 +105,12 @@ class SqlitePlatform extends SQLPlatform {
return parent::makeSelectOptions( $options );
}
+
+ public function buildGroupConcatField(
+ $delim, $table, $field, $conds = '', $join_conds = []
+ ) {
+ $fld = "group_concat($field," . $this->quoter->addQuotes( $delim ) . ')';
+
+ return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')';
+ }
}