Skip to content

Commit

Permalink
Support varchar(max) request parameters.
Browse files Browse the repository at this point in the history
issue #32
  • Loading branch information
pekim committed May 27, 2012
1 parent e4c388a commit c03c5ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/data-type.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,46 @@ TYPE =
dataLengthLength: 2
maximumLength: 8000
declaration: (parameter) ->
"varchar(#{@.maximumLength})"
if parameter.length
length = parameter.length
else if parameter.value
length = parameter.value.length
else
length = @.maximumLength

if length <= @maximumLength
"varchar(#{@.maximumLength})"
else
"varchar(max)"
writeParameterData: (buffer, parameter) ->
if parameter.length
length = parameter.length
else if parameter.value
length = parameter.value.length
else length = @.maximumLength
else
length = @.maximumLength

# ParamMetaData (TYPE_INFO)
buffer.writeUInt8(@.id)
buffer.writeUInt16LE(length)
if length <= @maximumLength
buffer.writeUInt16LE(length)
else
buffer.writeUInt16LE(MAX)
buffer.writeBuffer(new Buffer([0x00, 0x00, 0x00, 0x00, 0x00]))

# ParamLenData
if parameter.value
buffer.writeUInt16LE(length)
buffer.writeString(parameter.value, 'ascii')
if length <= @maximumLength
buffer.writeUInt16LE(length)
buffer.writeString(parameter.value, 'ascii')
else
# Length of all chunks.
buffer.writeUInt64LE(length)
# One chunk.
buffer.writeUInt32LE(length)
buffer.writeString(parameter.value, 'ascii')
# PLP_TERMINATOR (no more chunks).
buffer.writeUInt32LE(0)
else
buffer.writeUInt16LE(NULL)
0xAD:
Expand Down
7 changes: 7 additions & 0 deletions test/integration/parameterised-statements-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ exports.varChar = (test) ->
exports.varCharNull = (test) ->
execSql(test, TYPES.VarChar, null)

exports.varCharMax = (test) ->
longString = ''
for i in [1..(10 * 1000)]
longString += 'x'

execSql(test, TYPES.VarChar, longString)

exports.nVarChar = (test) ->
execSql(test, TYPES.NVarChar, 'qaz')

Expand Down

0 comments on commit c03c5ac

Please sign in to comment.