# __PACKAGE__->load_components(qw/PK::Auto/);
+sub _ora_last_insert_id {
+ my ($dbh, $sql) = @_;
+ $dbh->selectrow_array($sql);
+}
sub last_insert_id {
my ($self,$source,$col) = @_;
my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col));
- my $sql = "SELECT " . $seq . ".currval FROM DUAL";
- my ($id) = $self->dbh_do(sub { shift->selectrow_array($sql) });
+ my $sql = 'SELECT ' . $seq . '.currval FROM DUAL';
+ my ($id) = $self->dbh_do(\&_ora_last_insert_id($sql));
return $id;
}
+sub _ora_get_autoinc_seq {
+ my ($dbh, $source, $sql) = @_;
+
+ # trigger_body is a LONG
+ $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024);
+
+ my $sth = $dbh->prepare($sql);
+ $sth->execute( uc($source->name) );
+ while (my ($insert_trigger) = $sth->fetchrow_array) {
+ return uc($1) if $insert_trigger =~ m!(\w+)\.nextval!i; # col name goes here???
+ }
+ croak "Unable to find a sequence INSERT trigger on table '" . $source->name . "'.";
+}
+
sub get_autoinc_seq {
my ($self,$source,$col) = @_;
AND t.status = 'ENABLED'
};
- $self->dbh_do(sub {
- my $dbh = shift;
- # trigger_body is a LONG
- $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024);
- my $sth = $dbh->prepare($sql);
- $sth->execute( uc($source->name) );
- while (my ($insert_trigger) = $sth->fetchrow_array) {
- return uc($1) if $insert_trigger =~ m!(\w+)\.nextval!i; # col name goes here???
- }
- croak "Unable to find a sequence INSERT trigger on table '" . $source->name . "'.";
- });
+ $self->dbh_do(\&_ora_get_autoinc_seq, $source, $sql);
}
sub columns_info_for {
warn "DBD::Pg 1.49 is strongly recommended"
if ($DBD::Pg::VERSION < 1.49);
+sub _pg_last_insert_id {
+ my ($dbh, $seq) = @_;
+ $dbh->last_insert_id(undef,undef,undef,undef, {sequence => $seq});
+}
+
sub last_insert_id {
my ($self,$source,$col) = @_;
my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col));
- $self->dbh_do(sub { shift->last_insert_id(undef,undef,undef,undef, {sequence => $seq}) } );
+ $self->dbh_do(\&_pg_last_insert_id, $seq);
+}
+
+sub _pg_get_autoinc_seq {
+ my ($dbh, $schema, $table, @pri) = @_;
+
+ while (my $col = shift @pri) {
+ my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_hashref;
+ if(defined $info->{COLUMN_DEF} and
+ $info->{COLUMN_DEF} =~ /^nextval\(+'([^']+)'::(?:text|regclass)\)/) {
+ my $seq = $1;
+ # may need to strip quotes -- see if this works
+ return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq;
+ }
+ }
+ return;
}
sub get_autoinc_seq {
my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2)
: (undef,$source->name);
- $self->dbh_do(sub {
- my $dbh = shift;
- while (my $col = shift @pri) {
- my $info = $dbh->column_info(undef,$schema,$table,$col)->fetchrow_hashref;
- if (defined $info->{COLUMN_DEF} and $info->{COLUMN_DEF} =~
- /^nextval\(+'([^']+)'::(?:text|regclass)\)/)
- {
- my $seq = $1;
- return $seq =~ /\./ ? $seq : $info->{TABLE_SCHEM} . "." . $seq; # may need to strip quotes -- see if this works
- }
- }
- return;
- });
+ $self->dbh_do(\&_pg_get_autoinc_seq, $schema, $table, @pri);
}
sub sqlt_type {