Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for BINTEXT and BOOLEAN #254

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/protocol/Reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ Reader.prototype.readAlphanum = function readAlphanum() {
return this.readBytes(false, true);
}

Reader.prototype.readBoolean = function readBoolean() {
var value = this.buffer[this.offset++];
switch (value) {
case 0x02:
return true;
case 0x01:
return null;
default:
return false;
}
}

Reader.LobDescriptor = LobDescriptor;

function LobDescriptor(type, options, charLength, byteLength, locatorId, chunk, defaultType) {
Expand Down
1 change: 1 addition & 0 deletions lib/protocol/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ function isLob(column) {
case TypeCode.NCLOB:
case TypeCode.NLOCATOR:
case TypeCode.TEXT:
case TypeCode.BINTEXT:
return true;
default:
return false;
Expand Down
1 change: 1 addition & 0 deletions lib/protocol/ResultSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ function isLob(column) {
case TypeCode.NCLOB:
case TypeCode.NLOCATOR:
case TypeCode.TEXT:
case TypeCode.BINTEXT:
return true;
default:
return false;
Expand Down
32 changes: 32 additions & 0 deletions lib/protocol/Writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ Writer.prototype[TypeCode.BLOB] = function writeBLob(value) {
var buffer = new Buffer(10);
buffer.fill(0x00);
buffer[0] = TypeCode.BLOB;
if (util.isString(value)) {
value = util.convert.encode(value, this._useCesu8);
}
this.pushLob(buffer, value);
};

Expand Down Expand Up @@ -772,6 +775,35 @@ Writer.prototype[TypeCode.ST_GEOMETRY] = function writeST_GEOMETRY(value) {
}
}

Writer.prototype[TypeCode.BOOLEAN] = function writeBoolean(value) {
var buffer = new Buffer(2);
buffer[0] = TypeCode.BOOLEAN;
// 0x02 - True, 0x01 - Null, 0x00 - False
if (value === null) {
buffer[1] = 0x01;
} else if (util.isString(value)) {
if (value.toUpperCase() === 'TRUE' || value === '1') {
buffer[1] = 0x02;
} else if (value.toUpperCase() === 'FALSE' || value === '0') {
buffer[1] = 0x00;
} else if (value.toUpperCase() === 'UNKNOWN' || value.length === 0) {
buffer[1] = 0x01;
} else {
throw createInputError('BOOLEAN');
}
} else if (util.isNumber(value)) {
buffer[1] = value == 0 ? 0x00 : 0x02;
} else if (value === true) {
buffer[1] = 0x02;
} else if (value === false) {
buffer[1] = 0x00;
} else {
throw createInputError('BOOLEAN');
}

this.push(buffer);
}

function setChar(str, i, c) {
if(i >= str.length) return str;
return str.substring(0, i) + c + str.substring(i + 1);
Expand Down
4 changes: 3 additions & 1 deletion lib/protocol/common/DataFormatVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module.exports = {
EXTENDED_DATE_TIME_SUPPORT: 3,
LEVEL4: 4,
LEVEL5: 5,
LEVEL6: 6,
LEVEL7: 7,
// Maximum data format version supported by this driver
MAX_VERSION: 5,
MAX_VERSION: 7,
};
6 changes: 5 additions & 1 deletion lib/protocol/common/NormalizedTypeCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ NormalizedTypeCode[TypeCode.VARBINARY] = TypeCode.BINARY;
NormalizedTypeCode[TypeCode.BSTRING] = TypeCode.BINARY;
// BLob
NormalizedTypeCode[TypeCode.BLOB] = TypeCode.BLOB;
NormalizedTypeCode[TypeCode.LOCATOR] = TypeCode.BLOB;
// Clob
NormalizedTypeCode[TypeCode.CLOB] = TypeCode.CLOB;
// NCLob
NormalizedTypeCode[TypeCode.NCLOB] = TypeCode.NCLOB;
NormalizedTypeCode[TypeCode.NLOCATOR] = TypeCode.NCLOB;
NormalizedTypeCode[TypeCode.TEXT] = TypeCode.NCLOB;
NormalizedTypeCode[TypeCode.LOCATOR] = TypeCode.NCLOB;
// HANA sends back LOCATOR as input for BINTEXT, so this is not strictly necessary
NormalizedTypeCode[TypeCode.BINTEXT] = TypeCode.NCLOB;
// Date
NormalizedTypeCode[TypeCode.DATE] = TypeCode.DATE;
// Time
Expand All @@ -71,3 +73,5 @@ NormalizedTypeCode[TypeCode.SECONDDATE] = TypeCode.SECONDDATE;
// ST_GEOMETRY
NormalizedTypeCode[TypeCode.ST_GEOMETRY] = TypeCode.ST_GEOMETRY;
NormalizedTypeCode[TypeCode.ST_POINT] = TypeCode.ST_GEOMETRY;
// Boolean
NormalizedTypeCode[TypeCode.BOOLEAN] = TypeCode.BOOLEAN;
3 changes: 3 additions & 0 deletions lib/protocol/common/ReadFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var READ_DOUBLE = 'readDouble';
var READ_FLOAT = 'readFloat';
var READ_DECIMAL = 'readDecimal';
var READ_ALPHANUM = 'readAlphanum';
var READ_BOOLEAN = 'readBoolean';

ReadFunction[TypeCode.TINYINT] = READ_TINYINT;
ReadFunction[TypeCode.SMALLINT] = READ_SMALLINT;
Expand Down Expand Up @@ -67,8 +68,10 @@ ReadFunction[TypeCode.CLOB] = READ_CLOB;
ReadFunction[TypeCode.NCLOB] = READ_NCLOB;
ReadFunction[TypeCode.NLOCATOR] = READ_NCLOB;
ReadFunction[TypeCode.TEXT] = READ_NCLOB;
ReadFunction[TypeCode.BINTEXT] = READ_NCLOB;
ReadFunction[TypeCode.DOUBLE] = READ_DOUBLE;
ReadFunction[TypeCode.REAL] = READ_FLOAT;
ReadFunction[TypeCode.DECIMAL] = READ_DECIMAL;
ReadFunction[TypeCode.ST_GEOMETRY] = READ_BINARY;
ReadFunction[TypeCode.ST_POINT] = READ_BINARY;
ReadFunction[TypeCode.BOOLEAN] = READ_BOOLEAN;
2 changes: 1 addition & 1 deletion lib/protocol/common/TypeCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {
UNUSED12: 50,
TEXT: 51,
SHORTTEXT: 52,
UNUSED15: 53,
BINTEXT: 53,
UNUSED16: 54,
ALPHANUM: 55,
UNUSED18: 56,
Expand Down
2 changes: 2 additions & 0 deletions lib/protocol/part/ConnectOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function ConnectOptions() {
// Support for ALPHANUM, TEXT, SHORTTEXT, LONGDATE, SECONDDATE,
// DAYDATE, and SECONDTIME.
// * `5` Support for ST_GEOMETRY and ST_POINT
// * `6` Specifies to send the data type BINTEXT to the client
// * `7` Support for BOOLEAN
// TODO: Once implementation and testing for data format version 4 are
// complete, replace dataFormatVersion and dataFormatVersion2 with the
// commented-out lines.
Expand Down
Loading