这个逻辑有什么问题?
var selectString = 'SELECT EXISTS(SELECT 1 FROM users WHERE user="'+username+'")';
var queryUserExists = connection.query(selectString);
var resultsLength = queryUserExists._results.length;
console.log(queryUserExists);
if(resultsLength > 0){
socket.write("fail user already exists"+"\r\n");
} else {
console.log('insert=');
var query = connection.query (
'INSERT INTO users '+
'SET user = ?, password = ?, token = ?',
[username, password, token]
);
socket.write("success"+"\r\n");
}
resultsLength 始终返回零。使用此查询的正确方法是什么?
返回对象:
sql: 'SELECT 1 FROM users WHERE user = \'a new user is my name\' ORDER BY user LIMIT 1',
typeCast: true,
nestTables: false,
_resultSet: null,
_results: [],
_fields: [],
_index: 0,
_loadError: null }