iOS and SQLite

If this should go to the iOS channel please let me know and I will repost. It’s just that this is such a basic question.

Working on 1st iOS app - actually a redesign of existing desktop app for iPad. It requires a single SQLite database. But the database already exists so I don’t need to create the file as the iOS example project demonstrates. But I obviously need to connect to it.

To start out, I created an empty folder in my development area and placed a copy of the SQLite database in the new folder. I created a new iOS project and saved it to the same folder. Same way I work with desktop apps.

Now I think this is really a SCOPE question as much as anything. In the “App” object, inside the “OPEN” event handler, I placed the following code:

Dim dbFile As FolderItem = SpecialFolder.Documents.Child("Masons.sqlite")
  dbSQL = New iOSSQLiteDatabase
  dbSQL.DatabaseFile = dbFile
    If dbSQL.Connect() then
      bConnected = True
      lblDatabaseStatus.Text = "Created."
    End If
  Catch e As iOSSQLiteException
    bonnected = False
    lblDatabaseStatus.Text = "Error: " + e.Reason
  End Try

On “View1”, I placed a label and named it “lblDatabaseStatus” and made it PUBLIC. At this point there is nothing else in the project except what was created by starting a new project. I get a compile error that says lblDatabaseStatus.text doesn’t exist. By the way, the above code was copied from the example project with just minor changes.

To recap: dbSQL database file is PUBLIC iOSSQLiteDatabase property of the App object. bConnected is a PUBLIC BOOLEAN property of the App object. lblDatabaseStatus is a PUBLIC iOSLabel property of the View1 object.

The end project is going to have several “Views”, so the database object needs to be global.

Please help me get a basic start on this…

thanks in advance.

I moved everything from the App object to the View1 object and it compiled ok but got an error that said it was unable to open the database. That doesn’t tell me much.

move it all to a public module… that should relieve any “scope” issues.

Also is it “encyrpted”? I believe that iOS and Desktop versions encrypt differently , but I might be wrong

I don’t see anywhere in your description that you’ve copied your database to SpecialFolder.Documents. Did you step through the debugger? Does dbFile.Exists = True?

I suspect you’ll want to use a Copy Files Build Step to copy the DB to the App bundle resources. Then you’ll need to copy it from there to SpecialFolder.Documents when your app starts.

More information:

OK I followed the doc at “Copying Files to Device” and the Database now opens.

So, thanks so much guys. Off to the next step.