add ut_snumber, fix replacement of records with empty values in non-primary-keyed...
[freeside.git] / FS / FS / Record.pm
index 191eee5..b950e30 100644 (file)
@@ -313,9 +313,9 @@ sub qsearch {
     if ( $record->{$field} =~ /^\d+(\.\d+)?$/
          && $dbdef->table($table)->column($field)->type =~ /(int|serial)/i
     ) {
-      $sth->bind_param($bind++, $record->{$field}, SQL_INTEGER);
+      $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_INTEGER } );
     } else {
-      $sth->bind_param($bind++, $record->{$field}, SQL_VARCHAR);
+      $sth->bind_param($bind++, $record->{$field}, { TYPE => SQL_VARCHAR } );
     }
   }
 
@@ -838,7 +838,7 @@ sub replace {
         $old->getfield($_) eq ''
           #? "( $_ IS NULL OR $_ = \"\" )"
           ? ( driver_name eq 'Pg'
-                ? "$_ IS NULL"
+                ? "( $_ IS NULL OR $_ = '' )"
                 : "( $_ IS NULL OR $_ = \"\" )"
             )
           : "$_ = ". _quote($old->getfield($_),$old->table,$_)
@@ -1053,6 +1053,21 @@ sub ut_float {
   '';
 }
 
+=item ut_snumber COLUMN
+
+Check/untaint signed numeric data (whole numbers).  May not be null.  If there
+is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub ut_snumber {
+  my($self, $field) = @_;
+  $self->getfield($field) =~ /^(-?)\s*(\d+)$/
+    or return "Illegal or empty (numeric) $field: ". $self->getfield($field);
+  $self->setfield($field, "$1$2");
+  '';
+}
+
 =item ut_number COLUMN
 
 Check/untaint simple numeric data (whole numbers).  May not be null.  If there