From 02a049703de6055f09f44f89a5a821814696ce32 Mon Sep 17 00:00:00 2001 From: Max Kanat-Alexander Date: Thu, 7 Oct 2010 03:58:28 -0700 Subject: Bug 602165: Change sql_interval to sql_date_math, in preparation for MS-SQL and SQLite support. --- whine.pl | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'whine.pl') diff --git a/whine.pl b/whine.pl index 3932f854c..872061fb6 100755 --- a/whine.pl +++ b/whine.pl @@ -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 " . -- cgit v1.2.1