简体   繁体   English

如何在节点js中执行多行mysql查询语句,该语句具有50行查询

[英]How to execute multiline mysql query statements in node js which has like 50 lines of query

I have been trying to execute a mysql query through nodejs in a linux system but geting the errors. 我一直在尝试通过linux系统中的nodejs执行mysql查询,但收到错误。 I have enabled the multipleStatements: true also. 我启用了multipleStatement:也为true。 Here is the part of the query i am trying to use: 这是我要使用的查询部分:

select 
c.name as "Name",
cl.u_geographic_region as "Region",
CASE
WHEN cic.os like '%Windows%' THEN 'Windows'
WHEN cic.os like '%aix%' THEN 'AIX'
WHEN cic.os like '%esx%' THEN 'ESX'
WHEN cic.os like '%linux%' THEN 'Linux'
WHEN cic.os like '%solaris%' THEN 'Solaris'
ELSE 'UNKNOWN'
END as "Operating System",
ci.dns_domain as "Host domain",
ci.ip_address as "IP Address",
from
cmdb as c
join cmdb_ci ci on c.sys_id = ci.sys_id

In my windows laptop i was able to achieve the result of this big sql query by putting it in BackTicks. 在我的Windows笔记本电脑中,通过将它放在BackTicks中,我能够实现此大型sql查询的结果。 But when I use the backticks in linux its failing. 但是,当我在Linux中使用反引号时,它会失败。 Can anyone help me. 谁能帮我。

After going through some of the questions. 经过一些问题。 I found out that the version of node I was using(v0.10.32) was not able to read backticks(`). 我发现我正在使用的节点版本(v0.10.32)无法读取反引号(`)。 I tested the script on v6 with the backticks and it totally worked. 我在带有反引号的v6上测试了脚本,它完全可以正常工作。 So i gave \\n after every line of my query and it worked. 所以我在查询的每一行之后都给出了\\ n,它起作用了。 Below is the updated query. 下面是更新的查询。

"select c.name as 'Name',\n"+
"cl.u_geographic_region as 'Region',\n"+
"CASE\n"+
"WHEN cic.os like '%Windows%' THEN 'Windows'\n"+
"WHEN cic.os like '%aix%' THEN 'AIX'\n"+
"WHEN cic.os like '%esx%' THEN 'ESX'\n"+
"WHEN cic.os like '%linux%' THEN 'Linux'\n"+
"WHEN cic.os like '%solaris%' THEN 'Solaris'\n"+
"ELSE 'UNKNOWN'\n"+
"END as 'Operating System',\n"+
"ci.dns_domain as 'Host domain',\n"+
"ci.ip_address as 'IP Address',\n";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM