Permalink
Browse files

Add support for UniqueIdentifier (GUID) in result set rows.

Fixes #10
  • Loading branch information...
1 parent b2ac94c commit a7b5a17c27c6fca7b3a85bbaf2c5eef21937f964 @pekim pekim committed Feb 5, 2012
@@ -40,6 +40,10 @@ TYPE =
name: 'BigInt'
# Variable-length types
+ 0x24:
+ type: 'GUIDN'
+ name: 'UniqueIdentifierN'
+ dataLengthLength: 1
0x26:
type: 'INTN'
name: 'IntN'
@@ -99,11 +103,6 @@ TYPE =
###
# Variable-length types
- GUIDTYPE:
- id: 0x24
- variableLength: true
- name: 'UniqueIdentifier'
- dataLengthLength: 1
GUIDTYPE: 0x24 # UniqueIdentifier
DECIMALTYPE: 0x37 # Decimal (legacy support)
NUMERICTYPE: 0x3F # Numeric (legacy support)
@@ -137,6 +137,14 @@ parser = (buffer, columnsMetaData) ->
value *= sign
value /= Math.pow(10, columnMetaData.scale)
+ when 'UniqueIdentifierN'
+ switch dataLength
+ when 0
+ value = null
+ when 0x10
+ value = buffer.readArray(0x10)
+ else
+ throw new Error(sprintf('Unsupported guid size %d at offset 0x%04X', dataLength - 1, buffer.position))
else
throw new Error(sprintf('Unrecognised column type %s at offset 0x%04X', type.name, buffer.position))
break
File renamed without changes.
@@ -133,6 +133,14 @@ exports.nchar = (test) ->
exports.ncharNull = (test) ->
execSql(test, "select cast(null as nchar(5))", null)
+exports.guid = (test) ->
+ execSql(test, "select cast('01234567-89AB-CDEF-0123-456789ABCDEF' as uniqueidentifier)", [
+ 0x67, 0x45, 0x23, 0x01, 0xAB, 0x89, 0xEF, 0xCD,
+ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
+ ])
+
+exports.guidNull = (test) ->
+ execSql(test, "select cast(null as uniqueidentifier)", null)
execSql = (test, sql, expectedValue) ->
test.expect(2)
@@ -339,6 +339,28 @@ module.exports.intN = (test) ->
test.done()
+module.exports.guidN = (test) ->
+ colMetaData = [
+ {type: dataTypeByName.UniqueIdentifierN}
+ {type: dataTypeByName.UniqueIdentifierN}
+ ]
+
+ buffer = new WritableTrackingBuffer(0, 'ucs2')
+ buffer.writeBuffer(new Buffer([
+ 0,
+ 16, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
+ ]))
+ #console.log(buffer.data)
+
+ token = parser(new ReadableTrackingBuffer(buffer.data, 'ucs2'), colMetaData)
+ #console.log(token)
+
+ test.strictEqual(token.columns.length, 2)
+ test.strictEqual(token.columns[0].value, null)
+ test.deepEqual([0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef], token.columns[1].value)
+
+ test.done()
+
module.exports.floatN = (test) ->
colMetaData = [
{type: dataTypeByName.FloatN}

1 comment on commit a7b5a17

Contributor

zachaller commented on a7b5a17 Feb 7, 2012

Just want to say thanks a bunch. we are creating an api for some legacy software doing it in node but need to connect to ms sql and this helps.

Please sign in to comment.