I have a normal SQL query to return * from an existing table in an SQLiteDatabase. I know the table exists. It’s returned in the DB schema and it’s supposed to contain millions of records.
The query to select * from this table returns a Nil recordset. Everything I’ve read on the forum and elsewhere says that only happens when the query is malformed. But the query isn’t malformed. And, everyone says when the result is Nil, the database will throw an error. But the DB doesn’t throw an error.
The table exists, but I get a Nil recordset, and there is no error in the database.
Anyone have an idea what’s going on or what steps I should take to find out?
Thanks to your help, I’ve just found the cause of the problem.
It appears that the DB most likely was returning an error, and the problem was that the error dialog was not being shown because it was being triggered by a timer which went out of scope before firing. A real “forehead slapper” !
Well, that was part of the problem, but I just got the report back from the client, and it’s basically what I said before …
Here’s what we know:
the logs show the table was successfully added to the DB without error
we know the table exists, it’s returned in the schema
checking the record count(*) of the table shows the correct number of records are there
when attempting to load the table for display, the recordset is Nil, and DB.Error is true (this is API 1.0), but the error code is 0 (zero) = not an error.
I suppose that could reveal whether some column contains corrupted data, but I wonder what would that be? There are VARCHAR columns which are being fed memoryblock bytes. So far that has not caused any problems, but maybe there is a case where that could cause a problem?
Thanks for helping my (shrinking?) brain to work. I do need to sleep now but will return to this in the morning.
I presume you’re not using SQL reserved words as column names, if so you can get around it by wrapping each column name in ``s. As in Select col1, col2, col3 FROM myTable.
Is there another app you can run the SQL statement in. I’m thinking of something like MySQL workbench or MS SQL query analyser?
Currently we don’t use “DB.Error”. On error an exception arises and we just intercept it, the message says what is going on. Interestingly, many times the error code is 0.
Okay, so this is one of those cases. I did see the Try … Catch in the docs but as I mentioned, the app is API 1.0. Especially since I read about trouble with databases and API 2.0 I’m not changing any database code to API 2.0, but I could write a little test in a button or something just to see if it behaves differently.
Good idea, I’ll try that.
I would have, but the DB is many GB and the client has no way to send it.
The project is under NDA, so although I can discuss generic issues publicly like this, I can’t share any of the details about what it actually is.
Right. There is an error (DB.Error = true) and the error code is set, to 0 (zero) which means “not an error”. And Rick mentioned that this can happen, but didn’t say why (and my guess is nobody knows).