Skip to content

Commit d5e3fe8

Browse files
authored
Merge pull request #91 from rbetjes/fix_undefined_exception
fix for #89: prevent read attribute from undefined caused by info being empty array on error
2 parents 42c5c85 + f322cee commit d5e3fe8

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

lib/dashdb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ DASHDB.prototype.update = function(model, where, data, options, cb) {
8383
sql.merge(new ParameterizedSQL(')'));
8484
self.execute(sql.sql, stmt.params, options, function(err, info) {
8585
if (cb) {
86-
cb(err, {count: parseInt(info[0].affectedRows)});
86+
cb(err, {count: parseInt(info[0] ? info[0].affectedRows : 0)});
8787
}
8888
});
8989
};

test/dashdb.dml.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: loopback-connector-dashdb
3+
// This file is licensed under the Artistic License 2.0.
4+
// License text available at https://opensource.org/licenses/Artistic-2.0
5+
6+
'use strict';
7+
8+
/* eslint-env node, mocha */
9+
process.env.NODE_ENV = 'test';
10+
11+
require('should');
12+
13+
let db, FloatingPoint;
14+
15+
describe('dml', function() {
16+
before(function() {
17+
require('./init.js');
18+
});
19+
20+
describe('insert and patch', function() {
21+
before(function(done) {
22+
db = global.getDataSource();
23+
24+
FloatingPoint = db.define('FLOATING_POINT', {
25+
id: {type: String, length: 20, index: true},
26+
aFloat: {type: Number, dashdb: {dataType: 'double'}},
27+
});
28+
db.automigrate('FLOATING_POINT', done);
29+
});
30+
31+
// Return an async function create a record in floating_point table
32+
function createRecInFP(rec) {
33+
return function(done) {
34+
FloatingPoint.create(rec,
35+
function(err, p) {
36+
if (err) {
37+
done(err);
38+
} else {
39+
done();
40+
}
41+
});
42+
};
43+
}
44+
45+
describe('patch', function() {
46+
const rec = {aFloat: 42.234567};
47+
before(createRecInFP(rec));
48+
49+
it('should fail with a specific SQL error', async function() {
50+
await FloatingPoint.updateAll(rec, {aFloat: 42.234567890123456789})
51+
.should.be.rejectedWith(
52+
'[IBM][CLI Driver] CLI0135E Invalid scale value. SQLSTATE=HY094',
53+
);
54+
});
55+
});
56+
});
57+
});

test/table.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@
7474
"UID" VARCHAR(1024),
7575
"TTL" INT
7676
) ORGANIZE BY ROW;
77+
78+
CREATE TABLE "?"."FLOATING_POINT"
79+
( "ID" VARCHAR(20) NOT NULL,
80+
"A_FLOAT" DOUBLE
81+
) ORGANIZE BY ROW;

0 commit comments

Comments
 (0)