[sf-perl] PostgreSQL DBD ---- repost: sorry, I had the wrong subject in my previous post

Shane Hill shanehill00 at gmail.com
Thu Mar 31 19:41:46 PST 2005


> Looking at the DBI docs, it says, "For some drivers the $catalog,
> $schema, $table, and $field parameters are required (e.g., Pg)..."

That is from the DBI docs but looking at the docs for DBD::Pg it says:

"If you do not know the name of the sequence, you can provide a table
name and DBD::Pg will attempt to return the correct value."

and an example from the DBD::Pg docs is:

$dbh->last_insert_id(undef,undef,"lii2",undef)

well, that is what I am doing and I get an undefined return value. 
and yes, I am calling this immediately after I do an insert, as the
DBD::Pg docs suggest.
 
> Actually, $catalog should be undef (no such concept in Pg), but the
> schema is probably 'public' or your username, unless you're using
> different schemas.

I tried both 'public' and my username and I get the same result.  nada.

> Anyhow, I'm puzzled, but I have a fix.  After
> you've checked whether the INSERT succeeded (you're doing that anyway,
> RIGHT?!? ;) just do:
> 
>     SELECT currval('the_name_of_the_appropriate_seq');
> 
> Not quite as convenient, and I've got a query in to the DBD::Pg dev
> team, but it will work.

not convenient at all and yes I am checking for errors.  I have been
doing this successfully for years with the Pg module / class using:

$result->oidStatus

but I switch to the DBI in an effort to "standardize" my code and my
system takes a steaming dump on me.  lovely.

Not only will having to use the seq name be inconvenient, it will also
be completely antithetical to the rest of the code which is
generalized and abstracted from any particular data source.  I guess I
can make it an optional parameter to my method, but that seems a bit
lame.

Maybe I am doing something wrong.  I will continue to investigate,
thanks for the info.

cheers,

-Shane


More information about the SanFrancisco-pm mailing list