VSQLite++ 0.3
Loading...
Searching...
No Matches
connection.hpp
Go to the documentation of this file.
1/*##############################################################################
2 VSQLite++ - virtuosic bytes SQLite3 C++ wrapper
3
4 Copyright (c) 2006-2014 Vinzenz Feenstra vinzenz.feenstra@gmail.com
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15 * Neither the name of virtuosic bytes nor the names of its contributors may
16 be used to endorse or promote products derived from this software without
17 specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
30
31##############################################################################*/
32#ifndef GUARD_SQLITE_CONNECTION_HPP_INCLUDED
33#define GUARD_SQLITE_CONNECTION_HPP_INCLUDED
34#include <cstdint>
35#include <memory>
36#include <string>
39
47struct sqlite3;
48
49namespace sqlite {
50inline namespace v2 {
57
64 struct connection {
71 connection(std::string const &db);
72 connection(std::string const &db, filesystem_adapter_ptr fs);
73 connection(connection const &) = delete;
74 connection &operator=(connection const &) = delete;
75
89 connection(std::string const &db, sqlite::open_mode open_mode);
91
96
103 void attach(std::string const &db, std::string const &database_alias);
104
110 void detach(std::string const &database_alias);
111
115 std::int64_t get_last_insert_rowid();
116
120
121 private:
122 friend struct private_accessor;
123
124 private:
125 void open(std::string const &db);
126 void open(std::string const &db, bool readonly);
127 void open(std::string const &db, sqlite::open_mode open_mode);
128 void close();
130 void open_with_flags(std::string const &db, int flags);
131 sqlite3_stmt *acquire_cached_statement(std::string const &sql);
132 void release_cached_statement(std::string const &sql, sqlite3_stmt *stmt);
133
134 private:
135 sqlite3 *handle;
138 };
139} // namespace v2
140} // namespace sqlite
141#endif // GUARD_SQLITE_CONNECTION_HPP_INCLUDED
Tracks prepared statements by SQL text and hands them out on demand.
Pluggable abstraction for the filesystem operations used by sqlite::connection.
std::shared_ptr< filesystem_adapter > filesystem_adapter_ptr
@ open_readonly
Opens an existing database for reads only or fails.
@ open_existing
Opens an existing database; fails when it is missing.
@ always_create
Deletes any existing database file and recreates it.
@ open_or_create
Opens an existing database or creates it on demand.
LRU cache for prepared statements shared across sqlite::connection.
connection is used to open, close, attach and detach a database. Further it has to be passed to all c...
connection & operator=(connection const &)=delete
void configure_statement_cache(statement_cache_config const &cfg)
filesystem_adapter_ptr filesystem
void open(std::string const &db)
void open(std::string const &db, sqlite::open_mode open_mode)
void detach(std::string const &database_alias)
detaches a database via alias, if the same database was attached with several names they will be stil...
connection(std::string const &db, sqlite::open_mode open_mode, filesystem_adapter_ptr fs)
connection(std::string const &db, sqlite::open_mode open_mode)
constructor opens the database
void release_cached_statement(std::string const &sql, sqlite3_stmt *stmt)
void attach(std::string const &db, std::string const &database_alias)
attaches another database file to the database represented by the object of this class....
friend struct private_accessor
void open_with_flags(std::string const &db, int flags)
statement_cache cache_
std::int64_t get_last_insert_rowid()
Returns the last inserted rowid in the currently opened database.
connection(connection const &)=delete
~connection()
destructor closes the database automatically
statement_cache_config statement_cache_settings() const
connection(std::string const &db)
constructor opens the database
sqlite3_stmt * acquire_cached_statement(std::string const &sql)
connection(std::string const &db, filesystem_adapter_ptr fs)
void open(std::string const &db, bool readonly)
Configuration knobs for the built-in LRU statement cache.