-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sqlite] Fix iOS crash on int overflow #25322
[sqlite] Fix iOS crash on int overflow #25322
Conversation
thanks @peterferguson for the fix. we actually have a backlog to support BigInt and i think that's a better solution. let me clarify whether i can add BigInt support soon. otherwise i will merge the fix from you. does that sound good to you? |
Perfect that is much better 👍 |
hey @peterferguson! i just remembered that BigInt is still not supported on JSCRuntime. we may need more time to design a proper compatible API for BigInt. so we may better to resolve the crash first. at least to support support integer lower than diff --git a/apps/test-suite/tests/SQLiteNext.ts b/apps/test-suite/tests/SQLiteNext.ts
index cfe0d3ae8c..18fc06337b 100644
--- a/apps/test-suite/tests/SQLiteNext.ts
+++ b/apps/test-suite/tests/SQLiteNext.ts
@@ -48,6 +48,18 @@ CREATE TABLE IF NOT EXISTS Users (user_id INTEGER PRIMARY KEY NOT NULL, name VAR
await db.closeAsync();
});
+ it('should support bigger integers than int32_t', async () => {
+ const db = await SQLite.openDatabaseAsync(':memory:');
+ const value = 1700007974511;
+ const row = await db.getAsync<{ value: number }>(`SELECT ${value} as value`);
+ expect(row['value']).toBe(value);
+ const row2 = await db.getAsync<{ value: number }>('SELECT $value as value', {
+ $value: value,
+ });
+ expect(row2['value']).toBe(value);
+ await db.closeAsync();
+ });
+
it('should support PRAGMA statements', async () => {
const db = await SQLite.openDatabaseAsync(':memory:');
await db.execAsync(`
diff --git a/packages/expo-sqlite/ios/SQLiteModuleNext.swift b/packages/expo-sqlite/ios/SQLiteModuleNext.swift
index ea77177b10..ff43231acd 100644
--- a/packages/expo-sqlite/ios/SQLiteModuleNext.swift
+++ b/packages/expo-sqlite/ios/SQLiteModuleNext.swift
@@ -432,7 +432,7 @@ public final class SQLiteModuleNext: Module {
switch type {
case SQLITE_INTEGER:
- return sqlite3_column_int(instance, index)
+ return sqlite3_column_int64(instance, index)
case SQLITE_FLOAT:
return sqlite3_column_double(instance, index)
case SQLITE_TEXT:
@@ -460,8 +460,8 @@ public final class SQLiteModuleNext: Module {
sqlite3_bind_null(instance, index)
case _ as NSNull:
sqlite3_bind_null(instance, index)
- case let param as Int:
- sqlite3_bind_int(instance, index, Int32(param))
+ case let param as Int64:
+ sqlite3_bind_int64(instance, index, Int64(param))
case let param as Double:
sqlite3_bind_double(instance, index, param)
case let param as String:
|
@Kudo Just added the patch code and removed the other test I had written 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks much @peterferguson for your help 🔥
Fixes #25321 by adding a guard in
bindStatementParam