From 90e9fc296a9a450ecf270614eb8e3b87c5902485 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sat, 25 Jun 2016 22:24:42 +0200 Subject: [PATCH] Added a Database::buildStringCast and use on int/string join The database specific sql is untested, but sql is taken from docs mssql - knows about impilict casts - https://technet.microsoft.com/en-us/library/ms191530(v=sql.105).aspx mysql - knows about impilict casts oracle - https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj33562.html postgresql - https://www.postgresql.org/docs/9.2/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS sqlite - http://www.sqlite.org/lang_expr.html Bug: T69065 Change-Id: I3a83276dc65aae58124460af1810d37dff52e943 --- includes/db/Database.php | 9 +++++++++ includes/db/DatabaseOracle.php | 9 +++++++++ includes/db/DatabasePostgres.php | 9 +++++++++ includes/db/DatabaseSqlite.php | 9 +++++++++ includes/specials/SpecialProtectedpages.php | 2 +- 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 5b0f2303d5..f031d11d87 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1809,6 +1809,15 @@ abstract class DatabaseBase implements IDatabase { return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')'; } + /** + * @param string $field Field or column to cast + * @return string + * @since 1.28 + */ + public function buildStringCast( $field ) { + return $field; + } + public function selectDB( $db ) { # Stub. Shouldn't cause serious problems if it's not overridden, but # if your database engine supports a concept similar to MySQL's diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 33a8280410..171191bada 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -1555,6 +1555,15 @@ class DatabaseOracle extends Database { return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')'; } + /** + * @param string $field Field or column to cast + * @return string + * @since 1.28 + */ + public function buildStringCast( $field ) { + return 'CAST ( ' . $field . ' AS VARCHAR2 )'; + } + public function getSearchEngine() { return 'SearchOracle'; } diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index c8e9ac7ff6..9cd95a1b92 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -1535,6 +1535,15 @@ SQL; return '(' . $this->selectSQLText( $table, $fld, $conds, null, [], $join_conds ) . ')'; } + /** + * @param string $field Field or column to cast + * @return string + * @since 1.28 + */ + public function buildStringCast( $field ) { + return $field . '::text'; + } + public function getSearchEngine() { return 'SearchPostgres'; } diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 5bbba886e1..e6401b3979 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -832,6 +832,15 @@ class DatabaseSqlite extends Database { return parent::buildLike( $params ) . "ESCAPE '\' "; } + /** + * @param string $field Field or column to cast + * @return string + * @since 1.28 + */ + public function buildStringCast( $field ) { + return 'CAST ( ' . $field . ' AS TEXT )'; + } + /** * @return string */ diff --git a/includes/specials/SpecialProtectedpages.php b/includes/specials/SpecialProtectedpages.php index 342509c507..5bdae159eb 100644 --- a/includes/specials/SpecialProtectedpages.php +++ b/includes/specials/SpecialProtectedpages.php @@ -558,7 +558,7 @@ class ProtectedPagesPager extends TablePager { 'join_conds' => [ 'log_search' => [ 'LEFT JOIN', [ - 'ls_field' => 'pr_id', 'ls_value = pr_id' + 'ls_field' => 'pr_id', 'ls_value = ' . $this->mDb->buildStringCast( 'pr_id' ) ] ], 'logging' => [ -- 2.20.1