sql 查询不适用于 node.js mysql 但适用于终端

我病得最厉害

我有一个 sql 查询如下

select profileName from user where (id) in ( select id FROM( SELECT user_id1 as id from user_connection where user_id2=(select id from user where profileName='deva') UNION ALL SELECT user_id2 as id from user_connection where user_id1=(select id from user where profileName='deva')) t GROUP BY id) ;

在终端上像魔术一样工作,但在 node.js 上它有 sql 查询错误

exports.findFriends = function(userName,callback){
console.log('searching friends.... '+userName);
var findFriendsQuery = 'select profileName from user where (id) in ( select id FROM ( SELECT user_id1 as id from user_connection where user_id2=(select id from user where profileName= ? ) UNION ALL SELECT user_id2 as id from user_connection where user_id1=(select id from user where profileName=?)) t GROUP BY id)' ;
  db.query(findFriendsQuery,[userName],function(err,rows,fields){
    if(err){
     console.log(err);
     callback(1,-1,-1);
     }
    else{
        callback(0,rows,1);
        }
    });
};

sqlMessage: '你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 \'?)) t GROUP BY id)\' at line 1', sqlState: '42000', index: 0 附近使用正确的语法

阿里夫汗

您使用了 placeholder( ?) 两次,而只传递一次,您需要传递两次 ( [userName, userName])

exports.findFriends = function(userName,callback){
console.log('searching friends.... '+userName);
var findFriendsQuery = 'select profileName from user where (id) in ( select id FROM ( SELECT user_id1 as id from user_connection where user_id2=(select id from user where profileName= ? ) UNION ALL SELECT user_id2 as id from user_connection where user_id1=(select id from user where profileName=?)) t GROUP BY id)' ;
  db.query(findFriendsQuery,[userName, userName],function(err,rows,fields){
    if(err){
     console.log(err);
     callback(1,-1,-1);
     }
    else{
        callback(0,rows,1);
        }
    });
};

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

SQL查询适用于SQL Server,但不适用于MySQL

来自分类Dev

查询适用于mysql,但不适用于php sql调用

来自分类Dev

唯一不适用于Node.js Sails.js“ sails-mysql”

来自分类Dev

适用于Node.js的MySQL库中的错误

来自分类Dev

适用于Node.js的MySQL库中的错误

来自分类Dev

插入查询不适用于MySQL

来自分类Dev

MySQL查询不适用于PHP

来自分类Dev

sql查询不适用于order by

来自分类Dev

SQL 查询不适用于 RDS

来自分类Dev

Node.js Express渲染不适用于EJS

来自分类Dev

文件下载不适用于Node.js gridfs

来自分类Dev

$lookup 不适用于 Node.js 中的 $match

来自分类Dev

Jade 语法不适用于 pug : Node Js

来自分类Dev

POST 不适用于 Node.JS 和 Express

来自分类Dev

Node.js API-适用于Postman,但不适用于Angular.js

来自分类Dev

查询适用于 Windows 上的 MySQL,但不适用于 Ubuntu 上的 Mysql

来自分类Dev

Google Elevation呼叫适用于浏览器,但不适用于node.js

来自分类Dev

正则表达式适用于浏览器,但不适用于Node.js

来自分类Dev

PHP MYSQL查询不适用于PHP,但适用于PHPMyAdmin

来自分类Dev

适用于MYSQL但不适用于SQLite的查询(语法不同吗?)

来自分类Dev

查询适用于 mysql 但不适用于 java

来自分类Dev

SQL查询中的问题。适用于MAX,但不适用于MIN

来自分类Dev

查询适用于sql studio,但不适用于C#

来自分类Dev

Postgres 查询适用于 SQL 客户端,但不适用于 Hibernate

来自分类Dev

Spark Sql 查询适用于硬编码值但不适用于变量

来自分类Dev

MySQL查询中的单引号不适用于concat()

来自分类Dev

MySQL限制子句不适用于group by查询

来自分类Dev

MySQL查询不适用于Python脚本

来自分类Dev

MySQL插入查询不适用于插入

Related 相关文章

热门标签

归档