Class SQLiteHandler¶
- Defined in File SQLiteHandler.h
Class Documentation¶
-
class
SQLiteHandler
¶ Handler for the SQLite connection, including proper opening and closing of the database object.
Public Functions
-
SQLiteHandler
()¶ Default constructor.
-
~SQLiteHandler
()¶ Default destructor.
-
void
open
(const std::string &file_name)¶ Opens a database connection to the specified file name. If the file name is “:memory:”, instead opens a connection to an in-memory database object.
- Parameters
file_name
: the name of the file to open (or “:memory:” for in-memory databases)
-
void
close
()¶ Closes the sqlite3 connection to the database.
-
std::string
getErrorMsg
(int rc)¶ Gets the error message from the sqlite3 database operations.
- Return
- string containing the result code and the error message
- Parameters
rc
: the result code of the previous operation, to print out
-
std::string
getErrorMsg
()¶ Gets the error message from the database.
- Return
- the error message
-
void
backupFrom
(SQLiteHandler &sqlite_handler)¶ Copies the data from the provided SQLiteHander object to this database.
- Parameters
sqlite_handler
: the database containing data to copy
-
shared_ptr<SQLStatement>
prepare
(const std::string &command)¶ Prepares the given commmand within the statement object.
- Return
- pointer to the prepared statement
- Parameters
command
: the command to executestmt
: the statement to prepare within
-
void
createStatement
()¶ Creates a new statement for the database handler.
Use the supplied statement object for the database.
- Parameters
stmt
:
-
void
step
()¶ Steps the prepared statement forwards and reports any errors.
- Note
- stmt should have been opened from the same SQLiteHandler object using prepare()
- Parameters
stmt
: the statement to step forwards
-
void
finalise
()¶ Finalises the sqlite statement and reports any errors.
- Note
- stmt should have been opened from the same SQLiteHandler object using prepare()
- Parameters
stmt
: the statement to finalise
-
void
execute
(const string &command)¶ Executes a command from the database and reports any errors.
- Parameters
command
: the command to execute within the database
-
void
beginTransaction
()¶ Starts a transaction from this database object.
-
void
endTransaction
()¶ Ends the transaction from this database object.
-
bool
isOpen
()¶ Checks if the database is open.
- Return
- true, if the database is not a nullptr.
-
bool
hasTable
(const std::string &table_name)¶ Checks if the database has the specified table.
- Return
- true if the table exists
- Parameters
table_name
: the table name to check for existence
-