Jjanes has uploaded a new change for review. https://gerrit.wikimedia.org/r/288745
Change subject: PostgreSQL: Allow comparison of integers to strings. ...................................................................... PostgreSQL: Allow comparison of integers to strings. MySQL allows a join condition to compare in integer to a string. Introduce a provision for other database systems to adopt those semantics, and use it to fix bug T135216. Only PostgreSQL is addressed here, but the method should readily extend to other databases as well. Bug: T135216 Change-Id: Ie0592e38365cceb06f5a2fa4b42ced351ea3d2fa --- M includes/db/Database.php M includes/db/DatabasePostgres.php M includes/specials/SpecialProtectedpages.php 3 files changed, 27 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/45/288745/1 diff --git a/includes/db/Database.php b/includes/db/Database.php index 92e89b0..1da07c5 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1968,6 +1968,19 @@ } /** + * MySQL allows the comparison of integers to strings, in which case the numeric-looking + * prefix of the string is parsed to an integer. Other databases generally do not allow + * this. This adaptor takes a column name (or an already-quoted string literal) and emits + * the SQL needed to convert it to an integer in a manner compatible with MySQL semantics. + * + * @param string $s + * @return string + */ + public function extractInteger( $s ) { + return $s; + } + + /** * Quotes an identifier using `backticks` or "double quotes" depending on the database type. * MySQL uses `backticks` while basically everything else uses double quotes. * Since MySQL is the odd one out here the double quotes are our generic diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 839d6a0..ca744d0 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -600,6 +600,19 @@ } /** + * MySQL allows the comparison of integers to strings, in which case the numeric-looking + * prefix of the string is parsed to an integer. Other databases generally do not allow + * this. This adaptor takes a column name (or an already-quoted string literal) and emits + * the SQL needed to convert it to an integer in a manner compatible with MySQL semantics. + * + * @param string $s + * @return string + */ + public function extractInteger( $s ) { + return "substring(" . $s . " from '\s*([-+]?\d+)' ) :: integer"; + } + + /** * Estimate rows in dataset * Returns estimated count, based on EXPLAIN output * This is not necessarily an accurate estimate, so use sparingly diff --git a/includes/specials/SpecialProtectedpages.php b/includes/specials/SpecialProtectedpages.php index 54b471e..0196b50 100644 --- a/includes/specials/SpecialProtectedpages.php +++ b/includes/specials/SpecialProtectedpages.php @@ -537,7 +537,7 @@ 'join_conds' => [ 'log_search' => [ 'LEFT JOIN', [ - 'ls_field' => 'pr_id', 'ls_value = pr_id' + 'ls_field' => 'pr_id', $this->mDb->extractInteger( 'ls_value' ) . ' = pr_id' ] ], 'logging' => [ -- To view, visit https://gerrit.wikimedia.org/r/288745 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie0592e38365cceb06f5a2fa4b42ced351ea3d2fa Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Jjanes <jeff.ja...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits