]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 301062: [PostgreSQL] whine.pl fails when using PostgreSQL 8.0.x - Patch by Frédér...
authorlpsolit%gmail.com <>
Mon, 14 Nov 2005 01:36:20 +0000 (01:36 +0000)
committerlpsolit%gmail.com <>
Mon, 14 Nov 2005 01:36:20 +0000 (01:36 +0000)
Bugzilla/DB.pm
Bugzilla/DB/Mysql.pm
Bugzilla/DB/Pg.pm
Bugzilla/Search.pm
Bugzilla/Token.pm
contrib/sendunsentbugmail.pl
sanitycheck.cgi
userprefs.cgi
whine.pl

index c5f38d17bcf3b743814653b66af041e238a33123..ec189b7eed381f795cf9b56a921c048dd6622058 100644 (file)
@@ -1140,8 +1140,8 @@ formatted SQL command have prefix C<sql_>. All other methods have prefix C<bz_>.
 
  Description: Outputs proper SQL syntax for a time interval function.
               Abstract method, should be overriden by database specific code.
- Params:      $interval = the time interval requested (e.g. '30 minutes')
-              (scalar)
+ Params:      $interval - the time interval requested (e.g. '30') (integer)
+              $units    - the units the interval is in (e.g. 'MINUTE') (string)
  Returns:     formatted SQL for interval function (scalar)
 
 =item C<sql_position>
index e76dc4599b431cc23d06639e7692ae86b9dcba5a..ecdf63517823281f9aea4bcbf562f94661d2e56c 100644 (file)
@@ -132,9 +132,9 @@ sub sql_date_format {
 }
 
 sub sql_interval {
-    my ($self, $interval) = @_;
+    my ($self, $interval, $units) = @_;
     
-    return "INTERVAL $interval";
+    return "INTERVAL $interval $units";
 }
 
 sub sql_position {
index 84631e62b7dc17a8d6dd11ad34ca1371d98fe44a..8fc522490a862af21a32069c971e7370c62c1a79 100644 (file)
@@ -130,9 +130,9 @@ sub sql_date_format {
 }
 
 sub sql_interval {
-    my ($self, $interval) = @_;
+    my ($self, $interval, $units) = @_;
     
-    return "INTERVAL '$interval'";
+    return "$interval * INTERVAL '1 $units'";
 }
 
 sub sql_string_concat {
index 0e9a56b0f55ad490d4e6f9f0ef0d4f4ee5c103aa..aa9017fe521836e4e3ecfc90a0e077a2664545e4 100644 (file)
@@ -960,7 +960,7 @@ sub init {
                     $unitinterval = 'YEAR';
                 }
                 my $cutoff = "NOW() - " .
-                             $dbh->sql_interval("$quantity $unitinterval");
+                             $dbh->sql_interval($quantity, $unitinterval);
                 my $assigned_fieldid = &::GetFieldID('assigned_to');
                 push(@supptables, "LEFT JOIN longdescs AS comment_$table " .
                                   "ON comment_$table.who = bugs.assigned_to " .
index fe72915a36b4a725d2f0599b50fc5d7853f87e03..7404d61e5b62facdb522b27477eba4cfe14357c5 100644 (file)
@@ -103,7 +103,7 @@ sub IssuePasswordToken {
                     ON tokens.userid = profiles.userid
                     AND tokens.tokentype = 'password'
                     AND tokens.issuedate > NOW() - " .
-                    $dbh->sql_interval('10 MINUTE') . "
+                    $dbh->sql_interval(10, 'MINUTE') . "
                  WHERE " . $dbh->sql_istrcmp('login_name', $quotedloginname));
     my ($userid, $toosoon) = &::FetchSQLData();
 
index c82c0ae30c49d0c4b522e04ab7b78dd9eb4d405a..0bd6a9b17b4be7cdd3895f8d2f4e970073fb197f 100644 (file)
@@ -33,7 +33,7 @@ my $dbh = Bugzilla->dbh;
 SendSQL("SELECT bug_id FROM bugs 
           WHERE lastdiffed IS NULL
                 OR lastdiffed < delta_ts AND  delta_ts < NOW() - " 
-                 . $dbh->sql_interval('30 minute') .
+                 . $dbh->sql_interval(30, 'MINUTE') .
         " ORDER BY bug_id");
 my @list;
 while (MoreSQLData()) {
index c091e1041d95974b9bde2b9bf389f01faf15138a..aaac07bf65e37c5ba8e96b77ae8607f2fbf0378f 100755 (executable)
@@ -150,7 +150,7 @@ if (defined $cgi->param('cleangroupsnow')) {
     # If any page starts taking longer than one hour to load, this interval
     # should be revised.
     SendSQL("SELECT MAX(last_changed) FROM groups WHERE last_changed < NOW() - " . 
-            $dbh->sql_interval('1 HOUR'));
+            $dbh->sql_interval(1, 'HOUR'));
     (my $cutoff) = FetchSQLData();
     Status("Cutoff is $cutoff");
     SendSQL("SELECT COUNT(*) FROM user_group_map");
@@ -255,7 +255,7 @@ if (defined $cgi->param('rescanallBugMail')) {
     Status("OK, now attempting to send unsent mail");
     SendSQL("SELECT bug_id FROM bugs 
               WHERE (lastdiffed IS NULL OR lastdiffed < delta_ts) AND
-             delta_ts < now() - " . $dbh->sql_interval('30 minute') .
+             delta_ts < now() - " . $dbh->sql_interval(30, 'MINUTE') .
             " ORDER BY bug_id");
     my @list;
     while (MoreSQLData()) {
@@ -867,7 +867,7 @@ Status("Checking for unsent mail");
 
 SendSQL("SELECT bug_id " .
         "FROM bugs WHERE (lastdiffed IS NULL OR lastdiffed < delta_ts) AND " .
-        "delta_ts < now() - " . $dbh->sql_interval('30 minute') .
+        "delta_ts < now() - " . $dbh->sql_interval(30, 'MINUTE') .
         " ORDER BY bug_id");
 
 while (@row = FetchSQLData()) {
index 9ae558fa18e8955671533d1eaba4fbe90087533a..8d59a34e3174e6cd6661b2c3d20a7d8edc5664c3 100755 (executable)
@@ -49,7 +49,7 @@ sub DoAccount {
     $vars->{'realname'} = FetchSQLData();
 
     if(Param('allowemailchange')) {
-        SendSQL("SELECT tokentype, issuedate + " . $dbh->sql_interval('3 DAY') .
+        SendSQL("SELECT tokentype, issuedate + " . $dbh->sql_interval(3, 'DAY') .
                 ", eventdata
                     FROM tokens
                     WHERE userid = $userid
index fea9d3da36be8b71be69d1efc5d086b4f10afb9a..d8fc8ddd08b66f03d4ea77045ad9a749e2950c52 100755 (executable)
--- a/whine.pl
+++ b/whine.pl
@@ -34,6 +34,7 @@ use Bugzilla::Constants;
 use Bugzilla::Search;
 use Bugzilla::User;
 use Bugzilla::BugMail;
+use Bugzilla::Util;
 
 # create some handles that we'll need
 my $template = Bugzilla->template;
@@ -170,20 +171,21 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) {
         # A time greater than now means it still has to run today
         elsif ($time >= $now_hour) {
             # set it to today + number of hours
-            $sth = $dbh->prepare( "UPDATE whine_schedules " .
-                   "SET run_next = CURRENT_DATE() + " .
-                   $dbh->sql_interval('? HOUR') .
-                   " WHERE id = ?");
+            $sth = $dbh->prepare("UPDATE whine_schedules " .
+                                 "SET run_next = CURRENT_DATE + " .
+                                 $dbh->sql_interval('?', 'HOUR') .
+                                 " WHERE id = ?");
             $sth->execute($time, $schedule_id);
         }
         # the target time is less than the current time
         else { # set it for the next applicable day
-            my $nextdate = &get_next_date($day);
-            $sth = $dbh->prepare( "UPDATE whine_schedules " .
-                   "SET run_next = ? + " .
-                   $dbh->sql_interval('? HOUR') .
-                   " WHERE id = ?");
-            $sth->execute($nextdate, $time, $schedule_id);
+            $day = &get_next_date($day);
+            $sth = $dbh->prepare("UPDATE whine_schedules " .
+                                 "SET run_next = CURRENT_DATE + " .
+                                 $dbh->sql_interval('?', 'DAY') . " + " .
+                                 $dbh->sql_interval('?', 'HOUR') .
+                                 " WHERE id = ?");
+            $sth->execute($day, $time, $schedule_id);
         }
 
     }
@@ -195,10 +197,11 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) {
         # midnight
         my $target_time = ($time =~ /^\d+$/) ? $time : 0;
 
-        $sth = $dbh->prepare( "UPDATE whine_schedules " .
-               "SET run_next = ? + " .
-               $dbh->sql_interval('? HOUR') .
-               " WHERE id = ?");
+        $sth = $dbh->prepare("UPDATE whine_schedules " .
+                             "SET run_next = CURRENT_DATE + " .
+                             $dbh->sql_interval('?', 'DAY') . " + " .
+                             $dbh->sql_interval('?', 'HOUR') .
+                             " WHERE id = ?");
         $sth->execute($target_date, $target_time, $schedule_id);
     }
 }
@@ -596,23 +599,25 @@ sub reset_timer {
 
         my $nextdate = &get_next_date($run_day);
 
-        $sth = $dbh->prepare( "UPDATE whine_schedules " .
-                              "SET run_next = ? + " .
-                              $dbh->sql_interval('? HOUR') .
-                              " WHERE id = ?");
+        $sth = $dbh->prepare("UPDATE whine_schedules " .
+                             "SET run_next = CURRENT_DATE + " .
+                             $dbh->sql_interval('?', 'DAY') . " + " .
+                             $dbh->sql_interval('?', 'HOUR') .
+                             " WHERE id = ?");
         $sth->execute($nextdate, $target_time, $schedule_id);
         return;
     }
 
-    # Scheduling is done in terms of whole minutes, so we use subtraction to
-    # drop the seconds from the time.
     if ($minute_offset > 0) {
+        # Scheduling is done in terms of whole minutes.
+        my $next_run = $dbh->selectrow_array('SELECT NOW() + ' .
+                                             $dbh->sql_interval('?', 'MINUTE'),
+                                             undef, $minute_offset);
+        $next_run = format_time($next_run, "%Y-%m-%d %R");
+
         $sth = $dbh->prepare("UPDATE whine_schedules " .
-                             "SET run_next = NOW() + " .
-                             $dbh->sql_interval('? MINUTE') . " - " .
-                             $dbh->sql_interval('SECOND(NOW()) SECOND') .
-                             " WHERE id = ?");
-        $sth->execute($minute_offset, $schedule_id);
+                             "SET run_next = ? WHERE id = ?");
+        $sth->execute($next_run, $schedule_id);
     } else {
         # The minute offset is zero or less, which is not supposed to happen.
         # complain to STDERR
@@ -636,7 +641,7 @@ sub null_schedule {
 # time a schedule should run, excluding today
 #
 # It takes a run_day argument (see check_today, above, for an explanation),
-# and returns an SQL date
+# and returns an integer, representing a number of days.
 sub get_next_date {
     my $day = shift;
 
@@ -689,11 +694,5 @@ sub get_next_date {
             $add_days += $daysinmonth[$now_month];
         }
     }
-
-    # Get a date in whatever format the database will accept
-    $sth = $dbh->prepare("SELECT CURRENT_DATE() + " .
-                         $dbh->sql_interval('? DAY'));
-    $sth->execute($add_days);
-    return $sth->fetch->[0];
+    return $add_days;
 }
-