PDA

View Full Version : SQL error in latesttopics.php when permissions means no forums to display


bobbymac
10-10-2004, 12:10 PM
I suspect this qualifies as a bug.
I'll admit the circumstances to produce the error are probably not common, but here it is anyway. We created a page that used the latesttopics module. It was to display the latest topics for a single forum. However, when we denied all permissions on that forum (so no one even admins can view it), viewing that page generated an SQL error:


Database error in vBulletin 3.0.3:

Invalid SQL:
SELECT

thread.threadid, thread.title, thread.replycount, postusername, postuserid, thread.dateline AS postdateline, IF(views <= thread.replycount, thread.replycount+1, views) AS views, thread.lastposter, thread.lastpost, pollid
, thread.iconid AS threadiconid, iconpath AS threadiconpath
,thread.forumid, forum.title AS forumtitle
, post.pagetext AS preview
, NOT ISNULL(subscribethread.subscribethreadid) AS subscribed
FROM thread as thread
LEFT JOIN icon USING (iconid)
LEFT JOIN forum AS forum ON (thread.forumid = forum.forumid)
LEFT JOIN post AS post ON (post.postid = thread.firstpostid)
LEFT JOIN deletionlog AS deletionlog ON (thread.threadid = deletionlog.primaryid AND type = 'thread')
LEFT JOIN subscribethread AS subscribethread ON (subscribethread.threadid = thread.threadid AND subscribethread.userid = 2)
WHERE open <> '10' AND thread.visible = 1 AND thread.forumid NOT IN(18,24,23,22,21,20,19) Array AND deletionlog.primaryid IS NULL
ORDER BY lastpost DESC
LIMIT 10

mysql error: 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 'Array AND deletionlog.primaryid IS NULL
ORDER BY lastpost D

mysql error number: 1064


It's caused by the "Array" word in there, obviously not valid SQL syntax. This happens when the $inforums variable ends up being an empty array - it doesn't get converted to a string/imploded. I fixed it by the following addition of the else clause - assuming no forum has an ID of -1. It can't be set to an empty string otherwise it messes up the query (threads from all forums end up being returned rather than just the ones/none that are meant to be).

latesttopics.php - line 28 onwards. Added in else clause.

if (!empty($inforums))
{
$inforums = implode(',', $inforums);
}
##### MOD fixing code when no one has permission to view the forum(s) chosen - causes SQL error as $inforums remains an array
else {
$inforums = '-1';
}


I hope I've described it enough! :)

Brian
10-10-2004, 05:05 PM
Bugs forum. ;)