OpenMS
2.7.0
|
File adapter for Sqlite files. More...
#include <OpenMS/FORMAT/SqliteConnector.h>
Public Types | |
enum class | SqlOpenMode { READONLY , READWRITE , READWRITE_OR_CREATE } |
how an sqlite db should be opened More... | |
Public Member Functions | |
SqliteConnector ()=delete | |
Default constructor. More... | |
SqliteConnector (const String &filename, const SqlOpenMode mode=SqlOpenMode::READWRITE_OR_CREATE) | |
~SqliteConnector () | |
Destructor. More... | |
sqlite3 * | getDB () |
Returns the raw pointer to the database. More... | |
bool | tableExists (const String &tablename) |
Checks whether the given table exists. More... | |
Size | countTableRows (const String &table_name) |
bool | columnExists (const String &tablename, const String &colname) |
Checks whether the given table contains a certain column. More... | |
void | executeStatement (const String &statement) |
Executes a given SQL statement (insert statement) More... | |
void | executeBindStatement (const String &prepare_statement, const std::vector< String > &data) |
Executes raw data SQL statements (insert statements) More... | |
void | prepareStatement (sqlite3_stmt **stmt, const String &prepare_statement) |
Prepares a SQL statement. More... | |
Static Public Member Functions | |
static bool | tableExists (sqlite3 *db, const String &tablename) |
Checks whether the given table exists. More... | |
static bool | columnExists (sqlite3 *db, const String &tablename, const String &colname) |
Checks whether the given table contains a certain column. More... | |
static void | executeStatement (sqlite3 *db, const std::stringstream &statement) |
Executes a given SQL statement (insert statement) More... | |
static void | executeStatement (sqlite3 *db, const String &statement) |
Executes a given SQL statement (insert statement) More... | |
static void | prepareStatement (sqlite3 *db, sqlite3_stmt **stmt, const String &prepare_statement) |
Converts an SQL statement into a prepared statement. More... | |
static void | executeBindStatement (sqlite3 *db, const String &prepare_statement, const std::vector< String > &data) |
Executes raw data SQL statements (insert statements) More... | |
Protected Member Functions | |
void | openDatabase_ (const String &filename, const SqlOpenMode mode) |
Opens a new SQLite database. More... | |
Protected Attributes | |
sqlite3 * | db_ = nullptr |
File adapter for Sqlite files.
This class contains certain helper functions to deal with Sqlite files.
|
strong |
|
delete |
Default constructor.
|
explicit |
Constructor which opens a connection to filename
Exception::SqlOperationFailed | if the file does not exist/cannot be created (depending on mode ) |
~SqliteConnector | ( | ) |
Destructor.
Checks whether the given table contains a certain column.
tablename
The name of the table (needs to exist) colname
The name of the column to be checked
Checks whether the given table contains a certain column.
db
The sqlite database (needs to be open) tablename
The name of the table (needs to exist) colname
The name of the column to be checked
Counts the number of entries in SQL table table_name
Exception::SqlOperationFailed | if table is unknown |
|
inline |
Executes raw data SQL statements (insert statements)
This is useful for a case where raw data should be inserted into sqlite databases, and the raw data needs to be passed separately as it cannot be part of a true SQL statement
INSERT INTO TBL (ID, DATA) VALUES (100, ?1), (101, ?2), (102, ?3)"
See also https://www.sqlite.org/c3ref/bind_blob.html
statement
The SQL statement data
The data to bind
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
static |
Executes raw data SQL statements (insert statements)
This is useful for a case where raw data should be inserted into sqlite databases, and the raw data needs to be passed separately as it cannot be part of a true SQL statement
INSERT INTO TBL (ID, DATA) VALUES (100, ?1), (101, ?2), (102, ?3)"
See also https://www.sqlite.org/c3ref/bind_blob.html
db
The sqlite database (needs to be open) statement
The SQL statement data
The data to bind
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
inline |
Executes a given SQL statement (insert statement)
This is useful for writing a single row of data
statement
The SQL statement
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
static |
Executes a given SQL statement (insert statement)
This is useful for writing a single row of data. It wraps sqlite3_exec with proper error handling.
db
The sqlite database (needs to be open) statement
The SQL statement
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
static |
Executes a given SQL statement (insert statement)
This is useful for writing a single row of data. It wraps sqlite3_exec with proper error handling.
db
The sqlite database (needs to be open) statement
The SQL statement
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
inline |
Returns the raw pointer to the database.
|
protected |
Opens a new SQLite database.
@filename Filename of the database
|
static |
Converts an SQL statement into a prepared statement.
This routine converts SQL text into a prepared statement object and returns a pointer to that object. This interface requires a database connection created by a prior call to sqlite3_open() and a text string containing the SQL statement to be prepared. This API does not actually evaluate the SQL statement. It merely prepares the SQL statement for evaluation.
This is useful for handling errors in a consistent manner. Internally calls sqlite3_prepare_v2.
db
The sqlite database (needs to be open) stmt
The prepared statement (output) prepare_statement
The SQL statement to prepare (input)
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
inline |
Prepares a SQL statement.
This is useful for handling errors in a consistent manner.
db
The sqlite database (needs to be open) statement
The SQL statement data
The data to bind
Exception::IllegalArgument | is thrown if the SQL command fails. |
|
inline |
Checks whether the given table exists.
tablename
The name of the table to be checked
|
static |
Checks whether the given table exists.
db
The sqlite database (needs to be open) tablename
The name of the table to be checked
|
protected |