Interested in improving this site? Please check the To Do page.
sqlite.open
Opens (or creates) an SQLite database file.
Syntax
sqlite.open(dbfile)
Params
dbfile is a file path to the database file. If the file does not exist, sqlite.open will create it. Mac users: see the Notes section below.
Returns
A value that corresponds to the opened database ID.
Examples
on createDatabase () {
local (db);
db = sqlite.open("C:\\temp\\testdatabase.db3");
sqlite.close(db)}
sqlite.open will either open or create a database. If you want to make sure that you’re only creating a database (with an error if the database file already exists), here’s how you might implement that:
// only create the database if the file does not exist
if file.exists(filespec) {
return false};
return sqlite.open(filespec)
By contrast, if you only want to allow sqlite.open to open a database, but return an error if the file does not exist, here’s how that might work:
// return false if the database doesn't exist
if not (file.exists(filespec)) {
return false};
return sqlite.open(filespec)
Notes
Most likely, you should call sqlite.open within a try statement. If the open fails, a scriptError will be triggered.
The Frontier implementation of the SQLite wrapper works on OSX as well as Windows, but the Mac implementation is a bit convoluted. SQLite requires POSIX-based filenames passed to sqlite.open, so you’re likely to have to do some string conversion to make it work.
Warnings
Be careful if you’re a Mac user. We haven’t yet pulled together enough information to give you step-by-step usage instructions here, so be sure to back up your work before testing this verb on a Mac. Improperly formed file references on the Mac will crash the program.