fix times condition vs. mysql (causes billing errors even if not using), RT#10574
authorivan <ivan>
Mon, 11 Apr 2011 17:22:37 +0000 (17:22 +0000)
committerivan <ivan>
Mon, 11 Apr 2011 17:22:37 +0000 (17:22 +0000)
FS/FS/part_event/Condition.pm
FS/FS/part_event/Condition/cust_bill_has_service.pm
FS/FS/part_event/Condition/times.pm

index 9155a7d..6902774 100644 (file)
@@ -145,7 +145,7 @@ passed as an argument.
 This method is used for optimizing event queries.  You may want to add indices
 for any columns referenced.  It is acceptable to return an SQL fragment which
 partially tests the condition; doing so will still reduce the number of
-records which much be returned and tested with the B<condition> method.
+records which must be returned and tested with the B<condition> method.
 
 =cut
 
@@ -457,7 +457,7 @@ sub age2seconds_sql {
 
 }
 
-=item condition_sql_option_integer
+=item condition_sql_option_integer OPTION [ DRIVER_NAME ]
 
 As I<condition_sql_option>, but cast the option value to an integer so that
 comparison to other integers is type-correct.
@@ -465,8 +465,11 @@ comparison to other integers is type-correct.
 =cut
 
 sub condition_sql_option_integer {
-  my ($class, $option) = @_;
-  'CAST ('.$class->condition_sql_option($option).' AS INTEGER)';
+  my ($class, $option, $driver_name) = @_;
+
+  my $integer = ($driver_name =~ /^mysql/) ? 'UNSIGNED INTEGER' : 'INTEGER';
+
+  'CAST ('. $class->condition_sql_option($option). " AS $integer )";
 }
 
 =head1 NEW CONDITION CLASSES
index 744e079..7c1916b 100644 (file)
@@ -41,14 +41,14 @@ sub condition {
 sub condition_sql {
   my( $class, $table, %opt ) = @_;
 
-  my $integer = $opt{'driver_name'} =~ /^mysql/ ? 'UNSIGNED INTEGER' : 'INTEGER';
-  
-  my $servicenum = $class->condition_sql_option('has_service');
+  my $servicenum =
+    $class->condition_sql_option_integer('has_service', $opt{'driver_name'});
+
   my $sql = qq| 0 < ( SELECT COUNT(cs.svcpart)
      FROM cust_bill_pkg cbp, cust_svc cs
     WHERE cbp.invnum = cust_bill.invnum
       AND cs.pkgnum = cbp.pkgnum
-      AND cs.svcpart = CAST( $servicenum AS $integer )
+      AND cs.svcpart = $servicenum
   )
   |;
   return $sql;
index 91212e7..46c2967 100644 (file)
@@ -39,17 +39,20 @@ sub condition {
 }
 
 sub condition_sql {
-  my( $class, $table ) = @_;
+  my( $class, $table, %opt ) = @_;
 
   my %tablenum = %{ FS::part_event->eventtable_pkey_sql };
 
+  my $run_times =
+    $class->condition_sql_option_integer('run_times', $opt{'driver_name'});
+
   my $existing = "( SELECT COUNT(*) FROM cust_event
                       WHERE cust_event.eventpart = part_event.eventpart
                         AND cust_event.tablenum = $tablenum{$table}
                         AND status != 'failed'
                   )";
 
-  "$existing <= ". $class->condition_sql_option_integer('run_times');
+  "$existing <= $run_times";
 
 }