1

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.

Raghu Reddy
  • 45
  • 1
  • 7
  • You may find this helpful: http://stackoverflow.com/questions/6220420/how-do-i-do-a-multi-line-string-in-node-js – tier1 Feb 28 '17 at 17:21
  • so now should i be giving \ in the end of each line? even then it is not working. the node version what am using is v0.10.31. – Raghu Reddy Feb 28 '17 at 17:54
  • @tier1 - Thanks for the help. It worked and am able to pull the data from the mysql database. – Raghu Reddy Feb 28 '17 at 19:30

1 Answers1

3

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";
Raghu Reddy
  • 45
  • 1
  • 7