InvalidArgumentException: "$string ("") must be a string." using database query

Created on 13 October 2018, about 6 years ago
Updated 19 September 2024, 3 months ago

Steps to reproduce the bug:

- Create query string with WHERE clause containing LIKE.
- The argument passed to the LIKE condition is a named placeholder.
- The LIKE condition contains the % wildcard leading and trailing the value.
- The value is escaped with $injected_database->escapeLike() (NOTE: The InvalidArgumentException is still thrown if I don't escape the value)
- The value is a string of three numbers including: "000", "005", "123"

What behaviour I'm expecting:

- $injected_database->query($queryString, [':param' => '%' . $injected_database->escapeLike($search) . '%']);
will replace all instances in $queryString where ':param' exists with: '%123%' assuming $search = "123";

What happened instead:

Uncaught PHP Exception InvalidArgumentException: "$string ("") must be a string." at /core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php line 132

πŸ’¬ Support request
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component
DatabaseΒ  β†’

Last updated 2 days ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡¨πŸ‡¦Canada dj12djdjs Toronto, ON

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    ARe you sure this has actual results?

    
      ->condition('p.id', $pnoQuery, 'IN')
                ->condition('o.id', $oeQuery, 'IN');
    
    

    ie if $pnoQuery or $oeQuery are empty, this will likely error. You should check they're not empty before adding the conditions.

  • Status changed to Closed: works as designed 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    The additional information asked for in #10 that is need to help with that hasn't been provided in about 10 months. Hopefully, this has been resolved.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue β†’ (starting from "Install Drupal core").

    Thanks!

Production build 0.71.5 2024