conn.escape() fails under heavy loads

18 views
Skip to first unread message

Christopher Cato

unread,
Jul 17, 2014, 5:29:42 AM7/17/14
to node-...@googlegroups.com
Hi.

I recently discovered that conn.escape() fails sometimes, rendering the query as "undefined".

Example:

var query = ('select id from statistics.adstats where date="' +
                args['date'] +
                '" and advertiser=' +
                conn.escape(args['advertiser']) +
                ' and placement=' +
                conn.escape(args['placement']) +
                ' and format=' +
                conn.escape(args['format']) +
                ' and unit=' +
                conn.escape(args['unit']));
            conn.query(query, function (err, rows) {
                if (err) {
                    // If the first query fails, we can not proceed. Let's make an entry in the log and move on
                    app.errors++;
                    console.log(getPrettyDate() + " - " + getPrettyTime() + " DB Error: " +  err + " query:" + query);
                    console.log("Offending query:" + query);
                    conn.end();
                    return true;
                }

This would fail in something like 1 out of 1000 requests. Replacing conn.escape() with mysql.escape() resolves it as far as I can tell.
Reply all
Reply to author
Forward
0 new messages