Path: blob/main/contrib/kyua/utils/sqlite/c_gate.cpp
48178 views
// Copyright 2011 The Kyua Authors.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions are5// met:6//7// * Redistributions of source code must retain the above copyright8// notice, this list of conditions and the following disclaimer.9// * Redistributions in binary form must reproduce the above copyright10// notice, this list of conditions and the following disclaimer in the11// documentation and/or other materials provided with the distribution.12// * Neither the name of Google Inc. nor the names of its contributors13// may be used to endorse or promote products derived from this software14// without specific prior written permission.15//16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2728#include "utils/sqlite/c_gate.hpp"2930#include "utils/fs/path.hpp"31#include "utils/optional.ipp"32#include "utils/sqlite/database.hpp"3334namespace sqlite = utils::sqlite;3536using utils::none;373839/// Creates a new gateway to an existing C++ SQLite database.40///41/// \param database_ The database to connect to. This object must remain alive42/// while the newly-constructed database_c_gate is alive.43sqlite::database_c_gate::database_c_gate(database& database_) :44_database(database_)45{46}474849/// Destructor.50///51/// Destroying this object has no implications on the life cycle of the SQLite52/// database. Only the corresponding database object controls when the SQLite 353/// database is closed.54sqlite::database_c_gate::~database_c_gate(void)55{56}575859/// Creates a C++ database for a C SQLite 3 database.60///61/// \warning The created database object does NOT own the C database. You must62/// take care to properly destroy the input sqlite3 when you are done with it to63/// not leak resources.64///65/// \param raw_database The raw database to wrap temporarily.66///67/// \return The wrapped database without strong ownership on the input database.68sqlite::database69sqlite::database_c_gate::connect(::sqlite3* raw_database)70{71return database(none, static_cast< void* >(raw_database), false);72}737475/// Returns the C native SQLite 3 database.76///77/// \return A native sqlite3 object holding the SQLite 3 C API database.78::sqlite3*79sqlite::database_c_gate::c_database(void)80{81return static_cast< ::sqlite3* >(_database.raw_database());82}838485