Moved sqlite3 over here.

This commit is contained in:
Roland Bock
2021-08-01 20:37:36 +02:00
parent d0a8ea21af
commit 2e683a4b69
101 changed files with 4963 additions and 61 deletions

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2013 - 2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_BIND_RESULT_H
#define SQLPP_SQLITE3_BIND_RESULT_H
#include <memory>
#include <sqlpp11/chrono.h>
#include <sqlpp11/sqlite3/export.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4251)
#endif
namespace sqlpp
{
namespace sqlite3
{
namespace detail
{
struct prepared_statement_handle_t;
}
class SQLPP11_SQLITE3_EXPORT bind_result_t
{
std::shared_ptr<detail::prepared_statement_handle_t> _handle;
public:
bind_result_t() = default;
bind_result_t(const std::shared_ptr<detail::prepared_statement_handle_t>& handle);
bind_result_t(const bind_result_t&) = delete;
bind_result_t(bind_result_t&& rhs) = default;
bind_result_t& operator=(const bind_result_t&) = delete;
bind_result_t& operator=(bind_result_t&&) = default;
~bind_result_t() = default;
bool operator==(const bind_result_t& rhs) const
{
return _handle == rhs._handle;
}
template <typename ResultRow>
void next(ResultRow& result_row)
{
if (!_handle)
{
result_row._invalidate();
return;
}
if (next_impl())
{
if (not result_row)
{
result_row._validate();
}
result_row._bind(*this);
}
else
{
if (result_row)
result_row._invalidate();
}
}
void _bind_boolean_result(size_t index, signed char* value, bool* is_null);
void _bind_floating_point_result(size_t index, double* value, bool* is_null);
void _bind_integral_result(size_t index, int64_t* value, bool* is_null);
void _bind_unsigned_integral_result(size_t index, uint64_t* value, bool* is_null);
void _bind_text_result(size_t index, const char** text, size_t* len);
void _bind_blob_result(size_t index, const uint8_t** text, size_t* len);
void _bind_date_result(size_t index, ::sqlpp::chrono::day_point* value, bool* is_null);
void _bind_date_time_result(size_t index, ::sqlpp::chrono::microsecond_point* value, bool* is_null);
private:
bool next_impl();
};
} // namespace sqlite3
} // namespace sqlpp
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif

View File

@@ -0,0 +1,359 @@
/*
* Copyright (c) 2013 - 2016, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_CONNECTION_H
#define SQLPP_SQLITE3_CONNECTION_H
#ifdef SQLPP_USE_SQLCIPHER
#include <sqlcipher/sqlite3.h>
#else
#include <sqlite3.h>
#endif
#include <sqlpp11/connection.h>
#include <sqlpp11/schema.h>
#include <sqlpp11/serialize.h>
#include <sqlpp11/sqlite3/bind_result.h>
#include <sqlpp11/sqlite3/connection_config.h>
#include <sqlpp11/sqlite3/prepared_statement.h>
#include <sqlpp11/transaction.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/sqlite3/export.h>
#include <sstream>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4251)
#endif
namespace sqlpp
{
namespace sqlite3
{
namespace detail
{
struct connection_handle;
}
class connection;
struct serializer_t
{
serializer_t(const connection& db) : _db(db), _count(1)
{
}
template <typename T>
std::ostream& operator<<(T t)
{
return _os << t;
}
std::string escape(std::string arg);
std::string str() const
{
return _os.str();
}
size_t count() const
{
return _count;
}
void pop_count()
{
++_count;
}
const connection& _db;
std::stringstream _os;
size_t _count;
};
class SQLPP11_SQLITE3_EXPORT connection : public sqlpp::connection
{
std::unique_ptr<detail::connection_handle> _handle;
enum class transaction_status_type
{
none,
maybe,
active
};
transaction_status_type _transaction_status = transaction_status_type::none;
// direct execution
bind_result_t select_impl(const std::string& statement);
size_t insert_impl(const std::string& statement);
size_t update_impl(const std::string& statement);
size_t remove_impl(const std::string& statement);
// prepared execution
prepared_statement_t prepare_impl(const std::string& statement);
bind_result_t run_prepared_select_impl(prepared_statement_t& prepared_statement);
size_t run_prepared_execute_impl(prepared_statement_t& prepared_statement);
size_t run_prepared_insert_impl(prepared_statement_t& prepared_statement);
size_t run_prepared_update_impl(prepared_statement_t& prepared_statement);
size_t run_prepared_remove_impl(prepared_statement_t& prepared_statement);
public:
using _prepared_statement_t = prepared_statement_t;
using _context_t = serializer_t;
using _serializer_context_t = _context_t;
using _interpreter_context_t = _context_t;
struct _tags
{
using _null_result_is_trivial_value = std::true_type;
};
template <typename T>
static _context_t& _serialize_interpretable(const T& t, _context_t& context)
{
return ::sqlpp::serialize(t, context);
}
template <typename T>
static _context_t& _interpret_interpretable(const T& t, _context_t& context)
{
return ::sqlpp::serialize(t, context);
}
connection(connection_config config);
connection(connection&&) noexcept;
connection& operator=(connection&&) noexcept;
~connection();
connection(const connection&) = delete;
connection& operator=(const connection&) = delete;
//! select returns a result (which can be iterated row by row)
template <typename Select>
bind_result_t select(const Select& s)
{
_context_t context(*this);
serialize(s, context);
return select_impl(context.str());
}
template <typename Select>
_prepared_statement_t prepare_select(Select& s)
{
_context_t context(*this);
serialize(s, context);
return prepare_impl(context.str());
}
template <typename PreparedSelect>
bind_result_t run_prepared_select(const PreparedSelect& s)
{
s._prepared_statement._reset();
s._bind_params();
return run_prepared_select_impl(s._prepared_statement);
}
//! insert returns the last auto_incremented id (or zero, if there is none)
template <typename Insert>
size_t insert(const Insert& i)
{
_context_t context(*this);
serialize(i, context);
return insert_impl(context.str());
}
template <typename Insert>
_prepared_statement_t prepare_insert(Insert& i)
{
_context_t context(*this);
serialize(i, context);
return prepare_impl(context.str());
}
template <typename PreparedInsert>
size_t run_prepared_insert(const PreparedInsert& i)
{
i._prepared_statement._reset();
i._bind_params();
return run_prepared_insert_impl(i._prepared_statement);
}
//! update returns the number of affected rows
template <typename Update>
size_t update(const Update& u)
{
_context_t context(*this);
serialize(u, context);
return update_impl(context.str());
}
template <typename Update>
_prepared_statement_t prepare_update(Update& u)
{
_context_t context(*this);
serialize(u, context);
return prepare_impl(context.str());
}
template <typename PreparedUpdate>
size_t run_prepared_update(const PreparedUpdate& u)
{
u._prepared_statement._reset();
u._bind_params();
return run_prepared_update_impl(u._prepared_statement);
}
//! remove returns the number of removed rows
template <typename Remove>
size_t remove(const Remove& r)
{
_context_t context(*this);
serialize(r, context);
return remove_impl(context.str());
}
template <typename Remove>
_prepared_statement_t prepare_remove(Remove& r)
{
_context_t context(*this);
serialize(r, context);
return prepare_impl(context.str());
}
template <typename PreparedRemove>
size_t run_prepared_remove(const PreparedRemove& r)
{
r._prepared_statement._reset();
r._bind_params();
return run_prepared_remove_impl(r._prepared_statement);
}
//! execute arbitrary command (e.g. create a table)
size_t execute(const std::string& command);
template <
typename Execute,
typename Enable = typename std::enable_if<not std::is_convertible<Execute, std::string>::value, void>::type>
size_t execute(const Execute& x)
{
_context_t context(*this);
serialize(x, context);
return execute(context.str());
}
template <typename Execute>
_prepared_statement_t prepare_execute(Execute& x)
{
_context_t context(*this);
serialize(x, context);
return prepare_impl(context.str());
}
template <typename PreparedExecute>
size_t run_prepared_execute(const PreparedExecute& x)
{
x._prepared_statement._reset();
x._bind_params();
return run_prepared_execute_impl(x._prepared_statement);
}
//! escape given string (does not quote, though)
std::string escape(const std::string& s) const;
//! call run on the argument
template <typename T>
auto _run(const T& t, ::sqlpp::consistent_t) -> decltype(t._run(*this))
{
return t._run(*this);
}
template <typename Check, typename T>
auto _run(const T& t, Check) -> Check;
template <typename T>
auto operator()(const T& t) -> decltype(this->_run(t, sqlpp::run_check_t<_serializer_context_t, T>{}))
{
return _run(t, sqlpp::run_check_t<_serializer_context_t, T>{});
}
//! call prepare on the argument
template <typename T>
auto _prepare(const T& t, const std::true_type&) -> decltype(t._prepare(*this))
{
return t._prepare(*this);
}
template <typename T>
auto _prepare(const T& t, const std::false_type&) -> void;
template <typename T>
auto prepare(const T& t)
-> decltype(this->_prepare(t, typename sqlpp::prepare_check_t<_serializer_context_t, T>::type{}))
{
sqlpp::prepare_check_t<_serializer_context_t, T>{};
return _prepare(t, sqlpp::prepare_check_t<_serializer_context_t, T>{});
}
//! set the transaction isolation level for this connection
void set_default_isolation_level(isolation_level level);
//! get the currently active transaction isolation level
isolation_level get_default_isolation_level();
//! start transaction
void start_transaction();
//! commit transaction (or throw if the transaction has been finished already)
void commit_transaction();
//! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished
// already)
void rollback_transaction(bool report);
//! report a rollback failure (will be called by transactions in case of a rollback failure in the destructor)
void report_rollback_failure(const std::string message) noexcept;
//! get the last inserted id
uint64_t last_insert_id() noexcept;
::sqlite3* native_handle();
auto attach(const connection_config&, const std::string name) -> schema_t;
};
inline std::string serializer_t::escape(std::string arg)
{
return _db.escape(arg);
}
} // namespace sqlite3
} // namespace sqlpp
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include <sqlpp11/sqlite3/serializer.h>
#endif

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013 - 2016, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_CONNECTION_CONFIG_H
#define SQLPP_SQLITE3_CONNECTION_CONFIG_H
#include <string>
#include <iostream>
namespace sqlpp
{
namespace sqlite3
{
struct connection_config
{
connection_config() : path_to_database(), flags(0), vfs(), debug(false),password("")
{
}
connection_config(const connection_config&) = default;
connection_config(connection_config&&) = default;
connection_config(std::string path, int fl = 0, std::string vf = "", bool dbg = false,std::string password="")
: path_to_database(std::move(path)), flags(fl), vfs(std::move(vf)), debug(dbg),password(password)
{
}
bool operator==(const connection_config& other) const
{
return (other.path_to_database == path_to_database && other.flags == flags && other.vfs == vfs &&
other.debug == debug && other.password==password);
}
bool operator!=(const connection_config& other) const
{
return !operator==(other);
}
std::string path_to_database;
int flags;
std::string vfs;
bool debug;
std::string password;
};
}
}
#endif

View File

@@ -0,0 +1,237 @@
/*
* Copyright (c) 2017, Volker Aßmann
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DYNAMIC_LIBSQLITE3_H
#define DYNAMIC_LIBSQLITE3_H
#ifdef SQLPP_USE_SQLCIPHER
#include <sqlcipher/sqlite3.h>
#else
#include <sqlite3.h>
#endif
#include <stdexcept>
// namespace for internal sqlite function wrappers - when using this instead of sqlite3 direct linking
// do this:
// using namespace sqlpp::sqlite3::dyn;
// to override the libsqlite3 functions with these function pointers
#ifdef SQLPP_DYNAMIC_LOADING
namespace sqlpp
{
namespace sqlite3
{
namespace dynamic
{
/// load the SQLite libraries, optionally providing the filename (leave empty for default)
void init_sqlite(std::string libname);
#define DYNDEFINE(NAME) extern decltype(::NAME)* NAME
DYNDEFINE(sqlite3_open_v2);
DYNDEFINE(sqlite3_open);
DYNDEFINE(sqlite3_prepare_v2);
DYNDEFINE(sqlite3_exec);
DYNDEFINE(sqlite3_step);
DYNDEFINE(sqlite3_bind_int);
DYNDEFINE(sqlite3_close);
DYNDEFINE(sqlite3_initialize);
DYNDEFINE(sqlite3_os_init);
DYNDEFINE(sqlite3_os_end);
DYNDEFINE(sqlite3_bind_blob);
DYNDEFINE(sqlite3_bind_double);
DYNDEFINE(sqlite3_bind_int64);
DYNDEFINE(sqlite3_bind_null);
DYNDEFINE(sqlite3_bind_text);
DYNDEFINE(sqlite3_bind_value);
DYNDEFINE(sqlite3_libversion_number);
// DYNDEFINE(sqlite3_compileoption_used);
DYNDEFINE(sqlite3_threadsafe);
// DYNDEFINE(sqlite3_close_v2);
DYNDEFINE(sqlite3_shutdown);
DYNDEFINE(sqlite3_config);
DYNDEFINE(sqlite3_db_config);
DYNDEFINE(sqlite3_extended_result_codes);
DYNDEFINE(sqlite3_last_insert_rowid);
DYNDEFINE(sqlite3_changes);
DYNDEFINE(sqlite3_total_changes);
DYNDEFINE(sqlite3_interrupt);
DYNDEFINE(sqlite3_complete);
DYNDEFINE(sqlite3_complete16);
DYNDEFINE(sqlite3_busy_handler);
DYNDEFINE(sqlite3_busy_timeout);
DYNDEFINE(sqlite3_get_table);
DYNDEFINE(sqlite3_free_table);
// DYNDEFINE(sqlite3_realloc64);
DYNDEFINE(sqlite3_free);
// DYNDEFINE(sqlite3_msize);
DYNDEFINE(sqlite3_memory_used);
DYNDEFINE(sqlite3_memory_highwater);
DYNDEFINE(sqlite3_randomness);
DYNDEFINE(sqlite3_set_authorizer);
DYNDEFINE(sqlite3_progress_handler);
DYNDEFINE(sqlite3_open16);
// DYNDEFINE(sqlite3_uri_boolean);
// DYNDEFINE(sqlite3_uri_int64);
DYNDEFINE(sqlite3_errcode);
DYNDEFINE(sqlite3_errmsg);
DYNDEFINE(sqlite3_extended_errcode);
DYNDEFINE(sqlite3_limit);
DYNDEFINE(sqlite3_prepare);
DYNDEFINE(sqlite3_prepare16);
DYNDEFINE(sqlite3_prepare16_v2);
// DYNDEFINE(sqlite3_stmt_readonly);
// DYNDEFINE(sqlite3_stmt_busy);
// DYNDEFINE(sqlite3_bind_blob64);
DYNDEFINE(sqlite3_bind_text16);
// DYNDEFINE(sqlite3_bind_text64);
DYNDEFINE(sqlite3_bind_zeroblob);
DYNDEFINE(sqlite3_bind_parameter_count);
DYNDEFINE(sqlite3_bind_parameter_index);
DYNDEFINE(sqlite3_clear_bindings);
DYNDEFINE(sqlite3_column_count);
DYNDEFINE(sqlite3_data_count);
DYNDEFINE(sqlite3_column_bytes);
DYNDEFINE(sqlite3_column_bytes16);
DYNDEFINE(sqlite3_column_double);
DYNDEFINE(sqlite3_column_int);
DYNDEFINE(sqlite3_column_int64);
DYNDEFINE(sqlite3_column_text);
DYNDEFINE(sqlite3_column_type);
DYNDEFINE(sqlite3_column_value);
DYNDEFINE(sqlite3_column_blob);
DYNDEFINE(sqlite3_finalize);
DYNDEFINE(sqlite3_reset);
DYNDEFINE(sqlite3_create_function);
DYNDEFINE(sqlite3_create_function16);
// DYNDEFINE(sqlite3_create_function_v2);
DYNDEFINE(sqlite3_value_bytes);
DYNDEFINE(sqlite3_value_bytes16);
DYNDEFINE(sqlite3_value_double);
DYNDEFINE(sqlite3_value_int);
DYNDEFINE(sqlite3_value_int64);
DYNDEFINE(sqlite3_value_type);
DYNDEFINE(sqlite3_value_numeric_type);
DYNDEFINE(sqlite3_set_auxdata);
DYNDEFINE(sqlite3_result_blob);
// DYNDEFINE(sqlite3_result_blob64);
DYNDEFINE(sqlite3_result_double);
DYNDEFINE(sqlite3_result_error);
DYNDEFINE(sqlite3_result_error16);
DYNDEFINE(sqlite3_result_error_toobig);
DYNDEFINE(sqlite3_result_error_nomem);
DYNDEFINE(sqlite3_result_error_code);
DYNDEFINE(sqlite3_result_int);
DYNDEFINE(sqlite3_result_int64);
DYNDEFINE(sqlite3_result_null);
DYNDEFINE(sqlite3_result_text);
// DYNDEFINE(sqlite3_result_text64);
DYNDEFINE(sqlite3_result_text16);
DYNDEFINE(sqlite3_result_text16le);
DYNDEFINE(sqlite3_result_text16be);
DYNDEFINE(sqlite3_result_value);
DYNDEFINE(sqlite3_result_zeroblob);
DYNDEFINE(sqlite3_create_collation);
DYNDEFINE(sqlite3_create_collation_v2);
DYNDEFINE(sqlite3_create_collation16);
DYNDEFINE(sqlite3_collation_needed);
DYNDEFINE(sqlite3_collation_needed16);
#ifdef SQLITE_HAS_CODEC
DYNDEFINE(sqlite3_key);
DYNDEFINE(sqlite3_key_v2);
DYNDEFINE(sqlite3_rekey);
DYNDEFINE(sqlite3_rekey_v2);
DYNDEFINE(sqlite3_activate_see);
#endif
#ifdef SQLITE_ENABLE_CEROD
DYNDEFINE(sqlite3_activate_cerod);
#endif
DYNDEFINE(sqlite3_sleep);
DYNDEFINE(sqlite3_get_autocommit);
// DYNDEFINE(sqlite3_db_readonly);
DYNDEFINE(sqlite3_next_stmt);
DYNDEFINE(sqlite3_enable_shared_cache);
DYNDEFINE(sqlite3_release_memory);
// DYNDEFINE(sqlite3_db_release_memory);
// DYNDEFINE(sqlite3_soft_heap_limit64);
DYNDEFINE(sqlite3_table_column_metadata);
DYNDEFINE(sqlite3_load_extension);
DYNDEFINE(sqlite3_enable_load_extension);
DYNDEFINE(sqlite3_auto_extension);
// DYNDEFINE(sqlite3_cancel_auto_extension);
DYNDEFINE(sqlite3_reset_auto_extension);
DYNDEFINE(sqlite3_create_module);
DYNDEFINE(sqlite3_create_module_v2);
DYNDEFINE(sqlite3_declare_vtab);
DYNDEFINE(sqlite3_overload_function);
DYNDEFINE(sqlite3_blob_open);
DYNDEFINE(sqlite3_blob_close);
DYNDEFINE(sqlite3_blob_bytes);
DYNDEFINE(sqlite3_blob_read);
DYNDEFINE(sqlite3_blob_write);
DYNDEFINE(sqlite3_vfs_find);
DYNDEFINE(sqlite3_vfs_register);
DYNDEFINE(sqlite3_vfs_unregister);
DYNDEFINE(sqlite3_mutex_alloc);
DYNDEFINE(sqlite3_mutex_free);
DYNDEFINE(sqlite3_mutex_enter);
DYNDEFINE(sqlite3_mutex_try);
DYNDEFINE(sqlite3_mutex_leave);
// DYNDEFINE(sqlite3_mutex_held);
// DYNDEFINE(sqlite3_mutex_notheld);
DYNDEFINE(sqlite3_db_mutex);
DYNDEFINE(sqlite3_file_control);
DYNDEFINE(sqlite3_test_control);
DYNDEFINE(sqlite3_status);
DYNDEFINE(sqlite3_db_status);
DYNDEFINE(sqlite3_stmt_status);
DYNDEFINE(sqlite3_backup_init);
DYNDEFINE(sqlite3_backup_step);
DYNDEFINE(sqlite3_backup_finish);
DYNDEFINE(sqlite3_backup_remaining);
DYNDEFINE(sqlite3_backup_pagecount);
DYNDEFINE(sqlite3_unlock_notify);
// DYNDEFINE(sqlite3_stricmp);
// DYNDEFINE(sqlite3_strnicmp);
// DYNDEFINE(sqlite3_strglob);
// DYNDEFINE(sqlite3_log);
// DYNDEFINE(sqlite3_wal_autocheckpoint);
// DYNDEFINE(sqlite3_wal_checkpoint);
// DYNDEFINE(sqlite3_wal_checkpoint_v2);
// DYNDEFINE(sqlite3_vtab_config);
// DYNDEFINE(sqlite3_vtab_on_conflict);
// DYNDEFINE(sqlite3_rtree_geometry_callback);
// DYNDEFINE(sqlite3_rtree_query_callback);
} // namespace dynamic
} // namespace sqlite3
} // namespace sqlpp
#undef DYNDEFINE
#endif
#endif // DYNAMIC_LIBSQLITE3_H

View File

@@ -0,0 +1,18 @@
#ifndef SQLPP_SQLITE3_EXPORT_H
#define SQLPP_SQLITE3_EXPORT_H
#ifdef _WIN32
#ifdef SQLPP11_SHARED
#ifdef SQLPP11_COMPILING_DLL
#define SQLPP11_SQLITE3_EXPORT __declspec(dllexport)
#else
#define SQLPP11_SQLITE3_EXPORT __declspec(dllimport)
#endif
#else
#define SQLPP11_SQLITE3_EXPORT
#endif
#else
#define SQLPP11_SQLITE3_EXPORT
#endif
#endif

View File

@@ -0,0 +1,154 @@
/*
* Copyright (c) 2013 - 2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_INSERT_OR_H
#define SQLPP_SQLITE3_INSERT_OR_H
#include <sqlpp11/default_value.h>
#include <sqlpp11/insert_value_list.h>
#include <sqlpp11/into.h>
#include <sqlpp11/noop.h>
#include <sqlpp11/parameter_list.h>
#include <sqlpp11/prepared_insert.h>
#include <sqlpp11/statement.h>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
namespace sqlite3
{
struct insert_or_replace_name_t
{
};
struct insert_or_ignore_name_t
{
};
template <typename InsertOrAlternative>
struct insert_or_t : public statement_name_t<InsertOrAlternative>
{
using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t
{
};
template <typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
template <typename Db>
auto _run(Db& db) const -> decltype(db.insert(this->_get_statement()))
{
return db.insert(_get_statement());
}
template <typename Db>
auto _prepare(Db& db) const -> prepared_insert_t<Db, _statement_t>
{
return {{}, db.prepare_insert(_get_statement())};
}
};
};
template <typename Database, typename InsertOrAlternative>
using blank_insert_or_t =
statement_t<Database, insert_or_t<InsertOrAlternative>, no_into_t, no_insert_value_list_t>;
template <typename Database>
using blank_insert_or_replace_t = blank_insert_or_t<Database, insert_or_replace_name_t>;
template <typename Database>
using blank_insert_or_ignore_t = blank_insert_or_t<Database, insert_or_ignore_name_t>;
inline auto insert_or_replace() -> blank_insert_or_replace_t<void>
{
return {blank_insert_or_replace_t<void>()};
}
template <typename Table>
constexpr auto insert_or_replace_into(Table table) -> decltype(blank_insert_or_replace_t<void>().into(table))
{
return {blank_insert_or_replace_t<void>().into(table)};
}
template <typename Database>
constexpr auto dynamic_insert_or_replace(const Database&) -> decltype(blank_insert_or_replace_t<Database>())
{
return {blank_insert_or_replace_t<Database>()};
}
template <typename Database, typename Table>
constexpr auto dynamic_insert_or_replace_into(const Database&, Table table)
-> decltype(blank_insert_or_replace_t<Database>().into(table))
{
return {blank_insert_or_replace_t<Database>().into(table)};
}
inline auto insert_or_ignore() -> blank_insert_or_ignore_t<void>
{
return {blank_insert_or_ignore_t<void>()};
}
template <typename Table>
constexpr auto insert_or_ignore_into(Table table) -> decltype(blank_insert_or_ignore_t<void>().into(table))
{
return {blank_insert_or_ignore_t<void>().into(table)};
}
template <typename Database>
constexpr auto dynamic_insert_or_ignore(const Database&) -> decltype(blank_insert_or_ignore_t<Database>())
{
return {blank_insert_or_ignore_t<Database>()};
}
template <typename Database, typename Table>
constexpr auto dynamic_insert_or_ignore_into(const Database&, Table table)
-> decltype(blank_insert_or_ignore_t<Database>().into(table))
{
return {blank_insert_or_ignore_t<Database>().into(table)};
}
inline sqlite3::serializer_t& serialize(const sqlite3::insert_or_replace_name_t&, sqlite3::serializer_t& context)
{
context << "INSERT OR REPLACE ";
return context;
}
inline sqlite3::serializer_t& serialize(const sqlite3::insert_or_ignore_name_t&, sqlite3::serializer_t& context)
{
context << "INSERT OR IGNORE ";
return context;
}
}
}
#endif

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2013 - 2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_PREPARED_STATEMENT_H
#define SQLPP_SQLITE3_PREPARED_STATEMENT_H
#include <memory>
#include <sqlpp11/chrono.h>
#include <sqlpp11/sqlite3/export.h>
#include <string>
#include <vector>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4251)
#endif
namespace sqlpp
{
namespace sqlite3
{
class connection;
namespace detail
{
struct prepared_statement_handle_t;
}
class SQLPP11_SQLITE3_EXPORT prepared_statement_t
{
friend ::sqlpp::sqlite3::connection;
std::shared_ptr<detail::prepared_statement_handle_t> _handle;
public:
prepared_statement_t() = default;
prepared_statement_t(std::shared_ptr<detail::prepared_statement_handle_t>&& handle);
prepared_statement_t(const prepared_statement_t&) = delete;
prepared_statement_t(prepared_statement_t&& rhs) = default;
prepared_statement_t& operator=(const prepared_statement_t&) = delete;
prepared_statement_t& operator=(prepared_statement_t&&) = default;
~prepared_statement_t() = default;
bool operator==(const prepared_statement_t& rhs) const
{
return _handle == rhs._handle;
}
void _reset();
void _bind_boolean_parameter(size_t index, const signed char* value, bool is_null);
void _bind_floating_point_parameter(size_t index, const double* value, bool is_null);
void _bind_integral_parameter(size_t index, const int64_t* value, bool is_null);
void _bind_unsigned_integral_parameter(size_t index, const uint64_t* value, bool is_null);
void _bind_text_parameter(size_t index, const std::string* value, bool is_null);
void _bind_date_parameter(size_t index, const ::sqlpp::chrono::day_point* value, bool is_null);
void _bind_date_time_parameter(size_t index, const ::sqlpp::chrono::microsecond_point* value, bool is_null);
void _bind_blob_parameter(size_t index, const std::vector<uint8_t>* value, bool is_null);
};
} // namespace sqlite3
} // namespace sqlpp
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2013 - 2016, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_SERIALIZER_H
#define SQLPP_SQLITE3_SERIALIZER_H
#ifdef SQLPP_USE_SQLCIPHER
#include <sqlcipher/sqlite3.h>
#else
#include <sqlite3.h>
#endif
#include <sqlpp11/any.h>
#include <sqlpp11/data_types/day_point/operand.h>
#include <sqlpp11/data_types/floating_point/operand.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <sqlpp11/data_types/time_point/operand.h>
#include <sqlpp11/data_types/unsigned_integral/operand.h>
#include <sqlpp11/parameter.h>
#include <sqlpp11/pre_join.h>
#include <sqlpp11/some.h>
#include <sqlpp11/with.h>
#include <cmath>
namespace sqlpp
{
// Serialize parameters
template <typename ValueType, typename NameType>
sqlite3::serializer_t& serialize(const parameter_t<ValueType, NameType>&, sqlite3::serializer_t& context)
{
context << "?" << context.count();
context.pop_count();
return context;
}
// disable some stuff that won't work with sqlite3
#if SQLITE_VERSION_NUMBER < 3008003
template <typename Database, typename... Expressions>
sqlite3::serializer_t& serialize(const with_data_t<Database, Expressions...>&, sqlite3::serializer_t& context)
{
static_assert(wrong_t<Expressions...>::value, "Sqlite3: No support for with before version 3.8.3");
return context;
}
#endif
template <typename Select>
sqlite3::serializer_t& serialize(const any_t<Select>&, sqlite3::serializer_t& context)
{
static_assert(wrong_t<Select>::value, "Sqlite3: No support for any()");
return context;
}
template <typename Select>
sqlite3::serializer_t& serialize(const some_t<Select>&, sqlite3::serializer_t& context)
{
static_assert(wrong_t<Select>::value, "Sqlite3: No support for some()");
return context;
}
template <typename Lhs, typename Rhs>
sqlite3::serializer_t& serialize(const pre_join_t<outer_join_t, Lhs, Rhs>&, sqlite3::serializer_t& context)
{
static_assert(wrong_t<Lhs, Rhs>::value, "Sqlite3: No support for outer join");
return context;
};
template <typename Lhs, typename Rhs>
sqlite3::serializer_t& serialize(const pre_join_t<right_outer_join_t, Lhs, Rhs>&, sqlite3::serializer_t& context)
{
static_assert(wrong_t<Lhs, Rhs>::value, "Sqlite3: No support for right_outer join");
return context;
};
// Some special treatment of data types
template <typename Period>
sqlite3::serializer_t& serialize(const time_point_operand<Period>& t, sqlite3::serializer_t& context)
{
const auto dp = ::sqlpp::chrono::floor<::date::days>(t._t);
const auto time = ::date::make_time(t._t - dp);
const auto ymd = ::date::year_month_day{dp};
context << "STRFTIME('%Y-%m-%d %H:%M:%f', '" << ymd << ' ' << time << "')";
return context;
}
inline sqlite3::serializer_t& serialize(const day_point_operand& t, sqlite3::serializer_t& context)
{
const auto ymd = ::date::year_month_day{t._t};
context << "DATE('" << ymd << "')";
return context;
}
inline sqlite3::serializer_t& serialize(const floating_point_operand& t, sqlite3::serializer_t& context)
{
if (std::isnan(t._t))
context << "'NaN'";
else if (std::isinf(t._t))
{
if (t._t > std::numeric_limits<double>::max())
context << "'Inf'";
else
context << "'-Inf'";
}
else
context << t._t;
return context;
}
// sqlite3 accepts only signed integers,
// so we MUST perform a conversion from unsigned to signed
inline sqlite3::serializer_t& serialize(const unsigned_integral_operand& t, sqlite3::serializer_t& context)
{
context << static_cast<typename integral_operand::_value_t>(t._t);
return context;
}
}
#endif

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2013 - 2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_SQLITE3_H
#define SQLPP_SQLITE3_H
#include <sqlpp11/sqlite3/connection.h>
#include <sqlpp11/sqlite3/insert_or.h>
#endif