I'm currently working on learning modules that look interesting, and have decided to do this by writing a simple web-based image gallery. One of the modules I'm most interested in is Class::DBI, but I've begun to hit problems with this.

I'm trying to create new database rows with the create method, yet it just doesn't seem to be working at all.

The database I'm using is Postgres, and the table I'm trying to work off is set up so the id field is automatically set for me. I know it's trying to do something since if I miss out a required field it throws errors, and also if I try and load an invalid value such as a string into a numeric field. The sequence number Postgres uses to base new entries off is also incrementing. There currently aren't any constraints set up in the database itself, and the data used in the test program inserts no problem from the command line psql program.

The class works fine for reading the contents of the database too. Is it possible that Class::DBI is somehow creating the row and then deleting it again?

A cut-down test version of the code:

#!/usr/bin/perl use strict; use warnings; use Class::DBI; # Declare a base class for us. Gallery::Class::DBI package Gallery::Class::DBI; use base 'Class::DBI'; Gallery::Class::DBI->set_db('Main', 'dbi:Pg:dbname=database', 'user',' +password'); # Basic image declaration. package Gallery::Image; use base 'Gallery::Class::DBI'; Gallery::Image->table('gallery_images'); Gallery::Image->columns(All => qw/id title author height width filenam +e gallery/); # Do a creation. my $image = Gallery::Image->create({ title => 'Test', author => 1, height => 100, width => 100, filename => 'test.jpg', gallery => 1, }); $image->commit;

The Postgres SQL used to create the table:

CREATE TABLE gallery_images ( id SERIAL NOT NULL PRIMARY KEY, title TEXT, author INT NOT NULL, width INT, height INT, filename TEXT NOT NULL, gallery INT );

In reply to Problem with Class::DBI's create by Molt

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.