Crash with DatabaseRow on iOS

I’m following an example on RowSet and DatabaseRow from here:
https://documentation.xojo.com/topics/databases/adding-_updating_and_deleting_rows.html

I am getting a crash on Line 60, at: For Each Row As DatabaseRow in results

What is the obvious thing that I am missing here? Why does it crash?

If you open the SQLite Database in a DB editor and use the same select statement, do you get results?

The crash is on the DatabaseRow.constructor so it may be a data type that Xojo can’t read/convert.
Try narrowing the SQL select statement to only one column at first, and adding columns until it crashes.

1 Like

Seems like an internal thing… ?
Is there any datetime(.fromString) being used in your code?

1 Like

I suspect there is a column that contains date values.
The values must be in a format that is not compatible with the DatabaseRow constructor.

1 Like

Is ‘DatabaseRow’ a reserved variable? Just wondering…

DatabaseRow seems to be used as the datatype as it should …

You’re right, I was confusing its placement with ‘Row’…

Thank you guys! I have removed any select of date fields from the query and now the code works.

So now I will investigate further into the issues with date-fields.

I am making use of MBS CubeSQL libraries and maybe it is related to this library:

Call InternalCubeSQLLibraryMBS.Use
db = New SQLDatabaseMBS

Interesting: I have to wrap the SQL query for datefields into date and datetime functions:

sql  = "Select " _
+ "DateTime(DateCreated) As 'Created',  " _
+ "DateTime(DateUpdated) As 'Updated', " _
+ "Date(Birthdate) As 'Birthdate' " _
+ "FROM addresses "

otherwise, this line would crash:

For Each Row As DatabaseRow in results

In the sqlite database, the field definitions are like this:

DateUpdated timestamp
DateCreated timestamp
Birthdate date

I’ve never ever read anything about doing that…
https://www.sqlite.org/lang_datefunc.html
So this is sqlite specific.

The datetime() function returns the date and time as text in their same formats: YYYY-MM-DD HH:MM:SS.

That’s the format that DateTime.FromString() expects when the locale is not specified.