libcommonc++
0.7
|
A class representing a session with an embedded SQL database. More...
#include <SQLDatabase.h++>
Public Member Functions | |
SQLDatabase () | |
Construct a new SQLDatabase object. More... | |
virtual | ~SQLDatabase () |
Destructor. More... | |
String | getVersion () |
Get the version of the underlying SQLite database software. More... | |
void | open (const String &path, bool create=true, bool readOnly=false) |
Open the database. More... | |
void | close () |
Close the database. More... | |
uint_t | executeSQL (const String &sql) |
Execute an SQL statement. More... | |
void | interrupt () |
Interrupt any currently-executing SQL statement. More... | |
bool | isAutoCommit () |
Test if the database is currently in auto-commit mode. More... | |
SQLQuery * | prepareQuery (const String &sql) |
Create a query for the given SQL statement. More... | |
int64_t | getGeneratedKey () |
Get the generated key created by the last SQL "INSERT" statement. More... | |
uint_t | getModifiedRowCount () |
Get the number of rows modified by the last SQL statement. More... | |
void | begin () |
Begin a transaction. More... | |
void | commit () |
Commit a pending transaction. More... | |
void | rollback () |
Roll back a pending transaction. More... | |
Protected Member Functions | |
virtual bool | onProgress () |
A callback that's invoked periodically while a SQL statement is being executed. More... | |
virtual void | onCommit () |
A callback that's invoked each time a transaction is committed. More... | |
virtual void | onRollback () |
A callback that's invoked each time a transaction is rolled back. More... | |
A class representing a session with an embedded SQL database.
The class can be subclassed to provide custom implementations for the three callback methods.
SQLDatabase | ( | ) |
Construct a new SQLDatabase object.
|
virtual |
Destructor.
Closes the database, if it is open.
void begin | ( | ) |
Begin a transaction.
Transactions cannot be nested.
SQLException | If a database error occurs. |
void close | ( | ) |
Close the database.
Any pending uncommitted transactions will be rolled back. It is a programming error to close the database while SQLQuery objects that were created by that database still exist.
void commit | ( | ) |
Commit a pending transaction.
SQLException | If a database error occurs. |
TimeoutException | If a timeout occurs while waiting for database locks. The call should be retried in this case. |
Execute an SQL statement.
sql | The statement to execute. |
SQLException | If a database error occurs. |
InterruptedException | If the statement was interrupted via a call to interrupt(). |
int64_t getGeneratedKey | ( | ) |
Get the generated key created by the last SQL "INSERT" statement.
SQLException | If a database error occurs. |
uint_t getModifiedRowCount | ( | ) |
Get the number of rows modified by the last SQL statement.
String getVersion | ( | ) |
Get the version of the underlying SQLite database software.
void interrupt | ( | ) |
Interrupt any currently-executing SQL statement.
The corresponding method will throw an InterruptedException.
SQLException | If a database error occurs. |
bool isAutoCommit | ( | ) |
Test if the database is currently in auto-commit mode.
Auto-commit mode is on by default if a transaction is not currently in progress.
SQLException | If a database error occurs. |
|
protectedvirtual |
A callback that's invoked each time a transaction is committed.
The default implementation does nothing.
|
protectedvirtual |
A callback that's invoked periodically while a SQL statement is being executed.
The default implementation does nothing and returns true.
|
protectedvirtual |
A callback that's invoked each time a transaction is rolled back.
The default implementation does nothing.
void open | ( | const String & | path, |
bool | create = true , |
||
bool | readOnly = false |
||
) |
Open the database.
path | The pathname of the database file to open. |
create | A flag indicating whether the database should be created if it does not exist. |
readOnly | A flag indicating whether the database should be opened read-only. |
IOException | If the database file could not be opened. |
Create a query for the given SQL statement.
sql | The statement. |
SQLException | If a database error occurs. |
void rollback | ( | ) |
Roll back a pending transaction.
SQLException | If a database error occurs. |
TimeoutException | If a timeout occurs while waiting for database locks. The call should be retried in this case. |