我想知道如何使用 Node JS 获取条件,其中 mysql Select 请求为 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));
})
}
有了这个,我只能得到 Empty 和 Null 或者其中的东西。 我正在寻找一种方法来获取 EMPTY 或 NULL 或其中的某些内容。
非常感谢您的帮助
最佳答案
您可以在身份验证表中放入第二行,其中最多可能有 key 。因此,您可以使用 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 []>
关于mysql - 查看 mysql 请求是否为 Null、Empty set 或其中包含内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54754432/