如何在具有 50 行查询的节点 js 中执行多行 mysql 查询语句 [英] How to execute multiline mysql query statements in node js which has like 50 lines of query

查看:33
本文介绍了如何在具有 50 行查询的节点 js 中执行多行 mysql 查询语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过 linux 系统中的 nodejs 执行 mysql 查询,但出现错误.我也启用了 multipleStatements: true .这是我尝试使用的查询的一部分:

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

在我的 Windows 笔记本电脑中,我能够通过将它放在 BackTicks 中来获得这个大 sql 查询的结果.但是当我在 linux 中使用反引号时,它失败了.谁能帮帮我.

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.

推荐答案

经过一些问题.我发现我使用的节点版本(v0.10.32)无法读取反引号(`).我用反引号在 v6 上测试了脚本,它完全有效.所以我在查询的每一行之后都给出了 \n 并且它起作用了.以下是更新后的查询.

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";

这篇关于如何在具有 50 行查询的节点 js 中执行多行 mysql 查询语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆