Skip Menu |

This queue is for tickets about the DBIx-Class-Schema-Loader CPAN distribution.

Report information
The Basics
Id: 21758
Status: resolved
Priority: 0/
Queue: DBIx-Class-Schema-Loader

People
Owner: blblack [...] gmail.com
Requestors: brentdax [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.03000
Fixed in: 0.03008



Subject: Tables with reserved names fail to load
When trying to load a MySQL schema that contains a table with a reserved name ("group"), DBIx::Class::Schema::Loader 0.03000 emits several errors, stemming from its failure to enclose the table name in backticks. The attached patch fixes the issue on my system by putting backticks around the table names, but doesn't attempt to support other database engines; it may need further work before it can be applied. Ubuntu Linux 6.06 (kernel 2.6.15), Perl 5.8.7, DBI 1.50, DBIx::Class 0.06002, MySQL 5.0.22. Full error output: knightley::SchemaLoader::DBAuto::Group->table("group"); DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax t o use near 'group WHERE 1=0' at line 1 at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI.pm line 95. Can't set DBI::st=HASH(0x90c4008)->{NAME_lc}: unrecognised attribute name or invalid value at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI.pmline 96. knightley::SchemaLoader::DBAuto::Group->add_columns(()); DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax t o use near 'group' at line 1 at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI/mysql.pm line 71. DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI/mysql.pm line 72. group has no primary key at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader.pm line 122 knightley::SchemaLoader::DBAuto::Membership->table("membership"); knightley::SchemaLoader::DBAuto::Membership->add_columns("id", "group", "member", "role"); knightley::SchemaLoader::DBAuto::Membership->set_primary_key("id"); knightley::SchemaLoader::DBAuto::Membership->add_unique_constraint(["id"], undef); knightley::SchemaLoader::DBAuto::User->table("user"); knightley::SchemaLoader::DBAuto::User->add_columns("id", "email", "salt", "password", "job", "birthday", "balance"); knightley::SchemaLoader::DBAuto::User->set_primary_key("id"); knightley::SchemaLoader::DBAuto::User->add_unique_constraint(["id"], undef); DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax t o use near 'group' at line 1 at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI/mysql.pm line 37. DBD::mysql::st fetchrow_arrayref failed: fetch() without execute() at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI/mysql.pm line 38. Couldn't instantiate component "knightley::M::DBAuto", "Cannot load schema class 'knightley::SchemaLoader::DBAuto': Can't use an undefined value as an ARRAY reference at /usr/local/share/perl/5.8.7/DBIx/Class/Schema/Loader/DBI/mysql.pm line 38. Compilation failed in require at /usr/local/share/perl/5.8.7/Catalyst/Model/DBIC/Schema.pm line 275. at /usr/share/perl5/Module/Pluggable/Fast.pm line 86" at /usr/share/perl5/Module/Pluggable/Fast.pm line 86
Subject: mysql-table-name.patch
--- DBIx/Class/Schema/Loader/DBI.pm 2006-09-28 01:09:46.000000000 -0700 +++ DBIx/Class/Schema/Loader/DBI.pm.orig 2006-09-28 01:09:04.000000000 -0700 @@ -91,7 +91,7 @@ $table = $self->{db_schema} . $self->{_namesep} . $table; } - my $sth = $dbh->prepare("SELECT * FROM `$table` WHERE 1=0"); + my $sth = $dbh->prepare("SELECT * FROM $table WHERE 1=0"); $sth->execute; return \@{$sth->{NAME_lc}}; } --- DBIx/Class/Schema/Loader/DBI/mysql.pm 2006-09-28 01:02:57.000000000 -0700 +++ DBIx/Class/Schema/Loader/DBI/mysql.pm.orig 2006-09-28 01:02:07.000000000 -0700 @@ -31,7 +31,7 @@ my $dbh = $self->schema->storage->dbh; - my $query = "SHOW CREATE TABLE `${table}`"; + my $query = "SHOW CREATE TABLE ${table}"; my $sth = $dbh->prepare($query) or die("Cannot get table definition: $table"); $sth->execute; @@ -67,7 +67,7 @@ if(!exists($self->{_mysql_keys}->{$table})) { my %keydata; my $dbh = $self->schema->storage->dbh; - my $sth = $dbh->prepare("SHOW INDEX FROM `$table`"); + my $sth = $dbh->prepare("SHOW INDEX FROM $table"); $sth->execute; while(my $row = $sth->fetchrow_hashref) { next if $row->{Non_unique};
On Thu Sep 28 04:29:32 2006, BRENTDAX wrote: Show quoted text
> backticks. The attached patch fixes the issue on my system by putting > backticks around the table names, but doesn't attempt to support other > database engines; it may need further work before it can be applied.
I cunningly reversed the sense of the patch in my previous message. That's what I get for filing a bug report at 1:30 am. Corrected version attached.
--- DBIx/Class/Schema/Loader/DBI.pm.orig 2006-09-28 01:09:04.000000000 -0700 +++ DBIx/Class/Schema/Loader/DBI.pm 2006-09-28 01:09:46.000000000 -0700 @@ -91,7 +91,7 @@ $table = $self->{db_schema} . $self->{_namesep} . $table; } - my $sth = $dbh->prepare("SELECT * FROM $table WHERE 1=0"); + my $sth = $dbh->prepare("SELECT * FROM `$table` WHERE 1=0"); $sth->execute; return \@{$sth->{NAME_lc}}; } --- DBIx/Class/Schema/Loader/DBI/mysql.pm.orig 2006-09-28 01:02:07.000000000 -0700 +++ DBIx/Class/Schema/Loader/DBI/mysql.pm 2006-09-28 01:02:57.000000000 -0700 @@ -31,7 +31,7 @@ my $dbh = $self->schema->storage->dbh; - my $query = "SHOW CREATE TABLE ${table}"; + my $query = "SHOW CREATE TABLE `${table}`"; my $sth = $dbh->prepare($query) or die("Cannot get table definition: $table"); $sth->execute; @@ -67,7 +67,7 @@ if(!exists($self->{_mysql_keys}->{$table})) { my %keydata; my $dbh = $self->schema->storage->dbh; - my $sth = $dbh->prepare("SHOW INDEX FROM $table"); + my $sth = $dbh->prepare("SHOW INDEX FROM `$table`"); $sth->execute; while(my $row = $sth->fetchrow_hashref) { next if $row->{Non_unique};
I've patched this in the trunk rev, there should be a new bugfix release out later today (0.03008).
Fixed in 0.03008