From 5b0430fdf4617b396e462872d438a663b174a3a8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 12 Oct 2012 17:24:44 +0200 Subject: Completion of prepared query support --- odb/database.hxx | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'odb/database.hxx') diff --git a/odb/database.hxx b/odb/database.hxx index 99205e7..506245f 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -7,17 +7,27 @@ #include +#include // ODB_CXX11 + +#include #include +#include // std::auto_ptr, std::unique_ptr #include // std::size_t +#ifdef ODB_CXX11 +# include // std::function +#endif + #include #include #include +#include #include #include #include #include +#include namespace odb { @@ -214,6 +224,59 @@ namespace odb result query (const odb::query&, bool cache = true); + // Query preparation. + // + template + prepared_query + prepare_query (const char* name, const char*); + + template + prepared_query + prepare_query (const char* name, const std::string&); + + template + prepared_query + prepare_query (const char* name, const odb::query&); + + template + void + cache_query (const prepared_query&); + + template + void + cache_query (const prepared_query&, std::auto_ptr

params); + +#ifdef ODB_CXX11 + template + void + cache_query (const prepared_query&, std::unique_ptr

params); +#endif + + template + prepared_query + lookup_query (const char* name) const; + + template + prepared_query + lookup_query (const char* name, P*& params) const; + + // Prepared query factory. + // + public: +#ifdef ODB_CXX11 + typedef + std::function + query_factory_type; +#else + typedef void (*query_factory_type) (const char*, connection&); +#endif + + void + query_factory (const char* name, query_factory_type); + + query_factory_type + lookup_query_factory (const char* name) const; + // Native database statement execution. // public: @@ -326,8 +389,13 @@ namespace odb struct query_; protected: + typedef + std::map + query_factory_map; + database_id id_; tracer_type* tracer_; + query_factory_map query_factory_map_; }; } -- cgit v1.1