idb-pconnector
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -223,3 +223,3 @@ const idbp = require('./idb-pconnector'); | ||
connections = me.connections; | ||
try { | ||
@@ -420,11 +420,17 @@ await me.detachAll(); | ||
for ( parameter of params ){ | ||
if (typeof parameter === 'string'){ | ||
if (typeof parameter === 'string'){ //String | ||
boundParams.push([parameter, SQL_PARAM_INPUT_OUTPUT, idbp.SQL_BIND_CHAR]); | ||
} else if (typeof parameter === 'number') { | ||
boundParams.push( [parameter, SQL_PARAM_INPUT_OUTPUT, idbp.SQL_BIND_NUMERIC] ); | ||
} else if (typeof parameter === null) { | ||
} else if (typeof parameter === 'number') { //Number | ||
let indicator; | ||
Number.isInteger(parameter) ? indicator = idbp.SQL_BIND_INT : indicator = idbp.SQL_BIND_NUMERIC; | ||
boundParams.push( [parameter, SQL_PARAM_INPUT_OUTPUT, indicator] ); | ||
} else if (typeof parameter === null) { //Null | ||
boundParams.push([parameter, SQL_PARAM_INPUT_OUTPUT, idbp.SQL_BIND_NULL_DATA]); | ||
} else if (Buffer.isBuffer(parameter)){ //Binary/blob | ||
boundParams.push([parameter, SQL_PARAM_INPUT_OUTPUT, idbp.SQL_BIND_BINARY]); | ||
} else if (typeof parameter === 'boolean'){ //Boolean | ||
boundParams.push([parameter, SQL_PARAM_INPUT_OUTPUT, idbp.SQL_BIND_BOOLEAN]); | ||
} else { | ||
me.log(`Parameter that caused error was ${JSON.stringify(parameter)}`); | ||
throw TypeError('Parameters to bind should be string , number , or null'); | ||
throw TypeError('Parameters to bind should be String, Number, null, or Buffer'); | ||
} | ||
@@ -431,0 +437,0 @@ } |
@@ -84,4 +84,4 @@ const dba = require('idb-connector'); | ||
resolve(dbconn.debug(choice)); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -137,4 +137,4 @@ }); | ||
resolve(dbconn.getConnAttr(attribute)); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -157,4 +157,4 @@ }); | ||
resolve(dbconn.setConnAttr(attribute, value)); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -175,4 +175,4 @@ }); | ||
resolve(dbconn.validStmt(sql)); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -193,3 +193,3 @@ }); | ||
me.dbc = dbconn; | ||
me.stmt = dba.dbstmt(me.dbc); | ||
me.stmt = new dba.dbstmt(me.dbc); | ||
} | ||
@@ -200,3 +200,3 @@ | ||
* @param {Array} params - An Array of the parameter list. Each parameter element will also be an Array with 3 values (Value, In/out Type, Indicator). | ||
* @example bStmt.bindParam([ | ||
* @example dbStmt.bindParam([ | ||
* [2099, dba.SQL_PARAM_INPUT, dba.SQL_BIND_NUMERIC], | ||
@@ -206,10 +206,14 @@ * ['Node.Js', dba.SQL_PARAM_INPUT,dba.SQL_BIND_CHAR] | ||
* IN/OUT TYPE CAN BE: | ||
* 1. SQL_PARAM_INPUT | ||
* 2. SQL_PARAM_OUTPUT | ||
* 3. SQL_PARAM_INPUT_OUTPUT | ||
* - SQL_PARAM_INPUT | ||
* - SQL_PARAM_OUTPUT | ||
* - SQL_PARAM_INPUT_OUTPUT | ||
* INDICATORS CAN BE: | ||
* 1. SQL_BIND_CLOB | ||
* 2. SQL_BIND_CHAR | ||
* 3. SQL_BIND_NUMERIC | ||
* 4. SQL_BIND_NULL_DATA | ||
* - SQL_BIND_CLOB | ||
* - SQL_BIND_CHAR | ||
* - SQL_BIND_INT | ||
* - SQL_BIND_NULL_DATA | ||
* - SQL_BIND_NUMERIC | ||
* - SQL_BIND_BOOLEAN | ||
* - SQL_BIND_BINARY | ||
* - SQL_BIND_BLOB | ||
* @returns {Promise} - Promise object represents the execution of bindParam(). | ||
@@ -555,4 +559,4 @@ * @memberof Statement | ||
resolve(stmt.nextResult()); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -573,4 +577,4 @@ }); | ||
resolve(stmt.numFields()); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -591,4 +595,4 @@ }); | ||
resolve(stmt.numRows()); | ||
} catch (dbError) { | ||
reject(dbError); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
@@ -694,4 +698,8 @@ }); | ||
exports.SQL_BIND_CHAR = 1; | ||
exports.SQL_BIND_NUMERIC = 2; | ||
exports.SQL_BIND_INT = 2; | ||
exports.SQL_BIND_NULL_DATA = 3; | ||
exports.SQL_BIND_NUMERIC = 4; | ||
exports.SQL_BIND_BOOLEAN = 5; | ||
exports.SQL_BIND_BINARY = dba.SQL_BINARY; | ||
exports.SQL_BIND_BLOB = dba.SQL_BLOB; | ||
@@ -698,0 +706,0 @@ // export variables from original idb-connector |
{ | ||
"name": "idb-pconnector", | ||
"version": "0.1.0", | ||
"description": "Promised-based Db2 Connector for IBM i (pre-alpha, NOT PRODUCTION READY)", | ||
"version": "0.1.1", | ||
"description": "Promised-based Db2 Connector for IBM i (production-ready as a \"technology preview\")", | ||
"main": "lib/idb-pconnector.js", | ||
@@ -21,3 +21,3 @@ "scripts": { | ||
"dependencies": { | ||
"idb-connector": "^1.0.12" | ||
"idb-connector": "^1.1.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -213,10 +213,16 @@ # idb-pconnector | ||
IN/OUT TYPE CAN BE: | ||
1.SQL_PARAM_INPUT | ||
2.SQL_PARAM_OUTPUT | ||
3.SQL_PARAM_INPUT_OUTPUT | ||
- SQL_PARAM_INPUT | ||
- SQL_PARAM_OUTPUT | ||
- SQL_PARAM_INPUT_OUTPUT | ||
INDICATORS CAN BE: | ||
1. SQL_BIND_CLOB | ||
2. SQL_BIND_CHAR | ||
3. SQL_BIND_NUMERIC | ||
4. SQL_BIND_NULL_DATA | ||
- SQL_BIND_CHAR | ||
- SQL_BIND_INT | ||
- SQL_BIND_NUMERIC | ||
- SQL_BIND_BINARY | ||
- SQL_BIND_BLOB | ||
- SQL_BIND_CLOB | ||
- SQL_BIND_BOOLEAN | ||
- SQL_BIND_NULL_DATA | ||
``` | ||
@@ -223,0 +229,0 @@ |
@@ -0,1 +1,8 @@ | ||
/* | ||
* Test case for the idb-pconnector DBPool Class Functions. | ||
* Automated test Framework Mocha & assertion library Chai was used to create the test cases | ||
* You may need to download those modules to run these tests on your machine | ||
* To see results of individual test cases you can run npm test -g name_of_test | ||
*/ | ||
const assert = require('chai').assert; | ||
@@ -61,3 +68,3 @@ const expect = require('chai').expect; | ||
let res = await dbConn.setConnAttr(attr, value); | ||
expect(res).to.be.a('undefined'); | ||
expect(res).to.be.true; | ||
}); | ||
@@ -72,3 +79,3 @@ }); | ||
let res = await dbConn.debug(choice); | ||
expect(res).to.be.a('undefined'); | ||
expect(res).to.be.true; | ||
}); | ||
@@ -82,3 +89,3 @@ }); | ||
let res = await dbConn.disconn(); | ||
expect(res).to.be.a('undefined'); | ||
expect(res).to.be.true; | ||
}); | ||
@@ -91,5 +98,6 @@ }); | ||
let dbConn = new dba.Connection().connect(); | ||
await dbConn.disconn(); | ||
let res = await dbConn.close(); | ||
expect(res).to.be.a('undefined'); | ||
expect(res).to.be.true; | ||
}); | ||
}); |
@@ -1,5 +0,7 @@ | ||
/** | ||
* Like The Other Tests these are not behaving as expected | ||
* See Notes in mocha-issue.txt | ||
*/ | ||
/* | ||
* Test case for the idb-pconnector DBPool Class Functions. | ||
* Automated test Framework Mocha & assertion library Chai was used to create the test cases | ||
* You may need to download those modules to run these tests on your machine | ||
* To see results of individual test cases you can run npm test -g name_of_test | ||
*/ | ||
@@ -37,29 +39,27 @@ const expect = require('chai').expect; | ||
//could give assertion error (red herring?) , see detatch test in manualTest.js | ||
describe.only('detach', async () => { | ||
it('should make the connection available again and clear stmts', async (done) => { | ||
new Promise( async (resolve, reject) =>{ | ||
//get the conn | ||
let conn = await connPool.attach(); | ||
//perform some stmts | ||
await conn.getStatement().exec('SELECT * FROM QIWS.QCUSTCDT'); | ||
console.log(`\n${JSON.stringify(conn)}`); | ||
describe('detach', async () => { | ||
it('should make the connection available again and clear stmts', async () => { | ||
//get the conn | ||
let conn = await connPool.attach(); | ||
//perform some stmts | ||
await conn.getStatement().exec('SELECT * FROM QIWS.QCUSTCDT'); | ||
console.log(`\n${JSON.stringify(conn)}`); | ||
let stmtBefore = conn.statement, | ||
id = conn.poolIndex; | ||
await conn.detach(); | ||
let stmtBefore = conn.statement, | ||
id = conn.poolIndex; | ||
await conn.detach(); | ||
let detached = connPool.connections[id], | ||
stmtAfter = detached.statement; | ||
let detached = connPool.connections[id], | ||
stmtAfter = detached.statement; | ||
//after being detached available should be true again | ||
expect(detached.available).to.be.true; | ||
//make sure the statement was cleared | ||
expect(stmtBefore).to.not.equal(stmtAfter); | ||
await connPool.detach(conn); | ||
}); | ||
done(); | ||
expect(detached.available).to.be.true; | ||
//make sure the statement was cleared | ||
expect(stmtBefore).to.not.equal(stmtAfter); | ||
await connPool.detach(conn); | ||
}); | ||
}); | ||
describe.only('detachAll', async () => { | ||
describe('detachAll', async () => { | ||
it('should return all connections back to available', async () => { | ||
@@ -88,3 +88,3 @@ //ensure all connections reset before attaching all | ||
}); | ||
describe.only('retire', async () => { | ||
describe('retire', async () => { | ||
it('should remove a connection from the pool', async () => { | ||
@@ -104,3 +104,3 @@ let conn = await connPool.attach(), | ||
}); | ||
describe.only('retireAll', async () => { | ||
describe('retireAll', async () => { | ||
it('should remove all connection from the pool', async () => { | ||
@@ -114,27 +114,20 @@ log('Length Before: '+ connPool.connections.length); | ||
}); | ||
describe.only('runSql', async () => { | ||
it('should execute sql and return result set as an array if available , or return null', async (done) => { | ||
new Promise(async () => { | ||
let results = await connPool.runSql('SELECT * FROM QIWS.QCUSTCDT'); | ||
expect(results).to.be.an('array'); | ||
expect(results.length).to.be.gt(0); | ||
}); | ||
done(); | ||
describe('runSql', async () => { | ||
it('should execute sql and return result set as an array if available , or return null', async () => { | ||
let results = await connPool.runSql('SELECT * FROM QIWS.QCUSTCDT'); | ||
expect(results).to.be.an('array'); | ||
expect(results.length).to.be.gt(0); | ||
}); | ||
}); | ||
//could give assertion error (red herring?) , try manual prepareExecute test in manualTest.js | ||
describe.only('prepare, bind, execute', async () => { | ||
describe('prepare, bind, execute', async () => { | ||
it('should prepare bind and execute , return output params if available or result set if available', | ||
async (done) => { | ||
new Promise(async (resolve, reject) =>{ | ||
let cusNum = 938472, | ||
results = await connPool.prepareExecute('SELECT * FROM QIWS.QCUSTCDT WHERE CUSNUM = ?', [cusNum]); | ||
async () => { | ||
let cusNum = 938472, | ||
results = await connPool.prepareExecute('SELECT * FROM QIWS.QCUSTCDT WHERE CUSNUM = ?', [cusNum]); | ||
console.log(results); | ||
expect(results).to.be.an('array'); | ||
expect(results.length).to.be.gt(0); | ||
}); | ||
done(); | ||
console.log(results); | ||
expect(results).to.be.an('array'); | ||
expect(results.length).to.be.gt(0); | ||
}); | ||
}); | ||
/* | ||
* This is the test case document for the idb-pconnector | ||
* Test case for the idb-pconnector Statement Class Functions. | ||
* Automated test Framework Mocha & assertion library Chai was used to create the test cases | ||
* You may need to download those modules to run these tests on your machine | ||
* To see results of individual test cases you can run npm test -- --grep name_of_test | ||
* Update 6-21-18 Methods such as: Exec, Prepare, Bind, Execute, Fetch , FetchAll | ||
* were adjusted from Sync to Async. | ||
* Figuring out The way Mocha handles Async Promises Test Cases are still a work in progress. | ||
* When using async/await & not wrapping the test code in a new Promises timeouts would occur, | ||
* Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. | ||
* This Error is false because Tests in manualTest.js show that time taken by each test case <2000 ms. | ||
* When wrapping the test code in a new promise, Assertion Errors Are not being passed up to actually Fail | ||
* the tests , therefore a Falsly Passing Test may occur. | ||
* On Node version 8 an Unhandled Promise Rejection is printed to the console. | ||
* See mocha-issue.txt for more detailed information. | ||
* | ||
* To see results of individual test cases you can run npm test -g name_of_test | ||
*/ | ||
const assert = require('chai').assert; | ||
const expect = require('chai').expect; | ||
const dba = require('../lib/idb-pconnector'); | ||
const idbp = require('../lib/idb-pconnector'); | ||
const util = require('util'); | ||
@@ -28,51 +14,49 @@ | ||
// //if successful returns undefined | ||
describe('prepare', () => { | ||
it('Prepares valid SQL and sends it to the DBMS, if the input SQL Statement cannot be prepared error is returned. ', async (done) =>{ | ||
new Promise(async function(resolve, reject){ | ||
dbConn = new dba.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(), | ||
sql = 'SELECT * FROM QIWS.QCUSTCDT'; | ||
it('Prepares valid SQL and sends it to the DBMS, if the input SQL Statement cannot be prepared error is returned. ', async () =>{ | ||
dbConn = new idbp.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(), | ||
sql = 'SELECT * FROM QIWS.QCUSTCDT'; | ||
result = await dbStmt.prepare(sql); | ||
console.log(`Result is: ${result}`); | ||
expect(result).to.be.a('undefined'); | ||
}); | ||
done(); | ||
let result = await dbStmt.prepare(sql); | ||
console.log(`Result is: ${result}`); | ||
expect(result).to.be.a('undefined'); | ||
}); | ||
}); | ||
//if successful returns undefined. | ||
describe('bindParams', () => { | ||
it('associate parameter markers in an SQL statement to app variables', async (done) => { | ||
new Promise(async (resolve, reject) => { | ||
let sql = 'INSERT INTO QIWS.QCUSTCDT(CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) VALUES (?,?,?,?,?,?,?,?,?,?,?) with NONE ', | ||
dbStmt = new dba.Connection().connect().getStatement(), | ||
dbStmt2 = new dba.Connection().connect().getStatement(); | ||
it('associate parameter markers in an SQL statement to app variables', async () => { | ||
let countResult = await dbStmt2.exec('SELECT COUNT(CUSNUM) AS COUNT FROM QIWS.QCUSTCDT'), | ||
rowsBeforeCount = Number.parseInt(countResult[0].COUNT); | ||
let sql = 'INSERT INTO QIWS.QCUSTCDT(CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) VALUES (?,?,?,?,?,?,?,?,?,?,?) with NONE', | ||
dbStmt = new idbp.Connection().connect().getStatement(), | ||
dbStmt2 = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.bindParam([ | ||
[9997, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //CUSNUM | ||
['Doe', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //LASTNAME | ||
['J D', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //INITIAL | ||
['123 Broadway', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //ADDRESS | ||
['Hope', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //CITY | ||
['WA', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //STATE | ||
[98101, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //ZIP | ||
[2000, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //CREDIT LIMIT | ||
[1, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], // change | ||
[250, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //BAL DUE | ||
[0.00, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC] //CREDIT DUE | ||
]); | ||
await dbStmt.execute(); | ||
let params = [ | ||
[9997, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //CUSNUM | ||
['Doe', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //LASTNAME | ||
['J D', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //INITIAL | ||
['123 Broadway', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //ADDRESS | ||
['Hope', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //CITY | ||
['WA', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //STATE | ||
[98101, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //ZIP | ||
[2000, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //CREDIT LIMIT | ||
[1, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], // change | ||
[250.99, idbp.SQL_PARAM_INPUT, 4], //BAL DUE | ||
[0.78, idbp.SQL_PARAM_INPUT, 4] //CREDIT DUE | ||
]; | ||
let countResult2 = await dbStmt.exec('SELECT COUNT(CUSNUM) AS COUNT FROM QIWS.QCUSTCDT'), | ||
rowsBeforeCount2 = Number.parseInt(countResult2[0].COUNT); | ||
expect(rowsBeforeCount2).to.equal(rowsBeforeCount + 1); | ||
}); | ||
done(); | ||
let countResult = await dbStmt2.exec('SELECT COUNT(CUSNUM) AS COUNT FROM QIWS.QCUSTCDT'), | ||
rowsBeforeCount = Number.parseInt(countResult[0].COUNT); | ||
console.log(`Count Before is: ${rowsBeforeCount}`); | ||
console.log(`input: ${idbp.SQL_PARAM_INPUT}`); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.bindParam(params); | ||
await dbStmt.execute(); | ||
let countResult2 = await dbStmt.exec('SELECT COUNT(CUSNUM) AS COUNT FROM QIWS.QCUSTCDT'), | ||
rowsBeforeCount2 = Number.parseInt(countResult2[0].COUNT); | ||
console.log(`Count After is: ${rowsBeforeCount2}`); | ||
expect(rowsBeforeCount2).to.equal(rowsBeforeCount + 1); | ||
}); | ||
@@ -87,30 +71,24 @@ }); | ||
//if successful returns undefined | ||
describe('close', () => { | ||
it('frees the statement object. ', async (done) => { | ||
new Promise( async (resolve, reject) =>{ | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('frees the statement object. ', async () => { | ||
await dbStmt.exec(sql); | ||
let result = await dbStmt.close(); | ||
expect(result).to.be.a('undefined'); | ||
}); | ||
done(); | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.exec(sql); | ||
let result = await dbStmt.close(); | ||
expect(result).to.be.true; | ||
}); | ||
}); | ||
//if successful returns undefined | ||
//TODO: Ensure This a correct unit test for how closecursor may be used. | ||
describe('closeCursor', () => { | ||
it('closes any cursor associated with the dbstmt object and discards any pending results. ', async (done) => { | ||
new Promise(async (resolve, reject) => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('closes any cursor associated with the dbstmt object and discards any pending results. ', async () => { | ||
await dbStmt.exec(sql); | ||
let result = await dbStmt.closeCursor(); | ||
expect(result).to.be.a('undefined'); | ||
}); | ||
done(); | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.exec(sql); | ||
let result = await dbStmt.closeCursor(); | ||
expect(result).to.be.true; | ||
}); | ||
@@ -121,26 +99,25 @@ }); | ||
describe('commit', () => { | ||
it('adds all changes to the database that have been made on the connection since connect time ', async (done) => { | ||
new Promise( async (resolve, reject) => { | ||
let sql = 'INSERT INTO QIWS.QCUSTCDT(CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) VALUES (?,?,?,?,?,?,?,?,?,?,?) with NONE ', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('adds all changes to the database that have been made on the connection since connect time ', async () => { | ||
await dbStmt.prepare(sql); | ||
await dbStmt.bindParam([ | ||
[9997, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //CUSNUM | ||
['Johnson', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //LASTNAME | ||
['A J', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //INITIAL | ||
['453 Example', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //ADDRESS | ||
['Fort', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //CITY | ||
['TN', dba.SQL_PARAM_INPUT, dba.SQL_CHAR], //STATE | ||
[37211, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //ZIP | ||
[1000, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //CREDIT LIMIT | ||
[1, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], // change | ||
[150, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC], //BAL DUE | ||
[0.00, dba.SQL_PARAM_INPUT, dba.SQL_NUMERIC] //CREDIT DUE | ||
]); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.commit(); | ||
expect(result).to.be.a('undefined'); | ||
}); | ||
done(); | ||
let sql = 'INSERT INTO QIWS.QCUSTCDT(CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) VALUES (?,?,?,?,?,?,?,?,?,?,?) with NONE ', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
let params = [ | ||
[9997, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //CUSNUM | ||
['Johnson', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //LASTNAME | ||
['A J', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //INITIAL | ||
['453 Example', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //ADDRESS | ||
['Fort', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //CITY | ||
['TN', idbp.SQL_PARAM_INPUT, idbp.SQL_CHAR], //STATE | ||
[37211, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //ZIP | ||
[1000, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //CREDIT LIMIT | ||
[1, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], // change | ||
[150, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC], //BAL DUE | ||
[0.00, idbp.SQL_PARAM_INPUT, idbp.SQL_NUMERIC] //CREDIT DUE | ||
]; | ||
await dbStmt.prepare(sql); | ||
await dbStmt.bindParam(params); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.commit(); | ||
expect(result).to.be.true; | ||
}); | ||
@@ -151,16 +128,13 @@ }); | ||
describe('exec', () => { | ||
it('performs action of given SQL String', async (done) => { | ||
new Promise(async (resolve, reject) => { | ||
let dbConn = new dba.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(), | ||
sql = 'SELECT * FROM QIWS.QCUSTCDT WHERE CUSNUM = 938472'; | ||
it('performs action of given SQL String', async () => { | ||
let dbConn = new idbp.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(), | ||
sql = 'SELECT * FROM QIWS.QCUSTCDT WHERE CUSNUM = 938472'; | ||
let result = await dbStmt.exec(sql); | ||
let result = await dbStmt.exec(sql); | ||
console.log(`Exec results: ${JSON.stringify(result)}`); | ||
expect(result).to.be.an('array'); | ||
expect(result.length).to.be.greaterThan(0); | ||
}); | ||
done(); | ||
console.log(`Exec results: ${JSON.stringify(result)}`); | ||
expect(result).to.be.an('array'); | ||
expect(result.length).to.be.greaterThan(0); | ||
}); | ||
@@ -171,20 +145,18 @@ }); | ||
describe('execute', () => { | ||
it('retrieves results from execute function:', async (done) =>{ | ||
new Promise(async (resolve, reject) => { | ||
let sql = 'CALL AMUSSE.MAXBAL(?)', | ||
dbConn = new dba.Connection(); | ||
it('retrieves results from execute function:', async () =>{ | ||
let user = (process.env.USER).toUpperCase(), | ||
sql = `CALL ${user}.MAXBAL(?)`, | ||
dbConn = new idbp.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(), | ||
bal = 0; | ||
await dbStmt.prepare(sql); | ||
await dbStmt.bind([[bal, dba.SQL_PARAM_OUT, dba.SQL_NUMERIC]]); | ||
let result = await dbStmt.execute(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(), | ||
bal = 0; | ||
await dbStmt.prepare(sql); | ||
await dbStmt.bind([[bal, idbp.SQL_PARAM_OUT, idbp.SQL_NUMERIC]]); | ||
let result = await dbStmt.execute(); | ||
console.log(`ExecuteAsync results:\n ${JSON.stringify(result)}`); | ||
console.log(`Length of results: ${result.length}`); | ||
expect(result).to.be.a('array'); | ||
expect(result.length).to.be.greaterThan(0); | ||
}); | ||
done(); | ||
console.log(`ExecuteAsync results:\n ${JSON.stringify(result)}`); | ||
console.log(`Length of results: ${result.length}`); | ||
expect(result).to.be.a('array'); | ||
expect(result.length).to.be.greaterThan(0); | ||
}); | ||
@@ -195,20 +167,17 @@ }); | ||
describe('fetchAll', () => { | ||
it('retrieves results from execute function:', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbConn = new dba.Connection(); | ||
it('Fetches All rows from execute function:', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbConn = new idbp.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.fetchAll(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.fetchAll(); | ||
console.log(`Fetch All results:\n ${JSON.stringify(result)}`); | ||
console.log(`Size of the returned array: ${result.length}`); | ||
expect(result).to.be.a('array'); | ||
expect(result.length).to.be.greaterThan(0); | ||
}); | ||
done(); | ||
console.log(`Fetch All results:\n ${JSON.stringify(result)}`); | ||
console.log(`Size of the returned array: ${result.length}`); | ||
expect(result).to.be.a('array'); | ||
expect(result.length).to.be.greaterThan(0); | ||
}); | ||
@@ -220,17 +189,14 @@ }); | ||
describe('fetch', () => { | ||
it('retrieves results from execute function:', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbConn = new dba.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(); | ||
it('Fetches one row from execute function:', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbConn = new idbp.Connection(); | ||
dbConn.debug(true); | ||
let dbStmt = dbConn.connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.fetch(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.fetch(); | ||
console.log(`Fetch result:\n ${JSON.stringify(result)}`); | ||
expect(result).to.be.a('object'); | ||
}); | ||
done(); | ||
console.log(`Fetch result:\n ${JSON.stringify(result)}`); | ||
expect(result).to.be.a('object'); | ||
}); | ||
@@ -241,15 +207,12 @@ }); | ||
describe('numFields', () => { | ||
it('retrieves number of fields contained in result', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('retrieves number of fields contained in result', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let fields = await dbStmt.numFields(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let fields = await dbStmt.numFields(); | ||
console.log(`Number of Fields: ${fields}`); | ||
expect(fields).to.be.a('number'); | ||
}); | ||
done(); | ||
console.log(`Number of Fields: ${fields}`); | ||
expect(fields).to.be.a('number'); | ||
}); | ||
@@ -260,15 +223,12 @@ }); | ||
describe('numRows', () => { | ||
it('retrieves number of rows that were effected by a Querry', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('retrieves number of rows that were effected by a Querry', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let rows = await dbStmt.numRows(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let rows = await dbStmt.numRows(); | ||
console.log(`Number of Rows: ${rows}`); | ||
expect(rows).to.be.a('number'); | ||
}); | ||
done(); | ||
console.log(`Number of Rows: ${rows}`); | ||
expect(rows).to.be.a('number'); | ||
}); | ||
@@ -279,19 +239,16 @@ }); | ||
describe('fieldType', () => { | ||
it('requires an int index parameter. If a valid index is provided, returns the data type of the indicated column', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('requires an int index parameter. If a valid index is provided, returns the data type of the indicated column', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let col1 = await dbStmt.fieldType(0), | ||
col2 = await dbStmt.fieldType(1); | ||
let col1 = await dbStmt.fieldType(0), | ||
col2 = await dbStmt.fieldType(1); | ||
console.log(`column 1 fieldType = ${col1}`); | ||
console.log(`column 2 fieldType = ${col2}`); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
done(); | ||
console.log(`column 1 fieldType = ${col1}`); | ||
console.log(`column 2 fieldType = ${col2}`); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
@@ -302,19 +259,16 @@ }); | ||
describe('fieldWidth', () => { | ||
it('requires an int index parameter. If a valid index is provided, returns the field width of the indicated column', async (done) => { | ||
new Promise(async (resolve, reject) => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('requires an int index parameter. If a valid index is provided, returns the field width of the indicated column', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let col1 = await dbStmt.fieldWidth(0), | ||
col2 = await dbStmt.fieldWidth(1); | ||
let col1 = await dbStmt.fieldWidth(0), | ||
col2 = await dbStmt.fieldWidth(1); | ||
console.log(`column 1 fieldWidth = ${col1}`); | ||
console.log(`column 2 fieldWidth = ${col2}`); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
done(); | ||
console.log(`column 1 fieldWidth = ${col1}`); | ||
console.log(`column 2 fieldWidth = ${col2}`); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
@@ -325,20 +279,16 @@ }); | ||
describe('fieldNullable', () => { | ||
it('requires an int index parameter. If a valid index is provided, returns t/f if the indicated column can be Null', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('requires an int index parameter. If a valid index is provided, returns t/f if the indicated column can be Null', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let col1 = await dbStmt.fieldNullable(0), | ||
col2 = await dbStmt.fieldNullable(1); | ||
let col1 = await dbStmt.fieldNullable(0), | ||
col2 = await dbStmt.fieldNullable(1); | ||
console.log(`column 1 Nullable? = ${col1}`); | ||
console.log(`column 2 Nullable? = ${col2}`); | ||
//****Documnetation says it should return a boolean | ||
expect(col1).to.equal(false); | ||
expect(col2).to.equal(false); | ||
}); | ||
done(); | ||
console.log(`column 1 Nullable? = ${col1}`); | ||
console.log(`column 2 Nullable? = ${col2}`); | ||
expect(col1).to.equal(false); | ||
expect(col2).to.equal(false); | ||
}); | ||
@@ -349,19 +299,16 @@ }); | ||
describe('fieldName', () => { | ||
it('requires an int index parameter. If a valid index is provided,returns name of the indicated column ', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('requires an int index parameter. If a valid index is provided,returns name of the indicated column ', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let col1 = await dbStmt.fieldName(0), | ||
col2 = await dbStmt.fieldName(1); | ||
let col1 = await dbStmt.fieldName(0), | ||
col2 = await dbStmt.fieldName(1); | ||
console.log(`column 1 Name = ${col1}`); | ||
console.log(`column 2 Name = ${col2}`); | ||
expect(col1).to.be.a('string'); | ||
expect(col2).to.be.a('string'); | ||
}); | ||
done(); | ||
console.log(`column 1 Name = ${col1}`); | ||
console.log(`column 2 Name = ${col2}`); | ||
expect(col1).to.be.a('string'); | ||
expect(col2).to.be.a('string'); | ||
}); | ||
@@ -372,19 +319,16 @@ }); | ||
describe('fieldPrecise', () => { | ||
it('requires an int index parameter. If a valid index is provided, returns the precision of the indicated column', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('requires an int index parameter. If a valid index is provided, returns the precision of the indicated column', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let col1 = await dbStmt.fieldPrecise(0), | ||
col2 = await dbStmt.fieldPrecise(1); | ||
let col1 = await dbStmt.fieldPrecise(0), | ||
col2 = await dbStmt.fieldPrecise(1); | ||
console.log('column 1 fieldPrecision = : ' + col1); | ||
console.log('column 2 fieldPrecision = : ' + col2); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
done(); | ||
console.log('column 1 fieldPrecision = : ' + col1); | ||
console.log('column 2 fieldPrecision = : ' + col2); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
@@ -396,19 +340,16 @@ }); | ||
describe('fieldScale', () => { | ||
it('requires an int index parameter. If a valid index is provided, returns the scale of the indicated column', async function(done){ | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
it('requires an int index parameter. If a valid index is provided, returns the scale of the indicated column', async function(){ | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let col1 = await dbStmt.fieldScale(0), | ||
col2 = await dbStmt.fieldScale(1); | ||
let col1 = await dbStmt.fieldScale(0), | ||
col2 = await dbStmt.fieldScale(1); | ||
console.log(`column 1 fieldScale = ${col1}`); | ||
console.log(`column 2 fieldScale = ${col2}`); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
done(); | ||
console.log(`column 1 fieldScale = ${col1}`); | ||
console.log(`column 2 fieldScale = ${col2}`); | ||
expect(col1).to.be.a('number'); | ||
expect(col2).to.be.a('number'); | ||
}); | ||
@@ -420,8 +361,8 @@ }); | ||
it('sets StmtAttr Attrubte should be INT. Value can String or Int depending on the attribute', async () => { | ||
let attr = dba.SQL_ATTR_FOR_FETCH_ONLY, | ||
let attr = idbp.SQL_ATTR_FOR_FETCH_ONLY, | ||
value = 1, | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
let result = await dbStmt.setStmtAttr(attr, value); | ||
expect(result).to.be.a('undefined'); | ||
expect(result).to.be.true; | ||
}); | ||
@@ -433,4 +374,5 @@ }); | ||
it('if statement attribute exsits should return type String or Int depending on the attribute type', async () => { | ||
let attr = dba.SQL_ATTR_FOR_FETCH_ONLY; | ||
let dbStmt = new dba.Connection().connect().getStatement(); | ||
let attr = idbp.SQL_ATTR_FOR_FETCH_ONLY, | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
let result = await dbStmt.getStmtAttr(attr); | ||
@@ -448,3 +390,3 @@ console.log(`Stmt Attr: ${result}`); | ||
// let sql = "SELECT * FROM QIWS.QCUSTCDT"; | ||
// let dbStmt = new dba.Connection().connect().getStatement(); | ||
// let dbStmt = new idbp.Connection().connect().getStatement(); | ||
// await dbStmt.prepare(sql); | ||
@@ -459,12 +401,10 @@ // await dbStmt.execute(); | ||
describe('rollback', () => { | ||
it('Rollback all changes to the database that have been made on the connection', async (done) => { | ||
new Promise(async function(resolve, reject) { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new dba.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.rollback(); | ||
expect(result).to.be.a('undefined'); | ||
}); | ||
done(); | ||
it('Rollback all changes to the database that have been made on the connection', async () => { | ||
let sql = 'SELECT * FROM QIWS.QCUSTCDT', | ||
dbStmt = new idbp.Connection().connect().getStatement(); | ||
await dbStmt.prepare(sql); | ||
await dbStmt.execute(); | ||
let result = await dbStmt.rollback(); | ||
expect(result).to.be.true; | ||
}); | ||
@@ -478,3 +418,3 @@ }); | ||
// it('Returns the diagnostic information ', async () =>{ | ||
// let dbStmt = new dba.Connection().connect().getStatement(); | ||
// let dbStmt = new idbp.Connection().connect().getStatement(); | ||
// await dbStmt.stmtError(hType, recno); | ||
@@ -481,0 +421,0 @@ |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
605
146399
11
2609
1
Updatedidb-connector@^1.1.0