Skip to content

Commit

Permalink
[bun:sqlite] fix truncating to int32 in results (now truncates to int52)
Browse files Browse the repository at this point in the history
TODO: bigint
  • Loading branch information
Jarred-Sumner committed Nov 22, 2022
1 parent a251669 commit ce6fc86
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/bun.js/bindings/sqlite/JSSQLStatement.cpp
Expand Up @@ -992,14 +992,19 @@ static inline JSC::JSValue constructResultObject(JSC::JSGlobalObject* lexicalGlo

switch (sqlite3_column_type(stmt, i)) {
case SQLITE_INTEGER: {
result->putDirect(vm, name, jsNumber(sqlite3_column_int(stmt, i)), 0);
// https://github.com/oven-sh/bun/issues/1536
result->putDirect(vm, name, jsNumber(sqlite3_column_int64(stmt, i)), 0);
break;
}
case SQLITE_FLOAT: {
result->putDirect(vm, name, jsNumber(sqlite3_column_double(stmt, i)), 0);
break;
}
case SQLITE_TEXT: {
// > Note that the SQLITE_TEXT constant was also used in SQLite version
// > 2 for a completely different meaning. Software that links against
// > both SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT,
// > not SQLITE_TEXT.
case SQLITE3_TEXT: {
size_t len = sqlite3_column_bytes(stmt, i);
const unsigned char* text = len > 0 ? sqlite3_column_text(stmt, i) : nullptr;

Expand Down Expand Up @@ -1042,13 +1047,18 @@ static inline JSC::JSArray* constructResultRow(JSC::JSGlobalObject* lexicalGloba

switch (sqlite3_column_type(stmt, i)) {
case SQLITE_INTEGER: {
result->initializeIndex(scope, i, jsNumber(sqlite3_column_int(stmt, i)));
// https://github.com/oven-sh/bun/issues/1536
result->initializeIndex(scope, i, jsNumber(sqlite3_column_int64(stmt, i)));
break;
}
case SQLITE_FLOAT: {
result->initializeIndex(scope, i, jsNumber(sqlite3_column_double(stmt, i)));
break;
}
// > Note that the SQLITE_TEXT constant was also used in SQLite version
// > 2 for a completely different meaning. Software that links against
// > both SQLite version 2 and SQLite version 3 should use SQLITE3_TEXT,
// > not SQLITE_TEXT.
case SQLITE_TEXT: {
size_t len = sqlite3_column_bytes(stmt, i);
const unsigned char* text = len > 0 ? sqlite3_column_text(stmt, i) : nullptr;
Expand Down

0 comments on commit ce6fc86

Please sign in to comment.