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

completed updating integration tests to test uniqueidentifierN / guid #56

Closed
wants to merge 6 commits into from
Closed
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
33 changes: 32 additions & 1 deletion src/guid-parser.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,4 +21,35 @@ guidToArray = (guid) ->
final = [b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16] final = [b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16]


final final
exports.guidToArray = guidToArray exports.guidToArray = guidToArray

formatHex = (number) ->
hex = number.toString(16)
if hex.length == 1
hex = '0' + hex
return hex

arrayToGuid = (array) ->
guid = formatHex(array[3]) +
formatHex(array[2]) +
formatHex(array[1]) +
formatHex(array[0]) +
'-' +
formatHex(array[5]) +
formatHex(array[4]) +
'-' +
formatHex(array[7]) +
formatHex(array[6]) +
'-' +
formatHex(array[8]) +
formatHex(array[9]) +
'-' +
formatHex(array[10]) +
formatHex(array[11]) +
formatHex(array[12]) +
formatHex(array[13]) +
formatHex(array[14]) +
formatHex(array[15])
guid.toUpperCase()

exports.arrayToGuid = arrayToGuid
3 changes: 2 additions & 1 deletion src/value-parser.coffee
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
iconv = require('iconv-lite') iconv = require('iconv-lite')
sprintf = require('sprintf').sprintf sprintf = require('sprintf').sprintf
guidParser = require('./guid-parser')
require('./buffertools') require('./buffertools')


NULL = (1 << 16) - 1 NULL = (1 << 16) - 1
Expand Down Expand Up @@ -176,7 +177,7 @@ parse = (buffer, metaData) ->
when 0 when 0
value = null value = null
when 0x10 when 0x10
value = buffer.readArray(0x10) value = guidParser.arrayToGuid( buffer.readArray(0x10) )
else else
throw new Error(sprintf('Unsupported guid size %d at offset 0x%04X', dataLength - 1, buffer.position)) throw new Error(sprintf('Unsupported guid size %d at offset 0x%04X', dataLength - 1, buffer.position))
else else
Expand Down
6 changes: 2 additions & 4 deletions test/integration/datatypes-in-results-test.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ exports.imageNull = (test) ->
execSql(test, "select cast(null as image)", null) execSql(test, "select cast(null as image)", null)


exports.guid = (test) -> exports.guid = (test) ->
execSql(test, "select cast('01234567-89AB-CDEF-0123-456789ABCDEF' as uniqueidentifier)", [ execSql(test, "select cast('01234567-89AB-CDEF-0123-456789ABCDEF' as uniqueidentifier)", '01234567-89AB-CDEF-0123-456789ABCDEF')
0x67, 0x45, 0x23, 0x01, 0xAB, 0x89, 0xEF, 0xCD,
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF
])


exports.guidNull = (test) -> exports.guidNull = (test) ->
execSql(test, "select cast(null as uniqueidentifier)", null) execSql(test, "select cast(null as uniqueidentifier)", null)
Expand Down
5 changes: 3 additions & 2 deletions test/integration/parameterised-statements-test.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ execSql = (test, type, value) ->
else if (type == TYPES.BigInt) else if (type == TYPES.BigInt)
test.strictEqual(columns[0].value, value.toString()) test.strictEqual(columns[0].value, value.toString())
else if (type == TYPES.UniqueIdentifierN) else if (type == TYPES.UniqueIdentifierN)
test.deepEqual(columns[0].value, guidParser.guidToArray(value)) test.deepEqual(columns[0].value, value)
else else
test.strictEqual(columns[0].value, value) test.strictEqual(columns[0].value, value)
) )
Expand Down Expand Up @@ -299,7 +299,8 @@ execSqlOutput = (test, type, value) ->
else if (type == TYPES.BigInt) else if (type == TYPES.BigInt)
test.strictEqual(returnValue, value.toString()) test.strictEqual(returnValue, value.toString())
else if (type == TYPES.UniqueIdentifierN) else if (type == TYPES.UniqueIdentifierN)
test.deepEqual(returnValue, guidParser.guidToArray(value))
test.deepEqual(returnValue, value)
else else
test.strictEqual(returnValue, value) test.strictEqual(returnValue, value)


Expand Down
6 changes: 3 additions & 3 deletions test/unit/token/row-token-parser-test.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ module.exports.guidN = (test) ->
0, 0,
16, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef 16, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
])) ]))
#console.log(buffer.data) # console.log(buffer.data)


token = parser(new ReadableTrackingBuffer(buffer.data, 'ucs2'), colMetaData) token = parser(new ReadableTrackingBuffer(buffer.data, 'ucs2'), colMetaData)
#console.log(token) # console.log(token)


test.strictEqual(token.columns.length, 2) test.strictEqual(token.columns.length, 2)
test.strictEqual(token.columns[0].value, null) 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.deepEqual('67452301-AB89-EFCD-0123-456789ABCDEF', token.columns[1].value)


test.done() test.done()


Expand Down