Virgo is my name
Virgo is my name Home Blog About Login
SSLiteCpp 2.4.0+v0.29.0 released

SSLiteCpp 2.4.0+v0.29.0 released

Published by Virgo, on Oct 02, 2019. Unlicensed. 1178 views. Based on page loads (non unique).

SSQLiteCpp

A C++ SQLite3 library with encryption that sucks less.

A put together of SQLiteCpp and sqleet.

Example

#include <iostream>
#include <SSQLiteCpp/SQLiteCpp.h>

int main (int argc, char *argv[])
{
    // Using SQLITE_VERSION would require #include <sqleet.h> which we want to avoid: use SQLite::VERSION if possible.
    // std::cout << "SQlite3 version " << SQLITE_VERSION << std::endl;
    std::cout << "SQlite3 version " << SQLite::VERSION << " (" << SQLite::getLibVersion() << ")" << std::endl;
    std::cout << "SQliteC++ version " << SQLITECPP_VERSION << std::endl;

    try
    {
        // Open a database file in create/write mode
        SQLite::Database db("key.db", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);

        // Set encryption key
        db.key("password");

        std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";

        // Create a new table with an explicit "id" column aliasing the underlying rowid
        db.exec("DROP TABLE IF EXISTS test");
        db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)");

        // first row
        int nb = db.exec("INSERT INTO test VALUES (NULL, \"test\")");
        std::cout << "INSERT INTO test VALUES (NULL, \"test\")\", returned " << nb << std::endl;

        // second row
        nb = db.exec("INSERT INTO test VALUES (NULL, \"second\")");
        std::cout << "INSERT INTO test VALUES (NULL, \"second\")\", returned " << nb << std::endl;

        // update the second row
        nb = db.exec("UPDATE test SET value=\"second-updated\" WHERE id='2'");
        std::cout << "UPDATE test SET value=\"second-updated\" WHERE id='2', returned " << nb << std::endl;

        // Check the results : expect two row of result
        SQLite::Statement   query(db, "SELECT * FROM test");
        std::cout << "SELECT * FROM test :\n";
        while (query.executeStep())
        {
            std::cout << "row (" << query.getColumn(0) << ", \"" << query.getColumn(1) << "\")\n";
        }

        db.exec("DROP TABLE test");
    }
    catch (std::exception& e)
    {
        std::cout << "SQLite exception: " << e.what() << std::endl;
        return EXIT_FAILURE; // unexpected error : exit the example program
    }
}

Github

Virgo is my name
A website. ©2020 Virgo