Browse files

Merge branch 'pr/70'

  • Loading branch information...
2 parents 2705cd7 + 9e6941a commit e1135836b84700a68c4ccbd740a6ea0e116223de @pekim pekim committed Feb 3, 2013
Showing with 84 additions and 29 deletions.
  1. +38 −29 src/token/row-token-parser.coffee
  2. +46 −0 test/integration/connection-test.coffee
View
67 src/token/row-token-parser.coffee
@@ -1,29 +1,38 @@
-# s2.2.7.17
-
-valueParse = require('../value-parser')
-sprintf = require('sprintf').sprintf
-
-DIGITS_REGEX = /^\d+$/
-
-parser = (buffer, columnsMetaData) ->
- columns = []
- for columnMetaData in columnsMetaData
- #console.log sprintf('Token @ 0x%02X', buffer.position)
-
- value = valueParse(buffer, columnMetaData)
-
- column =
- value: value
- metadata: columnMetaData
-
- columns.push(column)
-
- if !(DIGITS_REGEX.test(columnMetaData.colName))
- columns[columnMetaData.colName] = column
-
- # Return token
- name: 'ROW'
- event: 'row'
- columns: columns
-
-module.exports = parser
+# s2.2.7.17
+
+valueParse = require('../value-parser')
+sprintf = require('sprintf').sprintf
+
+DIGITS_REGEX = /^\d+$/
+
+parser = (buffer, columnsMetaData) ->
+ columns = []
+ for columnMetaData in columnsMetaData
+ #console.log sprintf('Token @ 0x%02X', buffer.position)
+
+ value = valueParse(buffer, columnMetaData)
+
+ column =
+ value: value
+ metadata: columnMetaData
+
+ columns.push(column)
+
+ if !(DIGITS_REGEX.test(columnMetaData.colName))
+ saveColumn(columnMetaData.colName, columns, column)
+
+ # Return token
+ name: 'ROW'
+ event: 'row'
+ columns: columns
+
+saveColumn = (columnName, columns, value) ->
+ entry = columns[columnName]
+ if !entry
+ columns[columnName] = value;
+ else if Array.isArray(entry)
+ entry.push(value)
+ else
+ columns[columnName] = [entry, value]
+
+module.exports = parser
View
46 test/integration/connection-test.coffee
@@ -273,6 +273,52 @@ exports.numericColumnName = (test) ->
#console.log(text)
)
+exports.duplicateColumnNames = (test) ->
+ test.expect(10)
+
+ config = getConfig()
+
+ request = new Request('select 1 as abc, 2 as xyz, 3 as abc', (err, rowCount) ->
+ test.ok(!err)
+ test.strictEqual(rowCount, 1)
+
+ connection.close()
+ )
+
+ request.on('columnMetadata', (columnsMetadata) ->
+ test.strictEqual(columnsMetadata.length, 3)
+ )
+
+ request.on('row', (columns) ->
+ test.strictEqual(columns.length, 3)
+
+ test.strictEqual(columns[0].value, 1)
+ test.strictEqual(columns[1].value, 2)
+ test.strictEqual(columns[2].value, 3)
+
+ test.strictEqual(columns.abc[0].value, 1)
+ test.strictEqual(columns.abc[1].value, 3)
+ test.strictEqual(columns.xyz.value, 2)
+ )
+
+ 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 e113583

Please sign in to comment.