Ugly mySQL error when a blog does not exist

ddyrr - December 5, 2008 - 19:35
Project:Blog Add-ons
Version:6.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Once in awhile, a user will get the wrong URL of a blog, which results in a really ugly error:

* user warning: 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 query: SELECT COUNT(*) FROM node n WHERE n.type = 'blog' AND n.status = 1 AND n.uid = in ........../blog_addons/blog_addons.module on line 422.
* user warning: 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 'ORDER BY n.created DESC LIMIT 0, 20' at line 1 query: SELECT n.nid, n.created, YEAR(FROM_UNIXTIME(n.created)) AS year, MONTH(FROM_UNIXTIME(n.created)) AS month, DAY(FROM_UNIXTIME(n.created)) AS day FROM node n WHERE n.type = 'blog' AND n.status = 1 AND n.uid = ORDER BY n.created DESC LIMIT 0, 20 in ........../blog_addons/blog_addons.module on line 422.

This can be fixed with a simple check on line 420 of blog_addons.module:

<?php
if ($tempuser) {
   
$query = "SELECT n.nid, n.created, YEAR(FROM_UNIXTIME(n.created)) AS year, MONTH(FROM_UNIXTIME(n.created)) AS month, DAY(FROM_UNIXTIME(n.created)) AS day FROM {node} n WHERE n.type = 'blog' AND n.status = 1  AND n.uid = " . $tempuser->uid . " " . $limit $sortby;

   
$result = pager_query($query,variable_get('blog_addons_nposts_userhomepage', 20));
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.