Added a Database::buildStringCast and use on int/string join
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 25 Jun 2016 20:24:42 +0000 (22:24 +0200)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 3 Sep 2016 23:59:39 +0000 (23:59 +0000)
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
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php
includes/specials/SpecialProtectedpages.php

index 5b0f230..f031d11 100644 (file)
@@ -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
index 33a8280..171191b 100644 (file)
@@ -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';
        }
index c8e9ac7..9cd95a1 100644 (file)
@@ -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';
        }
index 5bbba88..e6401b3 100644 (file)
@@ -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
         */
index 342509c..5bdae15 100644 (file)
@@ -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' => [