Browse files

add parameterised value support for text

Signed-off-by: Zach Aller <zachaller@hotmail.com>
  • Loading branch information...
1 parent e113583 commit 48ea787a174dfd165de1ab83b65fd86b1916e507 @zachaller zachaller committed Feb 14, 2013
Showing with 38 additions and 2 deletions.
  1. +23 −0 src/data-type.coffee
  2. +15 −2 test/integration/parameterised-statements-test.coffee
View
23 src/data-type.coffee
@@ -201,6 +201,29 @@ TYPE =
hasTableName: true
hasTextPointerAndTimestamp: true
dataLengthLength: 4
+ declaration: (parameter) ->
+ 'text'
+ writeParameterData: (buffer, parameter) ->
+ if parameter.length
+ length = parameter.length
+ else if parameter.value?
+ length = parameter.value.toString().length
+ else
+ length = -1
+
+ # ParamMetaData (TYPE_INFO)
+ buffer.writeUInt8(typeByName.Text.id)
+ buffer.writeInt32LE(length)
+
+ # Collation
+ buffer.writeBuffer(new Buffer([0x00, 0x00, 0x00, 0x00, 0x00]))
+
+ # ParamLenData
+ if parameter.value?
+ buffer.writeInt32LE(length)
+ buffer.writeString(parameter.value.toString(), 'ascii')
+ else
+ buffer.writeInt32LE(length)
0x24:
type: 'GUIDN'
name: 'UniqueIdentifierN'
View
17 test/integration/parameterised-statements-test.coffee
@@ -102,6 +102,20 @@ exports.nVarCharMax = (test) ->
execSql(test, TYPES.NVarChar, longString)
+exports.textNull = (test) ->
+ execSql(test, TYPES.Text, null)
+
+exports.textEmpty = (test) ->
+ execSql(test, TYPES.Text, '')
+
+exports.textSmall = (test) ->
+ execSql(test, TYPES.Text, 'small')
+
+exports.textLarge = (test) ->
+ dBuf = new Buffer(5000000)
+ dBuf.fill('x')
+ execSql(test, TYPES.Text, dBuf.toString())
+
exports.smallDateTime = (test) ->
execSql(test, TYPES.SmallDateTime, new Date('December 4, 2011 10:04:00'))
@@ -299,7 +313,6 @@ execSqlOutput = (test, type, value) ->
else if (type == TYPES.BigInt)
test.strictEqual(returnValue, value.toString())
else if (type == TYPES.UniqueIdentifierN)
-
test.deepEqual(returnValue, value)
else
test.strictEqual(returnValue, value)
@@ -318,5 +331,5 @@ execSqlOutput = (test, type, value) ->
)
connection.on('debug', (text) ->
- #console.log(text)
+ # console.log(text)
)

0 comments on commit 48ea787

Please sign in to comment.