column called 'id'

[prev] [thread] [next] [Date index for 2004/06/18]

From: Robert Collier
Subject: column called 'id'
Date: 15:58 on 18 Jun 2004
Hi,

I'm just experimenting with Class::DBI and I've hit a big problem that  
I haven't worked out how to get around.

All my tables have a a primary key called 'id'. This seems to conflict  
with the 'id' function in Class::DBI.
Is there any workaround?

This is my code:

#! /usr/bin/perl

use strict;
use warnings;

#-------------------------------------------------

package Library::DBI;
use base 'Class::DBI';

Library::DBI->set_db('Main', 'DBI:Pg:dbname=library;host=*****',  
'*****', '*****');

#-------------------------------------------------

package Library::Book;
use base 'Library::DBI';

__PACKAGE__->table('books');
__PACKAGE__->columns(ALL => qw/id isbn title media publisher  
firstedition pub_date/);

#-------------------------------------------------

package main;

my @books = Library::Book->retrieve_all;

foreach my $book (@books) {
         print $book->title, "\n";
}

__END__

And my errors:

Column 'id' in Library::Book clashes with built-in method at  
/usr/share/perl5/Class/DBI.pm line 207
         Class::DBI::_carp('Library::Book','Column \'id\' in  
Library::Book clashes with built-in method') called at  
/usr/share/perl5/Class/DBI.pm line 379
          
Class::DBI::_make_method('Library::Book','id','CODE(0x83a3b08)') called  
at /usr/share/perl5/Class/DBI.pm line 371
          
Class::DBI::_mk_column_accessors('Library:: 
Book','id','isbn','title','media','publisher','firstedition','pub_date') 
  called at /usr/share/perl5/Class/DBI.pm line 282
          
Class::DBI::_set_columns('Library:: 
Book','ALL','id','isbn','title','media','publisher','firstedition','pub_ 
date',...) called at /usr/share/perl5/Class/DBI.pm line 269
          
Class::DBI::columns('Library:: 
Book','ALL','id','isbn','title','media','publisher','firstedition','pub_ 
date',...) called at ./test line 19
Library::Book can't SELECT
FROM   books
: DBD::Pg::st execute failed: ERROR:  parser: parse error at or near  
"FROM" [for Statement "SELECT
FROM   books
"] at /usr/share/perl5/Ima/DBI.pm line 714.
  at ./test line 25

	- Regards, Robert.

        -- 
        Robert Collier
rob@xxxxxxxxx.xxx
   OS X: Because making Unix user-friendly was easier than debugging  
Windows
         -- Simon Slavin, on a.f.c

column called 'id'
Robert Collier 15:58 on 18 Jun 2004

Re: column called 'id'
Tony Bowden 16:44 on 18 Jun 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52