From: Peter Rabbitson Date: Fri, 4 Sep 2009 09:56:00 +0000 (+0000) Subject: Rewrite selector using sqla X-Git-Tag: v0.08111~14^2~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=20f43d0c65d6b80671786ae197b500ecd96f001c;p=dbsrgits%2FDBIx-Class.git Rewrite selector using sqla --- diff --git a/Makefile.PL b/Makefile.PL index 8151718..1183fcf 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -40,7 +40,7 @@ requires 'MRO::Compat' => '0.09'; requires 'Module::Find' => '0.06'; requires 'Path::Class' => '0.16'; requires 'Scope::Guard' => '0.03'; -requires 'SQL::Abstract' => '1.56'; +requires 'SQL::Abstract' => '1.57'; requires 'SQL::Abstract::Limit' => '0.13'; requires 'Sub::Name' => '0.04'; diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 1a2bd8a..1348d33 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -60,18 +60,21 @@ sub _get_pg_search_path { sub _dbh_get_autoinc_seq { my ($self, $dbh, $schema, $table, $col) = @_; - - my @where = ( 'c.relname = ?', 'a.attname = ?' ); - my @bind = ($table, $col); - if( defined $schema && length $schema ) { - push @where, 'n.nspname = ?'; - push @bind, $schema; - } else { - push @where, 'pg_catalog.pg_table_is_visible(c.oid)'; - } - my $where = join ' AND ', @where; + my $sqlmaker = $self->sql_maker; + local $sqlmaker->{bindtype} = 'normal'; + + my ($where, @bind) = $self->sql_maker->where ({ + 'a.attnum' => {'>', 0}, + 'c.relname' => $table, + 'a.attname' => $col, + -not_bool => 'a.attisdropped', + (defined $schema && length $schema) + ? ( 'n.nspname' => $schema ) + : ( -bool => \'pg_catalog.pg_table_is_visible(c.oid)' ) + }); my ($seq_expr) = $dbh->selectrow_array(< 0 AND NOT a.attisdropped +$where + EOS - $seq_expr =~ /^nextval\(+'([^']+)'::(?:text|regclass)\)/i - or $self->throw_exception("could not parse sequence expression '$seq_expr'"); + unless (defined $seq_expr && $seq_expr =~ /^nextval\(+'([^']+)'::(?:text|regclass)\)/i ){ + $seq_expr = '' unless defined $seq_expr; + $self->throw_exception("could not parse sequence expression: '$seq_expr'"); + } return $1; }