Crash on db.connect

Things work fine in simulator.

When I attempt to run on an iPad it crashes when I attempt to connect to the database. I have nifty crash logs.

Of possible note: the database was copied from the computer to the documents folder using iMazing.

Any clues? Should I post the log?

-Bob

  • is it an SQLite database?
  • are you referencing it in the Documents folder?
  • do you have any error checking?
  • post the snippet of code where you connect

did you know you can put things in the Documents folder of your app with iTunes as well… you just need to add a line to the plist.info file to activate file sharing

It is an SQLite database.
It is in the documents folder.
The connect method does not throw an error (according to the docs).
Snippet:
if f1.Exists then
dbg.trace(“assigning file”)
self.db.DatabaseFile = f1
dbg.trace(" assigned")
if db.connect then
dbg.trace(“connected”)
ok = true
end
end

The dbg.trace() calls write to a log. I see " assigned." I do not see “connected.”

I would not expect a crash. I would expect the result to be false.

Thanks for the rapid response.

the connect could fail because of a non-db file, a corrupt file etc.

If DB.databaseFile.exists=True Then

I agree it could fail. If it fails I would expect it to return false not go boom.

I’m going to verify that I can open the file as a database.

Problem solved. Was bad file (it appears to have been an alias).

Thanks for helping me focus.

I still think it shouldn’t crash.

Hmmm… I use code like this… and it detects attempts to open a non-DB.

  If DB.databaseFile.exists=True Then //<==== You don't have this
    If DB.Connect=False Then
      x=db.ErrorCode
      If x=21 Or x=26 Then' File is encrypted or is not a database

An alias is just a pointer to a file. If the file does not exist, it is quite normal that the program crashes with a nil exception.

You may want to add a try catch to prevent a crash if the user copies an alias as you did, or verify with http://developer.xojo.com/xojo-io-folderitem$IsAlias before trying to open.

Even though this issue has been solved. I was curious as to what was going on.

I put my bad database where it could be opened when running on the simulator. Same problem (which was expected)… So, I wrapped the db.connect() method in try…catch. It still crashed. That is, I am getting an iosSqlitexception but the try…catch seems not to recognize it.

Is this a bug?

What exception(s) did you specify in the try-catch?