From Xojo Documentation

Revision as of 19:08, 27 January 2022 by Gperlman (talk | contribs) (Example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

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.


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
db.AddDatabase(f, "CompanyDatabase", "mylongpassword")
Catch error As IOException
MessageBox("The database could not be attached.")
End Try


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

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

currentDB.AddDatabase(AddDBFile, "locations", "myverylongpassword") // 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