blue_cowdawg has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

In my continuing journey towards Perl Nirvana I started examining the techniques I use for database access and how I pull data into my scripts and write them out. During one of this introspective sessions I started looking at the DBIx:: family of CPAN modules.

Lo and behold I stumbled across DBIx::Table and things looked good. I created a very simple table to work with as such:

create table venue ( venue_id integer not null auto_increment primary key, venue_name varchar(30) not null );
To "marry" it to DBIx::Table as per the man page I created a module such as:
package venue; use strict; use DBIx::Table; use vars qw / @ISA /; @ISA = qw / DBIx::Table /; sub describe { my $self = shift || return undef; $self->{'table'}='venue'; $self->{'unique_keys'}=[qw /venue_id/ ]; $self->{'columns'}= { venue_id => { 'immutable' => 1, 'autoincrement' => 1 }, venue_name => {quoted => 1 } }; } 1;
So far so good.

Now comes the time to test it out. One of the first things I want to do is add a new "venue" to my table so I invoke

my $obj2 = create venue(db=>$dbh);
So far so good. I read the man page and I surmise that I need to now take this "blank" record and do a
$obj2->set({venue_name=>'My New Venue'}); $obj2->commit();
Doing so I get an error:
A value is required for venue_id in row 0 in order to commit
Hmmm.. that's interesting given that venue_id is an auto_increment column and immutable. So what the hey...
$obj2->set(change=>{ venue_name => 'newVenue', venue_id=>$new_id}); $obj2->commit();
Changed the code and re-ran it and got:
Attempt to modify immutable column: venue_id
as I would have expected. I give up.. how does this thing work? Anybody out there get this to work?

Replies are listed 'Best First'.
Re: Insert records with DBIx::Table
by castaway (Parson) on Aug 10, 2004 at 17:57 UTC
    Looking at the module, it sounds like a nice idea, but its only partly done, and hasnt been touched for several years apparently. The actual code shows no special treatment of auto-increment values on INSERT, so I'm guessing the author kind of forgot that bit.. It's also missing most of a test suite..

    I suggest you take a peak at Class::DBI which can do all that and more, and is pretty active.

    C.

          Looking at the module, it sounds like a nice idea, but its only partly done, and hasnt been touched for several years apparently.

      Yeah... unfortunately that was the conclusion I came to and the email I sent to the author is still sitting in my mailserver's outgoing queue as "connection timed out, retrying for 5 days." Looks like the author has abandoned this module... drat!

      As per your suggestion I am experimenting (successufully I might add) with Class::DBI and freinds. Class::DBI::DATA::Schema is a very cool addition to the mix as well. Being able to embed the table creation code in my Perl source is one of the things I was after as well.