Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does SQLite have a C++ object-oriented interface?

Tags:

c++

sqlite

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;
};
like image 829
sashoalm Avatar asked Oct 24 '25 03:10

sashoalm


1 Answers

Searching for "SQLite RAII" on your search engine of choice finds this library.

like image 100
icktoofay Avatar answered Oct 26 '25 17:10

icktoofay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!