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, 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 #include "pqxx/compiler-public.hxx"
00019 #include "pqxx/compiler-internal-pre.hxx"
00020 
00021 #include "pqxx/util"
00022 
00023 namespace pqxx
00024 {
00025 class connection_base;
00026 class transaction_base;
00027 class result;
00028 
00030 namespace prepare
00031 {
00033 
00042 enum param_treatment
00043 {
00045   treat_binary,
00047   treat_string,
00049   treat_bool,
00051   treat_direct
00052 };
00053 
00054 
00056 class PQXX_LIBEXPORT declaration
00057 {
00058 public:
00059   declaration(connection_base &, const PGSTD::string &statement);
00060 
00062   const declaration &operator()(const PGSTD::string &sqltype,
00063         param_treatment) const;
00064 
00065 private:
00066   connection_base &m_home;
00067   const PGSTD::string &m_statement;
00068 };
00069 
00070 
00072 class PQXX_LIBEXPORT invocation
00073 {
00074 public:
00075   invocation(transaction_base &, const PGSTD::string &statement);
00076 
00078   result exec() const;
00079 
00081   invocation &operator()();
00082 
00084 
00088   template<typename T>
00089     invocation &operator()(const T &v, bool nonnull=true)
00090         { return setparam(to_string(v), nonnull); }
00091 
00093 
00108   template<typename T>
00109     invocation &operator()(T *v, bool nonnull=true)
00110         { return setparam((v ? to_string(v) : ""), nonnull); }
00111 
00113 
00117   invocation &operator()(const char *v, bool nonnull=true)
00118         { return setparam((v ? to_string(v) : ""), nonnull); }
00119 
00120 private:
00121   transaction_base &m_home;
00122   const PGSTD::string &m_statement;
00123   PGSTD::vector<PGSTD::string> m_values;
00124   PGSTD::vector<bool> m_nonnull;
00125 
00126   invocation &setparam(const PGSTD::string &, bool nonnull);
00127 };
00128 
00129 
00130 namespace internal
00131 {
00133 struct PQXX_PRIVATE prepared_def
00134 {
00136   struct param
00137   {
00138     PGSTD::string sqltype;
00139     param_treatment treatment;
00140 
00141     param(const PGSTD::string &SQLtype, param_treatment);
00142   };
00143 
00145   PGSTD::string definition;
00147   PGSTD::vector<param> parameters;
00149   bool registered;
00151   bool complete;
00152 
00153   prepared_def();
00154   explicit prepared_def(const PGSTD::string &);
00155 
00156   void addparam(const PGSTD::string &sqltype, param_treatment);
00157 };
00158 
00160 struct PQXX_PRIVATE get_sqltype
00161 {
00162   template<typename IT> const PGSTD::string &operator()(IT i)
00163   {
00164     return i->sqltype;
00165   }
00166 };
00167 
00168 } // namespace pqxx::prepared::internal
00169 } // namespace pqxx::prepared
00170 } // namespace pqxx
00171 
00172 #include "pqxx/compiler-internal-post.hxx"

Generated on Sat May 27 17:33:49 2006 for libpqxx by  doxygen 1.4.6