Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Data-ObjectDriver CPAN distribution.

Report information
The Basics
Id: 41880
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Data-ObjectDriver

People
Owner: yann.kerherve [...] gmail.com
Requestors: mkanat [...] bugzilla.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: DBD::Pg fails in fetch_id if a prefix is in use
Date: Mon, 22 Dec 2008 12:59:23 -0800
To: bug-Data-ObjectDriver [...] rt.cpan.org
From: Max Kanat-Alexander <mkanat [...] bugzilla.org>
I'm using TheSchwartz. I have a prefix of "ts_" on my TheSchwartz tables. Everything works fine with the mysql driver, but when I switch to the Pg driver, I get the following traceback: DBD::Pg::db last_insert_id failed: ERROR: relation "job_jobid_seq" does not exist at lib/Data/ObjectDriver/Driver/DBD/Pg.pm line 38. at lib/Data/ObjectDriver/Driver/DBD/Pg.pm line 38 Data::ObjectDriver::Driver::DBD::Pg::fetch_id('Data::ObjectDriver::Driver::DBD::Pg=HASH(0x9efc9b0)', 'TheSchwartz::Job', 'DBI::db=HASH(0x9f10874)', 'DBI::st=HASH(0x9f10bbc)') called at lib/Data/ObjectDriver/Driver/DBI.pm line 342 Data::ObjectDriver::Driver::DBI::_insert_or_replace('Data::ObjectDriver::Driver::DBI=HASH(0x9efcf50)', 'TheSchwartz::Job=HASH(0x9dbadf4)', 'HASH(0x9f08120)') called at lib/Data/ObjectDriver/Driver/DBI.pm line 278 Data::ObjectDriver::Driver::DBI::insert('Data::ObjectDriver::Driver::DBI=HASH(0x9efcf50)', 'TheSchwartz::Job=HASH(0x9dbadf4)') called at lib/TheSchwartz.pm line 364 TheSchwartz::insert_job_to_driver('Bugzilla::JobQueue=ARRAY(0x9f71448)', 'TheSchwartz::Job=HASH(0x9dbadf4)', 'Data::ObjectDriver::Driver::DBI=HASH(0x9efcf50)', '4b17e1b45d13c00689cf59d47817f877') called at lib/TheSchwartz.pm line 436 TheSchwartz::insert('Bugzilla::JobQueue=ARRAY(0x9f71448)', 'Bugzilla::Job::Mailer', 'HASH(0x9efc95c)') As you can see, it's using "job" as the prefix for the sequence, when "ts_job" should be the prefix.
Hi, This is totally untested... so could you test this for me please? I don't have a Pg installation handy. svn diff lib/Data/ObjectDriver/Driver/DBD/Pg.pm Index: lib/Data/ObjectDriver/Driver/DBD/Pg.pm =================================================================== --- lib/Data/ObjectDriver/Driver/DBD/Pg.pm (revision 549) +++ lib/Data/ObjectDriver/Driver/DBD/Pg.pm (working copy) @@ -28,7 +28,11 @@ sub sequence_name { my $dbd = shift; my($class) = @_; - join '_', $class->datasource, + + my $datasource = $class->datasource; + my $prefix = $class->prefix; + $datasource = join('', $prefix, $datasource) if $prefix; + join '_', $datasource, $dbd->db_column_name($class->datasource, $class->properties->{primary_key}), 'seq'; } Thanks
Added a nicer attachment with the patch
Index: lib/Data/ObjectDriver/Driver/DBD/Pg.pm =================================================================== --- lib/Data/ObjectDriver/Driver/DBD/Pg.pm (revision 549) +++ lib/Data/ObjectDriver/Driver/DBD/Pg.pm (working copy) @@ -28,7 +28,11 @@ sub sequence_name { my $dbd = shift; my($class) = @_; - join '_', $class->datasource, + + my $datasource = $class->datasource; + my $prefix = $class->prefix; + $datasource = join('', $prefix, $datasource) if $prefix; + join '_', $datasource, $dbd->db_column_name($class->datasource, $class->properties->{primary_key}), 'seq'; }
On Mon Dec 22 16:15:29 2008, YANNK wrote: Show quoted text
> This is totally untested... so could you test this for me please?
Okay, now I get: Cannot find method 'prefix' for class 'TheSchwartz::Job' at lib/Data/ObjectDriver/Driver/DBD/Pg.pm line 32
Show quoted text
> > Okay, now I get: > > Cannot find method 'prefix' for class 'TheSchwartz::Job' at > lib/Data/ObjectDriver/Driver/DBD/Pg.pm line 32
Oh, yeah... Here is a better patch I think. Better?
Index: lib/Data/ObjectDriver/Driver/DBD/Pg.pm =================================================================== --- lib/Data/ObjectDriver/Driver/DBD/Pg.pm (revision 549) +++ lib/Data/ObjectDriver/Driver/DBD/Pg.pm (working copy) @@ -27,17 +27,21 @@ sub sequence_name { my $dbd = shift; - my($class) = @_; - join '_', $class->datasource, + my($class, $driver) = @_; + + my $datasource = $class ->datasource; + my $prefix = $driver->prefix; + $datasource = join('', $prefix, $datasource) if $prefix; + join '_', $datasource, $dbd->db_column_name($class->datasource, $class->properties->{primary_key}), 'seq'; } sub fetch_id { my $dbd = shift; - my($class, $dbh, $sth) = @_; + my($class, $dbh, $sth, $driver) = @_; $dbh->last_insert_id(undef, undef, undef, undef, - { sequence => $dbd->sequence_name($class) }); + { sequence => $dbd->sequence_name($class, $driver) }); } sub bulk_insert {
On Mon Dec 22 16:34:08 2008, YANNK wrote: Show quoted text
> > > > Okay, now I get: > > > > Cannot find method 'prefix' for class 'TheSchwartz::Job' at > > lib/Data/ObjectDriver/Driver/DBD/Pg.pm line 32
> > Oh, yeah... Here is a better patch I think. Better?
ugh, this time with the full diff tree
Index: lib/Data/ObjectDriver/Driver/DBD/Pg.pm =================================================================== --- lib/Data/ObjectDriver/Driver/DBD/Pg.pm (revision 549) +++ lib/Data/ObjectDriver/Driver/DBD/Pg.pm (working copy) @@ -27,17 +27,21 @@ sub sequence_name { my $dbd = shift; - my($class) = @_; - join '_', $class->datasource, + my($class, $driver) = @_; + + my $datasource = $class ->datasource; + my $prefix = $driver->prefix; + $datasource = join('', $prefix, $datasource) if $prefix; + join '_', $datasource, $dbd->db_column_name($class->datasource, $class->properties->{primary_key}), 'seq'; } sub fetch_id { my $dbd = shift; - my($class, $dbh, $sth) = @_; + my($class, $dbh, $sth, $driver) = @_; $dbh->last_insert_id(undef, undef, undef, undef, - { sequence => $dbd->sequence_name($class) }); + { sequence => $dbd->sequence_name($class, $driver) }); } sub bulk_insert { Index: lib/Data/ObjectDriver/Driver/DBI.pm =================================================================== --- lib/Data/ObjectDriver/Driver/DBI.pm (revision 549) +++ lib/Data/ObjectDriver/Driver/DBI.pm (working copy) @@ -371,7 +371,7 @@ if (!$obj->is_pkless && ! $obj->has_primary_key) { my $pk = $obj->primary_key_tuple; ## but do that only for relation that aren't PK-less my $id_col = $pk->[0]; # XXX are we sure we will always use '0' ? - my $id = $dbd->fetch_id(ref($obj), $dbh, $sth); + my $id = $dbd->fetch_id(ref($obj), $dbh, $sth, $driver); $obj->$id_col($id); ## The ID is the only thing we *are* allowed to change on ## the original object.
On Mon Dec 22 16:35:40 2008, YANNK wrote: Show quoted text
> > Oh, yeah... Here is a better patch I think. Better?
> > ugh, this time with the full diff tree
Ah, yes, that fixes it! :-) Any chance of getting a new release with this patch in it?
This is checked in there http://code.sixapart.com/trac/Data-ObjectDriver/changeset/550 We'll release soonish. Yann