Skip to content

Commit 331148b

Browse files
author
bimalkjha
committed
fix test case issues and error handling
1 parent 0640adc commit 331148b

23 files changed

+84
-65
lines changed

lib/odbc.js

+25-30
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module.exports.open = function (connStr, options, cb)
105105
db = DBFactory(options);
106106

107107
db.open(connStr, function (err) {
108-
cb(err, db);
108+
cb && cb(err, db);
109109
});
110110
}; // ibmdb.open
111111

@@ -198,11 +198,11 @@ Database.prototype.open = function (connStr, cb) {
198198
{
199199
if(cb)
200200
{
201-
if (err) return cb(err);
202-
203-
self.connected = true;
204-
205-
return cb(err, result);
201+
if (err) cb(err);
202+
else {
203+
self.connected = true;
204+
cb(err, result);
205+
}
206206
}
207207
else
208208
{
@@ -334,7 +334,7 @@ Database.prototype.query = function (query, params, cb)
334334
if (result && typeof(result) === 'object') {
335335
fetchMore();
336336
} else {
337-
cb(initialErr, resultset);
337+
cb && cb(initialErr, resultset);
338338
return next();
339339
}
340340

@@ -496,7 +496,7 @@ Database.prototype.queryResult = function (query, params, cb)
496496
{
497497
if (err)
498498
{
499-
cb(err, null);
499+
cb && cb(err, null);
500500
return next();
501501
}
502502

@@ -505,7 +505,7 @@ Database.prototype.queryResult = function (query, params, cb)
505505
result.fetchMode = self.fetchMode;
506506
}
507507

508-
cb(err, result);
508+
cb && cb(err, result);
509509

510510
return next();
511511
} // function cbQuery
@@ -537,7 +537,7 @@ Database.prototype.queryResultSync = function (query, params)
537537
if(Array.isArray(params))
538538
{
539539
var err = parseParams(params);
540-
if(err) cb(err);
540+
if(err) cb && cb(err);
541541
}
542542
if(sql.search(/^call /i))
543543
{
@@ -853,7 +853,7 @@ Database.prototype.columns = function(catalog, schema, table, column, callback)
853853
result.fetchAll(function (err, data)
854854
{
855855
result.closeSync();
856-
callback(err, data);
856+
callback && callback(err, data);
857857
return next();
858858
});
859859
});
@@ -876,7 +876,7 @@ Database.prototype.tables = function(catalog, schema, table, type, callback)
876876
result.fetchAll(function (err, data)
877877
{
878878
result.closeSync();
879-
callback(err, data);
879+
callback && callback(err, data);
880880
return next();
881881
});
882882
});
@@ -1021,11 +1021,6 @@ odbc.ODBCStatement.prototype.execute = function (params, cb)
10211021
if (!cb && typeof params !== 'function')
10221022
{
10231023
deferred = Q.defer();
1024-
// if(!params)
1025-
// {
1026-
// params = null;
1027-
// }
1028-
10291024
}
10301025

10311026
self.queue = self.queue || new SimpleQueue();
@@ -1285,7 +1280,7 @@ odbc.ODBCStatement.prototype.executeDirect = function (sql, cb)
12851280

12861281
self.queue.push(function (next) {
12871282
self._executeDirect(sql, function (err, result) {
1288-
cb(err, result);
1283+
cb && cb(err, result);
12891284

12901285
return next();
12911286
});
@@ -1320,7 +1315,7 @@ odbc.ODBCStatement.prototype.executeNonQuery = function (params, cb)
13201315
{
13211316
if(!deferred)
13221317
{
1323-
if(cb) cb(err);
1318+
cb && cb(err);
13241319
}
13251320
else
13261321
{
@@ -1332,7 +1327,7 @@ odbc.ODBCStatement.prototype.executeNonQuery = function (params, cb)
13321327
if (err) {
13331328
if(!deferred)
13341329
{
1335-
if(cb) cb(err)
1330+
cb && cb(err)
13361331
}
13371332
else
13381333
{
@@ -1344,7 +1339,7 @@ odbc.ODBCStatement.prototype.executeNonQuery = function (params, cb)
13441339
self._executeNonQuery(function (err, result) {
13451340
if(!deferred)
13461341
{
1347-
if(cb) cb(err, result);
1342+
cb && cb(err, result);
13481343
}
13491344
else
13501345
{
@@ -1366,7 +1361,7 @@ odbc.ODBCStatement.prototype.executeNonQuery = function (params, cb)
13661361
self._executeNonQuery(function (err, result) {
13671362
if(!deferred)
13681363
{
1369-
if(cb) cb(err, result);
1364+
cb && cb(err, result);
13701365
}
13711366
else
13721367
{
@@ -1400,7 +1395,7 @@ odbc.ODBCStatement.prototype.prepare = function (sql, cb) {
14001395

14011396
self.queue.push(function (next) {
14021397
self._prepare(sql, function (err) {
1403-
if(cb) cb(err);
1398+
cb && cb(err);
14041399

14051400
return next();
14061401
});
@@ -1420,7 +1415,7 @@ odbc.ODBCStatement.prototype.bind = function (ary, cb) {
14201415
if(err && cb) cb(err);
14211416
}
14221417
self._bind(ary, function (err) {
1423-
if(cb) cb(err);
1418+
cb && cb(err);
14241419

14251420
//NOTE: we do not call next() here because
14261421
//we want to pop the next bind call only
@@ -1484,7 +1479,7 @@ Pool.prototype.open = function (connStr, callback)
14841479
db.lastUsed=null;
14851480
self.usedPool[connStr] = self.usedPool[connStr] || [];
14861481
self.usedPool[connStr].push(db);
1487-
callback(null, db);
1482+
callback && callback(null, db);
14881483
}
14891484
else if((self.maxPoolSize > 0) && (self.poolSize >= self.maxPoolSize))
14901485
{
@@ -1498,12 +1493,12 @@ Pool.prototype.open = function (connStr, callback)
14981493
self.usedPool[connStr] = self.usedPool[connStr] || [];
14991494
self.usedPool[connStr].push(db);
15001495
clearInterval(interval);
1501-
callback(null, db);
1496+
callback && callback(null, db);
15021497
}
15031498
if(timeout === 0)
15041499
{
15051500
clearInterval(interval);
1506-
callback(error, null);
1501+
callback && callback(error, null);
15071502
}
15081503
else
15091504
{
@@ -1525,7 +1520,7 @@ Pool.prototype.open = function (connStr, callback)
15251520
db.lastUsed = Date.now();
15261521
//call back early, we can do the rest of this stuff after the client
15271522
//thinks that the connection is closed.
1528-
if(cb) cb(null);
1523+
cb && cb(null);
15291524

15301525
// If this connection has some active transaction, rollback the
15311526
// transaction to free up the held resorces before moving back to
@@ -1565,7 +1560,7 @@ Pool.prototype.open = function (connStr, callback)
15651560
db.created = Date.now();
15661561
self.usedPool[connStr].push(db);
15671562
}
1568-
callback(error, db);
1563+
callback && callback(error, db);
15691564
}); //db.open
15701565
}
15711566
};
@@ -1650,7 +1645,7 @@ Pool.prototype.setConnectTimeout = function(timeout)
16501645
};
16511646

16521647
// Close idle connections
1653-
Pool.prototype.cleanUp = function(connStr, callback) {
1648+
Pool.prototype.cleanUp = function(connStr) {
16541649
var self = this;
16551650
if(self.availablePool[connStr].length < 2) return;
16561651

test/run-tests.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ function doTest(file, connectionString) {
5959
test.on("exit", function (code, signal) {
6060
clearTimeout(timer);
6161

62-
if (code && code != 0) {
62+
if (signal || (code && code != 0)) {
6363
errorCount += 1;
6464

6565
process.stdout.write("\033[01;31mfail \033[01;0m ");
6666

6767
if (timedOut) {
6868
process.stdout.write("(Timed Out)");
6969
}
70+
if(signal) console.log("Caught Signal ", signal);
7071
process.stdout.write("\n \033[01;34mStdout: \033[01;0m \n");
7172
process.stdout.write(testOut);
7273
process.stdout.write("\n \033[01;31mStderr: \033[01;0m \n");

test/test-all-data-types.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var common = require("./common")
44
, cn = common.connectionString;
55

66
ibmdb.open(cn, function(err, conn) {
7-
if(err) return console.log(err);
7+
if(err) console.log(err);
8+
assert.equal(err, null);
89

910
try {
1011
conn.querySync("drop table mytab1");

test/test-basic-test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var common = require("./common")
44
, cn = common.connectionString;
55

66
ibmdb.open(cn, {"fetchMode": 3}, function(err, conn) { // 3 means FETCH_ARRARY
7-
if(err) return console.log(err);
7+
if(err) console.log(err);
8+
assert.equal(err, null);
89

910
try{
1011
conn.querySync("drop table mytab1");

test/test-blob-file.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ibmdb.open(cn, function (err,conn)
1212
{
1313
if (err)
1414
{
15-
return console.log(err);
15+
console.log(err);
16+
process.exit(-1);
1617
}
1718
try {
1819
conn.querySync("drop table mytab");

test/test-blob-insert.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ ibmdb.open(cn, function (err,conn)
1717
{
1818
if (err)
1919
{
20-
return console.log(err);
20+
console.log(err);
2121
}
22+
assert.equal(err, null);
2223
try {
2324
conn.querySync("drop table mytab");
2425
} catch (e) {};

test/test-blocking-issue210.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var common = require("./common")
99
var startTime1, startTime2, totalTime1, totalTime2, dropTable = 0;
1010
var elapsedTime = ibmdb.getElapsedTime;
1111
var ret = pool.init(connectCount, connectionString);
12+
if(typeof ret === 'object') assert.equal(ret.message, undefined);
1213

1314
//moment().format("YYYY-MM-DD HH:mm:ss.SSS"));
1415
console.log(elapsedTime(), "Started pool.open, populate a table mtab1 of 100K rows.");

test/test-call-async.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ if(schema == undefined) schema = "NEWTON";
1111
ibmdb.open(cn, function (err, conn)
1212
{
1313
var query = "CaLL " + schema + ".proc1(?, ?, ?)";
14-
if(err) return console.log(err);
14+
if(err) console.log(err);
15+
assert.equal(err, null);
1516
try {
1617
conn.querySync("drop procedure " + schema + ".proc1(INT, INT, VARCHAR(20))");
1718
console.log("proc1 dropped.\n");

test/test-call-stmt.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ if(schema == undefined) schema = "NEWTON";
1010
var query = "CaLL " + schema + ".proc1(?, ?, ?)";
1111
ibmdb.open(cn, function (err, conn)
1212
{
13-
if(err) return console.log(err);
13+
if(err) console.log(err);
14+
assert.equal(err, null);
1415
try {
1516
conn.querySync("drop procedure " + schema + ".proc1(INT, INT, VARCHAR(20))");
1617
} catch(e) {}

test/test-ibm-db-issue14.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Test program to access DB2 sample database */
22
/*require the ibm_db module*/
33
var common = require("./common")
4+
, assert = require("assert")
45
, ibmdb = require("../");
56

67
var testTable = 'BIGINTTEST';
@@ -15,6 +16,7 @@ ibmdb.open(common.connectionString, function(err, conn)
1516
{
1617
if(err) {
1718
console.error("error: ", err.message);
19+
assert.equal(err.message, null);
1820
} else {
1921

2022
console.log('Connection to DB2 machine successful');

test/test-ibm-db-issue17.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*require the ibm_db module*/
22
var common = require("./common")
3+
, assert = require("assert")
34
, ibmdb = require("../");
45

56
var connString = 'DRIVER={DB2 ODBC Driver};DATABASE=SAMPLE;UID=db2admin;PWD=db2admin;HOSTNAME=localhost;port=50000;PROTOCOL=TCPIP';
@@ -16,6 +17,7 @@ ibmdb.open(common.connectionString, function(err, conn)
1617
{
1718
if(err) {
1819
console.error("error: ", err.message);
20+
assert.equal(err.message, null);
1921
} else {
2022

2123
console.log('Connection to DB2 machine successful');

test/test-ibm-db-issue18.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*require the ibm_db module*/
22
var common = require("./common")
33
, ibmdb = require("../")
4+
, assert = require("assert")
45
, db = new ibmdb.Database();
56

67
var connString = 'DRIVER={DB2 ODBC Driver};DATABASE=SAMPLE;UID=db2admin;PWD=db2admin;HOSTNAME=localhost;port=50000;PROTOCOL=TCPIP';
@@ -15,6 +16,7 @@ ibmdb.open(common.connectionString, function(err, conn)
1516
{
1617
if(err) {
1718
console.error("error: ", err.message);
19+
assert.equal(err.message, null);
1820
} else {
1921

2022
console.log('Connection to DB2 machine successful');
@@ -49,4 +51,4 @@ ibmdb.open(common.connectionString, function(err, conn)
4951
});
5052
});
5153
}
52-
});
54+
});

test/test-issue-54.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ select 'You will never get this message, either!' as msg; \
1818
"
1919

2020
db.open(common.connectionString, function(err) {
21-
console.log(err || "Connected")
21+
console.log(err || "Connected");
22+
assert.equal(err, null);
2223

2324
if (!err) {
2425
db.query(sql, function (err, results, more) {
25-
console.log("q1 result: ", err, results, more)
26+
console.log("q1 result: ", err, results, more);
2627

2728
if (!more) {
28-
console.log("Running second query")
29+
console.log("Running second query");
2930

3031
db.query("select 1 as x", function(err, results, more) {
31-
console.log("q2 result: ", err, results, more)
32+
console.log("q2 result: ", err, results, more);
3233

33-
db.close(function(err) { console.log(err || "Closed") })
34+
db.close(function(err) { console.log(err || "Closed"); })
3435
})
3536
}
3637
})
3738
}
38-
});
39+
});

test/test-issue-get-column-value-2.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var getSchema = function () {
1616
if (err) {
1717
console.error("connection error: ", err.message);
1818
db.close(function(){});
19-
return;
19+
assert(err.message, null);
2020
}
2121

2222
db.describe({database: 'SAMPLE', schema: 'AVINASH', table: common.tableName }, function (err, rows) {
@@ -42,4 +42,4 @@ var getSchema = function () {
4242
});
4343
};
4444

45-
getSchema();
45+
getSchema();

0 commit comments

Comments
 (0)