A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nodejs/node/commit/8664b9ad60 below:

disallow unsafe integer coercion in SQLite · nodejs/node@8664b9a · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+29

-4

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+29

-4

lines changed Original file line number Diff line number Diff line change

@@ -370,12 +370,21 @@ bool StatementSync::BindValue(const Local<Value>& value, const int index) {

370 370 371 371

Local<Value> StatementSync::ColumnToValue(const int column) {

372 372

switch (sqlite3_column_type(statement_, column)) {

373 -

case SQLITE_INTEGER:

373 +

case SQLITE_INTEGER: {

374 +

sqlite3_int64 value = sqlite3_column_int64(statement_, column);

374 375

if (use_big_ints_) {

375 -

return BigInt::New(env()->isolate(),

376 -

sqlite3_column_int64(statement_, column));

376 +

return BigInt::New(env()->isolate(), value);

377 +

} else if (std::abs(value) <= kMaxSafeJsInteger) {

378 +

return Number::New(env()->isolate(), value);

379 +

} else {

380 +

THROW_ERR_OUT_OF_RANGE(env()->isolate(),

381 +

"The value of column %d is too large to be "

382 +

"represented as a JavaScript number: %" PRId64,

383 +

column,

384 +

value);

385 +

return Local<Value>();

377 386

}

378 -

// Fall through.

387 +

}

379 388

case SQLITE_FLOAT:

380 389

return Number::New(env()->isolate(),

381 390

sqlite3_column_double(statement_, column));

Original file line number Diff line number Diff line change

@@ -388,6 +388,22 @@ suite('StatementSync.prototype.setReadBigInts()', () => {

388 388

message: /The "readBigInts" argument must be a boolean/,

389 389

});

390 390

});

391 + 392 +

test('BigInt is required for reading large integers', (t) => {

393 +

const db = new DatabaseSync(nextDb());

394 +

const bad = db.prepare(`SELECT ${Number.MAX_SAFE_INTEGER} + 1`);

395 +

t.assert.throws(() => {

396 +

bad.get();

397 +

}, {

398 +

code: 'ERR_OUT_OF_RANGE',

399 +

message: /^The value of column 0 is too large.*: 9007199254740992$/,

400 +

});

401 +

const good = db.prepare(`SELECT ${Number.MAX_SAFE_INTEGER} + 1`);

402 +

good.setReadBigInts(true);

403 +

t.assert.deepStrictEqual(good.get(), {

404 +

[`${Number.MAX_SAFE_INTEGER} + 1`]: 2n ** 53n,

405 +

});

406 +

});

391 407

});

392 408 393 409

suite('StatementSync.prototype.setAllowBareNamedParameters()', () => {

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4