开发者

node.js and mysql

result = db.query("SELECT user_id "+
  "FROM friends "+
  "WHERE user_id IN "+
    "(SELECT to_id FROM friends WHERE user_id = " + client.user_id + ") "+
    "AND to_id = " + client.user_id);

client.user_id is 1. checked and confirmed.

This statement has some issues with it. I have a console.log("a") after this line and it wont execute, but if i put a console.log("b"), it is executed.

just running the resulting sql query ie

SELECT user_id 
FROM friends 
WHERE user_id IN (SELECT to_id FROM friends WHERE user_id = 1) 
  AND to_id = 1

returns one row with user_id = 2

a separate node.js program with the query

SELECT user_id 
FROM friends 开发者_JAVA百科
WHERE user_id IN (SELECT to_id FROM friends WHERE user_id = 1) 
  AND to_id = 1

works just fine. which leads me to believe that it probably has to do smthng with client.user_id

any ideas?

UPDATE:

A test with client = {user_id: 1}

and the original query in a separate program is working...

Edit: the fundtion where this query is being used.

function subscribe_to_friends(client) {
result = db.query("select user_id from friends where user_id IN (select to_id from friends where user_id = " + client.user_id + ") and to_id = " + client.user_id);
}

and the function calling this

client.on('message', function(msg) {
    if(client.user_id == null) {
        client.user_id = msg.user_id
        subscribe_to_friends(client);
        clients.push(client);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜