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 
00064 class PQXX_LIBEXPORT declaration
00065 {
00066 public:
00067   declaration(connection_base &, const PGSTD::string &statement);
00068 
00070   const declaration &
00071   operator()(const PGSTD::string &sqltype, param_treatment) const;
00072 
00073 private:
00074   connection_base &m_home;
00075   const PGSTD::string &m_statement;
00076 };
00077 
00078 
00080 class PQXX_LIBEXPORT invocation
00081 {
00082 public:
00083   invocation(transaction_base &, const PGSTD::string &statement);
00084 
00086   result exec() const;
00087 
00089   invocation &operator()();
00090 
00092 
00096   template<typename T>
00097     invocation &operator()(const T &v, bool nonnull=true)
00098         { return setparam(to_string(v), nonnull); }
00099 
00101 
00116   template<typename T>
00117     invocation &operator()(T *v, bool nonnull=true)
00118         { return setparam((v ? to_string(v) : ""), nonnull); }
00119 
00121 
00125   invocation &operator()(const char *v, bool nonnull=true)
00126         { return setparam((v ? to_string(v) : ""), nonnull); }
00127 
00128 private:
00129   transaction_base &m_home;
00130   const PGSTD::string &m_statement;
00131   PGSTD::vector<PGSTD::string> m_values;
00132   PGSTD::vector<bool> m_nonnull;
00133 
00134   invocation &setparam(const PGSTD::string &, bool nonnull);
00135 };
00136 
00137 
00138 namespace internal
00139 {
00141 struct PQXX_PRIVATE prepared_def
00142 {
00144   struct param
00145   {
00146     PGSTD::string sqltype;
00147     param_treatment treatment;
00148 
00149     param(const PGSTD::string &SQLtype, param_treatment);
00150   };
00151 
00153   PGSTD::string definition;
00155   PGSTD::vector<param> parameters;
00157   bool registered;
00159   bool complete;
00160 
00161   prepared_def();
00162   explicit prepared_def(const PGSTD::string &);
00163 
00164   void addparam(const PGSTD::string &sqltype, param_treatment);
00165 };
00166 
00168 struct PQXX_PRIVATE get_sqltype
00169 {
00170   template<typename IT> const PGSTD::string &operator()(IT i)
00171   {
00172     return i->sqltype;
00173   }
00174 };
00175 
00176 } // namespace pqxx::prepared::internal
00177 } // namespace pqxx::prepared
00178 } // namespace pqxx
00179 
00180 #include "pqxx/compiler-internal-post.hxx"

Generated on Wed Sep 6 16:54:12 2006 for libpqxx by  doxygen 1.4.7