Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
using a reserved word column name for unique key or primary key results in sql error
example
$schema['test'] = array(
'fields' => array(
'key' => array(
'type' => 'serial',
),
),
'primary key' => array('key'),
);
sql result
CREATE TABLE test ( `key` INT auto_increment DEFAULT NULL, PRIMARY KEY (key) )
so there should be an apostrophe around column names everywhere
Comment | File | Size | Author |
---|---|---|---|
#5 | column_quote_pkey.patch | 751 bytes | Pasqualle |
#3 | column_quote.patch | 739 bytes | Pasqualle |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedIn the current Core API, using a reserved word as a column name is *not* supported (anywhere). Don't do that.
Comment #2
Pasqualleok, if reserved word as column name is not supported then we do not need quotes on columns..
it is sloppy coding to have quotes on one place but do not have on other places..
Comment #3
PasqualleComment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedWell. My remark was for 6.x.
In 7.x and beyond, columns using reserved words will be supported one day. The query builder that is being prepared in http://drupal.org/node/225450 will allow us to do that for general queries.
So you can use your energy in making sure that the schema API also properly escape column names, thus fixing the bug you spotted initially.
Comment #5
Pasquallethis patch should quote columns listed as primary keys, unique keys or as indexes
Comment #6
PasqualleComment #7
Pasquallelocale.install
resulted in sql error
Comment #8
Crell CreditAttribution: Crell commentedI'm certain this no longer applies, but there's a new thread for dealing with this in D7: #315047: All schema API operations should be reserved-word safe.
I'm marking this down D6 rather than duplicate in case Gabor wants to do something with it, but for D7 let's use the other thread.
Comment #9
dpearcefl CreditAttribution: dpearcefl commentedIs this still an issue using current Drupal 6?
Comment #10
MurzThis bug is still here on Drupal 6.22 (see bug #304421: drupal_install_schema() function must always enclose field names).
I test this bug now in Drupal 7.2 and can't reproduce this bug, all works normally. So seems it fixed in 7.x, maybe you can backport db creating process from 7.x to 6.x?
Comment #11
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe database layer in Drupal 7 is vastly different then Drupal 6, so the solution has to be different. #5 has a patch that needs review, and should probably be extended to cover PostgreSQL and the other schema operations (alter table, add index, etc.).
Comment #12
danblack CreditAttribution: danblack commented