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?


In reply to Insert records with DBIx::Table by blue_cowdawg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.