summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2005-02-27 10:18:49 +0000
committerivan <ivan>2005-02-27 10:18:49 +0000
commit9d013bfbad3913b8ab9f1885fc66ba34032f1b0a (patch)
tree7b9f6954582c57bc3ff09ebce3d6f45b3fcec59f /FS
parent5ab9170358e085b26752d19a05b382680108384e (diff)
fix replacement in edge case with NULL integer fields in a table without a primary key
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Record.pm33
1 files changed, 25 insertions, 8 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index cf0ac3b2f..5465f078a 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -890,13 +890,25 @@ sub replace {
). ' WHERE '.
join(' AND ',
map {
- $old->getfield($_) eq ''
- #? "( $_ IS NULL OR $_ = \"\" )"
- ? ( driver_name eq 'Pg'
- ? "( $_ IS NULL OR $_ = '' )"
- : "( $_ IS NULL OR $_ = \"\" )"
- )
- : "$_ = ". _quote($old->getfield($_),$old->table,$_)
+
+ if ( $old->getfield($_) eq '' ) {
+
+ #false laziness w/qsearch
+ if ( driver_name eq 'Pg' ) {
+ my $type = $old->dbdef_table->column($_)->type;
+ if ( $type =~ /(int|serial)/i ) {
+ qq-( $_ IS NULL )-;
+ } else {
+ qq-( $_ IS NULL OR $_ = '' )-;
+ }
+ } else {
+ qq-( $_ IS NULL OR $_ = "" )-;
+ }
+
+ } else {
+ "$_ = ". _quote($old->getfield($_),$old->table,$_);
+ }
+
} ( $primary_key ? ( $primary_key ) : real_fields($old->table) )
)
;
@@ -1572,9 +1584,14 @@ sub _quote {
my($value, $table, $column) = @_;
my $column_obj = $dbdef->table($table)->column($column);
my $column_type = $column_obj->type;
+ my $nullable = $column_obj->null;
+
+ warn " $table.$column: $value ($column_type".
+ ( $nullable ? ' NULL' : ' NOT NULL' ).
+ ")\n" if $DEBUG > 2;
if ( $value eq '' && $column_type =~ /^int/ ) {
- if ( $column_obj->null ) {
+ if ( $nullable ) {
'NULL';
} else {
cluck "WARNING: Attempting to set non-null integer $table.$column null; ".