Skip Menu |

This queue is for tickets about the SQL-Translator CPAN distribution.

Report information
The Basics
Id: 62250
Status: resolved
Priority: 0/
Queue: SQL-Translator

People
Owner: Nobody in particular
Requestors: nick [...] physics.umn.edu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.11011



Subject: SQL::Translator::Producer::MySQL doesn't support DROP PRIMARY KEY
Date: Mon, 18 Oct 2010 21:20:37 -0500
To: bug-SQL-Translator [...] rt.cpan.org
From: Nick Bertrand <nick [...] physics.umn.edu>
If alter_drop_constraint is called with a constraint of type PRIMARY_KEY, an invalid SQL line similar to the following is produced: ALTER TABLE table DROP INDEX The correct line should be something similar to this: ALTER TABLE table DROP PRIMARY KEY The following script illustrates the issue (can be found in attachment): use SQL::Translator::Producer::MySQL; use SQL::Translator::Schema::Table; use SQL::Translator::Schema::Constants; my $table = SQL::Translator::Schema::Table->new( name => 'table', ); my $constraint = $table->add_constraint( fields => [ 'field' ], type => PRIMARY_KEY, ); print SQL::Translator::Producer::MySQL::alter_drop_constraint($constraint); The following patch produces valid SQL (also found in attachment): --- a/lib/SQL/Translator/Producer/MySQL.pm 2010-06-03 03:54:59.000000000 -0500 +++ b/lib/SQL/Translator/Producer/MySQL.pm 2010-10-18 21:09:52.479548000 -0500 @@ -662,8 +662,8 @@ my $out = sprintf('ALTER TABLE %s DROP %s %s', $qt . $c->table->name . $qt, - $c->type eq FOREIGN_KEY ? $c->type : "INDEX", - $qc . $c->name . $qc ); + ($c->type eq FOREIGN_KEY || $c->type eq PRIMARY_KEY) ? $c->type : "INDEX", + $c->type eq PRIMARY_KEY ? '' : $qc . $c->name . $qc ); return $out; } Possibly relevant info: perl version: v5.8.9 built for amd64-freebsd-thread-multi SQL::Translator version: 0.11006 SQL::Translator::Producer::MySQL version: 1.59 OS: FreeBSD 7.1-RELEASE-p14 Thanks, Nick Bertrand
Download files.tar.gz
application/x-gzip 607b

Message body not shown because it is not plain text.

Really a bug. I've created a pull request on github to correct the Producer::MySQL behaviour. Thank you for the bug report and the fix.
On Sun Jan 08 18:47:47 2012, SKNPP wrote: Show quoted text
> Really a bug. I've created a pull request on github to correct the > Producer::MySQL behaviour. > Thank you for the bug report and the fix.
Applied to master.