Problem/Motivation

There are two hardcoded SQL statements,one in hook_cron() and one in getQuery(), that use the MySQL specific function CURDATE(). This produces less than ideal results on PostgreSQL:

PDOException: SQLSTATE[42883]: Undefined function: 7 ERROR:  function curdate() does not exist                                                                                           [error]
LINE 2:     WHERE (send_again = CURDATE() OR send_again IS NULL)
                                ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.: SELECT nlid FROM {newsletter_list}
    WHERE (send_again = CURDATE() OR send_again IS NULL)
    AND (send_rate = 'Daily' OR send_rate = 'Weekly' OR send_rate = 'Monthly'); Array
(
)
 in newsletter_cron() (line 373 of /path/to/drupal/all/modules/contrib/newsletter/newsletter.module).

and

PDOException: SQLSTATE[42883]: Undefined function: 7 ERROR:  function curdate() does not exist                                                                                           [error]
LINE 6: ...(list.last_sent IS NULL )) AND (list.send_again = CURDATE() ...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.: SELECT DISTINCT tax.nid AS nid, node.created AS created
FROM 
{taxonomy_index} tax
INNER JOIN {newsletter_list} list ON list.nlid = 5
INNER JOIN {node} node ON tax.nid = node.nid
WHERE  (tax.tid IN  (:db_condition_placeholder_0)) AND ((list.last_sent  0
)
 in NewsletterAutomated->getNodes() (line 139 of /path/to/drupal/sites/all/modules/contrib/newsletter/includes/newsletter.automated.inc).

Proposed resolution

In addition to using format_time() instead of the mySQL specific function, the attached patch also uses standard db_select() in one instance to make the logic easier to understand.

Remaining tasks

I'm open to suggestions and improvements on this patch, especially regarding the construction of the $todays_date variable.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Juterpillar created an issue. See original summary.

Juterpillar’s picture

FileSize
1.67 KB