prepared_statement.hxx

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/prepared_statement.hxx
00005  *
00006  *   DESCRIPTION
00007  *      Helper classes for defining and executing prepared statements
00008  *   See the connection_base hierarchy for more about prepared statements
00009  *
00010  * Copyright (c) 2006-2009, Jeroen T. Vermeulen <jtv@xs4all.nl>
00011  *
00012  * See COPYING for copyright license.  If you did not receive a file called
00013  * COPYING with this source code, please notify the distributor of this mistake,
00014  * or contact the author.
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #ifndef PQXX_H_PREPARED_STATEMENT
00019 #define PQXX_H_PREPARED_STATEMENT
00020 
00021 #include "pqxx/compiler-public.hxx"
00022 #include "pqxx/compiler-internal-pre.hxx"
00023 
00024 #include "pqxx/internal/statement_parameters.hxx"
00025 
00026 
00027 namespace pqxx
00028 {
00029 class connection_base;
00030 class transaction_base;
00031 class result;
00032 
00034 namespace prepare
00035 {
00123 
00124 
00141 enum param_treatment
00142 {
00144   treat_binary,
00146   treat_string,
00148   treat_bool,
00150   treat_direct
00151 };
00152 
00153 
00155 
00163 class PQXX_LIBEXPORT declaration
00164 {
00165 public:
00166   declaration(connection_base &, const PGSTD::string &statement);
00167 
00169   const declaration &
00170   operator()(const PGSTD::string &sqltype, param_treatment=treat_direct) const;
00171 
00173 
00180   const declaration &etc(param_treatment=treat_direct) const;
00181 
00182 private:
00184   declaration &operator=(const declaration &);
00185 
00186   connection_base &m_home;
00187   const PGSTD::string m_statement;
00188 };
00189 
00190 
00192 class PQXX_LIBEXPORT invocation : internal::statement_parameters
00193 {
00194 public:
00195   invocation(transaction_base &, const PGSTD::string &statement);
00196 
00198   result exec() const;
00199 
00201   bool exists() const;
00202 
00204   invocation &operator()() { add_param(); return *this; }
00205 
00207 
00210   template<typename T> invocation &operator()(const T &v)
00211         { add_param(v); return *this; }
00212 
00214 
00218   template<typename T> invocation &operator()(const T &v, bool nonnull)
00219         { add_param(v, nonnull); return *this; }
00220 
00222 
00240   template<typename T> invocation &operator()(T *v, bool nonnull=true)
00241         { add_param(v, nonnull); return *this; }
00242 
00244 
00248   invocation &operator()(const char *v, bool nonnull=true)
00249         { add_param(v, nonnull); return *this; }
00250 
00251 private:
00253   invocation &operator=(const invocation &);
00254 
00255   transaction_base &m_home;
00256   const PGSTD::string m_statement;
00257   PGSTD::vector<PGSTD::string> m_values;
00258   PGSTD::vector<bool> m_nonnull;
00259 
00260   invocation &setparam(const PGSTD::string &, bool nonnull);
00261 };
00262 
00263 
00264 namespace internal
00265 {
00267 struct PQXX_LIBEXPORT prepared_def
00268 {
00270   struct param
00271   {
00272     PGSTD::string sqltype;
00273     param_treatment treatment;
00274 
00275     param(const PGSTD::string &SQLtype, param_treatment);
00276   };
00277 
00279   PGSTD::string definition;
00281   PGSTD::vector<param> parameters;
00283   bool registered;
00285   bool complete;
00286 
00288   bool varargs;
00289 
00291   param_treatment varargs_treatment;
00292 
00293   prepared_def();
00294   explicit prepared_def(const PGSTD::string &);
00295 
00296   void addparam(const PGSTD::string &sqltype, param_treatment);
00297 };
00298 
00300 struct PQXX_PRIVATE get_sqltype
00301 {
00302   template<typename IT> const PGSTD::string &operator()(IT i)
00303   {
00304     return i->sqltype;
00305   }
00306 };
00307 
00308 } // namespace pqxx::prepare::internal
00309 } // namespace pqxx::prepare
00310 } // namespace pqxx
00311 
00312 #include "pqxx/compiler-internal-post.hxx"
00313 
00314 #endif
00315 

Generated on Mon Feb 15 18:22:41 2010 for libpqxx by  doxygen 1.5.5