PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1: SELECT n.uid AS uid, n.created AS created FROM {node} n WHERE (n.status = :db_condition_placeholder_0) AND (n.type IN ()) ; Array ( [:db_condition_placeholder_0] => 1 ) in function _archive_post_count() (row 385 in file ................../sites/all/modules/archive/archive.module).

Comments

sandu.camerzan’s picture

Status: Active » Needs review

Yes, I got this bug as well.
I found and fixed the issue, but I don't know how to create a patch using Git for Drupal.org, I'll have to look into it for improving my future contributions.

The fix:

<?php
[...]
function _archive_post_count($type, $date) {
  $final_types = _archive_types_sql_array($type);
  $node_query = db_select('node', 'n');
  $node_query->fields('n', array('uid', 'created'));
  $node_query->condition('n.status', 1);
  if(!empty($final_types)) //added this line
    $node_query->condition('n.type', $final_types, 'IN');
 [...]
?>

This is the problem: When adding an IN condition to a dynamic query, in this case $node_query->condition('n.type', $final_types, 'IN') will throw errors when the $final_types variable passed is empty or not an array.

Hope this helps. Sorry again for not submitting a patch, as the best way should be. Have a nice day!

jasonglisson’s picture

This fixed my error message for the calendar block. But now when I click on one of the link within the calendar block, I get this.

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND (n.created >= '1328072400') AND (n.created <= '1330578000') ) subquery' at line 1: SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {node} n WHERE (n.status = :db_condition_placeholder_0) AND (n.type IN ()) AND (n.created >= :db_condition_placeholder_1) AND (n.created <= :db_condition_placeholder_2) ) subquery; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 1328072400 [:db_condition_placeholder_2] => 1330578000 ) in PagerDefault->execute() (line 74 of ........................./includes/pager.inc).

Obviously it's a pager.inc conflict. But does anyone know what the fix would be?

mlleepeter’s picture

I had had same problem but it seems to be fixed after I set the available content type into a certain type (such as "article") in /admin/config/user-interface/archive.