Tag: null

无法使用节点将空值发送到MySQL数据库

我试图发送null到我的MySQL数据库使用node.js: con.query("INSERT INTO Routes (routeTrigger) VALUES ( " + null + " )", {title: 'test'}, function(err, result) { if (err) throw err; }); 但是在数据库中查看时,更新后的值为“null”。 数据库null应该读取“ NULL ”。 如果我发送资金NULL,而不是工作(在节点)。 如果我发送“NULL”它发送string“NULL”,而不是数据库null。

使用包含空字节的string创build奇怪的Date()

我知道JavaScript不会终止像C或C ++这样的string,但我遇到了一个我无法解释的情况。 看下面的代码(在Node.js v0.10.5中执行): > new Date('123') Fri Jan 01 123 00:00:00 GMT+0100 (CET) // UNIX epoch : -58285702800000 > new Date('123\056') Fri Jan 01 123 00:00:00 GMT+0100 (CET) // UNIX epoch : -58285702800000 > new Date('123\0456') Tue Jun 01 123 00:00:00 GMT+0200 (CEST) // UNIX epoch : -58272660000000 > new Date('123\0567') Thu Jul 01 […]

当string可能为空时,确定节点JS中的string长度

我正在尝试学习Node,并具有以下function: this.logMeIn = function(username,stream) { if (username === null || username.length() < 1) { stream.write("Invalid username, please try again:\n\r"); return false; } else { ….etc 我正在通过它 if (!client.loggedIn) { if (client.logMeIn(String(data.match(/\S+/)),stream)) { 我已经尝试了==和===,但我仍然收到错误,因为用户名未检测到它为空,并且username.length()失败: if (username === null || username.length() < 1) { ^ TypeError: Property 'length' of object null is not a function 我确信Node不会评估||的第二部分 在if语句中,当第一部分是真实的 […]

检查节点中的错误参数

在asynchronous操作中传递一个错误参数是节点中的约定: async.someMagicalDust(function(callback) { // some asynchronous task // […] callback(); }, function(err) { // final callback if(err) throw err; // […] }); 也许我太天真了,但是我从来没有对if(variable)符号的大爱好者 – 可能从Cinheritance,因为过去已经讨论过很多次了 。 另一方面,我有时遇到一个null参数,这个错误检查: if(typeof err !== 'undefined' && err !== null) 有点太冗长了。 另一个解决scheme是 if(err != null) 但我认为非严格的检查可能会非常棘手,即使我认为与空比较是正常的。 检查节点中错误参数的最佳方法是什么?