0
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?

1 Answer 1

1

You're missing a whitespace before the limit keyword:

+ (start >= 0 && limit >= 0 ? ' LIMIT ' + start + ',' + limit : '');
// Here -----------------------^
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.