SQLite comes with a C-style interface, where you need to explicitly close every resource (no destructors).
int rc = sqlite3_open16(databaseFileName, &sqlite->db);
...
sqlite3_close(_sqlite->db);
Is there a C++ interface or a wrapper around the C-style interface available, which would add destructors, like gtkmm is to GTK+? Something like:
class SQLiteDb
{
public:
SQLiteDb() {
int rc = sqlite3_open16(databaseFileName, &db);
if(rc != SQLITE_OK){
std::string errorText = sqlite3_errmsg(db);
throw std::runtime_error(errorText);
}
}
~SQLiteDb() {
sqlite3_close(db);
}
private:
sqlite3 *db;
};
Searching for "SQLite RAII" on your search engine of choice finds this library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With