RBSQLiteConnection Class Reference

Inherits from NSObject
Declared in RBSQLiteConnection.h

Overview

A connection to an SQLite database.

  dataFilePath

The filesystem path to the database file.

@property (nonatomic, readonly, nonnull) NSString *dataFilePath

Declared In

RBSQLiteConnection.h

  state

The current state of the database connection.

@property (atomic, readonly) RBSQLiteConnectionState state

Declared In

RBSQLiteConnection.h

– connectToFile:

Opens the connection to the specified database file.

- (BOOL)connectToFile:(nonnull NSString *)target

Parameters

target

The filesystem path to the database file on disk. Create an in memory database by passing in :memory:.

Return Value

true if the connection was opened successfully, false if there was an error.

Declared In

RBSQLiteConnection.h

– connectToFile:withFlags:usingVFS:

Opens the connection to the specified database file using a virtual filesystem.

- (BOOL)connectToFile:(nonnull NSString *)target withFlags:(int)flags usingVFS:(nonnull NSString *)vfs

Parameters

target

The filesystem path to the database file on disk.

flags

One or more sqlite3 connection flags to use when opening the connection.

vfs

The name of the registered virtual filesystem to use.

Return Value

true if the connection was opened successfully, false if there was an error.

Declared In

RBSQLiteConnection.h

– disconnect

Closes the connection to the database.

- (BOOL)disconnect

Return Value

true if the connection was closed successfully.

Declared In

RBSQLiteConnection.h

– execute:bindings:

Executes an SQL query and returns the result set.

- (nullable RBSQLiteResult *)execute:(nonnull NSString *)queryString bindings:(nullable NSArray *)bindings

Parameters

queryString

The SQL query string to execute, where the ‘?’ character denotes a binding.

bindings

The objects to bind respectively to the query string.

Return Value

An RBSQLiteResult object that provides the resulting data for the executed SQL query, or nil if there was an error.

Declared In

RBSQLiteConnection.h

– tableExistsWithName:

Determines whether a table with the given name exists in the database.

- (BOOL)tableExistsWithName:(nonnull NSString *)name

Parameters

name

The name of the table.

Return Value

true if the table exists, false if not.

Declared In

RBSQLiteConnection.h

– schemaFromTableName:

Inspects the table with the given name and creates an RBSQLiteTableSchema object describing it.

- (nullable RBSQLiteTableSchema *)schemaFromTableName:(nonnull NSString *)tableName

Parameters

tableName

The name of the table.

Return Value

The RBSQLiteTableSchema object, or nil if there was an error.

Declared In

RBSQLiteConnection.h

– createOrUpdateTableWithSchema:

Creates a new table, or adjusts an existing table with the same name, using the given RBSQLiteTableSchema.

- (BOOL)createOrUpdateTableWithSchema:(nonnull RBSQLiteTableSchema *)schema

Parameters

schema

The schema that describes the table to create or amend to.

Return Value

true if the table was created or amended successfully and now matches the schema, false if there was an error.

Discussion

Note: This method only adds missing fields, it does not adjust existing fields.

Declared In

RBSQLiteConnection.h

– createTableWithSchema:

Creates a new table using the given RBSQLiteTableSchema.

- (nonnull RBSQLiteResult *)createTableWithSchema:(nonnull RBSQLiteTableSchema *)schema

Parameters

schema

The schema that describes the table to create.

Return Value

An RBSQLiteResult object that provides the information about the executed SQL query.

Declared In

RBSQLiteConnection.h

– updateTableWithSchema:

Adjusts an existing table with the same name to match the given RBSQLiteTableSchema.

- (BOOL)updateTableWithSchema:(nonnull RBSQLiteTableSchema *)schema

Parameters

schema

The schema that describes the table to adjust to.

Return Value

true if the table was updated successfully, false if there was an error.

Discussion

Note: This method only adds missing fields, it does not adjust existing fields.

Declared In

RBSQLiteConnection.h

– addField:toTable:

Adds a new field to a database table.

- (nonnull RBSQLiteResult *)addField:(nonnull RBSQLiteFieldSchema *)field toTable:(nonnull NSString *)tableName

Parameters

field

The schema of the field to add.

tableName

The name of the table to add the new field to.

Return Value

An RBSQLiteResult object that provides the information about the executed SQL query.

Declared In

RBSQLiteConnection.h

  lastInsertedRowId

The primary key of the last inserted row.

@property (nonatomic, readonly) long long int lastInsertedRowId

Declared In

RBSQLiteConnection.h

  lastErrorMessage

The error message of the last operation that failed.

@property (nonatomic, readonly, nullable) NSString *lastErrorMessage

Declared In

RBSQLiteConnection.h

– logErrorMessage

Prints the last error message to the console.

- (void)logErrorMessage

Declared In

RBSQLiteConnection.h

– backupDatabaseToDatabase:

Copies all tables and data from this database connection to the given database connection.

- (BOOL)backupDatabaseToDatabase:(nonnull RBSQLiteConnection *)databaseConnection

Parameters

databaseConnection

The database connection to backup to.

Return Value

true if the backup was successful, false if there was an error.

Declared In

RBSQLiteConnection.h

– backupDatabaseToFile:withFlags:usingVFS:

Copies all tables and data from this database connection to a file.

- (BOOL)backupDatabaseToFile:(nonnull NSString *)filename withFlags:(int)flags usingVFS:(nonnull NSString *)vfs

Parameters

filename

The local filesystem path to create the backup SQLite database file at.

flags

One or more sqlite3 connection flags to use when opening the connection to the backup file.

vfs

The name of the registered virtual filesystem to use when opening the connection to the backup file.

Return Value

true if the backup was successful, false if there was an error.

Declared In

RBSQLiteConnection.h

– populateDatabaseFromFile:withFlags:usingVFS:

Reads all of the tables and data from the specified SQLite file into this connection.

- (BOOL)populateDatabaseFromFile:(nonnull NSString *)filename withFlags:(int)flags usingVFS:(nonnull NSString *)vfs

Parameters

filename

The path to the database file to read from.

flags

One or more sqlite3 connection flags to use when opening the connection.

vfs

The name of the registered virtual filesystem to use when opening the connection.

Return Value

true if the transfer was successful, false if there was an error.

Declared In

RBSQLiteConnection.h