View on GitHub

SQLiteC++

SQLiteC++ (SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper.

Download this project as a .zip file Download this project as a tar.gz file

About SQLite:

SQLite is a library that implements a serverless transactional SQL database engine. It is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain. http://www.sqlite.org/about.html

About SQLiteC++:

SQLiteC++ offers an encapsulation arround the native C APIs of sqlite, with a few intuitive and well documented C++ class.

Doxygen documentation: http://srombauts.github.com/SQLiteCpp/doc/html/annotated.html

The goals of SQLiteC++ are:

It is designed using the Resource Acquisition Is Initialization (RAII) idom (see http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization), and throwing exceptions in case of SQLite errors (exept in destructors, where assert() are used instead). Each SQLiteC++ object must be constructed with a valid SQLite database connection, and then is always valid until destroyed.

 Suported platforms:

Developements and tests are done under the following OSs :

Dependencies:

Installation:

To use this wrappers, you need to add the 10 SQLiteC++ source files from the src/ directory in your project code base, and compile/link against the sqlite library.

License

Copyright (c) 2012-2013 Sébastien Rombauts (sebastien.rombauts@gmail.com)

Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT)

Getting started

First sample demonstrates how to query a database and get results:

try
{
    // Open a database file
    SQLite::Database    db("example.db3");

    // Compile a SQL query, containing one parameter (index 1)
    SQLite::Statement   query(db, "SELECT * FROM test WHERE size > ?");

    // Bind the integer value 6 to the first parameter of the SQL query
    query.bind(1, 6);

    // Loop to execute the query step by step, to get rows of result
    while (query.executeStep())
    {
        // Demonstrate how to get some typed column value
        int         id      = query.getColumn(0);
        const char* value   = query.getColumn(1);
        int         size    = query.getColumn(2);

        std::cout << "row: " << id << ", " << value << ", " << size << std::endl;
    }
}
catch (std::exception& e)
{
    std::cout << "exception: " << e.what() << std::endl;
}

Second sample shows how to manage a transaction:

try
{
    SQLite::Database    db("transaction.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);

    db.exec("DROP TABLE IF EXISTS test");

    // Begin transaction
    SQLite::Transaction transaction(db);

    db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)");

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

    // Commit transaction
    transaction.commit();
}
catch (std::exception& e)
{
    std::cout << "exception: " << e.what() << std::endl;
}

How to contribute

GitHub website

The most efficient way to help and contribute to this wrapper project is to use the tools provided by GitHub:

Contact

You can also email me directly, I will answer any questions and requests.

Coding Style Guidelines

The source code use the CamelCase naming style variant where :

See also - Some other simple C++ SQLite wrappers:

See also the file WRAPPERS.md offering a more complete comparison of other wrappers.