Page 1 of 1

SQLITE CREATE DATABASE DBEXPRESS

Posted: Wed 10 Sep 2014 08:35
by MrAndini
Hello

I am using SQLITE with DBExpress under C++ builder XE4 and I cannot get the connection to create a database file if the file exists.

Code: Select all

		
TSQLConnection * SQLConnection;

// Devart SQL Lite Direct connection
SQLConnection->ConnectionName = "Devart SQLite Direct";
SQLConnection->DriverName     = "DevartSQLiteDirect";
SQLConnection->GetDriverFunc  = "getSQLDriverSQLiteDirect";
SQLConnection->LibraryName    = "dbexpsqlite40.dll";
SQLConnection->LoginPrompt    = false;
SQLConnection->Params->BeginUpdate();
SQLConnection->Params->Clear();
SQLConnection->Params->Add("DataBase=" + DatabaseFilename);
SQLConnection->Params->Add("FailIfMissing=False");
SQLConnection->Params->EndUpdate();
SQLConnection->ParamsLoaded = true;
SQLConnection->Connected = true;
I get a file is missing exception when I try to open the database.
If I connect to an already existing database then that works fine.
I would like the open to create an empty database file if there isn't one already

There are examples on her for the LiteDAC which specify setting the Options, these don't exist for the DBExpress connection.

Re: SQLITE CREATE DATABASE DBEXPRESS

Posted: Wed 10 Sep 2014 09:41
by AlexP
Hello,

To create a new DB, you should set theForceCreateDatabase param to True (SQLConnection1.Params.Add('ForceCreateDatabase=true') ), and specify the new DB file in the DataBase param. When opening connection, a database will be created automatically.