Skip to content

Commit

Permalink
Fix type inference of non-integer numbers (tediousjs#475)
Browse files Browse the repository at this point in the history
Also included test against getTypeByValue to simplify future type inference confirmations
  • Loading branch information
ajcrites committed May 17, 2017
1 parent d542c4a commit 2f59a23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ let getTypeByValue = function (value) {
return TYPES.NVarChar

case 'number':
for (item of Array.from(map)) {
if (item.js === Number) {
return item.sql
}
if (value % 1 === 0) {
return TYPES.Int
} else {
return TYPES.Float
}

return TYPES.Int

case 'boolean':
for (item of Array.from(map)) {
if (item.js === Boolean) {
Expand Down Expand Up @@ -1558,7 +1556,8 @@ module.exports = {
ISOLATION_LEVEL,
TYPES,
MAX: 65535, // (1 << 16) - 1
map
map,
getTypeByValue
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/common/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@ describe('Unit', () => {
done()
})
})

it('infer type by value', () => {
assert.strictEqual(sql.Int, sql.getTypeByValue(23))
assert.strictEqual(sql.Float, sql.getTypeByValue(1.23))
})
})

0 comments on commit 2f59a23

Please sign in to comment.