# 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
    00119   template<typename T>
    00120     invocation &operator()(T *v, bool nonnull=true)
    00121         { return setparam((v ? to_string(v) : ""), nonnull); }
    00122
    00124
    00128   invocation &operator()(const char *v, bool nonnull=true)
    00129         { return setparam((v ? to_string(v) : ""), nonnull); }
    00130
    00131 private:
    00132   transaction_base &m_home;
    00133   const PGSTD::string &m_statement;
    00134   PGSTD::vector<PGSTD::string> m_values;
    00135   PGSTD::vector<bool> m_nonnull;
    00136
    00137   invocation &setparam(const PGSTD::string &, bool nonnull);
    00138 };
    00139
    00140
    00141 namespace internal
    00142 {
    00144 struct PQXX_PRIVATE prepared_def
    00145 {
    00147   struct param
    00148   {
    00149     PGSTD::string sqltype;
    00150     param_treatment treatment;
    00151
    00152     param(const PGSTD::string &SQLtype, param_treatment);
    00153   };
    00154
    00156   PGSTD::string definition;
    00158   PGSTD::vector<param> parameters;
    00160   bool registered;
    00162   bool complete;
    00163
    00164   prepared_def();
    00165   explicit prepared_def(const PGSTD::string &);
    00166
    00167   void addparam(const PGSTD::string &sqltype, param_treatment);
    00168 };
    00169
    00171 struct PQXX_PRIVATE get_sqltype
    00172 {
    00173   template<typename IT> const PGSTD::string &operator()(IT i)
    00174   {
    00175     return i->sqltype;
    00176   }
    00177 };
    00178
    00179 } // namespace pqxx::prepared::internal
    00180 } // namespace pqxx::prepared
    00181 } // namespace pqxx
    00182
    00183 #include "pqxx/compiler-internal-post.hxx"