Problem/Motivation

The patch for #1184082: Like queries failing on postgres with standard_conforming_strings turned on. removed the calls to $this->quote() but did not remove the comment and additional code added in #910388: Installation fails on PostgreSQL >=8.4: Invalid escape sequence..

Follow-up: Cleanup use of static usage within method.

Proposed resolution

Replace static $variables with a static class variable with an appropriate name after mapConditionOperator method.

Remaining tasks

  • Write patch
  • Review patch

User interface changes

None.

API changes

Yes. Add a class variable to the database class, but does not remove any functionality.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

c960657’s picture

Status: Active » Needs review
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

I have no clue about Postgres, but if this comes back green, I feel comfortable RTBCing this. :)

catch’s picture

Title: Clean-up of mapConditionOperator() » Remove static caching of array in mapConditionOperator()
Status: Reviewed & tested by the community » Active

This looks fine to remove that extra logic, so I've committed pushed it, however why are we keeping a static in that method just to save building the array each time? Moving back to active to discuss.

catch’s picture

Issue summary: View changes

typo

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • catch committed 2a3251a on 8.3.x
    Issue #1565972 by c960657: Clean-up of mapConditionOperator().
    
    

  • catch committed 2a3251a on 8.3.x
    Issue #1565972 by c960657: Clean-up of mapConditionOperator().
    
    

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pjohans’s picture

We should get rid of the static keyword - it is not needed - the array will be set no matter what

pjohans’s picture

Component: ajax system » postgresql db driver
Status: Active » Needs review
mradcliffe’s picture

Thanks for the patch, @pjohans. I queued up a postgresql test since this affects that driver only.

+++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
@@ -300,7 +300,7 @@ public function createDatabase($database) {
-    static $specials = array(
+    $specials = array(
       // In PostgreSQL, 'LIKE' is case-sensitive. For case-insensitive LIKE
...
       'LIKE' => array('operator' => 'ILIKE'),

Perhaps this should be a protected static variable on the Connection class instead of a scoped variable that's instantiated every time. I doubt there would be any meaningful performance leaving it without static though.

daffie’s picture

Status: Needs review » Needs work

Making the specials array a class property would be in my eyes the best solution from a OOP perspective. Can we give the class variable the same name as the method that it belongs to.

The same problem exists with the Connection class from the SQLite driver and with the class Drupal\Core\Database\Query\Condition.

Also adding some docblocks to mapConditionOperator methods would not be a mistake. They are all inheritdocs.

mradcliffe’s picture

Issue summary: View changes
mradcliffe’s picture

How about this for PostgreSQL, SQLite and Condition operator?

I made the static protected variables unique to each class because the implementation might be different. I don't think we have an interface that's for all 3.

Flipped to 8.3.x because I applied to 8.3.x. The patch should still apply to 8.2.x.

Status: Needs review » Needs work

The last submitted patch, 13: drupal-1565972-map-condition-operator-static-fix-13.patch, failed testing.

Status: Needs review » Needs work

daffie’s picture

I am reviewing this issue for the patch from comment #13, because that is the patch for Drupal 8.3.
This issue is not a bug, so this patch cannot be applied to 8.2.

THe patch for 8.3 looks good to me. I have only one nitpick and that can be fixed on commit:

+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
@@ -24,6 +24,19 @@ class Connection extends DatabaseConnection {
+   * We don't want to override any of the defaults.
...
+    // We don't want to override any of the defaults.

The same comment twice. Please remove the second one.

@mradcliffe: Would you be interested in reviewing the PostgreSQL issues: #2057693: PostgreSQL orderBy method adds fields it doesn't need to, leading to fatal errors when the result is used as an insert subquery and #2238253: Add bindValue to a PDO::PARAM_* type in database query arguments?

mradcliffe’s picture

Yep. I need a bit of detox and de-jetlag. I haven't made it home yet.

Crell’s picture

This change seems fine to me as a cleanup.

tim.plunkett’s picture

  1. +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
    @@ -24,6 +24,19 @@ class Connection extends DatabaseConnection {
    +  static protected $sqliteConditionOperatorMap = [
    

    Nit, switch to protected static

    ~/www/d8/core$ ag "static public" | wc -l
          10
    ~/www/d8/core$ ag "public static" | wc -l
        3080
    ~/www/d8/core$ ag "static protected" | wc -l
          10
    ~/www/d8/core$ ag "protected static" | wc -l
         192
    
  2. +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
    @@ -370,14 +383,7 @@ public function createDatabase($database) {
    +    return isset(self::$sqliteConditionOperatorMap[$operator]) ? self::$sqliteConditionOperatorMap[$operator] : NULL;
    
    +++ b/core/lib/Drupal/Core/Database/Query/Condition.php
    @@ -297,34 +322,14 @@ function __clone() {
    +    if (isset(self::$conditionOperatorMap[$operator])) {
    +      $return = self::$conditionOperatorMap[$operator];
    ...
    +      $return = isset(self::$conditionOperatorMap[$operator]) ? self::$conditionOperatorMap[$operator] : array();
    

    Not that we'd often be extending this class, but wouldn't static:: be more useful than self::?

catch’s picture

Status: Reviewed & tested by the community » Needs work

CNW for #21, both good changes.

bzrudi71’s picture

mradcliffe’s picture

Manually confirmed that #18 and #21 comments were applied to the patch.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Then I guess it's RTBC again.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed dc5b0a4 and pushed to 8.3.x. Thanks!

  • alexpott committed dc5b0a4 on 8.3.x
    Issue #1565972 by mradcliffe, bzrudi71, pjohans, c960657, daffie, tim....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.