[Dbix-class] bug with find_or_new and update_or_insert,
for postgres DB
Patrick Weemeeuw
pweemeeuw at telenet.be
Sun Jan 6 01:19:50 GMT 2008
See below.
BTW: thanks for this great package!
-- patrick
DB schema (postgres):
| CREATE SEQUENCE article_artid_seq;
|
| create table article (
| artId integer NOT NULL DEFAULT nextval('article_artid_seq'),
| day char(8) NOT NULL,
| seqnr integer NOT NULL,
| visibility char(1) NOT NULL CHECK ( visibility = 'P' OR visibility = 'R' OR visibility = '' ),
| title varchar(100) NOT NULL, -- ftext
| body text NOT NULL, -- ftext
| UNIQUE (day,seqnr),
| UNIQUE (artid)
| );
|
| ALTER SEQUENCE article_artid_seq OWNED BY article.artId;
Corresponding DBIx class:
| package BoDDB::Article;
|
| use base qw/DBIx::Class/;
|
| __PACKAGE__->load_components(qw/PK::Auto Core/);
|
| __PACKAGE__->table('article');
|
| __PACKAGE__->add_columns(
| 'artid' => { is_auto_increment => 1, sequence => 'article_artid_seq' },
| 'day' => {},
| 'seqnr' => {},
| 'visibility' => {},
| 'title' => {},
| 'body' => {},
| );
|
| __PACKAGE__->set_primary_key(qw/artid/);
|
| __PACKAGE__->has_many(
| indexentries => 'BoDDB::ArtIndex',
| 'artid',
| { cascading_delete => 1 }
| );
|
| 1;
Test program:
| #!/usr/bin/perl
|
| use BoDDB;
|
| my $schema = BoDDB->connect(
| 'dbi:Pg:dbname=BoD',
| 'patrick',
| '',
| {}
| );
|
| # print $schema, "\n";
|
| print $DBIx::Class::VERSION, "\n" ;
|
| use Data::Dumper;
|
| # my @all = $schema->resultset('Article')->all;
| # print Dumper(\@all);
|
| my $art = $schema->resultset('Article')->find_or_new( { artid => undef } );
| $art->day('20022222');
| $art->seqnr(3);
| $art->visibility('P');
| $art->title('ttt');
| $art->body('bbb');
|
| # print Dumper($art);
|
| $art->update_or_insert;
Result:
| $ perl -I ../lib testme3.pl
| 0.08008
| DBIx::Class::Row::update_or_insert(): DBI Exception: DBD::Pg::st execute failed: ERROR: null value in column "artid" violates not-null constraint
| [for Statement "INSERT INTO article (artid, body, day, seqnr, title, visibility) VALUES (?, ?, ?, ?, ?, ?)" with ParamValues: 6='P', 4='3', 1=undef, 3='20022222', 2='bbb', 5='ttt'] at testme3.pl line 30
When I remove the not null constraint for article.artid, I get
the following error:
| $ perl -I ../lib testme3.pl
| 0.08008
| DBIx::Class::Row::update_or_insert(): DBI Exception: DBD::Pg::db last_insert_id failed: no statement executing
| [for Statement "SELECT currval(?)"] at testme3.pl line 30
| $
More information about the DBIx-Class
mailing list