libpqxx 4.0
prepared_statement.hxx
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-2011, 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 binarystring;
00030 class connection_base;
00031 class transaction_base;
00032 class result;
00033 
00034 
00036 namespace prepare
00037 {
00120 
00121 class PQXX_LIBEXPORT invocation : internal::statement_parameters
00122 {
00123 public:
00124   invocation(transaction_base &, const PGSTD::string &statement);
00125 
00127   result exec() const;
00128 
00130   bool exists() const;
00131 
00133   invocation &operator()() { add_param(); return *this; }
00134 
00136 
00139   template<typename T> invocation &operator()(const T &v)
00140         { add_param(v, true); return *this; }
00141 
00143 
00146   invocation &operator()(const binarystring &v)
00147         { add_binary_param(v, true); return *this; }
00148 
00150 
00154   template<typename T> invocation &operator()(const T &v, bool nonnull)
00155         { add_param(v, nonnull); return *this; }
00156 
00158 
00162   invocation &operator()(const binarystring &v, bool nonnull)
00163         { add_binary_param(v, nonnull); return *this; }
00164 
00166 
00184   template<typename T> invocation &operator()(T *v, bool nonnull=true)
00185         { add_param(v, nonnull); return *this; }
00186 
00188 
00192   invocation &operator()(const char *v, bool nonnull=true)
00193         { add_param(v, nonnull); return *this; }
00194 
00195 private:
00197   invocation &operator=(const invocation &);
00198 
00199   transaction_base &m_home;
00200   const PGSTD::string m_statement;
00201   PGSTD::vector<PGSTD::string> m_values;
00202   PGSTD::vector<bool> m_nonnull;
00203 
00204   invocation &setparam(const PGSTD::string &, bool nonnull);
00205 };
00206 
00207 
00208 namespace internal
00209 {
00211 struct PQXX_LIBEXPORT prepared_def
00212 {
00214   PGSTD::string definition;
00216   bool registered;
00217 
00218   prepared_def();
00219   explicit prepared_def(const PGSTD::string &);
00220 };
00221 
00222 } // namespace pqxx::prepare::internal
00223 } // namespace pqxx::prepare
00224 } // namespace pqxx
00225 
00226 #include "pqxx/compiler-internal-post.hxx"
00227 
00228 #endif
00229