Closed pawlowskim closed 2 years ago
Hello, I haven't seen similar behavior on my 3+ year experience using this library. It's possible that your app logic has a bug and sends the wrong milliseconds. Have you logged that? Double check your DELETEs on that table as well if you have any.
There is another possible source of bugs. SUM(col) of a column that can contain NULL will return NULL if any of the values is NULL. So your "?? 0" logic would apply in this situation. You can do SUM(COALESCE(steps, 0)) to treat NULL rows as 0 or extend the WHERE clause to filter NULLs with "steps IS NOT NULL"
We are using this library for about 6-9 months so far, and didn't noticed such behaviour yet.
millisecondsSinceEpoch
so it's also not the case (but I will add additional logging to be sure in the future).Any other ideas?
Thanks for quick response.
@pawlowskim Unfortunately I cannot help you without a way to reproduce the issue. Is not very probable this is a bug in the library as it simply calls the native SQLCipher implementations for Android and iOS. I would double check your where conditions, which if they are incorrect it will return 0 steps.
Do you know maybe what kind of values could trigger the query to return 0? I couldn't dig into it from native implementation for iOS. And since nulls inserted to the database works as expected (rows are omitted, not returns a 0 as a output from the query) I don't have any idea what to check.
@pawlowskim The only values that could trigger a 0 from your code snippet would be
You may want to include extra logging in your app when you reach a 0 value, like:
if (steps == 0) {
// Assert no rows with the where condition
// Run "SELECT COUNT(*) as num_rows from $STEPS_TABLE_NAME WHERE userId = ? AND timestamp >= ?"
// Check that the number of rows is actually 0, otherwise there is a bug somewhere
}
Hello, we occurred a bug in our production application. Basically we are gathering users steps, and storing it in local database. In some part of the application we have such piece of code
It works in general. But last days, we faced a problem that this query stopped working at runtime. We are executing it each time we got an event about new steps. From logs that user sent we found out, that this query returned correct value, and 3 seconds later it started returning 0, until user restarted the application.
No errors occurred meantime, connection was still on. This last for some time, meantime we were writing records to the same database, so even if data was somehow deleted (unlikely) it should return new entered data, but it didn't.
My questions are: