Permalink
Browse files

Don't make column value or metadata available by column name when the…

… name is numeric.

issue #66
  • Loading branch information...
1 parent 7bb98fb commit d6a61edad4157677db8ad8e842d56da33f3b6626 @pekim pekim committed Dec 30, 2012
@@ -2,6 +2,8 @@
metadataParse = require('../metadata-parser')
+DIGITS_REGEX = /^\d+$/
+
parser = (buffer, colMetadata, tdsVersion) ->
columnCount = buffer.readUInt16LE()
@@ -30,7 +32,9 @@ parser = (buffer, colMetadata, tdsVersion) ->
tableName: tableName
columns.push(column)
- columns[column.colName] = column
+
+ if !(DIGITS_REGEX.test(column.colName))
+ columns[column.colName] = column
# Return token
name: 'COLMETADATA'
@@ -3,6 +3,8 @@
valueParse = require('../value-parser')
sprintf = require('sprintf').sprintf
+DIGITS_REGEX = /^\d+$/
+
parser = (buffer, columnsMetaData) ->
columns = []
for columnMetaData in columnsMetaData
@@ -15,7 +17,9 @@ parser = (buffer, columnsMetaData) ->
metadata: columnMetaData
columns.push(column)
- columns[columnMetaData.colName] = column
+
+ if !(DIGITS_REGEX.test(columnMetaData.colName))
+ columns[columnMetaData.colName] = column
# Return token
name: 'ROW'
@@ -234,6 +234,45 @@ exports.execSql = (test) ->
#console.log(text)
)
+exports.numericColumnName = (test) ->
+ test.expect(5)
+
+ config = getConfig()
+
+ request = new Request('select 8 as [123]', (err, rowCount) ->
+ test.ok(!err)
+ test.strictEqual(rowCount, 1)
+
+ connection.close()
+ )
+
+ request.on('columnMetadata', (columnsMetadata) ->
+ test.strictEqual(columnsMetadata.length, 1)
+ )
+
+ request.on('row', (columns) ->
+ test.strictEqual(columns.length, 1)
+ test.strictEqual(columns[0].value, 8)
+ )
+
+ connection = new Connection(config)
+
+ connection.on('connect', (err) ->
+ connection.execSql(request)
+ )
+
+ connection.on('end', (info) ->
+ test.done()
+ )
+
+ connection.on('infoMessage', (info) ->
+ #console.log("#{info.number} : #{info.message}")
+ )
+
+ connection.on('debug', (text) ->
+ #console.log(text)
+ )
+
exports.execSqlMultipleTimes = (test) ->
timesToExec = 5
sqlExecCount = 0

0 comments on commit d6a61ed

Please sign in to comment.