libglim  0.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Types | Public Member Functions | Protected Attributes
glim::Sqlite Class Reference

The database. More...

#include <sqlite.hpp>

Public Types

enum  Flags { existing = 1 }
 Flags for the Sqlite constructor. More...

Public Member Functions

Sqliteexec (const char *query)
 Execute the given query, throwing SqliteEx on failure. More...
template<typename StringLike >
Sqliteexec2 (StringLike query)
 Invokes exec on query.c_str(). More...
 Sqlite (std::string filename, int flags=0)
 Opens the database. More...
 ~Sqlite ()
 Closes the database. More...

Protected Attributes

std::string filename
 Filename the database was opened with; we need it to reopen the database on fork()s. More...

Detailed Description

The database.

According to sqlite3_open documentation, only the thread that opened the database can safely access it. This restriction was relaxed, as described in the FAQ (the "Is SQLite threadsafe?" question), so we can use the library from multiple threads, but only if no more than one thread at a time accesses the database. This restriction is, in fact, beneficial if the database is used from a single application: by restricting access to a sigle thread at a time, we effectively avoid all deadlock issues.
This library goals are:

The library is targeted at SQLite setup which is not -DTHREADSAFE, since this is the default setup on UNIX architectures.

This file is a header-only library, whose sole dependencies should be standard STL and posix threading libraries. You can extract this file out of the "glim" library to include it separately in your project.

This library is targeted at UTF-8 API. There is no plans to support the UTF-16 API.

See also:

Member Enumeration Documentation

Flags for the Sqlite constructor.


The file will be checked for existence.

SqliteEx is thrown if the file is not accessible; format of the error description is "$filename: $strerror".
Usage example:

Sqlite db ("filename", Sqlite::existing);

Constructor & Destructor Documentation

glim::Sqlite::Sqlite ( std::string  filename,
int  flags = 0 

Opens the database.

filenameDatabase filename (UTF-8).
flagsOptional. Currently there is the existing flag.
SqliteExThrown if we can't open the database.
glim::Sqlite::~Sqlite ( )

Closes the database.

SqliteExThrown if we can't close the database.

Member Function Documentation

Sqlite & glim::Sqlite::exec ( const char *  query)

Execute the given query, throwing SqliteEx on failure.


glim::Sqlite sqlite (":memory:");
sqlite.exec ("PRAGMA page_size = 4096") .exec ("PRAGMA secure_delete = 1");
template<typename StringLike >
Sqlite& glim::Sqlite::exec2 ( StringLike  query)

Invokes exec on query.c_str().


glim::Sqlite sqlite (":memory:");
for (std::string pv: {"page_size = 4096", "secure_delete = 1"}) sqlite->exec2 ("PRAGMA " + pv);

Field Documentation

std::string glim::Sqlite::filename

Filename the database was opened with; we need it to reopen the database on fork()s.

std::string is used to avoid memory allocation issues.

The documentation for this class was generated from the following file: