File adapter for Sqlite files.
More...
#include <OpenMS/FORMAT/SqliteConnector.h>
File adapter for Sqlite files.
This class contains certain helper functions to deal with Sqlite files.
- Note
- This is the public, SQLite-free interface. The raw SQLite C API (
sqlite3*/sqlite3_stmt* handling and the Internal::SqliteHelper statement helpers) lives in the non-installed implementation header <OpenMS/FORMAT/SqliteConnector_impl.h>, which must only be included from .cpp files inside libOpenMS. Keeping the SQLite types out of this header is what allows SQLite to be a fully private dependency of OpenMS.
◆ SqlOpenMode
how an sqlite db should be opened
| Enumerator |
|---|
| READ_ONLY | the DB must exist and is read-only
|
| READONLY | compatibility alias for READ_ONLY
|
| READWRITE | the DB is readable and writable, but must exist when opening it
|
| READWRITE_OR_CREATE | the DB readable and writable and is created new if not present already
|
◆ SqliteConnector() [1/2]
◆ SqliteConnector() [2/2]
Constructor which opens a connection to filename
- Exceptions
-
◆ ~SqliteConnector()
◆ columnExists()
| bool columnExists |
( |
const std::string & |
tablename, |
|
|
const std::string & |
colname |
|
) |
| |
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
- Returns
- Whether the column exists or not
◆ countTableRows()
| Size countTableRows |
( |
const std::string & |
table_name | ) |
|
Counts the number of entries in SQL table table_name
- Exceptions
-
◆ executeBindStatement()
| void executeBindStatement |
( |
const std::string & |
prepare_statement, |
|
|
const std::vector< std::string > & |
data |
|
) |
| |
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
prepare_statement The SQL statement data The data to bind
- Exceptions
-
◆ executeStatement()
| void executeStatement |
( |
const std::string & |
statement | ) |
|
Executes a given SQL statement (insert statement)
This is useful for writing a single row of data
statement The SQL statement
- Exceptions
-
◆ openDatabase_()
| void openDatabase_ |
( |
const std::string & |
filename, |
|
|
const SqlOpenMode |
mode |
|
) |
| |
|
protected |
Opens a new SQLite database.
- Parameters
-
| [in] | filename | Filename of the database |
| [in] | mode | See SqlOpenMode |
- Note
- Call this only once!
◆ tableExists()
| bool tableExists |
( |
const std::string & |
tablename | ) |
|
Checks whether the given table exists.
tablename The name of the table to be checked
- Returns
- Whether the table exists or not
◆ Internal::SqliteConnectorFriend
◆ db_