db_change_column does this:

$ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old");

I can't find that syntax in the mysql documentation, http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
And it fails on my server, with an error like

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 'TO mail_old' at line 1 query: ALTER TABLE users RENAME mail TO mail_old in /srv/http/teaserstallion.com/work/ep/htdocs/update.php on line 125.

Comments

sivaji_ganesh_jojodae’s picture

Status: Active » Needs review

Indeed its a bug. The correct syntax for MySQL is as follow

ALTER TABLE tablename CHANGE COLUMN oldname newname definition;

The statements that causes this warning message is in update.php line no 125

  $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $column TO ". $column ."_old"); 
  // tries the rename the column but fails because of syntax error

  // remaining lines are redundant trying to replicate the same task as line one.
  // adds a new column 
  $ret[] = update_sql("ALTER TABLE {". $table ."} ADD $column_new $type");
  // sets the value to new column
  $ret[] = update_sql("UPDATE {". $table ."} SET $column_new = ". $column ."_old");
  // sets default and not null attributes
  if ($default) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET $default"); }
  if ($not_null) { $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $column_new SET NOT NULL"); }
  // drops the old column
  $ret[] = update_sql("ALTER TABLE {". $table ."} DROP ". $column ."_old");

First line in the above code is wrong it suppose to be

  $ret[] = update_sql("ALTER TABLE {". $table ."} CHANGE COLUMN $column ". $column ."_old". $type);
damien tournoud’s picture

Status: Needs review » Closed (won't fix)

db_change_column() is deprecated. Use db_change_field().

damien tournoud’s picture

Title: db_change_column fails on mysql » Remove db_change_column
Version: 6.x-dev » 7.x-dev
Category: bug » task
Status: Closed (won't fix) » Active

From the documentation of db_change_column():

Change a column definition using syntax appropriate for PostgreSQL.

We need to remove that from D7.

turadg’s picture

Is db_change_column() deprecated as of D6 or D7?

If it is deprecated in D6, and since it can't be removed, can the documentation be updated to indicate that it is deprecated?
http://api.drupal.org/api/function/db_change_column/6

Perhaps also it could log to watchdog that a deprecated function was called.

Crell’s picture

Status: Active » Fixed

There is no db_change_column() function in D7 HEAD right now, so I'm going to assume this was fixed along the way somewhere. :-)

Status: Fixed » Closed (fixed)

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