diff --git a/spec/db.spec.js b/spec/db.spec.js index 7931b2b..92260a2 100644 --- a/spec/db.spec.js +++ b/spec/db.spec.js @@ -758,6 +758,20 @@ describe('db', () => { }, 5000); }); }); + + it('should query single result from function', async () => { + const query = dbConn.query('SELECT CURRENT_TIMESTAMP'); + const result = await query.execute(); + expect(result[0].rows[0]).to.be.not.null; + expect(result[0].rowCount).to.eql(1); + let expected; + if (dbClient === 'sqlserver') { + expected = 1; + } else if (dbClient === 'sqlite') { + expected = 0; + } + expect(result[0].affectedRows).to.eql(expected); + }); } describe('.executeQuery', () => { diff --git a/src/db/clients/sqlserver.js b/src/db/clients/sqlserver.js index 82b2a6f..1663c8c 100644 --- a/src/db/clients/sqlserver.js +++ b/src/db/clients/sqlserver.js @@ -89,8 +89,10 @@ export function query(conn, queryText) { queryRequest = request; const result = await promiseQuery; - const data = request.multiple ? result.datasets : result.dataset; - const affectedRows = result.affectedRows.reduce((a, b) => a + b, 0); + const data = request.multiple ? result.recordsets : result.recordset; + const affectedRows = result.rowsAffected ? + result.rowsAffected.reduce((a, b) => a + b, 0) : + undefined; const commands = identifyCommands(queryText).map((item) => item.type);