freeside/FS/FS Record.pm,1.92,1.93
ivan
ivan at pouncequick.420.am
Sun Feb 27 02:18:52 PST 2005
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv7626
Modified Files:
Record.pm
Log Message:
fix replacement in edge case with NULL integer fields in a table without a primary key
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- Record.pm 29 Dec 2004 12:00:06 -0000 1.92
+++ Record.pm 27 Feb 2005 10:18:49 -0000 1.93
@@ -890,13 +890,25 @@
). ' 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 @@
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; ".
More information about the freeside-commits
mailing list