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:
To "marry" it to DBIx::Table as per the man page I created a module such as:create table venue ( venue_id integer not null auto_increment primary key, venue_name varchar(30) not null );
So far so good.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;
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
So far so good. I read the man page and I surmise that I need to now take this "blank" record and do amy $obj2 = create venue(db=>$dbh);
Doing so I get an error:$obj2->set({venue_name=>'My New Venue'}); $obj2->commit();
Hmmm.. that's interesting given that venue_id is an auto_increment column and immutable. So what the hey...A value is required for venue_id in row 0 in order to commit
Changed the code and re-ran it and got:$obj2->set(change=>{ venue_name => 'newVenue', venue_id=>$new_id}); $obj2->commit();
as I would have expected. I give up.. how does this thing work? Anybody out there get this to work?Attempt to modify immutable column: venue_id
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Insert records with DBIx::Table
by castaway (Parson) on Aug 10, 2004 at 17:57 UTC | |
by blue_cowdawg (Monsignor) on Aug 11, 2004 at 12:24 UTC |