IBM / nodejs-idb-connector

A JavaScript (Node.js) library for communicating with Db2 for IBM i, with support for queries, procedures, and much more. Uses traditional callback-style syntax
MIT License
38 stars 23 forks source link

feat: Have dbconn.close() disconnect if connected #106

Closed abmusse closed 4 years ago

abmusse commented 4 years ago

Currently to close the connection we need to run [dbconn.disconn]() before running [dbconn.close]().

Calling dbconn.close without calling dbconn.disconn leads to the following error:

> const { dbconn } = require('idb-connector')
undefined
> const connection = new dbconn()
undefined
> connection.conn('*LOCAL')
undefined
> connection.close()
Thrown:
Error: SQLSTATE=PAERR SQLCODE=-1 SQLFreeConnect Failed

I propose we add check within dbconn.close if its connected then disconnect.

> const { dbconn } = require('./lib/binding/Release/napi3-ibmi-ppc64/db2ia')
undefined
> const connection = new dbconn()
undefined
> connection.debug(true)
true
> connection.conn('*LOCAL')
SQLConnect(0): conn obj [1805d4b70] handler [2]
undefined
> connection.close()
SQLDisconnect: conn obj [1805d4b70] handler [2]
SQLFreeConnect: conn obj [1805d4b70] handler [2]
SQLFreeConnect[0]
true