Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

pulled/merged latest pekim/tedious master, added test for string guid #55

Closed
wants to merge 5 commits into from

2 participants

Cort Fritz Mike D Pilsbury
Cort Fritz

No description provided.

Cort Fritz and others added some commits
Cort Fritz Update src/guid-parser.coffee
helper to reverse the guid-to-array parsing for use on the way back out
049b39f
Cort Fritz moved guid parsing to buffer reading d687e25
Cort Fritz Merge branch 'master' of https://github.com/pekim/tedious
..to ensure I have latest.
4e815b8
Cort Fritz converted test to check for string guid on way out d90ccd7
Mike D Pilsbury
Owner

Microsoft documentation shows uniqueidentifiers with uppercase hex digits. I think that it would be better if the guid were exposed similarly formatted. Is that reasonable or not? I'm undecided.

Three integration tests fail, because they have not yet been updated.
To run all tests, including the integration tests, the scripts/tests-all script can be used.

The integration tests expect a file like this at $HOME/.tedious/test-connection.json .

{
  "config": {
    "server": "192.168.1.212",
    "userName": "test",
    "password": "test",
    "options": {
      "port": 1433,
      "connectTimeout": 1000,
      "database": "test"
    }
  }
}
Cort Fritz
Cort Fritz cortfritz closed this
Cort Fritz

submitting new pull request with full integration tests working

Cort Fritz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 1, 2012
  1. Update src/guid-parser.coffee

    Cort Fritz authored
    helper to reverse the guid-to-array parsing for use on the way back out
Commits on Oct 26, 2012
  1. moved guid parsing to buffer reading

    Cort Fritz authored
Commits on Oct 29, 2012
  1. Merge branch 'master' of https://github.com/pekim/tedious

    Cort Fritz authored
    ..to ensure I have latest.
  2. converted test to check for string guid on way out

    Cort Fritz authored
Commits on Oct 30, 2012
  1. fixed integration tests

    Cort Fritz authored
This page is out of date. Refresh to see the latest.
33 src/guid-parser.coffee
View
@@ -21,4 +21,35 @@ guidToArray = (guid) ->
final = [b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16]
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  src/value-parser.coffee
View
@@ -1,5 +1,6 @@
iconv = require('iconv-lite')
sprintf = require('sprintf').sprintf
+guidParser = require('./guid-parser')
require('./buffertools')
NULL = (1 << 16) - 1
@@ -176,7 +177,7 @@ parse = (buffer, metaData) ->
when 0
value = null
when 0x10
- value = buffer.readArray(0x10)
+ value = guidParser.arrayToGuid( buffer.readArray(0x10) )
else
throw new Error(sprintf('Unsupported guid size %d at offset 0x%04X', dataLength - 1, buffer.position))
else
13 test-connection.json
View
@@ -0,0 +1,13 @@
+{
+ "config": {
+ "server": "pzkhzqgfrs.database.windows.net",
+ "userName": "API@pzkhzqgfrs.database.windows.net",
+ "password": "MDMC@A@pi!007",
+ "options": {
+ "database": "MDM",
+ "encrypt": true,
+ "port": 1433,
+ "connectTimeout": 1000
+ }
+ }
+}
6 test/integration/datatypes-in-results-test.coffee
View
@@ -212,10 +212,8 @@ exports.imageNull = (test) ->
execSql(test, "select cast(null as image)", 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
- ])
+ execSql(test, "select cast('01234567-89AB-CDEF-0123-456789ABCDEF' as uniqueidentifier)", '01234567-89AB-CDEF-0123-456789ABCDEF')
+
exports.guidNull = (test) ->
execSql(test, "select cast(null as uniqueidentifier)", null)
5 test/integration/parameterised-statements-test.coffee
View
@@ -249,7 +249,7 @@ execSql = (test, type, value) ->
else if (type == TYPES.BigInt)
test.strictEqual(columns[0].value, value.toString())
else if (type == TYPES.UniqueIdentifierN)
- test.deepEqual(columns[0].value, guidParser.guidToArray(value))
+ test.deepEqual(columns[0].value, value)
else
test.strictEqual(columns[0].value, value)
)
@@ -299,7 +299,8 @@ execSqlOutput = (test, type, value) ->
else if (type == TYPES.BigInt)
test.strictEqual(returnValue, value.toString())
else if (type == TYPES.UniqueIdentifierN)
- test.deepEqual(returnValue, guidParser.guidToArray(value))
+
+ test.deepEqual(returnValue, value)
else
test.strictEqual(returnValue, value)
6 test/unit/token/row-token-parser-test.coffee
View
@@ -441,14 +441,14 @@ module.exports.guidN = (test) ->
0,
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)
- #console.log(token)
+ # 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.deepEqual('67452301-AB89-EFCD-0123-456789ABCDEF', token.columns[1].value)
test.done()
13 tests-connection.json
View
@@ -0,0 +1,13 @@
+{
+ "config": {
+ "server": "pzkhzqgfrs.database.windows.net",
+ "userName": "API@pzkhzqgfrs.database.windows.net",
+ "password": "MDMC@A@pi!007",
+ "options": {
+ "database": "MDM",
+ "encrypt": true,
+ "port": 1433,
+ "connectTimeout": 1000
+ }
+ }
+}
Something went wrong with that request. Please try again.