mssql
Advanced tools
Comparing version 7.1.3 to 7.2.0
@@ -0,1 +1,7 @@ | ||
v7.2.0 (2021-07-29) | ||
------------------- | ||
[new] Update Geography field parsing to provide lat/lng props from Geography Point ((#1282)[https://github.com/tediousjs/node-mssql/pull/1282]) | ||
[fix] Handle errors when adding rows to bulk operations ((#1264)[https://github.com/tediousjs/node-mssql/pull/1264]) | ||
[fix] Input/Output parameter passing fix for msnodesqlv8 driver ((#1275)[https://github.com/tediousjs/node-mssql/pull/1275]) | ||
v7.1.3 (2021-06-11) | ||
@@ -2,0 +8,0 @@ ------------------- |
@@ -0,0 +0,0 @@ 'use strict' |
@@ -0,0 +0,0 @@ 'use strict' |
@@ -361,3 +361,3 @@ 'use strict' | ||
const param = this.parameters[name] | ||
if (param.io === 1) { | ||
if (param.io === 1 || (param.io === 2 && param.value)) { | ||
params.push(castParameter(param.value, param.type, param)) | ||
@@ -637,3 +637,15 @@ } | ||
let cmd = `declare ${['@___return___ int'].concat(params).join(', ')};` | ||
// set output params w/ values | ||
const sets = [] | ||
for (const name in this.parameters) { | ||
if (!objectHasProperty(this.parameters, name)) { | ||
continue | ||
} | ||
const param = this.parameters[name] | ||
if (param.io === 2 && param.value) { | ||
sets.push(`set @${param.name}=?`) | ||
} | ||
} | ||
let cmd = `declare ${['@___return___ int'].concat(params).join(', ')};${sets.join(';')};` | ||
cmd += `exec @___return___ = ${procedure} ` | ||
@@ -640,0 +652,0 @@ |
@@ -269,3 +269,11 @@ 'use strict' | ||
this.parent.acquire(this, (err, connection) => { | ||
if (err) return callback(err) | ||
const callbackWithRelease = (err, ...args) => { | ||
try { | ||
this.parent.release(connection) | ||
} catch (e) { | ||
// noop | ||
} | ||
callback(err, ...args) | ||
} | ||
if (err) return callbackWithRelease(err) | ||
@@ -276,4 +284,3 @@ debug('connection(%d): borrowed to request #%d', IDS.get(connection), IDS.get(this)) | ||
debug('request(%d): canceled', IDS.get(this)) | ||
this.parent.release(connection) | ||
return callback(new RequestError('Canceled.', 'ECANCEL')) | ||
return callbackWithRelease(new RequestError('Canceled.', 'ECANCEL')) | ||
} | ||
@@ -312,9 +319,8 @@ | ||
this.parent.release(connection) | ||
hasReturned = true | ||
if (this.stream) { | ||
callback(null, rowCount) | ||
callbackWithRelease(null, rowCount) | ||
} else { | ||
callback(error, rowCount) | ||
callbackWithRelease(error, rowCount) | ||
} | ||
@@ -331,3 +337,7 @@ } | ||
for (const row of table.rows) { | ||
bulk.addRow(row) | ||
try { | ||
bulk.addRow(row) | ||
} catch (e) { | ||
return handleError(true, connection, e) | ||
} | ||
} | ||
@@ -334,0 +344,0 @@ |
@@ -56,4 +56,7 @@ 'use strict' | ||
const parsePoints = (buffer, count) => { | ||
const parsePoints = (buffer, count, isGeometryPoint) => { | ||
// s2.1.5 + s2.1.6 | ||
// The key distinction for parsing is that a GEOGRAPHY POINT is ordered Lat (y) then Long (x), | ||
// while a GEOMETRY POINT is ordered x then y. | ||
// Further, there are additional range constraints on GEOGRAPHY POINT that are useful for testing that the coordinate order has not been flipped, such as that Lat must be in the range [-90, +90]. | ||
@@ -65,8 +68,27 @@ const points = [] | ||
for (let i = 1; i <= count; i++) { | ||
const point = new Point() | ||
points.push(point) | ||
point.x = buffer.readDoubleLE(buffer.position) | ||
point.y = buffer.readDoubleLE(buffer.position + 8) | ||
buffer.position += 16 | ||
if (isGeometryPoint) { | ||
// GEOMETRY POINT (s2.1.6): x then y. | ||
for (let i = 1; i <= count; i++) { | ||
const point = new Point() | ||
points.push(point) | ||
point.x = buffer.readDoubleLE(buffer.position) | ||
point.y = buffer.readDoubleLE(buffer.position + 8) | ||
buffer.position += 16 | ||
} | ||
} else { | ||
// GEOGRAPHY POINT (s2.1.5): Lat (y) then Long (x). | ||
for (let i = 1; i <= count; i++) { | ||
const point = new Point() | ||
points.push(point) | ||
point.lat = buffer.readDoubleLE(buffer.position) | ||
point.lng = buffer.readDoubleLE(buffer.position + 8) | ||
// For backwards compatibility, preserve the coordinate inversion in x and y. | ||
// A future breaking change likely eliminate x and y for geography points in favor of just the lat and lng fields, as they've proven marvelously confusing. | ||
// See discussion at: https://github.com/tediousjs/node-mssql/pull/1282#discussion_r677769531 | ||
point.x = point.lat | ||
point.y = point.lng | ||
buffer.position += 16 | ||
} | ||
} | ||
@@ -187,3 +209,3 @@ | ||
const parseGeography = buffer => { | ||
const parseGeography = (buffer, isUsingGeometryPoints) => { | ||
// s2.1.1 + s.2.1.2 | ||
@@ -233,3 +255,3 @@ | ||
value.points = parsePoints(buffer, numberOfPoints) | ||
value.points = parsePoints(buffer, numberOfPoints, isUsingGeometryPoints) | ||
@@ -296,8 +318,8 @@ if (properties.Z) { | ||
geography (buffer) { | ||
return parseGeography(buffer) | ||
return parseGeography(buffer, /* isUsingGeometryPoints: */false) | ||
}, | ||
geometry (buffer) { | ||
return parseGeography(buffer) | ||
return parseGeography(buffer, /* isUsingGeometryPoints: */true) | ||
} | ||
} |
@@ -0,0 +0,0 @@ MIT License |
@@ -24,3 +24,3 @@ { | ||
], | ||
"version": "7.1.3", | ||
"version": "7.2.0", | ||
"main": "index.js", | ||
@@ -27,0 +27,0 @@ "repository": "github:tediousjs/node-mssql", |
56
test.js
'use strict' | ||
const mssql = require('./') | ||
const [, , max] = process.argv | ||
const sqlConfig = { | ||
password: 'P@ssw0rd', | ||
database: 'test', | ||
password: 'Upper_l0wercase', | ||
database: 'di_production', | ||
stream: false, | ||
// driver: 'msnodesqlv8', | ||
authentication: { | ||
type: 'test', | ||
}, | ||
options: { | ||
@@ -15,34 +16,37 @@ trustServerCertificate: true, | ||
encrypt: true, | ||
abortTransactionOnError: false | ||
abortTransactionOnError: false, | ||
}, | ||
pool: { | ||
max: max ? parseInt(max) : 10, | ||
min: 0 | ||
max: 1, | ||
min: 0, | ||
}, | ||
port: 1433, | ||
user: 'sa', | ||
server: 'localhost' | ||
}; | ||
server: 'localhost', | ||
} | ||
(async () => { | ||
async function main () { | ||
const pool = new mssql.ConnectionPool(sqlConfig) | ||
try { | ||
await pool.connect(); | ||
await pool.connect() | ||
const request = pool.request(); | ||
request.arrayRowMode = true; | ||
request.multiple = true; | ||
const table = new mssql.Table('Sandbox.dbo.BulkTest') | ||
table.create = true | ||
table.columns.add('ABigInt', mssql.BigInt); | ||
table.rows.add(1.2) | ||
const result = await request.batch('SELECT 1;'); | ||
const transaction = new mssql.Transaction(pool); | ||
await transaction.begin(); | ||
Object.entries(result.recordset.columns).forEach(([key, value]) => { | ||
console.log(`Column: ${key}, ${JSON.stringify(value)}`); | ||
}); | ||
} catch (err) { | ||
console.error(err) | ||
try { | ||
const request = new mssql.Request(transaction) | ||
await request.bulk(table) | ||
await transaction.commit(); | ||
} catch (error) { | ||
console.error(error) | ||
await transaction.rollback(); | ||
} finally { | ||
console.log('closing pool') | ||
await pool.close() | ||
console.log('closed') | ||
await pool.close(); | ||
} | ||
})() | ||
} | ||
main().catch(console.error); |
Sorry, the diff of this file is too big to display
258789
2156
37
5029