SQLiteDatabase.AddDatabase

From Xojo Documentation

Method

SQLiteDatabase.AddDatabase(file As FolderItem, databaseName As String[, password As String])

New in 2019r2

Supported for all project types and targets.


Adds the SQLite database referred to by file to the database object and names it databaseName.

Notes

When a database has been added, it is possible to do cross-database queries. In order to add an encrypted database, you must pass the correct password for the database to be attached.

You should prefix all SQL queries to tables in the added database with the databaseName.

If the database cannot be added, an IOException occurs.

Var f As FolderItem = SpecialFolder.Desktop.Child("MyDatabase")
Var db As New SQLiteDatabase
Try
db.AddDatabase(f, "CompanyDatabase", "mylongpassword")
Catch error As IOException
MessageBox("The database could not be attached."
End Try

Example

This example adds a database file to an existing, connected database, currentDB:

Var addDBFile As New FolderItem("AddDB.sqlite")

Try
currentDB.AddDatabase(AddDBFile, "locations") // currentDB is already connected elsewhere
MessageBox("Database attached.")
// Queries against the added database would be prefixed with "locations", such as
// SELECT City FROM locations.Addresses WHERE ST = 'TX'
Catch error As IOException
MessageBox("The database could not be added.")
End Try