Permalink
Browse files

0 value is not null

empty string is not null
code cleanup
fix #12
  • Loading branch information...
1 parent 041deeb commit 3a50011c89497fe23258837bd1f3e341f0081e17 @hgourvest committed Oct 2, 2012
Showing with 9 additions and 13 deletions.
  1. +6 −6 lib/index.js
  2. +3 −7 lib/serialize.js
View
@@ -748,7 +748,7 @@ function SQLParamDouble(value) {
}
SQLParamDouble.prototype.encode = function(data) {
- if (this.value) {
+ if (this.value != null) {
data.addDouble(this.value);
data.addInt(0);
} else {
@@ -768,7 +768,7 @@ function SQLParamString(value) {
}
SQLParamString.prototype.encode = function(data) {
- if (this.value) {
+ if (this.value != null) {
data.addText(this.value, DEFAULT_ENCODING);
data.addInt(0);
} else {
@@ -789,7 +789,7 @@ function SQLParamQuad(value) {
}
SQLParamQuad.prototype.encode = function(data) {
- if (this.value) {
+ if (this.value != null) {
data.addInt(this.value.low);
data.addInt(this.value.high);
data.addInt(0);
@@ -812,7 +812,7 @@ function SQLParamDate(value) {
}
SQLParamDate.prototype.encode = function(data) {
- if (this.value) {
+ if (this.value != null) {
var value = this.value.getTime() - this.value.getTimezoneOffset() * MsPerMinute;
var time = value % TimeCoeff;
var date = (value - time) / TimeCoeff + DateOffset;
@@ -1638,13 +1638,13 @@ Connection.prototype.executeStatement = function(transaction, statement, params,
var input = statement.input;
if (input.length) {
if (!(params instanceof Array)) {
- if (params != undefined) {
+ if (params !== undefined) {
params = [params];
} else {
params = [];
}
}
- if (!params || params.length != input.length) {
+ if (params === undefined || params.length != input.length) {
throw new Error("expected parametters: " + input.length);
}
params = PrepareParams(params, input);
View
@@ -311,8 +311,6 @@ XdrReader.prototype.readDouble = function () {
XdrReader.prototype.readArray = function () {
var len = this.readInt();
if (len) {
- //var r = new Buffer(len);
- //this.buffer.copy(r, 0, this.pos);
var r = this.buffer.slice(this.pos, this.pos + len);
this.pos += align(len);
return r;
@@ -324,12 +322,8 @@ XdrReader.prototype.readBuffer = function (len) {
len = this.readInt();
}
if (len) {
- //var r = new Buffer(len);
- //this.buffer.copy(r, 0, this.pos);
var r = this.buffer.slice(this.pos, this.pos + len);
this.pos += align(len);
- console.log(r.length);
- console.log(r);
return r;
}
};
@@ -340,9 +334,11 @@ XdrReader.prototype.readString = function (encoding) {
};
XdrReader.prototype.readText = function (len, encoding) {
- if (len) {
+ if (len > 0) {
var r = this.buffer.toString(encoding, this.pos, this.pos + len);
this.pos += align(len);
return r;
+ } else {
+ return '';
}
};

0 comments on commit 3a50011

Please sign in to comment.