iOS: `get()` and `getArray()` always throw on iOS: the result set is read before `next()`
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 88/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- ios, sqlite, typescript
Rechercherichtung
Beginne in src/sqlite/sqlite.ios.ts bei getRaw(), und vergleiche dann dessen Resultset-Behandlung mit selectRaw() und den Hilfsfunktionen getResultsAsObject()/getResultsAsArray(). Überprüfe die iOS-Reproduktion sowohl für get() als auch für getArray(), einschließlich eines leeren Ergebnisses, und bestätige, dass die erste Zeile zurückgegeben wird, während bei keiner Zeile null ohne den TypeError zurückgegeben wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Environment
@nativescript-community/sqlite |
3.5.9 (latest) |
@nativescript/core |
9.1.2 |
@nativescript/ios |
9.1.0 |
| NativeScript CLI | 9.1.1 |
| Xcode | 26.3 |
| Device | iPhone 16 Pro simulator, iOS 18.6 |
Android (@nativescript/android 9.1.1) is unaffected - the same code path works there.
What happens
Every call to db.get() or db.getArray() rejects, no matter what the query is or whether it matches any row:
NSqlite Error: TypeError: Cannot read properties of null (reading 'enumerateKeysAndObjectsUsingBlock')
at throwError (node_modules/@nativescript-community/sqlite/sqlite.common.js:72)
Minimal reproduction
import { openOrCreate } from '@nativescript-community/sqlite';
import { knownFolders, path } from '@nativescript/core';
const db = openOrCreate(path.join(knownFolders.documents().path, 'repro.sqlite'));
await db.execute('CREATE TABLE IF NOT EXISTS t (a INTEGER)');
await db.execute('INSERT INTO t (a) VALUES (1)');
await db.select('SELECT a FROM t'); // [{ a: 1 }]
await db.get('SELECT a FROM t'); // throws
Cause
getRaw() in src/sqlite/sqlite.ios.ts hands the fresh FMResultSet straight to getResultsAsObject() / getResultsAsArray() (links below are to the v3.5.9 tag):
and those read resultDictionary right away:
FMDB's resultDictionary describes the row the result set currently sits on, and a result set that has never been stepped sits on no row, so it returns nil - hence the TypeError on null. selectRaw() in the same file gets this right, which is why select() works and get() does not:
Suggested fix
Step onto the first row, and report "no row" rather than an empty object:
function getRaw(db: SQLiteDatabase, query: string, params: SqliteParams, asObject: boolean, options?: SqliteRequestOptions): SqliteRow | SqliteParam[] {
const s = db.db.executeQueryWithArgumentsInArray(query, paramsToStringArray(params));
if (!s) {
throw db.db.lastError();
}
if (!s.next()) {
s.close();
return null;
}
const transformBlobs = options?.transformBlobs ?? db.transformBlobs;
const row = asObject ? getResultsAsObject(s, transformBlobs) : getResultsAsArray(s, transformBlobs);
s.close();
return row;
}
get() and getArray() already coerce a falsy result to null, so the signature does not change.
Workaround
Read single rows through select() and take the first element:
const rows = await db.select(query, params);
const row = rows[0] || null;
PR
I'm happy to open a pull request with the fix above (getRaw() in src/sqlite/sqlite.ios.ts)
- Vorherrschende Sprache
- TypeScript
- Sterne
- 26
- Forks
- 4
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nativescript-community/sqlite
-
v6Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
Alle Issues in nativescript-community/sqlite
Ähnliche Issues
-
bug via-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
pingdotgg/t3code#14452 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
solana-foundation/program-examples#747 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 9 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
remotion-dev/remotion#11847 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
openwatersio/slackwater#355 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
melgarafael/DeskcommCRM#1998 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag