Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: ask [...] develooper.com
Cc:
AdminCc:

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



Subject: column_is_nullable method
It'd be useful to have something like this in Class::DBI::mysql as a complement to column_type. sub column_is_nullable { my $class = shift; my $col = shift or die "Need a column for column_null"; $class->_column_info->{$col}->{null} eq 'YES' ? 1 : 0; }
Subject: Re: [rt.cpan.org #18031] column_is_nullable method
Date: Tue, 7 Mar 2006 10:09:02 +0000
To: via RT <bug-Class-DBI-mysql [...] rt.cpan.org>
From: Tony Bowden <tony [...] kasei.com>
On Tue, Mar 07, 2006 at 04:40:03AM -0500, via RT wrote: Show quoted text
> It'd be useful to have something like this in Class::DBI::mysql as a complement to column_type. > sub column_is_nullable { > my $class = shift; > my $col = shift or die "Need a column for column_null"; > $class->_column_info->{$col}->{null} eq 'YES' ? 1 : 0; > }
I'm slightly wary of needing to gradually expose the entire underlying database structure like this, but I'm open to persuasion on this one... Tony
Subject: Re: [rt.cpan.org #18031] column_is_nullable method
Date: Tue, 7 Mar 2006 02:42:15 -0800
To: bug-Class-DBI-mysql [...] rt.cpan.org
From: Ask Bjørn Hansen <ask [...] develooper.com>
On Mar 7, 2006, at 2:09 AM, Tony Bowden via RT wrote: Show quoted text
> On Tue, Mar 07, 2006 at 04:40:03AM -0500, via RT wrote:
>> It'd be useful to have something like this in Class::DBI::mysql as >> a complement to column_type. >> sub column_is_nullable { >> my $class = shift; >> my $col = shift or die "Need a column for column_null"; >> $class->_column_info->{$col}->{null} eq 'YES' ? 1 : 0; >> }
> > I'm slightly wary of needing to gradually expose the entire underlying > database structure like this, but I'm open to persuasion on this > one...
We have an application where the UI sometimes gets an empty string where the database needs "NULL" (think integer field where we distinguish between NULL and 0). Our actual implementation is below. If you'd like to "do it properly" rather than this gradual expansion then it'd be worthwhile, I think, to cache the information in set_up_table when it's pulled anyway. By the way, I think it'd be (even) better if it was possible to make those attributes accessible via CDBI::Column; but I haven't looked into what the API for that should look like. - ask package EPC::Class::DBI::mysql; use strict; use base 'Class::DBI::mysql'; # we know we never change the columns, so we can get the column info once __PACKAGE__->mk_classdata('__column_info'); sub _column_info { my $class = shift; return $class->__column_info if $class->__column_info; my $col_info = $class->SUPER::_column_info(@_); $class->__column_info($col_info); $col_info; } # http://rt.cpan.org//Ticket/Display.html?id=18031 sub column_is_nullable { my $class = shift; my $col = shift or die "Need a column for column_null"; $class->_column_info->{$col}->{null} eq 'YES' ? 1 : 0; } 1;
Subject: Re: [rt.cpan.org #18031] column_is_nullable method
Date: Wed, 8 Mar 2006 07:19:34 +0000
To: "ask [...] develooper.com via RT" <bug-Class-DBI-mysql [...] rt.cpan.org>
From: Tony Bowden <tony [...] kasei.com>
On Tue, Mar 07, 2006 at 05:42:33AM -0500, ask@develooper.com via RT wrote: Show quoted text
> If you'd like to "do it properly" rather than this gradual expansion > then it'd be worthwhile, I think, to cache the information in > set_up_table when it's pulled anyway.
That has potential. Would you see there just being a method that returns the hash of info? Or something more advanced? Show quoted text
> By the way, I think it'd be (even) better if it was possible to make > those attributes accessible via CDBI::Column; but I haven't looked > into what the API for that should look like.
I had been thinking that myself, but hadn't got much further than CDBI::mysql adding methods directly into CDBI::Column, which is a long term recipe for disaster! Tony