Reputation: 63
var query =
'SELECT '
+ prefix + 'threads.tid as _tid, '
+ prefix + 'threads.fid as _cid, '
+ prefix + 'threads.firstpost as _pid, '
+ prefix + 'threads.views as _viewcount, '
+ prefix + 'threads.subject as _title, '
+ prefix + 'threads.dateline as _timestamp, '
+ prefix + 'threads.sticky as _pinned, '
+ prefix + 'posts.uid as _uid, '
+ prefix + 'posts.tid as _post_tid, '
+ prefix + 'posts.message as _content, '
+ 'IF(filetype like "image%", CONCAT("/uploads/files/MyBBAttachment/", attachname), NULL) as _images, '
+ 'IF(filetype like "image%", GROUP_CONCAT(filename SEPARATOR ","), NULL) as _imgnames, '
+ 'IF(filetype not like "image%", CONCAT("/uploads/files/MyBBAttachment/", attachname), NULL) as _attachments, '
+ 'IF(filetype not like "image%", GROUP_CONCAT(filename SEPARATOR ","), NULL) as _attachnames '
+ 'FROM ' + prefix + 'posts LEFT JOIN ' + prefix + 'attachments ON (' + prefix + 'posts.pid = ' + prefix + 'attachments.pid), ' + prefix + 'threads '
+ 'WHERE ' + prefix + 'threads.firstpost=' + prefix + 'posts.pid '
+ 'GROUP BY ' + prefix + 'posts.pid'
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
Above query doesn't work in Node.js, I get following error:
{ Error: ER_PARSE_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 '0,600000' at line 1
But when I run similar thing in PHPMyAdmin, it works:
SELECT mybb_threads.tid as _tid, mybb_threads.fid as _cid, mybb_threads.firstpost as _pid, mybb_threads.views as _viewcount, mybb_threads.subject as _title, mybb_threads.dateline as _timestamp, mybb_threads.sticky as _pinned, mybb_posts.uid as _uid, mybb_posts.tid as _post_tid, mybb_posts.message as _content
FROM mybb_posts LEFT JOIN mybb_attachments ON mybb_posts.pid = mybb_attachments.pid, mybb_threads
where mybb_threads.firstpost=mybb_posts.pid
group by mybb_posts.pid
LIMIT 0, 100
How do I make var query work?
Upvotes: 0
Views: 64
Reputation: 311073
You're missing a whitespace before the limit
keyword:
+ (start >= 0 && limit >= 0 ? ' LIMIT ' + start + ',' + limit : '');
// Here -----------------------^
Upvotes: 1