我想知道如何使用节点js进行对照,其中mysql选择请求为null,空集或其中有东西。
我有:
function checkKey(key, cb) {
var activated = "";
var sqlcheck = "SELECT activated from authentification where discord_key = ?";
console.log("in function");
DB.query(sqlcheck, [key], function (err, result) {
if (err) throw (err);
if (result[0] && result[0].activated) {
activated = result[0].activated;
console.log("filled key");
} else {
activated = false;
console.log("empty key");
}
cb(activatedkey(activated));
//return (activatedkey(activated));
})
}
这样,我只会空虚,无效或其中的东西。我正在寻找一种使空,无效或其中的东西的方法。
非常感谢您的帮助
您可以将第二行放入您的 authentification 表中,并最多可能钥匙。因此,您都可以用一个或OR行,按键订购限制限制1。
SELECT activated
FROM authentification
WHERE discord_key = 123456
OR discord_key = 9999999
ORDER BY discord_key LIMIT 1;
示例
MariaDB [test_arduino]> SELECT * FROM authentification;
+----+-----------+-------------+
| id | activated | discord_key |
+----+-----------+-------------+
| 1 | 1 | 12345 |
| 2 | EMPTY | 9999999 |
+----+-----------+-------------+
2 rows in set (0.001 sec)
MariaDB []> SELECT activated
-> FROM authentification
-> WHERE discord_key = 12345
-> OR discord_key = 9999999
-> ORDER BY discord_key LIMIT 1;
+-----------+
| activated |
+-----------+
| 1 |
+-----------+
1 row in set (0.001 sec)
MariaDB []> SELECT activated
-> FROM authentification
-> WHERE discord_key = 123456
-> OR discord_key = 9999999
-> ORDER BY discord_key LIMIT 1;
+-----------+
| activated |
+-----------+
| EMPTY |
+-----------+
1 row in set (0.001 sec)
MariaDB []>