Comments (5)
Dear Gwendal,
This morning my app crashes at startup, please find Crash Report attached.
If I take the code and run from Xcode, it will not crash.
This has to do with the same PatientTimeLine function that has the NULL value issues.
Hope this helps.
Regards, André Hartman
Crash Report.txt
from grdb.swift.
🎁 Thank you very much @ahartman,
This sample project and data indeed reveals a bug in GRDB. This bug prevents a normal error to be reported to your app. Next version will fix this.
Until then, I commented out the assertion, and the error is now correctly reported to your app (caught in DBModel.getPatientTimeline()
):
could not decode Date from database value NULL
column: "minVisitVisitCreated"
column index: 2
row: [id:2289 patientName:"Aaliyah" minVisitVisitCreated:NULL maxVisitVisitDate:NULL]
sql: SELECT
"patient"."id", "patient"."patientName",
MIN("visit"."visitCreated") AS "minVisitVisitCreated",
MAX("visit"."visitDate") AS "maxVisitVisitDate"
FROM "patient"
LEFT JOIN "visit"
ON ("visit"."patientId" = "patient"."id")
AND ("visit"."visitCalendar" IN (?, ?)) AND ("visit"."visitCalendar" IN (?, ?))
GROUP BY "patient"."id"
ORDER BY "patient"."patientName"
arguments: ["Marieke", "Marieke nieuwe", "Marieke", "Marieke nieuwe"]
So the database contains NULL in the minVisitVisitCreated
column. This can happen when MIN("visit"."visitCreated")
is NULL (if there is no filtered visit, for example).
This NULL value is decoded into PatientTimelineInfo
, which has non-null dates:
struct PatientTimelineInfo: Decodable, FetchableRecord {
var patient: PatientInfo.Patient
var minVisitVisitCreated: Date
var maxVisitVisitDate: Date
}
The fix (in your app) is to modify PatientTimelineInfo
so that its dates are optional:
struct PatientTimelineInfo: Decodable, FetchableRecord {
var patient: PatientInfo.Patient
var minVisitVisitCreated: Date? // nil when there is no visit
var maxVisitVisitDate: Date? // nil when there is no visit
}
I'll take care of the bug in GRDB that prevented the correct error to be reported in the first place. 👍
from grdb.swift.
from grdb.swift.
Oh, yes, thanks for reminding me about this.
So I restored the .having(filteredVisits.isEmpty == false)
line.
It runs correctly.
The SQL looks valid, if not ideal (note the repetition of the "visit"."visitCalendar" IN (?, ?)
condition, which is superfluous):
SELECT
"patient"."id", "patient"."patientName",
MIN("visit"."visitCreated") AS "minVisitVisitCreated",
MAX("visit"."visitDate") AS "maxVisitVisitDate"
FROM "patient"
LEFT JOIN "visit"
ON ("visit"."patientId" = "patient"."id")
AND ("visit"."visitCalendar" IN (?, ?))
AND ("visit"."visitCalendar" IN (?, ?))
AND ("visit"."visitCalendar" IN (?, ?))
GROUP BY "patient"."id"
HAVING COUNT(DISTINCT "visit"."rowid") > 0
ORDER BY "patient"."patientName"
Would you please remind me what prevents you from restoring the having clause? Now that I have a running app, it's easier to reproduce!
from grdb.swift.
from grdb.swift.
Related Issues (20)
- Request: Add citation to the repo HOT 3
- Cocoapods hasn't published since 6.24.1 HOT 2
- Cocoapods 6.26.0 release is not available in Cocapods Specs repo HOT 1
- Privacy Manifest: Entry missing for accessing file timestamps via creationDate API HOT 4
- When transaction updating multiple records in the database, if one of the records does not exist, it leads to update failure. HOT 4
- Avoid conflict with other SPM packages by renaming the CSQLite SPM target
- ValueObservation.tracking called on the updating thread HOT 5
- GRDB does not seem to copy over all rows when inserting within a migration HOT 4
- Unable to decode database NULL value as Swift nil value of type Int? when using ScopeAdapter built from splittingRowAdapters HOT 13
- PlayerRequest.swift is identical in GRDBAsyncDemo and GRDBCombineDemo HOT 4
- App crashes with many (not all) users running iOS 17.4.1 HOT 8
- Library fails to compile when targeting Linux using a SQLite library that doesn't support snapshots HOT 3
- 0xdead10cc prevention — `checkForSuspensionViolation` on every `Statement.step` HOT 6
- Weird db read issue HOT 7
- Error for query count grouped HOT 4
- GRDB 6 missing DatabasePool/DatabaseQueue interchangeability HOT 3
- Thread running at User-initiated quality-of-service class waiting on a thread without a QoS class specified (base priority 0). Investigate ways to avoid priority inversions HOT 1
- [best practices] How can insert a same type of record into 2 tables HOT 8
- Using experimental CTE
- How to store database connection HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grdb.swift.