[Dbix-class] find_or_create problem with Pg: proposed patch
Alex Povolotsky
tarkhil at over.ru
Thu Apr 3 16:30:55 BST 2008
Hello!
Attempt to insert into postgres table with undef's for columns with
default values yields an error. It is especially bad with find_or_create
sub.
I've made and tested a simple patch, it looks working ok.
--- DBIx/Class/Storage/DBI/Pg.pm.orig 2007-08-12 01:07:58.000000000 +0400
+++ DBIx/Class/Storage/DBI/Pg.pm 2008-04-03 19:26:46.000000000 +0400
@@ -13,6 +13,20 @@
warn "DBD::Pg 1.49 is strongly recommended"
if ($DBD::Pg::VERSION < 1.49);
+sub insert {
+ my ($self, $source, $to_insert) = @_;
+ for my $col ( keys %$to_insert ) {
+ if (!defined($to_insert->{$col})) {
+ # Possible fix up case
+ my $colinfo = $source->column_info($col);
+ if (!$colinfo->{is_nullable} && $colinfo->{default_value}) {
+ delete $to_insert->{$col};
+ }
+ }
+ }
+ $self->SUPER::insert($source, $to_insert);
+}
+
sub _dbh_last_insert_id {
my ($self, $dbh, $seq) = @_;
$dbh->last_insert_id(undef, undef, undef, undef, {sequence => $seq});
Alex.
More information about the DBIx-Class
mailing list