MyBB Community Forums

Full Version: [F] Archive - SQL bug fetching attachments/posts with abandoned thread [C-StefanT]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
MyBB 1.4.6

Error log contains:
<error>
        <dateline>1244532827</dateline>
        <script></script>
        <line>0</line>
        <type>20</type>
        <friendly_type>MyBB SQL Error</friendly_type>
        <message>SQL Error: 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
Query: SELECT * FROM mybb_attachments WHERE pid IN ()</message>
</error>
while accessing "abandoned" threads in archive mode. With "abandoned" I mean threads which exists in mybb_threads table but do not have any posts in mybb_posts - probably because of MyBB or DB error (e.g. restarting DB server, timeout, race condition etc.).

Simple patch: [attachment=14188]
Nicely found...! Patch seems to fix the problem...
Personally I'd favor not running the query at all in there is nothing to look up, but the fix does work fine.
So, really, a fix could be:

$pids = implode(",", $pids);

if($pids)
{
	// Build attachments cache
	$query = $db->simple_select("attachments", "*", "pid IN ({$pids})");
	while($attachment = $db->fetch_array($query))
	{
		$acache[$attachment['pid']][$attachment['aid']] = $attachment;
	}
}
Yes, that sounds better
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

With regards,
MyBB Group