Skip to content
Browse files

Handle empty values for text/ntext/image distinct from null.

  • Loading branch information...
1 parent 48ea787 commit fd7ead703f488fcee323c9f339a2ac1c730197c9 @pekim committed Feb 17, 2013
Showing with 14 additions and 3 deletions.
  1. +5 −3 src/value-parser.coffee
  2. +9 −0 test/integration/datatypes-in-results-test.coffee
View
8 src/value-parser.coffee
@@ -14,6 +14,7 @@ UNKNOWN_PLP_LEN = new Buffer([0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
parse = (buffer, metaData) ->
value = undefined
dataLength = undefined
+ textPointerNull = undefined
type = metaData.type
@@ -25,6 +26,7 @@ parse = (buffer, metaData) ->
buffer.readBuffer(8)
else
dataLength = 0
+ textPointerNull = true
if !dataLength && dataLength != 0
# s2.2.4.2.1
@@ -125,17 +127,17 @@ parse = (buffer, metaData) ->
else
value = readBinary(buffer, dataLength)
when 'Text'
- if dataLength == 0
+ if textPointerNull
value = null
else
value = readChars(buffer, dataLength, metaData.collation.codepage)
when 'NText'
- if dataLength == 0
+ if textPointerNull
value = null
else
value = readNChars(buffer, dataLength)
when 'Image'
- if dataLength == 0
+ if textPointerNull
value = null
else
value = readBinary(buffer, dataLength)
View
9 test/integration/datatypes-in-results-test.coffee
@@ -120,6 +120,9 @@ exports.moneyNull = (test) ->
exports.varchar = (test) ->
execSql(test, "select cast('abcde' as varchar(10))", 'abcde')
+exports.varcharEmpty = (test) ->
+ execSql(test, "select cast('' as varchar(10))", '')
+
exports.varcharNull = (test) ->
execSql(test, "select cast(null as varchar(10))", null)
@@ -197,12 +200,18 @@ exports.ncharNull = (test) ->
exports.text = (test) ->
execSql(test, "select cast('abc' as text) as text", 'abc')
+exports.textEmpty = (test) ->
+ execSql(test, "select cast('' as text) as text", '')
+
exports.textNull = (test) ->
execSql(test, "select cast(null as text) as text", null)
exports.ntext = (test) ->
execSql(test, "select cast('abc' as ntext) as text", 'abc')
+exports.ntextEmpty = (test) ->
+ execSql(test, "select cast('' as ntext) as text", '')
+
exports.ntextNull = (test) ->
execSql(test, "select cast(null as ntext) as text", null)

0 comments on commit fd7ead7

Please sign in to comment.
Something went wrong with that request. Please try again.