Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gaurav.kapoor created an issue. See original summary.

gaurav.kapoor’s picture

dhruveshdtripathi’s picture

Assigned: Unassigned » dhruveshdtripathi
dhruveshdtripathi’s picture

Status: Needs review » Reviewed & tested by the community
xjm’s picture

Title: Replace all calls to db_like, which is deprecated » Replace all calls to db_like(), which is deprecated
Status: Reviewed & tested by the community » Needs work

Thanks @gaurav.kapoor!

There are some more:

[ibnsina:drupal | Thu 17:46:59] $ grep -r "db_like" *
core/includes/database.inc: * You must use a query builder like db_select() in order to use db_like() on
core/includes/database.inc: * all supported database systems. Using db_like() with db_query() or
core/includes/database.inc: *   ->condition('name', db_like($prefix) . '%', 'LIKE')
core/includes/database.inc:function db_like($string) {
core/lib/Drupal/Core/Database/Connection.php:   *   array(':pattern' => db_like($prefix) . '%')
core/lib/Drupal/Core/Database/Query/ConditionInterface.php:   *  ->condition('name', db_like($name), 'LIKE')
core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php:      ->condition('name', db_like('Ring_'), 'LIKE')
core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php:      ->condition('name', db_like('abc%\_'), 'LIKE')

For the docs, maybe we should have one followup to remove docs references to all the functions once the code references are removed, as I mentioned in a different issue (for db_delete() I think). Edit: I added a suggestion for that to #2848161: [meta] Replace calls to deprecated db_*() wrappers.

shashikant_chauhan’s picture

working on the issue.

shashikant_chauhan’s picture

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All calls to db_like() have been replaced.
The function has already been marked as deprecated.
The function is still being mentioned in documentation. Two of those instances are being replaced in this patch. If the committer does not want this the two hunks can be removed on commit.
The patch is RTBC for me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2850037-7.patch, failed testing.

daffie’s picture

Back to Rtbc.

daffie’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Database/Connection.php
@@ -1018,7 +1018,7 @@ public function escapeAlias($field) {
    * @code
    * $result = db_query(
    *   'SELECT * FROM person WHERE name LIKE :pattern',
-   *   array(':pattern' => db_like($prefix) . '%')
+   *   array(':pattern' => \Drupal::database()->escapeLike($prefix) . '%')
    * );

+++ b/core/lib/Drupal/Core/Database/Query/ConditionInterface.php
@@ -31,7 +31,7 @@
    * to tell the database that case insensitive equivalence is desired:
    * @code
    * db_select('users')
-   *  ->condition('name', db_like($name), 'LIKE')
+   *  ->condition('name', \Drupal::database()->escapeLike($name), 'LIKE')
    * @endcode
    * Use 'LIKE BINARY' instead of 'LIKE' for case sensitive queries.

Hmm, these documentation changes do not look right. Also, there's a db_select() on that line that it would conflict with. Probably we should have a holistic issue for updating the ConditionInterface docs.

+++ b/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
@@ -83,7 +83,7 @@ function testLikeEscape() {
-      ->condition('name', db_like('Ring_'), 'LIKE')
+      ->condition('name', \Drupal::database()->escapeLike('Ring_'), 'LIKE')
       ->countQuery()
       ->execute()
       ->fetchField();
@@ -114,7 +114,7 @@ function testLikeBackslash() {

@@ -114,7 +114,7 @@ function testLikeBackslash() {
     $this->assertIdentical($num_matches, '2', 'Found 2 records.');
     // Match only the former using a LIKE expression with no wildcards.
     $num_matches = db_select('test', 't')
-      ->condition('name', db_like('abc%\_'), 'LIKE')
+      ->condition('name', \Drupal::database()->escapeLike('abc%\_'), 'LIKE')

These are the self-tests; see similar comments on #2848952: Replace all calls to db_merge(), which is deprecated.

Thanks for your work on this!

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

voleger’s picture

Issue summary: View changes
voleger’s picture

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

MerryHamster’s picture

MerryHamster’s picture

Assigned: shashikant_chauhan » Unassigned
Status: Needs work » Needs review
voleger’s picture

Status: Needs review » Needs work

Needs to add legacy test and follow recommendations from #2991337: Document the recommended ways to obtain the database connection object

andypost’s picture

And views should be fixed in #2784739: Fix PostgreSQL operator in views

voleger’s picture

Addressed #20
Related PostgreSQL issue has updated scope, so replacements should happen in this issue.

voleger’s picture

FileSize
14.57 KB
mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Only references to db_like remaining in database.inc and DatabaseLegacyTest after applying the patch. RTBC.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed a0608f0 and pushed to 8.7.x. Thanks!

  • catch committed a0608f0 on 8.7.x
    Issue #2850037 by voleger, shashikant_chauhan, gaurav.kapoor,...
Berdir’s picture

+++ b/core/modules/views/src/Plugin/views/filter/StringFilter.php
@@ -23,6 +25,42 @@ class StringFilter extends FilterPluginBase {
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $connection) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+    $this->connection = $connection;
+  }
+

This broke TMGMT because we had our own constructor with an injected dependency.

I'll fix it, but it's nicer to make new arguments optional with a fallback and deprecation message.

I know our BC rules don't require that but it's become the de-facto standard and maybe we should update the rules? :)

Status: Fixed » Closed (fixed)

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

cilefen’s picture