SQLITE CREATE DATABASE DBEXPRESS

SQLITE CREATE DATABASE DBEXPRESS

Postby MrAndini » Wed 10 Sep 2014 08:35

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.
MrAndini
 
Posts: 19
Joined: Mon 07 Oct 2013 11:18

Re: SQLITE CREATE DATABASE DBEXPRESS

Postby AlexP » Wed 10 Sep 2014 09:41

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.
AlexP
Devart Team
 
Posts: 5528
Joined: Tue 10 Aug 2010 11:35


Return to dbExpress driver for SQLite