connection-factory.hxx   connection-factory.hxx 
skipping to change at line 30 skipping to change at line 30
#include <odb/sqlite/connection.hxx> #include <odb/sqlite/connection.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class LIBODB_SQLITE_EXPORT connection_factory class LIBODB_SQLITE_EXPORT connection_factory
{ {
public: public:
virtual details::shared_ptr<connection> virtual connection_ptr
connect () = 0; connect () = 0;
public: public:
typedef sqlite::database database_type; typedef sqlite::database database_type;
virtual void virtual void
database (database_type&) = 0; database (database_type&) = 0;
virtual virtual
~connection_factory (); ~connection_factory ();
}; };
// Share a single connection. // Share a single connection.
// //
class LIBODB_SQLITE_EXPORT single_connection_factory: class LIBODB_SQLITE_EXPORT single_connection_factory:
public connection_factory public connection_factory
{ {
public: public:
single_connection_factory (): db_ (0) {} single_connection_factory (): db_ (0) {}
virtual details::shared_ptr<connection> virtual connection_ptr
connect (); connect ();
virtual void virtual void
database (database_type&); database (database_type&);
virtual virtual
~single_connection_factory (); ~single_connection_factory ();
private: private:
single_connection_factory (const single_connection_factory&); single_connection_factory (const single_connection_factory&);
single_connection_factory& operator= (const single_connection_factory &); single_connection_factory& operator= (const single_connection_factory &);
private: protected:
class single_connection: public connection class single_connection: public connection
{ {
public: public:
// NULL factory value indicates that the connection is not in use. single_connection (database_type&, int extra_flags = 0);
// single_connection (database_type&, sqlite3*);
single_connection (database_type&,
int extra_flags,
single_connection_factory*);
private: private:
static bool static bool
zero_counter (void*); zero_counter (void*);
private: private:
friend class single_connection_factory; friend class single_connection_factory;
shared_base::refcount_callback callback_; shared_base::refcount_callback callback_;
// NULL factory value indicates that the connection is not in use.
//
single_connection_factory* factory_; single_connection_factory* factory_;
}; };
friend class single_connection; friend class single_connection;
private: typedef details::shared_ptr<single_connection> single_connection_ptr;
// This function is called when the factory needs to create the
// connection.
//
virtual single_connection_ptr
create ();
protected:
// Return true if the connection should be deleted, false otherwise. // Return true if the connection should be deleted, false otherwise.
// //
bool bool
release (single_connection*); release (single_connection*);
private: protected:
database_type* db_; database_type* db_;
details::mutex mutex_; details::mutex mutex_;
details::shared_ptr<single_connection> connection_; single_connection_ptr connection_;
}; };
// Create a new connection every time one is requested. // Create a new connection every time one is requested.
// //
class LIBODB_SQLITE_EXPORT new_connection_factory: class LIBODB_SQLITE_EXPORT new_connection_factory:
public connection_factory public connection_factory
{ {
public: public:
new_connection_factory (): db_ (0), extra_flags_ (0) {} new_connection_factory (): db_ (0), extra_flags_ (0) {}
virtual details::shared_ptr<connection> virtual connection_ptr
connect (); connect ();
virtual void virtual void
database (database_type&); database (database_type&);
private: private:
new_connection_factory (const new_connection_factory&); new_connection_factory (const new_connection_factory&);
new_connection_factory& operator= (const new_connection_factory&); new_connection_factory& operator= (const new_connection_factory&);
private: private:
skipping to change at line 157 skipping to change at line 165
min_ (min_connections), min_ (min_connections),
extra_flags_ (0), extra_flags_ (0),
in_use_ (0), in_use_ (0),
waiters_ (0), waiters_ (0),
db_ (0), db_ (0),
cond_ (mutex_) cond_ (mutex_)
{ {
// @@ check min_ <= max_ // @@ check min_ <= max_
} }
virtual details::shared_ptr<connection> virtual connection_ptr
connect (); connect ();
virtual void virtual void
database (database_type&); database (database_type&);
virtual virtual
~connection_pool_factory (); ~connection_pool_factory ();
private: private:
connection_pool_factory (const connection_pool_factory&); connection_pool_factory (const connection_pool_factory&);
connection_pool_factory& operator= (const connection_pool_factory&); connection_pool_factory& operator= (const connection_pool_factory&);
private: protected:
class pooled_connection: public connection class pooled_connection: public connection
{ {
public: public:
// NULL pool value indicates that the connection is not in use. pooled_connection (database_type&, int extra_flags = 0);
// pooled_connection (database_type&, sqlite3*);
pooled_connection (database_type&,
int extra_flags,
connection_pool_factory*);
private: private:
static bool static bool
zero_counter (void*); zero_counter (void*);
private: private:
friend class connection_pool_factory; friend class connection_pool_factory;
shared_base::refcount_callback callback_; shared_base::refcount_callback callback_;
// NULL pool value indicates that the connection is not in use.
//
connection_pool_factory* pool_; connection_pool_factory* pool_;
}; };
friend class pooled_connection; friend class pooled_connection;
typedef std::vector<details::shared_ptr<pooled_connection> > connecti ons;
private: typedef details::shared_ptr<pooled_connection> pooled_connection_ptr;
typedef std::vector<pooled_connection_ptr> connections;
// This function is called whenever the pool needs to create a new
// connection.
//
virtual pooled_connection_ptr
create ();
protected:
// Return true if the connection should be deleted, false otherwise. // Return true if the connection should be deleted, false otherwise.
// //
bool bool
release (pooled_connection*); release (pooled_connection*);
private: protected:
const std::size_t max_; const std::size_t max_;
const std::size_t min_; const std::size_t min_;
int extra_flags_; int extra_flags_;
std::size_t in_use_; // Number of connections currently in use. std::size_t in_use_; // Number of connections currently in use.
std::size_t waiters_; // Number of threads waiting for a connection. std::size_t waiters_; // Number of threads waiting for a connection.
database_type* db_; database_type* db_;
connections connections_; connections connections_;
 End of changes. 16 change blocks. 
22 lines changed or deleted 38 lines changed or added


 connection.hxx   connection.hxx 
skipping to change at line 16 skipping to change at line 16
#ifndef ODB_SQLITE_CONNECTION_HXX #ifndef ODB_SQLITE_CONNECTION_HXX
#define ODB_SQLITE_CONNECTION_HXX #define ODB_SQLITE_CONNECTION_HXX
#include <odb/pre.hxx> #include <odb/pre.hxx>
#include <sqlite3.h> #include <sqlite3.h>
#include <memory> // std::auto_ptr #include <memory> // std::auto_ptr
#include <odb/forward.hxx> #include <odb/forward.hxx>
#include <odb/connection.hxx>
#include <odb/details/mutex.hxx> #include <odb/details/mutex.hxx>
#include <odb/details/condition.hxx> #include <odb/details/condition.hxx>
#include <odb/details/shared-ptr.hxx> #include <odb/details/shared-ptr.hxx>
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx> #include <odb/sqlite/forward.hxx>
#include <odb/sqlite/transaction-impl.hxx>
#include <odb/sqlite/auto-handle.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class statement; class statement;
class statement_cache; class statement_cache;
class LIBODB_SQLITE_EXPORT connection: public details::shared_base class connection;
typedef details::shared_ptr<connection> connection_ptr;
class LIBODB_SQLITE_EXPORT connection: public odb::connection
{ {
public: public:
typedef sqlite::statement_cache statement_cache_type; typedef sqlite::statement_cache statement_cache_type;
typedef sqlite::database database_type; typedef sqlite::database database_type;
virtual virtual
~connection (); ~connection ();
connection (database_type&, int extra_flags = 0); connection (database_type&, int extra_flags = 0);
connection (database_type&, sqlite3* handle);
database_type& database_type&
database () database ()
{ {
return db_; return db_;
} }
public: public:
virtual transaction_impl*
begin ();
transaction_impl*
begin_immediate ();
transaction_impl*
begin_exclusive ();
public:
using odb::connection::execute;
virtual unsigned long long
execute (const char* statement, std::size_t length);
public:
sqlite3* sqlite3*
handle () handle ()
{ {
return handle_; return handle_;
} }
statement_cache_type& statement_cache_type&
statement_cache () statement_cache ()
{ {
return *statement_cache_; return *statement_cache_;
skipping to change at line 78 skipping to change at line 102
// Reset active and finalize uncached statements. // Reset active and finalize uncached statements.
// //
void void
clear (); clear ();
private: private:
connection (const connection&); connection (const connection&);
connection& operator= (const connection&); connection& operator= (const connection&);
private: private:
void
init ();
private:
// Needed to break the circular connection-database dependency
// (odb::connection has the odb::database member).
//
database_type& db_; database_type& db_;
sqlite3* handle_;
auto_handle<sqlite3> handle_;
// Keep statement_cache_ after handle_ so that it is destroyed before
// the connection is closed.
//
std::auto_ptr<statement_cache_type> statement_cache_;
// Unlock notification machinery. // Unlock notification machinery.
// //
private: private:
bool unlocked_; bool unlocked_;
details::mutex unlock_mutex_; details::mutex unlock_mutex_;
details::condition unlock_cond_; details::condition unlock_cond_;
friend void friend void
connection_unlock_callback (void**, int); connection_unlock_callback (void**, int);
// Linked list of active and uncached statements currently associated // Linked list of active and uncached statements currently associated
// with this connection. // with this connection.
// //
private: private:
friend class statement; friend class statement;
statement* statements_; statement* statements_;
std::auto_ptr<statement_cache_type> statement_cache_;
}; };
} }
} }
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_CONNECTION_HXX #endif // ODB_SQLITE_CONNECTION_HXX
 End of changes. 8 change blocks. 
4 lines changed or deleted 39 lines changed or added


 database.hxx   database.hxx 
skipping to change at line 31 skipping to change at line 31
#include <odb/sqlite/forward.hxx> #include <odb/sqlite/forward.hxx>
#include <odb/sqlite/connection.hxx> #include <odb/sqlite/connection.hxx>
#include <odb/sqlite/connection-factory.hxx> #include <odb/sqlite/connection-factory.hxx>
#include <odb/sqlite/transaction-impl.hxx> #include <odb/sqlite/transaction-impl.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class transaction_impl;
class LIBODB_SQLITE_EXPORT database: public odb::database class LIBODB_SQLITE_EXPORT database: public odb::database
{ {
public: public:
typedef sqlite::connection connection_type;
public:
database (const std::string& name, database (const std::string& name,
int flags = SQLITE_OPEN_READWRITE, int flags = SQLITE_OPEN_READWRITE,
bool foreign_keys = true,
std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> =
std::auto_ptr<connection_factory> (0)); std::auto_ptr<connection_factory> (0));
// Extract the database parameters from the command line. The // Extract the database parameters from the command line. The
// following options are recognized: // following options are recognized:
// //
// --database // --database
// --create // --create
// --read-only // --read-only
// --options-file // --options-file
skipping to change at line 60 skipping to change at line 60
// For more information, see the output of the print_usage() function // For more information, see the output of the print_usage() function
// below. If erase is true, the above options are removed from the ar gv // below. If erase is true, the above options are removed from the ar gv
// array and the argc count is updated accordingly. The command line // array and the argc count is updated accordingly. The command line
// options override the flags passed as an argument. This constructor // options override the flags passed as an argument. This constructor
// may throw the cli_exception exception. // may throw the cli_exception exception.
// //
database (int& argc, database (int& argc,
char* argv[], char* argv[],
bool erase = false, bool erase = false,
int flags = SQLITE_OPEN_READWRITE, int flags = SQLITE_OPEN_READWRITE,
bool foreign_keys = true,
std::auto_ptr<connection_factory> = std::auto_ptr<connection_factory> =
std::auto_ptr<connection_factory> (0)); std::auto_ptr<connection_factory> (0));
static void static void
print_usage (std::ostream&); print_usage (std::ostream&);
public: public:
const std::string& const std::string&
name () const name () const
{ {
return name_; return name_;
} }
int int
flags () const flags () const
{ {
return flags_; return flags_;
} }
public: bool
using odb::database::execute; foreign_keys () const
{
virtual unsigned long long return foreign_keys_;
execute (const char* statement, std::size_t length); }
// Transactions.
//
public: public:
virtual transaction_impl* virtual transaction_impl*
begin (); begin ();
transaction_impl* transaction_impl*
begin_immediate (); begin_immediate ();
transaction_impl* transaction_impl*
begin_exclusive (); begin_exclusive ();
public: public:
details::shared_ptr<connection_type> connection_ptr
connection (); connection ();
public: public:
virtual virtual
~database (); ~database ();
protected:
virtual odb::connection*
connection_ ();
private: private:
std::string name_; std::string name_;
int flags_; int flags_;
bool foreign_keys_;
std::auto_ptr<connection_factory> factory_; std::auto_ptr<connection_factory> factory_;
}; };
} }
} }
#include <odb/sqlite/database.ixx> #include <odb/sqlite/database.ixx>
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_DATABASE_HXX #endif // ODB_SQLITE_DATABASE_HXX
 End of changes. 9 change blocks. 
9 lines changed or deleted 17 lines changed or added


 database.ixx   database.ixx 
// file : odb/sqlite/database.ixx // file : odb/sqlite/database.ixx
// author : Boris Kolpackov <boris@codesynthesis.com> // author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file // license : GNU GPL v2; see accompanying LICENSE file
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
inline details::shared_ptr<database::connection_type> database:: inline connection_ptr database::
connection () connection ()
{ {
return factory_->connect (); // Go through the virtual connection_() function instead of
// directly to allow overriding.
//
return connection_ptr (
static_cast<sqlite::connection*> (connection_ ()));
} }
} }
} }
 End of changes. 2 change blocks. 
2 lines changed or deleted 6 lines changed or added


 forward.hxx   forward.hxx 
skipping to change at line 19 skipping to change at line 19
#include <odb/pre.hxx> #include <odb/pre.hxx>
#include <odb/forward.hxx> #include <odb/forward.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class database; class database;
class connection; class connection;
typedef details::shared_ptr<connection> connection_ptr;
class connection_factory; class connection_factory;
class transaction; class transaction;
class query; class query;
// Implementation details. // Implementation details.
// //
class binding; class binding;
class select_statement; class select_statement;
template <typename T> template <typename T>
class object_statements; class object_statements;
template <typename T> template <typename T>
class view_statements;
template <typename T>
class container_statements; class container_statements;
class query_params; class query_params;
} }
namespace details namespace details
{ {
template <> template <>
struct counter_type<sqlite::connection>
{
typedef shared_base counter;
};
template <>
struct counter_type<sqlite::query_params> struct counter_type<sqlite::query_params>
{ {
typedef shared_base counter; typedef shared_base counter;
}; };
} }
} }
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_FORWARD_HXX #endif // ODB_SQLITE_FORWARD_HXX
 End of changes. 3 change blocks. 
0 lines changed or deleted 10 lines changed or added


 object-statements.hxx   object-statements.hxx 
skipping to change at line 18 skipping to change at line 18
#include <odb/pre.hxx> #include <odb/pre.hxx>
#include <vector> #include <vector>
#include <cassert> #include <cassert>
#include <cstddef> // std::size_t #include <cstddef> // std::size_t
#include <odb/forward.hxx> #include <odb/forward.hxx>
#include <odb/traits.hxx> #include <odb/traits.hxx>
#include <odb/cache-traits.hxx> #include <odb/cache-traits.hxx>
#include <odb/details/shared-ptr.hxx> #include <odb/details/shared-ptr.hxx>
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/binding.hxx> #include <odb/sqlite/binding.hxx>
#include <odb/sqlite/statement.hxx> #include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statements-base.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class connection; class LIBODB_SQLITE_EXPORT object_statements_base: public statements_ba
se
class LIBODB_SQLITE_EXPORT object_statements_base:
public details::shared_base
{ {
public: public:
typedef sqlite::connection connection_type;
connection_type&
connection ()
{
return conn_;
}
// Locking. // Locking.
// //
void void
lock () lock ()
{ {
assert (!locked_); assert (!locked_);
locked_ = true; locked_ = true;
} }
void void
skipping to change at line 71 skipping to change at line 63
{ {
return locked_; return locked_;
} }
public: public:
virtual virtual
~object_statements_base (); ~object_statements_base ();
protected: protected:
object_statements_base (connection_type& conn) object_statements_base (connection_type& conn)
: conn_ (conn), locked_ (false) : statements_base (conn), locked_ (false)
{ {
} }
struct auto_unlock
{
// Unlocks the statement on construction and re-locks it on
// destruction.
//
auto_unlock (object_statements_base&);
~auto_unlock ();
private:
auto_unlock (const auto_unlock&);
auto_unlock& operator= (const auto_unlock&);
private:
object_statements_base& s_;
};
protected: protected:
connection_type& conn_;
bool locked_; bool locked_;
}; };
template <typename T> template <typename T>
class object_statements: public object_statements_base class object_statements: public object_statements_base
{ {
public: public:
typedef T object_type; typedef T object_type;
typedef odb::object_traits<object_type> object_traits; typedef odb::object_traits<object_type> object_traits;
typedef typename object_traits::id_type id_type; typedef typename object_traits::id_type id_type;
skipping to change at line 137 skipping to change at line 144
private: private:
auto_lock (const auto_lock&); auto_lock (const auto_lock&);
auto_lock& operator= (const auto_lock&); auto_lock& operator= (const auto_lock&);
private: private:
object_statements& s_; object_statements& s_;
bool locked_; bool locked_;
}; };
// public:
//
object_statements (connection_type&); object_statements (connection_type&);
virtual
~object_statements ();
// Delayed loading. // Delayed loading.
// //
void void
delay_load (const id_type& id, delay_load (const id_type& id,
object_type& obj, object_type& obj,
const typename object_cache_traits::position_type& p) const typename object_cache_traits::position_type& p)
{ {
delayed_.push_back (delayed_load (id, obj, p)); delayed_.push_back (delayed_load (id, obj, p));
} }
 End of changes. 9 change blocks. 
16 lines changed or deleted 26 lines changed or added


 object-statements.ixx   object-statements.ixx 
// file : odb/sqlite/object-statements.ixx // file : odb/sqlite/object-statements.ixx
// author : Boris Kolpackov <boris@codesynthesis.com> // author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file // license : GNU GPL v2; see accompanying LICENSE file
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
// //
// auto_unlock
//
inline object_statements_base::auto_unlock::
auto_unlock (object_statements_base& s)
: s_ (s)
{
s_.unlock ();
}
inline object_statements_base::auto_unlock::
~auto_unlock ()
{
s_.lock ();
}
//
// auto_lock // auto_lock
// //
template <typename T> template <typename T>
inline object_statements<T>::auto_lock:: inline object_statements<T>::auto_lock::
auto_lock (object_statements& s) auto_lock (object_statements& s)
: s_ (s) : s_ (s)
{ {
if (!s_.locked ()) if (!s_.locked ())
{ {
s_.lock (); s_.lock ();
 End of changes. 1 change blocks. 
0 lines changed or deleted 16 lines changed or added


 object-statements.txx   object-statements.txx 
skipping to change at line 21 skipping to change at line 21
#include <odb/exceptions.hxx> #include <odb/exceptions.hxx>
#include <odb/sqlite/connection.hxx> #include <odb/sqlite/connection.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
template <typename T> template <typename T>
object_statements<T>:: object_statements<T>::
~object_statements ()
{
}
template <typename T>
object_statements<T>::
object_statements (connection_type& conn) object_statements (connection_type& conn)
: object_statements_base (conn), : object_statements_base (conn),
container_statement_cache_ (conn), container_statement_cache_ (conn),
in_image_binding_ (in_image_bind_, object_traits::in_column_count ), in_image_binding_ (in_image_bind_, object_traits::in_column_count ),
out_image_binding_ (out_image_bind_, object_traits::out_column_co unt), out_image_binding_ (out_image_bind_, object_traits::out_column_co unt),
id_image_binding_ (in_image_bind_ + object_traits::in_column_coun t, 1) id_image_binding_ (in_image_bind_ + object_traits::in_column_coun t, 1)
{ {
image_.version = 0; image_.version = 0;
in_image_version_ = 0; in_image_version_ = 0;
out_image_version_ = 0; out_image_version_ = 0;
skipping to change at line 73 skipping to change at line 79
// Our calls to init/load below can result in additional delayed // Our calls to init/load below can result in additional delayed
// loads being added to the delayed_ vector. We need to process // loads being added to the delayed_ vector. We need to process
// those before we call the post callback. // those before we call the post callback.
// //
object_traits::init (*l.obj, image (), db); object_traits::init (*l.obj, image (), db);
object_traits::load_ (*this, *l.obj); // Load containers, etc. object_traits::load_ (*this, *l.obj); // Load containers, etc.
if (!delayed_.empty ()) if (!delayed_.empty ())
load_delayed_ (); load_delayed_ ();
object_traits::callback (db, *l.obj, callback_event::post_load); // Temporarily unlock the statement for the post_load call so that
// it can load objects of this type recursively. This is safe to do
// because we have completely loaded the current object. Also the
// delayed_ list is clear before the unlock and should be clear on
// re-lock (since a callback can only call public API functions
// which will make sure all the delayed loads are processed before
// returning).
//
{
auto_unlock u (*this);
object_traits::callback (db, *l.obj, callback_event::post_load);
}
g.release (); g.release ();
} }
} }
template <typename T> template <typename T>
void object_statements<T>:: void object_statements<T>::
clear_delayed_ () clear_delayed_ ()
{ {
// Remove the objects from the session cache. // Remove the objects from the session cache.
 End of changes. 2 change blocks. 
1 lines changed or deleted 18 lines changed or added


 query.hxx   query.hxx 
skipping to change at line 118 skipping to change at line 118
}; };
// //
// //
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
struct query_column; struct query_column;
class LIBODB_SQLITE_EXPORT query class LIBODB_SQLITE_EXPORT query
{ {
public: public:
struct clause_part
{
enum kind_type
{
column,
param,
native,
boolean
};
clause_part (kind_type k): kind (k) {}
clause_part (kind_type k, const std::string& p): kind (k), part (p)
{}
clause_part (bool p): kind (boolean), bool_part (p) {}
kind_type kind;
std::string part;
bool bool_part;
};
query () query ()
: parameters_ (new (details::shared) query_params) : parameters_ (new (details::shared) query_params)
{ {
} }
// True or false literal.
//
explicit
query (bool v)
: parameters_ (new (details::shared) query_params)
{
clause_.push_back (clause_part (v));
}
explicit explicit
query (const std::string& q) query (const char* native)
: clause_ (q), parameters_ (new (details::shared) query_params) : parameters_ (new (details::shared) query_params)
{ {
clause_.push_back (clause_part (clause_part::native, native));
}
explicit
query (const std::string& native)
: parameters_ (new (details::shared) query_params)
{
clause_.push_back (clause_part (clause_part::native, native));
}
query (const char* table, const char* column)
: parameters_ (new (details::shared) query_params)
{
append (table, column);
} }
template <typename T> template <typename T>
explicit explicit
query (val_bind<T> v) query (val_bind<T> v)
: parameters_ (new (details::shared) query_params) : parameters_ (new (details::shared) query_params)
{ {
append<T, type_traits<T>::db_type_id> (v); append<T, type_traits<T>::db_type_id> (v);
} }
skipping to change at line 157 skipping to change at line 199
query (const query&); query (const query&);
query& query&
operator= (const query&); operator= (const query&);
public: public:
std::string std::string
clause () const; clause () const;
const char*
clause_prefix () const;
binding& binding&
parameters_binding () const; parameters_binding () const;
details::shared_ptr<query_params> details::shared_ptr<query_params>
parameters () const; parameters () const;
public: public:
bool
empty () const
{
return clause_.empty ();
}
static const query true_expr;
bool
const_true () const
{
return clause_.size () == 1 &&
clause_.front ().kind == clause_part::boolean &&
clause_.front ().bool_part;
}
void
optimize ();
public:
template <typename T> template <typename T>
static val_bind<T> static val_bind<T>
_val (const T& x) _val (const T& x)
{ {
return val_bind<T> (x); return val_bind<T> (x);
} }
template <typename T> template <typename T>
static ref_bind<T> static ref_bind<T>
_ref (const T& x) _ref (const T& x)
skipping to change at line 185 skipping to change at line 250
return ref_bind<T> (x); return ref_bind<T> (x);
} }
public: public:
query& query&
operator+= (const query&); operator+= (const query&);
query& query&
operator+= (const std::string& q) operator+= (const std::string& q)
{ {
size_t n (clause_.size ()); append (q);
if (n != 0 && clause_[n - 1] != ' ' && !q.empty () && q[0] != ' ')
clause_ += ' ';
clause_ += q;
return *this; return *this;
} }
template <typename T> template <typename T>
query& query&
operator+= (val_bind<T> v) operator+= (val_bind<T> v)
{ {
append<T, type_traits<T>::db_type_id> (v); append<T, type_traits<T>::db_type_id> (v);
return *this; return *this;
} }
skipping to change at line 219 skipping to change at line 279
public: public:
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
void void
append (val_bind<T>); append (val_bind<T>);
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
void void
append (ref_bind<T>); append (ref_bind<T>);
void
append (const std::string& native);
void
append (const char* table, const char* column);
private: private:
void void
add (details::shared_ptr<query_param>); add (details::shared_ptr<query_param>);
private: private:
std::string clause_; typedef std::vector<clause_part> clause_type;
clause_type clause_;
details::shared_ptr<query_params> parameters_; details::shared_ptr<query_params> parameters_;
}; };
inline query inline query
operator+ (const query& x, const query& y) operator+ (const query& x, const query& y)
{ {
query r (x); query r (x);
r += y; r += y;
return r; return r;
} }
skipping to change at line 328 skipping to change at line 396
template <typename T> template <typename T>
inline query inline query
operator+ (ref_bind<T> b, const std::string& s) operator+ (ref_bind<T> b, const std::string& s)
{ {
query r; query r;
r += b; r += b;
r += s; r += s;
return r; return r;
} }
inline query LIBODB_SQLITE_EXPORT query
operator&& (const query& x, const query& y) operator&& (const query&, const query&);
{
query r ("(");
r += x;
r += ") AND (";
r += y;
r += ")";
return r;
}
inline query LIBODB_SQLITE_EXPORT query
operator|| (const query& x, const query& y) operator|| (const query&, const query&);
{
query r ("(");
r += x;
r += ") OR (";
r += y;
r += ")";
return r;
}
inline query LIBODB_SQLITE_EXPORT query
operator! (const query& x) operator! (const query&);
{
query r ("NOT (");
r += x;
r += ")";
return r;
}
// query_column // query_column
// //
template <typename T, typename T2> template <typename T, typename T2>
class copy_bind: public val_bind<T> class copy_bind: public val_bind<T>
{ {
public: public:
explicit explicit
copy_bind (const T2& v): val_bind<T> (val), val (v) {} copy_bind (const T2& v): val_bind<T> (val), val (v) {}
skipping to change at line 379 skipping to change at line 425
const T val; const T val;
}; };
template <typename T> template <typename T>
const T& const T&
type_instance (); type_instance ();
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
struct query_column struct query_column
{ {
explicit // Note that we keep shalow copies of the table and column names.
query_column (const char* name) //
: name_ (name) query_column (const char* table, const char* column)
: table_ (table), column_ (column)
{ {
} }
const char* const char*
name () const table () const
{ {
return name_; return table_;
}
const char*
column () const
{
return column_;
} }
// is_null, is_not_null // is_null, is_not_null
// //
public: public:
query query
is_null () const is_null () const
{ {
query q (name_); query q (table_, column_);
q += "IS NULL"; q += "IS NULL";
return q; return q;
} }
query query
is_not_null () const is_not_null () const
{ {
query q (name_); query q (table_, column_);
q += "IS NOT NULL"; q += "IS NOT NULL";
return q; return q;
} }
// in // in
// //
public: public:
query query
in (const T&, const T&) const; in (const T&, const T&) const;
skipping to change at line 441 skipping to change at line 494
public: public:
query query
equal (const T& v) const equal (const T& v) const
{ {
return equal (val_bind<T> (v)); return equal (val_bind<T> (v));
} }
query query
equal (val_bind<T> v) const equal (val_bind<T> v) const
{ {
query q (name_); query q (table_, column_);
q += "="; q += "=";
q.append<T, ID> (v); q.append<T, ID> (v);
return q; return q;
} }
template <typename T2> template <typename T2>
query query
equal (val_bind<T2> v) const equal (val_bind<T2> v) const
{ {
copy_bind<T, T2> c (v.val); copy_bind<T, T2> c (v.val);
return equal (c); return equal (c);
} }
query query
equal (ref_bind<T> r) const equal (ref_bind<T> r) const
{ {
query q (name_); query q (table_, column_);
q += "="; q += "=";
q.append<T, ID> (r); q.append<T, ID> (r);
return q; return q;
} }
friend query friend query
operator== (const query_column& c, const T& v) operator== (const query_column& c, const T& v)
{ {
return c.equal (v); return c.equal (v);
} }
skipping to change at line 526 skipping to change at line 579
public: public:
query query
unequal (const T& v) const unequal (const T& v) const
{ {
return unequal (val_bind<T> (v)); return unequal (val_bind<T> (v));
} }
query query
unequal (val_bind<T> v) const unequal (val_bind<T> v) const
{ {
query q (name_); query q (table_, column_);
q += "!="; q += "!=";
q.append<T, ID> (v); q.append<T, ID> (v);
return q; return q;
} }
template <typename T2> template <typename T2>
query query
unequal (val_bind<T2> v) const unequal (val_bind<T2> v) const
{ {
copy_bind<T, T2> c (v.val); copy_bind<T, T2> c (v.val);
return unequal (c); return unequal (c);
} }
query query
unequal (ref_bind<T> r) const unequal (ref_bind<T> r) const
{ {
query q (name_); query q (table_, column_);
q += "!="; q += "!=";
q.append<T, ID> (r); q.append<T, ID> (r);
return q; return q;
} }
friend query friend query
operator!= (const query_column& c, const T& v) operator!= (const query_column& c, const T& v)
{ {
return c.unequal (v); return c.unequal (v);
} }
skipping to change at line 611 skipping to change at line 664
public: public:
query query
less (const T& v) const less (const T& v) const
{ {
return less (val_bind<T> (v)); return less (val_bind<T> (v));
} }
query query
less (val_bind<T> v) const less (val_bind<T> v) const
{ {
query q (name_); query q (table_, column_);
q += "<"; q += "<";
q.append<T, ID> (v); q.append<T, ID> (v);
return q; return q;
} }
template <typename T2> template <typename T2>
query query
less (val_bind<T2> v) const less (val_bind<T2> v) const
{ {
copy_bind<T, T2> c (v.val); copy_bind<T, T2> c (v.val);
return less (c); return less (c);
} }
query query
less (ref_bind<T> r) const less (ref_bind<T> r) const
{ {
query q (name_); query q (table_, column_);
q += "<"; q += "<";
q.append<T, ID> (r); q.append<T, ID> (r);
return q; return q;
} }
friend query friend query
operator< (const query_column& c, const T& v) operator< (const query_column& c, const T& v)
{ {
return c.less (v); return c.less (v);
} }
skipping to change at line 696 skipping to change at line 749
public: public:
query query
greater (const T& v) const greater (const T& v) const
{ {
return greater (val_bind<T> (v)); return greater (val_bind<T> (v));
} }
query query
greater (val_bind<T> v) const greater (val_bind<T> v) const
{ {
query q (name_); query q (table_, column_);
q += ">"; q += ">";
q.append<T, ID> (v); q.append<T, ID> (v);
return q; return q;
} }
template <typename T2> template <typename T2>
query query
greater (val_bind<T2> v) const greater (val_bind<T2> v) const
{ {
copy_bind<T, T2> c (v.val); copy_bind<T, T2> c (v.val);
return greater (c); return greater (c);
} }
query query
greater (ref_bind<T> r) const greater (ref_bind<T> r) const
{ {
query q (name_); query q (table_, column_);
q += ">"; q += ">";
q.append<T, ID> (r); q.append<T, ID> (r);
return q; return q;
} }
friend query friend query
operator> (const query_column& c, const T& v) operator> (const query_column& c, const T& v)
{ {
return c.greater (v); return c.greater (v);
} }
skipping to change at line 781 skipping to change at line 834
public: public:
query query
less_equal (const T& v) const less_equal (const T& v) const
{ {
return less_equal (val_bind<T> (v)); return less_equal (val_bind<T> (v));
} }
query query
less_equal (val_bind<T> v) const less_equal (val_bind<T> v) const
{ {
query q (name_); query q (table_, column_);
q += "<="; q += "<=";
q.append<T, ID> (v); q.append<T, ID> (v);
return q; return q;
} }
template <typename T2> template <typename T2>
query query
less_equal (val_bind<T2> v) const less_equal (val_bind<T2> v) const
{ {
copy_bind<T, T2> c (v.val); copy_bind<T, T2> c (v.val);
return less_equal (c); return less_equal (c);
} }
query query
less_equal (ref_bind<T> r) const less_equal (ref_bind<T> r) const
{ {
query q (name_); query q (table_, column_);
q += "<="; q += "<=";
q.append<T, ID> (r); q.append<T, ID> (r);
return q; return q;
} }
friend query friend query
operator<= (const query_column& c, const T& v) operator<= (const query_column& c, const T& v)
{ {
return c.less_equal (v); return c.less_equal (v);
} }
skipping to change at line 866 skipping to change at line 919
public: public:
query query
greater_equal (const T& v) const greater_equal (const T& v) const
{ {
return greater_equal (val_bind<T> (v)); return greater_equal (val_bind<T> (v));
} }
query query
greater_equal (val_bind<T> v) const greater_equal (val_bind<T> v) const
{ {
query q (name_); query q (table_, column_);
q += ">="; q += ">=";
q.append<T, ID> (v); q.append<T, ID> (v);
return q; return q;
} }
template <typename T2> template <typename T2>
query query
greater_equal (val_bind<T2> v) const greater_equal (val_bind<T2> v) const
{ {
copy_bind<T, T2> c (v.val); copy_bind<T, T2> c (v.val);
return greater_equal (c); return greater_equal (c);
} }
query query
greater_equal (ref_bind<T> r) const greater_equal (ref_bind<T> r) const
{ {
query q (name_); query q (table_, column_);
q += ">="; q += ">=";
q.append<T, ID> (r); q.append<T, ID> (r);
return q; return q;
} }
friend query friend query
operator>= (const query_column& c, const T& v) operator>= (const query_column& c, const T& v)
{ {
return c.greater_equal (v); return c.greater_equal (v);
} }
skipping to change at line 950 skipping to change at line 1003
// //
public: public:
template <typename T2, database_type_id ID2> template <typename T2, database_type_id ID2>
query query
operator== (const query_column<T2, ID2>& c) const operator== (const query_column<T2, ID2>& c) const
{ {
// We can compare columns only if we can compare their C++ types. // We can compare columns only if we can compare their C++ types.
// //
(void) (sizeof (type_instance<T> () == type_instance<T2> ())); (void) (sizeof (type_instance<T> () == type_instance<T2> ()));
query q (name_); query q (table_, column_);
q += "="; q += "=";
q += c.name (); q.append (c.table (), c.column ());
return q; return q;
} }
template <typename T2, database_type_id ID2> template <typename T2, database_type_id ID2>
query query
operator!= (const query_column<T2, ID2>& c) const operator!= (const query_column<T2, ID2>& c) const
{ {
// We can compare columns only if we can compare their C++ types. // We can compare columns only if we can compare their C++ types.
// //
(void) (sizeof (type_instance<T> () != type_instance<T2> ())); (void) (sizeof (type_instance<T> () != type_instance<T2> ()));
query q (name_); query q (table_, column_);
q += "!="; q += "!=";
q += c.name (); q.append (c.table (), c.column ());
return q; return q;
} }
template <typename T2, database_type_id ID2> template <typename T2, database_type_id ID2>
query query
operator< (const query_column<T2, ID2>& c) const operator< (const query_column<T2, ID2>& c) const
{ {
// We can compare columns only if we can compare their C++ types. // We can compare columns only if we can compare their C++ types.
// //
(void) (sizeof (type_instance<T> () < type_instance<T2> ())); (void) (sizeof (type_instance<T> () < type_instance<T2> ()));
query q (name_); query q (table_, column_);
q += "<"; q += "<";
q += c.name (); q.append (c.table (), c.column ());
return q; return q;
} }
template <typename T2, database_type_id ID2> template <typename T2, database_type_id ID2>
query query
operator> (const query_column<T2, ID2>& c) const operator> (const query_column<T2, ID2>& c) const
{ {
// We can compare columns only if we can compare their C++ types. // We can compare columns only if we can compare their C++ types.
// //
(void) (sizeof (type_instance<T> () > type_instance<T2> ())); (void) (sizeof (type_instance<T> () > type_instance<T2> ()));
query q (name_); query q (table_, column_);
q += ">"; q += ">";
q += c.name (); q.append (c.table (), c.column ());
return q; return q;
} }
template <typename T2, database_type_id ID2> template <typename T2, database_type_id ID2>
query query
operator<= (const query_column<T2, ID2>& c) const operator<= (const query_column<T2, ID2>& c) const
{ {
// We can compare columns only if we can compare their C++ types. // We can compare columns only if we can compare their C++ types.
// //
(void) (sizeof (type_instance<T> () <= type_instance<T2> ())); (void) (sizeof (type_instance<T> () <= type_instance<T2> ()));
query q (name_); query q (table_, column_);
q += "<="; q += "<=";
q += c.name (); q.append (c.table (), c.column ());
return q; return q;
} }
template <typename T2, database_type_id ID2> template <typename T2, database_type_id ID2>
query query
operator>= (const query_column<T2, ID2>& c) const operator>= (const query_column<T2, ID2>& c) const
{ {
// We can compare columns only if we can compare their C++ types. // We can compare columns only if we can compare their C++ types.
// //
(void) (sizeof (type_instance<T> () >= type_instance<T2> ())); (void) (sizeof (type_instance<T> () >= type_instance<T2> ()));
query q (name_); query q (table_, column_);
q += ">="; q += ">=";
q += c.name (); q.append (c.table (), c.column ());
return q; return q;
} }
private: private:
const char* name_; const char* table_;
const char* column_;
}; };
// Provide operator+() for using columns to construct native
// query fragments (e.g., ORDER BY).
//
template <typename T, database_type_id ID>
inline query
operator+ (const query_column<T, ID>& c, const std::string& s)
{
query q (c.table (), c.column ());
q += s;
return q;
}
template <typename T, database_type_id ID>
inline query
operator+ (const std::string& s, const query_column<T, ID>& c)
{
query q (s);
q.append (c.table (), c.column ());
return q;
}
template <typename T, database_type_id ID>
inline query
operator+ (const query_column<T, ID>& c, const query& q)
{
query r (c.table (), c.column ());
r += q;
return r;
}
template <typename T, database_type_id ID>
inline query
operator+ (const query& q, const query_column<T, ID>& c)
{
query r (q);
r.append (c.table (), c.column ());
return r;
}
// //
// //
template <typename T, database_type_id> template <typename T, database_type_id>
struct query_param_impl; struct query_param_impl;
// INTEGER // INTEGER
// //
template <typename T> template <typename T>
struct query_param_impl<T, id_integer>: query_param struct query_param_impl<T, id_integer>: query_param
{ {
skipping to change at line 1184 skipping to change at line 1277
std::size_t size_; std::size_t size_;
}; };
} }
} }
// odb::query specialization for SQLite. // odb::query specialization for SQLite.
// //
namespace odb namespace odb
{ {
template <typename T> template <typename T>
class query<T, sqlite::query>: public object_traits<T>::query_type class query<T, sqlite::query>: public query_selector<T>::type
{ {
public: public:
// We don't define any typedefs here since they may clash with // We don't define any typedefs here since they may clash with
// column names defined by our base type. // column names defined by our base type.
// //
query () query ()
{ {
} }
explicit explicit
query (bool v)
: query_selector<T>::type (v)
{
}
explicit
query (const char* q)
: query_selector<T>::type (q)
{
}
explicit
query (const std::string& q) query (const std::string& q)
: object_traits<T>::query_type (q) : query_selector<T>::type (q)
{ {
} }
template <typename T2> template <typename T2>
explicit explicit
query (sqlite::val_bind<T2> v) query (sqlite::val_bind<T2> v)
: object_traits<T>::query_type (sqlite::query (v)) : query_selector<T>::type (sqlite::query (v))
{ {
} }
template <typename T2> template <typename T2>
explicit explicit
query (sqlite::ref_bind<T2> r) query (sqlite::ref_bind<T2> r)
: object_traits<T>::query_type (sqlite::query (r)) : query_selector<T>::type (sqlite::query (r))
{ {
} }
query (const sqlite::query& q) query (const sqlite::query& q)
: object_traits<T>::query_type (q) : query_selector<T>::type (q)
{ {
} }
template <sqlite::database_type_id ID> template <sqlite::database_type_id ID>
query (const sqlite::query_column<bool, ID>& qc) query (const sqlite::query_column<bool, ID>& qc)
: object_traits<T>::query_type (qc) : query_selector<T>::type (qc)
{ {
} }
}; };
} }
#include <odb/sqlite/query.ixx> #include <odb/sqlite/query.ixx>
#include <odb/sqlite/query.txx> #include <odb/sqlite/query.txx>
#include <odb/post.hxx> #include <odb/post.hxx>
 End of changes. 50 change blocks. 
75 lines changed or deleted 181 lines changed or added


 query.txx   query.txx 
skipping to change at line 16 skipping to change at line 16
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
// query // query
// //
template <database_type_id ID> template <database_type_id ID>
query:: query::
query (const query_column<bool, ID>& c) query (const query_column<bool, ID>& c)
: clause_ (c.name ()), : parameters_ (new (details::shared) query_params)
parameters_ (new (details::shared) query_params)
{ {
// Cannot use IS TRUE here since database type can be a non- // Cannot use IS TRUE here since database type can be a non-
// integral type. // integral type.
// //
clause_ += " = "; append (c.table (), c.column ());
append ("=");
append<bool, ID> (val_bind<bool> (true)); append<bool, ID> (val_bind<bool> (true));
} }
// query_column // query_column
// //
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
query query_column<T, ID>:: query query_column<T, ID>::
in (const T& v1, const T& v2) const in (const T& v1, const T& v2) const
{ {
query q (name_); query q (table_, column_);
q += "IN ("; q += "IN (";
q.append<T, ID> (val_bind<T> (v1)); q.append<T, ID> (val_bind<T> (v1));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v2)); q.append<T, ID> (val_bind<T> (v2));
q += ")"; q += ")";
return q; return q;
} }
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
query query_column<T, ID>:: query query_column<T, ID>::
in (const T& v1, const T& v2, const T& v3) const in (const T& v1, const T& v2, const T& v3) const
{ {
query q (name_); query q (table_, column_);
q += "IN ("; q += "IN (";
q.append<T, ID> (val_bind<T> (v1)); q.append<T, ID> (val_bind<T> (v1));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v2)); q.append<T, ID> (val_bind<T> (v2));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v3)); q.append<T, ID> (val_bind<T> (v3));
q += ")"; q += ")";
return q; return q;
} }
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
query query_column<T, ID>:: query query_column<T, ID>::
in (const T& v1, const T& v2, const T& v3, const T& v4) const in (const T& v1, const T& v2, const T& v3, const T& v4) const
{ {
query q (name_); query q (table_, column_);
q += "IN ("; q += "IN (";
q.append<T, ID> (val_bind<T> (v1)); q.append<T, ID> (val_bind<T> (v1));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v2)); q.append<T, ID> (val_bind<T> (v2));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v3)); q.append<T, ID> (val_bind<T> (v3));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v4)); q.append<T, ID> (val_bind<T> (v4));
q += ")"; q += ")";
return q; return q;
} }
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
query query_column<T, ID>:: query query_column<T, ID>::
in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) co nst in (const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) co nst
{ {
query q (name_); query q (table_, column_);
q += "IN ("; q += "IN (";
q.append<T, ID> (val_bind<T> (v1)); q.append<T, ID> (val_bind<T> (v1));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v2)); q.append<T, ID> (val_bind<T> (v2));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v3)); q.append<T, ID> (val_bind<T> (v3));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v4)); q.append<T, ID> (val_bind<T> (v4));
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (v5)); q.append<T, ID> (val_bind<T> (v5));
q += ")"; q += ")";
return q; return q;
} }
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
template <typename I> template <typename I>
query query_column<T, ID>:: query query_column<T, ID>::
in_range (I begin, I end) const in_range (I begin, I end) const
{ {
query q (name_); query q (table_, column_);
q += "IN ("; q += "IN (";
for (I i (begin); i != end; ++i) for (I i (begin); i != end; ++i)
{ {
if (i != begin) if (i != begin)
q += ","; q += ",";
q.append<T, ID> (val_bind<T> (*i)); q.append<T, ID> (val_bind<T> (*i));
} }
q += ")"; q += ")";
 End of changes. 7 change blocks. 
8 lines changed or deleted 8 lines changed or added


 result.hxx   result.hxx 
// file : odb/sqlite/result.hxx // file : odb/sqlite/result.hxx
// author : Boris Kolpackov <boris@codesynthesis.com> // author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC // copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file // license : GNU GPL v2; see accompanying LICENSE file
#ifndef ODB_SQLITE_RESULT_HXX #ifndef ODB_SQLITE_RESULT_HXX
#define ODB_SQLITE_RESULT_HXX #define ODB_SQLITE_RESULT_HXX
#include <odb/pre.hxx> #include <odb/pre.hxx>
#include <cstddef> // std::size_t #include <odb/traits.hxx>
#include <odb/result.hxx> #include <odb/result.hxx>
#include <odb/details/shared-ptr.hxx> #include <odb/details/shared-ptr.hxx>
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx> // query, query_params #include <odb/sqlite/forward.hxx> // query, query_params
#include <odb/sqlite/statement.hxx> #include <odb/sqlite/statement.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class LIBODB_SQLITE_EXPORT result_impl_base class LIBODB_SQLITE_EXPORT result_impl_base
{ {
public: public:
result_impl_base (const query&, details::shared_ptr<select_statement> ); result_impl_base (const query&, details::shared_ptr<select_statement> );
protected: protected:
// We need to hold on to the query parameters because SQLite uses // We need to hold on to the query parameters because SQLite uses
// the parameter buffers to find each next row. // the parameter buffers to find each next row.
// //
details::shared_ptr<query_params> params_; details::shared_ptr<query_params> params_;
details::shared_ptr<select_statement> statement_; details::shared_ptr<select_statement> statement_;
}; };
template <typename T> template <typename T, class_kind kind>
class result_impl: public odb::result_impl<T>, public result_impl_base class result_impl;
{
public:
typedef typename odb::result_impl<T>::pointer_type pointer_type;
typedef typename odb::result_impl<T>::pointer_traits pointer_traits;
typedef typename odb::result_impl<T>::object_type object_type;
typedef typename odb::result_impl<T>::id_type id_type;
typedef typename odb::result_impl<T>::object_traits object_traits;
virtual
~result_impl ();
result_impl (const query&,
details::shared_ptr<select_statement>,
object_statements<object_type>&);
virtual void
load (object_type&);
virtual id_type
load_id ();
virtual void
next ();
virtual void
cache ();
virtual std::size_t
size ();
using odb::result_impl<T>::current;
private:
void
load_image ();
private:
object_statements<object_type>& statements_;
};
} }
} }
#include <odb/sqlite/result.txx>
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_RESULT_HXX #endif // ODB_SQLITE_RESULT_HXX
// Include result specializations so that the user code only needs
// to include this header.
//
#include <odb/sqlite/object-result.hxx>
#include <odb/sqlite/view-result.hxx>
 End of changes. 6 change blocks. 
46 lines changed or deleted 5 lines changed or added


 statement-cache.hxx   statement-cache.hxx 
skipping to change at line 15 skipping to change at line 15
#ifndef ODB_SQLITE_STATEMENT_CACHE_HXX #ifndef ODB_SQLITE_STATEMENT_CACHE_HXX
#define ODB_SQLITE_STATEMENT_CACHE_HXX #define ODB_SQLITE_STATEMENT_CACHE_HXX
#include <odb/pre.hxx> #include <odb/pre.hxx>
#include <map> #include <map>
#include <typeinfo> #include <typeinfo>
#include <odb/forward.hxx> #include <odb/forward.hxx>
#include <odb/details/shared-ptr.hxx> #include <odb/details/shared-ptr.hxx>
#include <odb/details/type-info.hxx> #include <odb/details/type-info.hxx>
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/statement.hxx> #include <odb/sqlite/statement.hxx>
#include <odb/sqlite/statements-base.hxx>
#include <odb/sqlite/object-statements.hxx> #include <odb/sqlite/object-statements.hxx>
#include <odb/sqlite/view-statements.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class connection; class connection;
class LIBODB_SQLITE_EXPORT statement_cache class LIBODB_SQLITE_EXPORT statement_cache
{ {
skipping to change at line 72 skipping to change at line 76
} }
simple_statement& simple_statement&
rollback_statement () const rollback_statement () const
{ {
return *rollback_; return *rollback_;
} }
template <typename T> template <typename T>
object_statements<T>& object_statements<T>&
find () find_object ()
{ {
map::iterator i (map_.find (&typeid (T))); map::iterator i (map_.find (&typeid (T)));
if (i != map_.end ()) if (i != map_.end ())
return static_cast<object_statements<T>&> (*i->second); return static_cast<object_statements<T>&> (*i->second);
details::shared_ptr<object_statements<T> > p ( details::shared_ptr<object_statements<T> > p (
new (details::shared) object_statements<T> (conn_)); new (details::shared) object_statements<T> (conn_));
map_.insert (map::value_type (&typeid (T), p)); map_.insert (map::value_type (&typeid (T), p));
return *p; return *p;
} }
template <typename T>
view_statements<T>&
find_view ()
{
map::iterator i (map_.find (&typeid (T)));
if (i != map_.end ())
return static_cast<view_statements<T>&> (*i->second);
details::shared_ptr<view_statements<T> > p (
new (details::shared) view_statements<T> (conn_));
map_.insert (map::value_type (&typeid (T), p));
return *p;
}
private: private:
void void
begin_immediate_statement_ () const; begin_immediate_statement_ () const;
void void
begin_exclusive_statement_ () const; begin_exclusive_statement_ () const;
private: private:
typedef std::map<const std::type_info*, typedef std::map<const std::type_info*,
details::shared_ptr<object_statements_base>, details::shared_ptr<statements_base>,
details::type_info_comparator> map; details::type_info_comparator> map;
connection& conn_; connection& conn_;
details::shared_ptr<simple_statement> begin_; details::shared_ptr<simple_statement> begin_;
mutable details::shared_ptr<simple_statement> begin_immediate_; mutable details::shared_ptr<simple_statement> begin_immediate_;
mutable details::shared_ptr<simple_statement> begin_exclusive_; mutable details::shared_ptr<simple_statement> begin_exclusive_;
details::shared_ptr<simple_statement> commit_; details::shared_ptr<simple_statement> commit_;
details::shared_ptr<simple_statement> rollback_; details::shared_ptr<simple_statement> rollback_;
 End of changes. 6 change blocks. 
2 lines changed or deleted 22 lines changed or added


 statement.hxx   statement.hxx 
skipping to change at line 23 skipping to change at line 23
#include <string> #include <string>
#include <cstddef> // std::size_t #include <cstddef> // std::size_t
#include <cassert> #include <cassert>
#include <odb/forward.hxx> #include <odb/forward.hxx>
#include <odb/details/shared-ptr.hxx> #include <odb/details/shared-ptr.hxx>
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/binding.hxx> #include <odb/sqlite/binding.hxx>
#include <odb/sqlite/connection.hxx> #include <odb/sqlite/connection.hxx>
#include <odb/sqlite/auto-handle.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class connection; class connection;
class LIBODB_SQLITE_EXPORT statement: public details::shared_base class LIBODB_SQLITE_EXPORT statement: public details::shared_base
{ {
skipping to change at line 134 skipping to change at line 136
} }
} }
// Cached state (protected part). // Cached state (protected part).
// //
protected: protected:
void void
finilize () finilize ()
{ {
list_remove (); list_remove ();
stmt_.reset ();
if (stmt_ != 0)
{
sqlite3_finalize (stmt_);
stmt_ = 0;
}
} }
protected: protected:
friend class connection; friend class connection;
connection& conn_; connection& conn_;
sqlite3_stmt* stmt_; auto_handle<sqlite3_stmt> stmt_;
bool active_; bool active_;
bool cached_; bool cached_;
private: private:
void void
init (const char* statement, std::size_t n); init (const char* statement, std::size_t n);
// Doubly-linked list of active/uncached statements. // Doubly-linked list of active/uncached statements.
// //
skipping to change at line 222 skipping to change at line 219
}; };
class LIBODB_SQLITE_EXPORT select_statement: public statement class LIBODB_SQLITE_EXPORT select_statement: public statement
{ {
public: public:
select_statement (connection& conn, select_statement (connection& conn,
const std::string& statement, const std::string& statement,
binding& cond, binding& cond,
binding& data); binding& data);
select_statement (connection& conn,
const std::string& statement,
binding& data);
// Common select interface expected by the generated code. // Common select interface expected by the generated code.
// //
public: public:
enum result enum result
{ {
success, success,
no_data, no_data,
truncated truncated
}; };
skipping to change at line 279 skipping to change at line 280
void void
reload (); reload ();
private: private:
select_statement (const select_statement&); select_statement (const select_statement&);
select_statement& operator= (const select_statement&); select_statement& operator= (const select_statement&);
private: private:
bool done_; bool done_;
binding& cond_; binding* cond_;
binding& data_; binding& data_;
}; };
class LIBODB_SQLITE_EXPORT insert_statement: public statement class LIBODB_SQLITE_EXPORT insert_statement: public statement
{ {
public: public:
insert_statement (connection& conn, insert_statement (connection& conn,
const std::string& statement, const std::string& statement,
binding& data); binding& data);
 End of changes. 5 change blocks. 
8 lines changed or deleted 9 lines changed or added


 traits.hxx   traits.hxx 
skipping to change at line 12 skipping to change at line 12
// author : Boris Kolpackov <boris@codesynthesis.com> // author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file // license : GNU GPL v2; see accompanying LICENSE file
#ifndef ODB_SQLITE_TRAITS_HXX #ifndef ODB_SQLITE_TRAITS_HXX
#define ODB_SQLITE_TRAITS_HXX #define ODB_SQLITE_TRAITS_HXX
#include <odb/pre.hxx> #include <odb/pre.hxx>
#include <string> #include <string>
#include <vector>
#include <cstddef> // std::size_t #include <cstddef> // std::size_t
#include <odb/traits.hxx> #include <odb/traits.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/details/buffer.hxx> #include <odb/details/buffer.hxx>
#include <odb/details/wrapper-p.hxx>
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
enum database_type_id enum database_type_id
{ {
skipping to change at line 55 skipping to change at line 59
template <> template <>
struct image_traits<id_text> {typedef details::buffer image_type;}; struct image_traits<id_text> {typedef details::buffer image_type;};
template <> template <>
struct image_traits<id_blob> {typedef details::buffer image_type;}; struct image_traits<id_blob> {typedef details::buffer image_type;};
// //
// value_traits // value_traits
// //
template <typename W, database_type_id, bool null_handler>
struct wrapped_value_traits;
template <typename T, database_type_id> template <typename T, database_type_id>
struct default_value_traits; struct default_value_traits;
template <typename T, database_type_id, bool w = details::wrapper_p<T>:
:r>
struct select_traits;
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
class value_traits: public default_value_traits<T, ID> struct select_traits<T, ID, false>
{
typedef default_value_traits<T, ID> type;
};
template <typename W, database_type_id ID>
struct select_traits<W, ID, true>
{
typedef
wrapped_value_traits<W, ID, wrapper_traits<W>::null_handler>
type;
};
template <typename T, database_type_id ID>
class value_traits: public select_traits<T, ID>::type
{
};
// The wrapped_value_traits specializations should be able to handle
// any value type which means we have to have every possible signature
// of the set_value() and set_image() functions.
//
template <typename W, database_type_id ID>
struct wrapped_value_traits<W, ID, false>
{
typedef wrapper_traits<W> wtraits;
typedef typename wtraits::wrapped_type wrapped_type;
typedef W value_type;
typedef wrapped_type query_type;
typedef typename image_traits<ID>::image_type image_type;
typedef value_traits<wrapped_type, ID> vtraits;
static void
set_value (W& v, const image_type& i, bool is_null)
{
vtraits::set_value (wtraits::set_ref (v), i, is_null);
}
static void
set_image (image_type& i, bool& is_null, const W& v)
{
vtraits::set_image (i, is_null, wtraits::get_ref (v));
}
// TEXT and BLOB.
//
static void
set_value (W& v, const details::buffer& b, std::size_t n, bool is_nul
l)
{
vtraits::set_value (wtraits::set_ref (v), b, n, is_null);
}
static void
set_image (details::buffer& b, std::size_t& n, bool& is_null, const W
& v)
{
vtraits::set_image (b, n, is_null, wtraits::get_ref (v));
}
};
template <typename W, database_type_id ID>
struct wrapped_value_traits<W, ID, true>
{ {
typedef wrapper_traits<W> wtraits;
typedef typename wtraits::wrapped_type wrapped_type;
typedef W value_type;
typedef wrapped_type query_type;
typedef typename image_traits<ID>::image_type image_type;
typedef value_traits<wrapped_type, ID> vtraits;
static void
set_value (W& v, const image_type& i, bool is_null)
{
if (is_null)
wtraits::set_null (v);
else
vtraits::set_value (wtraits::set_ref (v), i, is_null);
}
static void
set_image (image_type& i, bool& is_null, const W& v)
{
is_null = wtraits::get_null (v);
if (!is_null)
vtraits::set_image (i, is_null, wtraits::get_ref (v));
}
// TEXT and BLOB.
//
static void
set_value (W& v, const details::buffer& b, std::size_t n, bool is_nul
l)
{
if (is_null)
wtraits::set_null (v);
else
vtraits::set_value (wtraits::set_ref (v), b, n, is_null);
}
static void
set_image (details::buffer& b, std::size_t& n, bool& is_null, const W
& v)
{
is_null = wtraits::get_null (v);
if (!is_null)
vtraits::set_image (b, n, is_null, wtraits::get_ref (v));
}
}; };
template <typename T, database_type_id ID> template <typename T, database_type_id ID>
struct default_value_traits struct default_value_traits
{ {
typedef T value_type; typedef T value_type;
typedef T query_type; typedef T query_type;
typedef typename image_traits<ID>::image_type image_type; typedef typename image_traits<ID>::image_type image_type;
static void static void
skipping to change at line 121 skipping to change at line 239
bool& is_null, bool& is_null,
const std::string&); const std::string&);
}; };
// const char* specialization // const char* specialization
// //
// Specialization for const char* which only supports initialization // Specialization for const char* which only supports initialization
// of an image from the value but not the other way around. This way // of an image from the value but not the other way around. This way
// we can pass such values to the queries. // we can pass such values to the queries.
// //
template <> struct LIBODB_SQLITE_EXPORT c_string_value_traits
struct LIBODB_SQLITE_EXPORT default_value_traits<const char*, id_text>
{ {
typedef const char* value_type; typedef const char* value_type;
typedef const char* query_type; typedef const char* query_type;
typedef details::buffer image_type; typedef details::buffer image_type;
static void static void
set_image (details::buffer&, set_image (details::buffer&,
std::size_t& n, std::size_t& n,
bool& is_null, bool& is_null,
const char*); const char*);
}; };
template <>
struct LIBODB_SQLITE_EXPORT default_value_traits<const char*, id_text>:
c_string_value_traits
{
};
template <std::size_t n>
struct default_value_traits<char[n], id_text>: c_string_value_traits
{
};
template <std::size_t n>
struct default_value_traits<const char[n], id_text>: c_string_value_tra
its
{
};
// std::vector<char> (buffer) specialization.
//
template <>
struct LIBODB_SQLITE_EXPORT default_value_traits<std::vector<char>, id_
blob>
{
public:
typedef std::vector<char> value_type;
typedef std::vector<char> query_type;
typedef details::buffer image_type;
static void
set_value (value_type& v,
const details::buffer& b,
std::size_t n,
bool is_null)
{
if (!is_null)
v.assign (b.data (), b.data () + n);
else
v.clear ();
}
static void
set_image (details::buffer&,
std::size_t& n,
bool& is_null,
const value_type&);
};
// //
// type_traits // type_traits
// //
template <typename T> template <typename T>
struct default_type_traits; struct default_type_traits;
template <typename T> template <typename T>
class type_traits: public default_type_traits<T> class type_traits: public default_type_traits<T>
{ {
skipping to change at line 242 skipping to change at line 404
struct default_type_traits<std::string> struct default_type_traits<std::string>
{ {
static const database_type_id db_type_id = id_text; static const database_type_id db_type_id = id_text;
}; };
template <> template <>
struct default_type_traits<const char*> struct default_type_traits<const char*>
{ {
static const database_type_id db_type_id = id_text; static const database_type_id db_type_id = id_text;
}; };
template <std::size_t n>
struct default_type_traits<char[n]>
{
static const database_type_id db_type_id = id_text;
};
template <std::size_t n>
struct default_type_traits<const char[n]>
{
static const database_type_id db_type_id = id_text;
};
} }
} }
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_TRAITS_HXX #endif // ODB_SQLITE_TRAITS_HXX
 End of changes. 10 change blocks. 
3 lines changed or deleted 184 lines changed or added


 transaction-impl.hxx   transaction-impl.hxx 
skipping to change at line 24 skipping to change at line 24
#include <odb/sqlite/version.hxx> #include <odb/sqlite/version.hxx>
#include <odb/sqlite/forward.hxx> #include <odb/sqlite/forward.hxx>
#include <odb/sqlite/details/export.hxx> #include <odb/sqlite/details/export.hxx>
namespace odb namespace odb
{ {
namespace sqlite namespace sqlite
{ {
class LIBODB_SQLITE_EXPORT transaction_impl: public odb::transaction_im pl class LIBODB_SQLITE_EXPORT transaction_impl: public odb::transaction_im pl
{ {
protected: public:
friend class database;
friend class transaction;
typedef sqlite::database database_type; typedef sqlite::database database_type;
typedef sqlite::connection connection_type; typedef sqlite::connection connection_type;
enum lock enum lock
{ {
deferred, deferred,
immediate, immediate,
exclusive exclusive
}; };
transaction_impl (database_type&, lock); transaction_impl (database_type&, lock);
transaction_impl (connection_ptr, lock);
virtual virtual
~transaction_impl (); ~transaction_impl ();
virtual void virtual void
start ();
virtual void
commit (); commit ();
virtual void virtual void
rollback (); rollback ();
connection_type& connection_type&
connection (); connection ();
private: private:
details::shared_ptr<connection_type> connection_; connection_ptr connection_;
lock lock_;
}; };
} }
} }
#include <odb/sqlite/transaction-impl.ixx> #include <odb/sqlite/transaction-impl.ixx>
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_TRANSACTION_IMPL_HXX #endif // ODB_SQLITE_TRANSACTION_IMPL_HXX
 End of changes. 4 change blocks. 
5 lines changed or deleted 7 lines changed or added


 transaction.hxx   transaction.hxx 
skipping to change at line 48 skipping to change at line 48
// //
connection_type& connection_type&
connection (); connection ();
// Return current transaction or throw if there is no transaction // Return current transaction or throw if there is no transaction
// in effect. // in effect.
// //
static transaction& static transaction&
current (); current ();
// Set the current thread's transaction.
//
static void
current (transaction&);
public: public:
transaction_impl& transaction_impl&
implementation (); implementation ();
}; };
} }
} }
#include <odb/sqlite/transaction.ixx> #include <odb/sqlite/transaction.ixx>
#include <odb/post.hxx> #include <odb/post.hxx>
 End of changes. 1 change blocks. 
0 lines changed or deleted 5 lines changed or added


 transaction.ixx   transaction.ixx 
skipping to change at line 40 skipping to change at line 40
database () database ()
{ {
return static_cast<database_type&> (odb::transaction::database ()); return static_cast<database_type&> (odb::transaction::database ());
} }
inline transaction::connection_type& transaction:: inline transaction::connection_type& transaction::
connection () connection ()
{ {
return implementation ().connection (); return implementation ().connection ();
} }
inline void transaction::
current (transaction& t)
{
odb::transaction::current (t);
}
} }
} }
 End of changes. 1 change blocks. 
0 lines changed or deleted 6 lines changed or added


 version.hxx   version.hxx 
skipping to change at line 32 skipping to change at line 32
// Version AABBCCDD // Version AABBCCDD
// 2.0.0 02000000 // 2.0.0 02000000
// 2.1.0 02010000 // 2.1.0 02010000
// 2.1.1 02010100 // 2.1.1 02010100
// 2.2.0.a1 02019901 // 2.2.0.a1 02019901
// 3.0.0.b2 02999952 // 3.0.0.b2 02999952
// //
// Check that we have compatible ODB version. // Check that we have compatible ODB version.
// //
#if ODB_VERSION != 10500 #if ODB_VERSION != 10600
# error incompatible odb interface version detected # error incompatible odb interface version detected
#endif #endif
// libodb-sqlite version: odb interface version plus the bugfix // libodb-sqlite version: odb interface version plus the bugfix
// version. // version.
// //
#define LIBODB_SQLITE_VERSION 1050000 #define LIBODB_SQLITE_VERSION 1060000
#define LIBODB_SQLITE_VERSION_STR "1.5.0" #define LIBODB_SQLITE_VERSION_STR "1.6.0"
#include <odb/post.hxx> #include <odb/post.hxx>
#endif // ODB_SQLITE_VERSION_HXX #endif // ODB_SQLITE_VERSION_HXX
 End of changes. 2 change blocks. 
3 lines changed or deleted 3 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/