iOS: `get()` and `getArray()` always throw on iOS: the result set is read before `next()`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 88/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- ios, sqlite, typescript
Línea de trabajo
Empieza en src/sqlite/sqlite.ios.ts, en getRaw(), y compara después su gestión del conjunto de resultados con selectRaw() y los helpers getResultsAsObject()/getResultsAsArray(). Verifica la reproducción en iOS tanto para get() como para getArray(), incluido un resultado vacío, y confirma que se devuelve la primera fila, mientras que cuando no hay ninguna fila se devuelve null sin el TypeError.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
- Lenguaje dominante
- TypeScript
- Estrellas
- 26
- Forks
- 4
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nativescript-community/sqlite
-
v6Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
Todos los issues de nativescript-community/sqlite
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/vscode-livepreview#876 ·
Los mantenedores suelen responder en 1 día
-
needs-triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
JustJarethB/invoicer#54 ·
-
ICP 1.2.0 shows a scheduled task's interval in milliseconds under the label "Interval (In seconds)"AbiertoNeeds Triage Type/Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
wso2/product-integrator#2585 ·
Los mantenedores suelen responder en 1 día
-
Add: Telemundo West sdAbiertocheck:passed streams:add
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
design
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
MTES-MCT/monitor-field#119 ·
Los mantenedores suelen responder en 1 día