diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-10-07 03:58:28 -0700 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2010-10-07 03:58:28 -0700 |
commit | 02a049703de6055f09f44f89a5a821814696ce32 (patch) | |
tree | 5918c91ceea49d280c8c3c0ce795da549a8bf4c6 /whine.pl | |
parent | Bug 26074 - Ability to limit search by number of Comments (diff) | |
download | bugzilla-02a049703de6055f09f44f89a5a821814696ce32.tar.gz bugzilla-02a049703de6055f09f44f89a5a821814696ce32.tar.bz2 bugzilla-02a049703de6055f09f44f89a5a821814696ce32.zip |
Bug 602165: Change sql_interval to sql_date_math, in preparation for
MS-SQL and SQLite support.
Diffstat (limited to 'whine.pl')
-rwxr-xr-x | whine.pl | 44 |
1 files changed, 24 insertions, 20 deletions
@@ -150,20 +150,22 @@ 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 = " . + $dbh->sql_date_math('CURRENT_DATE', '+', '?', '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 $day = &get_next_date($day); + my $run_next = $dbh->sql_date_math('(' + . $dbh->sql_date_math('CURRENT_DATE', '+', '?', 'DAY') + . ')', '+', '?', 'HOUR'); $sth = $dbh->prepare("UPDATE whine_schedules " . - "SET run_next = (CURRENT_DATE + " . - $dbh->sql_interval('?', 'DAY') . ") + " . - $dbh->sql_interval('?', 'HOUR') . - " WHERE id = ?"); + "SET run_next = $run_next + WHERE id = ?"); $sth->execute($day, $time, $schedule_id); } @@ -176,11 +178,12 @@ while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) { # midnight my $target_time = ($time =~ /^\d+$/) ? $time : 0; + my $run_next = $dbh->sql_date_math('(' + . $dbh->sql_date_math('CURRENT_DATE', '+', '?', 'DAY') + . ')', '+', '?', 'HOUR'); $sth = $dbh->prepare("UPDATE whine_schedules " . - "SET run_next = (CURRENT_DATE + " . - $dbh->sql_interval('?', 'DAY') . ") + " . - $dbh->sql_interval('?', 'HOUR') . - " WHERE id = ?"); + "SET run_next = $run_next + WHERE id = ?"); $sth->execute($target_date, $target_time, $schedule_id); } } @@ -584,21 +587,22 @@ sub reset_timer { my $target_time = ($run_time =~ /^\d+$/) ? $run_time : 0; my $nextdate = &get_next_date($run_day); - + my $run_next = $dbh->sql_date_math('(' + . $dbh->sql_date_math('CURRENT_DATE', '+', '?', 'DAY') + . ')', '+', '?', 'HOUR'); $sth = $dbh->prepare("UPDATE whine_schedules " . - "SET run_next = (CURRENT_DATE + " . - $dbh->sql_interval('?', 'DAY') . ") + " . - $dbh->sql_interval('?', 'HOUR') . - " WHERE id = ?"); + "SET run_next = $run_next + WHERE id = ?"); $sth->execute($nextdate, $target_time, $schedule_id); return; } 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); + + my $next_run = $dbh->selectrow_array( + 'SELECT ' . $dbh->sql_date_math('NOW()', '+', '?', 'MINUTE'), + undef, $minute_offset); $next_run = format_time($next_run, "%Y-%m-%d %R"); $sth = $dbh->prepare("UPDATE whine_schedules " . |