Skip to content

Commit a01e943

Browse files
committed
Tests for 64-bit Integers
1 parent 3a01f67 commit a01e943

File tree

2 files changed

+180
-6
lines changed

2 files changed

+180
-6
lines changed

test/dataTypeNumber.js

Lines changed: 172 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var oracledb = require('oracledb');
3737
var should = require('should');
3838
var assist = require('./dataTypeAssist.js');
3939
var dbConfig = require('./dbconfig.js');
40+
var async = require('async');
4041

4142
describe('26. dataTypeNumber.js', function() {
4243

@@ -46,11 +47,7 @@ describe('26. dataTypeNumber.js', function() {
4647

4748
before('get one connection', function(done) {
4849
oracledb.getConnection(
49-
{
50-
user: dbConfig.user,
51-
password: dbConfig.password,
52-
connectString: dbConfig.connectString
53-
},
50+
dbConfig,
5451
function(err, conn) {
5552
should.not.exist(err);
5653
connection = conn;
@@ -112,4 +109,173 @@ describe('26. dataTypeNumber.js', function() {
112109
});
113110
});
114111

115-
});
112+
// GitHub issue 833
113+
// https://github.com/oracle/node-oracledb/issues/833
114+
describe('26.3 large integers that cannot fit inside a 32-bit integer', function() {
115+
116+
it('26.3.1 original case', function(done) {
117+
118+
var num = 999999999999;
119+
async.series([
120+
function(cb) {
121+
var proc = "BEGIN \n" +
122+
" DECLARE \n" +
123+
" e_table_missing EXCEPTION; \n" +
124+
" PRAGMA EXCEPTION_INIT(e_table_missing, -00942); \n" +
125+
" BEGIN \n" +
126+
" EXECUTE IMMEDIATE('DROP TABLE nodb_tab_bignum PURGE'); \n" +
127+
" EXCEPTION \n" +
128+
" WHEN e_table_missing \n" +
129+
" THEN NULL; \n" +
130+
" END; \n" +
131+
" EXECUTE IMMEDIATE (' \n" +
132+
" CREATE TABLE nodb_tab_bignum ( \n" +
133+
" id NUMBER NOT NULL, \n" +
134+
" content NUMBER(12, 0) \n" +
135+
" ) \n" +
136+
" '); \n" +
137+
"END; ";
138+
139+
connection.execute(
140+
proc,
141+
function(err) {
142+
should.not.exist(err);
143+
cb();
144+
}
145+
);
146+
},
147+
function(cb) {
148+
var sql = "insert into nodb_tab_bignum (id, content) values (1, :n)";
149+
connection.execute(
150+
sql,
151+
{ n: num },
152+
function(err) {
153+
should.not.exist(err);
154+
cb();
155+
}
156+
);
157+
},
158+
function(cb) {
159+
var sql = "select content from nodb_tab_bignum where id = 1";
160+
connection.execute(
161+
sql,
162+
function(err, result) {
163+
should.not.exist(err);
164+
should.strictEqual(
165+
result.rows[0][0],
166+
num
167+
);
168+
cb();
169+
}
170+
);
171+
},
172+
function(cb) {
173+
var sql = "DROP TABLE nodb_tab_bignum PURGE";
174+
connection.execute(
175+
sql,
176+
function(err) {
177+
should.not.exist(err);
178+
cb();
179+
}
180+
);
181+
}
182+
], done);
183+
});
184+
}); // 26.3
185+
186+
/*
187+
* The maximum safe integer in JavaScript is (2^53 - 1) i.e. 9007199254740992.
188+
* The minimum safe integer in JavaScript is (-(2^53 - 1)).
189+
* Numbers out of above range will be rounded.
190+
*/
191+
describe('26.4 Large number, edge cases', function() {
192+
193+
it('26.4.1 maximum safe integer, (2^53 - 1)', function(done) {
194+
195+
var num = 9007199254740992;
196+
var sql = "select " + num + " from dual";
197+
connection.execute(
198+
sql,
199+
function(err, result) {
200+
should.not.exist(err);
201+
should.strictEqual(
202+
result.rows[0][0],
203+
num
204+
);
205+
done();
206+
}
207+
);
208+
});
209+
210+
it('26.4.2 Negative - maximum safe integer + 1', function(done) {
211+
212+
var actual = '9007199254740993';
213+
var expected = 9007199254740992;
214+
215+
var sql = "SELECT TO_NUMBER( " + actual + " ) FROM DUAL";
216+
connection.execute(
217+
sql,
218+
function(err, result) {
219+
should.not.exist(err);
220+
var outNum = result.rows[0][0];
221+
should.strictEqual(outNum, expected);
222+
done();
223+
}
224+
);
225+
});
226+
227+
it('26.4.3 minimum safe integer', function(done) {
228+
229+
var num = -9007199254740992;
230+
var sql = "select " + num + " from dual";
231+
connection.execute(
232+
sql,
233+
function(err, result) {
234+
should.not.exist(err);
235+
should.strictEqual(
236+
result.rows[0][0],
237+
num
238+
);
239+
done();
240+
}
241+
);
242+
});
243+
244+
it('26.4.4 Negative - minimum safe integer - 1', function(done) {
245+
var actual = '-9007199254740993';
246+
var expected = -9007199254740992;
247+
248+
var sql = "SELECT TO_NUMBER( " + actual + " ) FROM DUAL";
249+
connection.execute(
250+
sql,
251+
function(err, result) {
252+
should.not.exist(err);
253+
var outNum = result.rows[0][0];
254+
should.strictEqual(outNum, expected);
255+
done();
256+
}
257+
);
258+
});
259+
260+
it('26.4.5 gets correct number via fetching as string', function(done) {
261+
var num = '-9007199254740993';
262+
263+
var sql = "SELECT TO_NUMBER( " + num + " ) AS TS_NUM FROM DUAL";
264+
connection.execute(
265+
sql,
266+
[],
267+
{
268+
fetchInfo : { "TS_NUM" : { type : oracledb.STRING } }
269+
},
270+
function(err, result) {
271+
should.not.exist(err);
272+
var got = result.rows[0][0];
273+
should.strictEqual(got, num);
274+
done();
275+
}
276+
);
277+
});
278+
279+
}); // 26.4
280+
281+
});

test/list.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,14 @@ Overview of node-oracledb functional tests
539539
26.1.5 columns fetched from REF CURSORS can be mapped by oracledb.fetchAsString
540540
26.2 stores null value correctly
541541
26.2.1 testing Null, Empty string and Undefined
542+
26.3 large integers that cannot fit inside a 32-bit integer
543+
26.3.1 original case
544+
26.4 Large number, edge cases
545+
26.4.1 maximum safe integer, (2^53 - 1)
546+
26.4.2 Negative - maximum safe integer + 1
547+
26.4.3 minimum safe integer
548+
26.4.4 Negative - minimum safe integer - 1
549+
26.4.5 gets correct number via fetching as string
542550

543551
27. dataTypeNumber2.js
544552
27.1 testing NUMBER(p, s) data

0 commit comments

Comments
 (0)