Allow dash (-) in tables names and prevent prefix substitution in data

Created on 7 November 2018, about 6 years ago
Updated 22 October 2023, about 1 year ago

This is a follow up issue on https://www.drupal.org/project/drupal/issues/2986452 πŸ› Database reserved keywords need to be quoted as per the ANSI standard Fixed , where in #50 and #60 these are discussed.

#50 was about - not being allowed in table names, which they are as long as the tables are properly quoted.

#60 was about the { } prefix substitution anywhere in the sql string. This means that if you happen to have a custom query where {...} occurs in for example a value set, the prefix is inserted at that point.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
DatabaseΒ  β†’

Last updated 2 days ago

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

πŸ‡§πŸ‡ͺBelgium kriboogh

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.

  • πŸ‡ΊπŸ‡ΈUnited States mile23 Seattle, WA

    Even though it's fair to say these should be two separate issues, these are both bugs, because hyphen is legal in table names and should not be a special case.

    In fact, the reason I'm commenting here is because our project (DKAN) can create and delete a table with a hyphen in the name, but it can't be used in a DBAL query. See here: https://github.com/GetDKAN/dkan/blob/2.x/modules/common/src/Storage/Abst...

    We see errors like this, against a table name with a hyphen:

    drush dkan:harvest:run hospital-summary
    
    In ExceptionHandler.php line 46:
    
    
      SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.harvest_hospi  
      talsummary_runs' doesn't exist: SELECT "t"."id" AS "id"                      
      FROM                                                                         
      "harvest_hospitalsummary_runs" "t"; Array                                    
      (                                                                            
      )                                                                            
    
    In StatementWrapperIterator.php line 110:
    
      SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.harvest_hospi  
    
      talsummary_runs' doesn't exist drush dkan:harvest:run hospital-summary
    
    In ExceptionHandler.php line 46:
    
    
      SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.harvest_hospi  
      talsummary_runs' doesn't exist: SELECT "t"."id" AS "id"                      
      FROM                                                                         
      "harvest_hospitalsummary_runs" "t"; Array                                    
      (                                                                            
      )                                                                            
    

    But querying the DB we see this:

    mysql> show tables like 'harvest%';
    
    +---------------------------------+
    |Tables_in_db (harvest%)        |
    
    +---------------------------------+
    |harvest_hospital-summary_hashes|
    |harvest_hospital-summary_runs  |
    |harvest_plans                  |
    
    +---------------------------------+
    
    3 rows in set (0.01 sec)
    

    This means that Drupal's DBAL created the table, but the table name is somehow modified during the query.

    This is using Drupal 10.0.11.

  • last update about 1 year ago
    Patch Failed to Apply
Production build 0.71.5 2024