nodeJS中的多语句查询抛出错误

时间:2017-06-22 10:12:02

标签: mysql sql node.js error-handling

在我的应用程序中,我需要在单个查询中执行多个select语句。 我正在使用node-querybuilder

https://www.npmjs.com/package/node-querybuilder

我正在使用.query方法执行自定义查询(不生成查询) 这是代码

    user.earning_information = function(key){
    return new Promise(function(resolve,reject){
        let balance = user.userData.balance;
        let query = "SELECT SUM(`amount`) as `total_earnings` FROM `earnings` WHERE `tid` = "+key+";";
            query += "SELECT SUM(`amount`) as `total_earnings_ref` FROM `earnings` WHERE `tid` = "+key+" AND `type` LIKE 'ref%';";
            query += "SELECT SUM(`amount`) as `total_earnings_ref1` FROM `earnings` WHERE `tid` = "+key+" AND `type` = 'ref';";
            query += "SELECT SUM(`amount`) as `total_earnings_ref2` FROM `earnings` WHERE `tid` = "+key+" AND `type` = 'ref_pa';";
            query += "SELECT SUM(`amount`) as `total_earnings_ref3` FROM `earnings` WHERE `tid` = "+key+" AND `type` = 'ref_supa';";
            query += "SELECT SUM(`amount`) as `total_earnings_invest` FROM `earnings` WHERE `tid` = "+key+" AND `type` = 'invest';";
        console.log(query);
        dbc.db_query(query).then(function(data){            
            console.log(data);
        }).catch(function(err){
            console.log(err);
        });
    });
}

我已经将查询记录到控制台了,这就是我得到的,我甚至在phpmyadmin上运行它并且它可以工作并返回数据。

SELECT SUM(amount)as total_earnings FROM earnings WHERE tid = 157632672; SELECT SUM(amount)as total_earnings_ref FROM { {1}} WHERE earnings = 157632672 AND tid LIKE'ref%'; SELECT SUM(type)为amount FROM total_earnings_ref1 WHERE {{1} } = 157632672 AND earnings ='ref'; SELECT SUM(tid)为type FROM amount WHERE total_earnings_ref2 = 157632672 AND earnings = 'ref_pa'; SELECT SUM(tid)as type FROM amount WHERE total_earnings_ref3 = 157632672 AND earnings ='ref_supa'; SELECT SUM({{1 } {} tid FROM type WHERE amount = 157632672 AND total_earnings_invest ='invest';

但是,当我以编程方式运行它时,会抛出此错误。

earnings

知道为什么会这样吗? 顺便说一下,数据库是mySQL,错误是MariaDB。

0 个答案:

没有答案