Skip Menu |

This queue is for tickets about the Class-DBI-mysql CPAN distribution.

Report information
The Basics
Id: 19303
Status: open
Priority: 0/
Queue: Class-DBI-mysql

People
Owner: Nobody in particular
Requestors: mromani [...] ottotecnica.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.00
Fixed in: (no value)



Subject: set_up_table() croaks on views with message "$table has no primary key" (with patch)
(This bug is related to bug 17084 in Class-DBI-Loader - http://rt.cpan.org/Public/Bug/Display.html?id=17084 ) Class::DBI::Loader calls set_up_table, which in turn croak()s if no primary key can be found for a certain table. As far as the mentioned method is concerned, views appear as normal tables, but a DESCRIBE query on them shows no primary key. My patch makes set_up_table() emit a warning instead of _croak()ing if no primary keys are found but the table is in fact a VIEW. The patch makes use of INFORMATION_SCHEMA.VIEWS table, therefore some tests are needed to detect if the version of MySQL server we are talking to supports that feature. AFAICT this patch is NOT required if one doesn't make use of a Loader, i.e. one is writing his/her table classes by hand.
Subject: mysql.pm.diff
--- /var/sambashare/mysql.pm.orig 2006-05-17 14:05:16.000000000 +0200 +++ /var/sambashare/mysql.pm.modified 2006-05-17 14:03:13.000000000 +0200 @@ -56,6 +56,7 @@ =cut __PACKAGE__->set_sql(desc_table => 'DESCRIBE __TABLE__'); +__PACKAGE__->set_sql(is_view => 'SELECT COUNT(*) FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA=(SELECT DATABASE()) AND TABLE_NAME=?'); sub set_up_table { my $class = shift; @@ -67,7 +68,12 @@ push @cols, $col; push @pri, $col if $hash->{key} eq "PRI"; } - $class->_croak("$table has no primary key") unless @pri; + $sth->finish; + ($sth = $class->sql_is_view)->execute($table); + my $is_view = ($sth->fetchrow_array)[0]; + $sth->finish; + $class->_croak("$table has no primary key") unless (@pri || $is_view); + $class->_carp("$table is a VIEW: cannot determine primary key") if($is_view); $class->columns(Primary => @pri); $class->columns(All => @cols); }
Subject: Re: [rt.cpan.org #19303] set_up_table() croaks on views with message "$table has no primary key" (with patch)
Date: Wed, 17 May 2006 13:21:34 +0100
To: Guest via RT <bug-Class-DBI-mysql [...] rt.cpan.org>
From: Tony Bowden <tony [...] tmtm.com>
On Wed, May 17, 2006 at 08:19:13AM -0400, Guest via RT wrote: Show quoted text
> set_up_table croak()s if no primary key can be found for a certain table.
I would say that this is the correct behaviour. Show quoted text
> My patch makes set_up_table() emit a warning instead of _croak()ing if > no primary keys are found but the table is in fact a VIEW.
How does this help? Show quoted text
> The patch makes use of INFORMATION_SCHEMA.VIEWS table, therefore some > tests are needed to detect if the version of MySQL server we are talking > to supports that feature.
I see no such checks in your patch? Tony
On Mer. 17 Mag. 2006 08:22:01, tony@tmtm.com wrote: Show quoted text
> On Wed, May 17, 2006 at 08:19:13AM -0400, Guest via RT wrote:
> > set_up_table croak()s if no primary key can be found for a certain
table. Show quoted text
> > I would say that this is the correct behaviour. >
> > My patch makes set_up_table() emit a warning instead of _croak()ing if > > no primary keys are found but the table is in fact a VIEW.
> > How does this help?
If I have views in my database I can't use Class::DBI::Loader because set_up_table doesn't distinguish between them and croak()s before the hand-written classes for the views (where I can define primary keys myself) can be loaded. Show quoted text
>
> > The patch makes use of INFORMATION_SCHEMA.VIEWS table, therefore some > > tests are needed to detect if the version of MySQL server we are talking > > to supports that feature.
> > I see no such checks in your patch? >
That's why I wrote "tests are needed". I just wanted to issue a warning for those willing to use the patch. Maybe a better wording would be "please make sure that your mysql server has support for information_schema.views". Show quoted text
> > Tony >
Marcello
Subject: Re: [rt.cpan.org #19303] set_up_table() croaks on views with message "$table has no primary key" (with patch)
Date: Wed, 17 May 2006 13:38:36 +0100
To: Guest via RT <bug-Class-DBI-mysql [...] rt.cpan.org>
From: Tony Bowden <tony [...] tmtm.com>
On Wed, May 17, 2006 at 08:35:55AM -0400, Guest via RT wrote: Show quoted text
> If I have views in my database I can't use Class::DBI::Loader because > set_up_table doesn't distinguish between them and croak()s before the > hand-written classes for the views (where I can define primary keys > myself) can be loaded.
That sounds like a bug with Class::DBI::Loader, then. Tony
On Mer. 17 Mag. 2006 08:39:01, tony@tmtm.com wrote: Show quoted text
> On Wed, May 17, 2006 at 08:35:55AM -0400, Guest via RT wrote:
> > If I have views in my database I can't use Class::DBI::Loader because > > set_up_table doesn't distinguish between them and croak()s before the > > hand-written classes for the views (where I can define primary keys > > myself) can be loaded.
> > That sounds like a bug with Class::DBI::Loader, then. > > Tony >
Well, after searching aroung a bit, I concluded that this might be a bug of MySQL itself. http://bugs.mysql.com/bug.php?id=4607 "MySQL Bugs: #4607: Views: Descriptive information is lost for view definition"