我正在使用sql数据库提供服务。我确实结合了两个查询来创建单个查询,因为查询存储在不同的表中。但是它在我试图执行最终查询的代码的最后部分给出了错误。
代码如下:
const mysql = require('mysql');
const express = require('express');
var app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var mysqlConnection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'abc',
});
mysqlConnection.connect((err) => {
if (!err)
console.info('DB connection Succeed...!!');
else
console.error('DB connection Error \n Error :' + JSON.stringify(err, undefined, 2));
});
app.listen(4001, ()=> console.log('Express server is running on port 4001 '));
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
if (req.method === 'OPTIONS'){
res.header("Access-Control-Allow-Methods", "POST, PUT, PATCH, DELETE, GET");
return res.status(200).json({});
}
if (req.method === 'PATCH'){
res.header("Access-Control-Allow-Methods", "POST, PUT, PATCH, DELETE, GET");
return res.status(200).json({});
}
next();
});
app.get('/drawChart',(req,res)=>{
var query1 = null;
var query2 = null;
var finalquery = null;
var finquery=null;
mysqlConnection.query('SELECT * FROM t_table WHERE t_code= ?', 70, function',function(err, result){
if (err)
return res.json({})
query1=result[0].T_QUERY;
});
mysqlConnection.query('SELECT * FROM t_table_attr_val WHERE Table_ATTR_TYPE="GROUPBY" and t_CODE=?', 70, ', function(err, result){
if (err)
return res.json({})
query2=result[0].T_ATTR TYPE;
finalquery=query1 + ' Group by ';
finalquery +=query2;
console.log(finalquery)
});
mysqlConnection.query(finalquery,function(err,result){
if(err)
return res.json({})
console.log("result is "+ result);
})
});
这是错误消息
Cannot use 'in' operator to search for 'typeCast' in null
at Connection.query
(C:\Users\ASUS\node_modules\mysql\lib\Connection.js:186:47)
我无法弄清楚代码出了什么问题。