On 12/28/05, John Siracusa <[EMAIL PROTECTED]> wrote:
> All tests pass for me in Pg 8.1.  I was able to reproduce your errors by
> downgrading my Pg to 7.4.7, and I'll work on fixing them for the next
> release.

Thanks John,

Just a little bit more info on the sequence failures.  I ran into the
same problem when trying to create new records in my code:

update() - DBD::Pg::st execute failed: ERROR:  null value in column
"id" violates not-null constraint

It can't figure out what the sequence is, and tries to insert a NULL
into the primary key column.  I worked around it by specifying the
sequence directly in my Object class:

__PACKAGE__->meta->primary_key_sequence_names('pages_id_seq');


Here are the details of my setup in case it helps:

CREATE TABLE pages (
    id serial PRIMARY KEY,
    name varchar(100),
    title varchar(200),
    content text,
    UNIQUE (name)
);

package My::DB::Page;

use strict;

use My::DB::Object;
our @ISA = qw(My::DB::Object);

__PACKAGE__->meta->table('pages');

__PACKAGE__->meta->columns(
    id        => { type => 'integer', not_null => 1 },
    name      => { type => 'varchar', length => 100 },
    title     => { type => 'varchar', length => 200 },
    content   => { type => 'text' },
);

__PACKAGE__->meta->primary_key_sequence_names('pages_id_seq');

__PACKAGE__->meta->primary_key_columns([ 'id' ]);

__PACKAGE__->meta->add_unique_keys([ 'name' ]);

__PACKAGE__->meta->initialize;

1;

Everything in there was generated by Rose::DB::Object, except for the
'primary_key_sequence_names' which I added manually.  I noticed that
if the call to 'primary_key_sequence_names' occurs after the call to
'primary_key_columns' I end up getting [undef, 'id'] as my sequence. 
I guess this is another hint at what is happening. 
'primary_key_columns' is setting the sequence to [undef] and
'primary_key_sequence_names' is adding to the end of it.

I am guessing that upgrading to Pg 8.0 or 8.1 would probably solve
this, but I think it should work with 7.4 as well.

I have tried to track this problem down in the code, but the sequence
generation seems to jump around a lot, and I couldn't figure it out.

Hope this helps...

Cheers,

Cees


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to