简体   繁体   中英

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. I have enabled the multipleStatements: true also. 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. But when I use the backticks in linux its failing. 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(`). I tested the script on v6 with the backticks and it totally worked. So i gave \\n after every line of my query and it worked. 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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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