db_change_field() cannot rename reserved name columns

hass - January 4, 2009 - 22:36
Project:Drupal
Version:6.x-dev
Component:database system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

A db columns in linkchecker module is named 'update'. I tried to rename this column to changed, but the ALTER in update.php fails every time.

<?php
  db_change_field
($ret, 'linkchecker_tasks', 'update', 'changed', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
?>

Error:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update `changed` INT NOT NULL DEFAULT 0' at line 1 query: ALTER TABLE linkchecker_tasks CHANGE update `changed` INT NOT NULL DEFAULT 0 in includes\database.mysql-common.inc on line 520.

So I've added curly quotes to the `update` column and executed it by hand what worked.

ALTER TABLE linkchecker_tasks CHANGE `update` `changed` INT NOT NULL DEFAULT 0

To get the module fixed I need to use the SQL statement and cannot use db_change_field(). I think core should also be able to handle reserved names.

#1

Jorrit - June 28, 2009 - 20:49
Status:active» needs review

The original field name is not enclosed with backticks. The attached patch fixes this.

AttachmentSize
dbchangefield-reserved-words.patch 858 bytes
 
 

Drupal is a registered trademark of Dries Buytaert.