Skip to content

TSQLite3DatabaseConnection

Ivan Semenkov edited this page Jan 31, 2021 · 2 revisions

Table of contents

About

TSQLite3DatabaseConnection class encapsulates the connection to SQLite3 database.

uses
  sqlite3.connection;
  
type  
  TSQLite3DatabaseConnection = class

Create

A new database connection can be created by call its constructor.

constructor Create (AErrorsStack : PSQL3LiteErrorsStack; AHandle : 
  ppsqlite3; AFilename : String; AFlags : TConnectFlags);

AErrorsStack is a pointer to SQLite3ErrorsStack class.

AHandle is a pointer to SQLite3 database handle.

AFlags is a additional database connection flags.

Example
uses
  libpassqlite, sqlite3.errors_stack, sqlite3.connection;
  
var
  errors : TSQLite3ErrorsStack;
  handle : psqlite3;
  connection : TSQLite3DatabaseConnection;
  
begin
  errors := TSQLite3ErrorsStack.Create;
  connection := TSQLite3DatabaseConnection.Create(@errors, @handle, 'database', 
    [SQLITE_OPEN_CREATE, SQLITE_OPEN_READWRITE]);
    
  FreeAndNil(connection);
  FreeAndNil(errors);
end;

Connection flags

Additional parameters for control over the new database connection.

TConnectFlags = set of TConnectFlag;
TConnectFlag = (
SQLITE_OPEN_READONLY

The database is opened in read-only mode.

SQLITE_OPEN_READONLY,
SQLITE_OPEN_CREATE

The database is created if it does not already exist.

SQLITE_OPEN_CREATE,
SQLITE_OPEN_READWRITE

The database is opened for reading and writing if possible, or reading only if the file is write protected by the operating system.

SQLITE_OPEN_READWRITE,
SQLITE_OPEN_URI

The filename can be interpreted as a URI if this flag is set.

SQLITE_OPEN_URI,
SQLITE_OPEN_MEMORY

The database will be opened as an in-memory database.

SQLITE_OPEN_MEMORY,
SQLITE_OPEN_NOMUTEX

The new database connection will use the "multi-thread" threading mode. This means that separate threads are allowed to use SQLite at the same time, as long as each thread is using a different database connection.

SQLITE_OPEN_NOMUTEX,
SQLITE_OPEN_FULLMUTEX

The new database connection will use the "serialized" threading mode. This means the multiple threads can safely attempt to use the same database connection at the same time. (Mutexes will block any actual concurrency, but in this mode there is no harm in trying.)

SQLITE_OPEN_FULLMUTEX,
SQLITE_OPEN_SHAREDCACHE

The database is opened shared cache enabled.

SQLITE_OPEN_SHAREDCACHE,
SQLITE_OPEN_PRIVATECACHE

The database is opened shared cache disabled.

SQLITE_OPEN_PRIVATECACHE,
SQLITE_OPEN_NOFOLLOW

The database filename is not allowed to be a symbolic link.

SQLITE_OPEN_NOFOLLOW
);