00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef RESOURCEPOOL_SQL_RTSQLEXECUTE_IMPL_HH
00025 #define RESOURCEPOOL_SQL_RTSQLEXECUTE_IMPL_HH
00026
00027 #include "config.h"
00028 #include "util/Clone.hh"
00029
00030 #include "ResourcePool/SQL/Factory.hh"
00031 #include "ResourcePool/SQL/BindOutInterface.hh"
00032
00033 #ifdef HAVE_MYSQL
00034 #include "ResourcePool/mysql/ResourcePool.hh"
00035 #include "ResourcePool/mysql/Resource.hh"
00036 #include <mysql/mysql.h>
00037 #endif
00038
00039 #ifdef HAVE_ORACLE
00040 #include "ResourcePool/oracle/ResourcePool.hh"
00041 #include "ResourcePool/oracle/Resource.hh"
00042 #include "ResourcePool/oracle/oracleType.hh"
00043 #endif
00044
00045
00046 #include <sstream>
00047
00048 namespace fatalmind {
00049 namespace SQL {
00050
00051 template<class TM>
00052 class RTSQLExecute_Impl: public Clone {
00053 public:
00054 RTSQLExecute_Impl() {
00055 };
00056 virtual ~RTSQLExecute_Impl() {
00057 }
00058
00059 virtual void bind(const int pos, const char, bool nul = false) = 0;
00060 virtual void bind(const int pos, const signed char, bool nul = false) = 0;
00061 virtual void bind(const int pos, const unsigned char, bool nul = false) = 0;
00062
00063 virtual void bind(const int pos, const short int val, bool nul = false) = 0;
00064 virtual void bind(const int pos, const int val, bool nul = false) = 0;
00065 virtual void bind(const int pos, const long int val, bool nul = false) = 0;
00066
00067 virtual void bind(const int pos, const unsigned short int val, bool nul = false) = 0;
00068 virtual void bind(const int pos, const unsigned int val, bool nul = false) = 0;
00069 virtual void bind(const int pos, const unsigned long int val, bool nul = false) = 0;
00070
00071 virtual void bind(const int pos, const float val, bool nul = false) = 0;
00072 virtual void bind(const int pos, const double val, bool nul = false) = 0;
00073 virtual void bind(const int pos, const long double val, bool nul = false) = 0;
00074 virtual void bind(const int pos, const std::string& val, bool nul = false) = 0;
00075
00076 virtual void clearParameters() = 0;
00077
00078 virtual void execute(SQLResource<TM>& hand) = 0;
00079 virtual void outputoperator(std::ostream&) const = 0;
00080
00081 virtual const Clone* getPlainSpecializedCommand() const = 0;
00082
00083 template<class CS>
00084 static typename CS::Impl* newRealCommand(
00085 typename SQLFactory<TM>::databaseType_t a_type
00086 , typename CS::RTC& a_that
00087 , const std::string& a_sql
00088 ) {
00089 switch(a_type) {
00090 #ifdef HAVE_MYSQL
00091 case SQLFactory<TM>::MYSQL :
00092 case SQLFactory<TM>::MYSQLTX :
00093 return new typename CS::template Specialized<fatalmind::ResourceType::mysql>::Impl(a_that, a_sql);
00094 break;
00095 #endif
00096 #ifdef HAVE_ORACLE
00097 case SQLFactory<TM>::OCI:
00098 return new typename CS::template Specialized<fatalmind::ResourceType::oracle>::Impl(a_that, a_sql);
00099 break;
00100 #endif
00101 default:
00102 std::ostringstream oss;
00103 oss << "Assertaion failure (type=" << a_type << ")";
00104 throw Exception(oss.str());
00105 break;
00106 }
00107 }
00108 };
00109
00110 template<class TM>
00111 class RTSQLSelectRow_Impl
00112 : public RTSQLExecute_Impl<TM>
00113 {
00114 public:
00115 RTSQLSelectRow_Impl() {
00116 };
00117
00118 virtual void bindout(const int pos, char& val, bool& isnull) = 0;
00119 virtual void bindout(const int pos, char& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00120 virtual void bindout(const int pos, signed char& val, bool& isnull) = 0;
00121 virtual void bindout(const int pos, signed char& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00122 virtual void bindout(const int pos, unsigned char& val, bool& isnull) = 0;
00123 virtual void bindout(const int pos, unsigned char& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00124
00125 virtual void bindout(const int pos, short int& val, bool& isnull) = 0;
00126 virtual void bindout(const int pos, short int& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00127 virtual void bindout(const int pos, int& val, bool& isnull) = 0;
00128 virtual void bindout(const int pos, int& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00129 virtual void bindout(const int pos, long int& val, bool& isnull) = 0;
00130 virtual void bindout(const int pos, long int& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00131
00132 virtual void bindout(const int pos, unsigned short int& val, bool& isnull) = 0;
00133 virtual void bindout(const int pos, unsigned short int& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00134 virtual void bindout(const int pos, unsigned int& val, bool& isnull) = 0;
00135 virtual void bindout(const int pos, unsigned int& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00136 virtual void bindout(const int pos, unsigned long int& val, bool& isnull) = 0;
00137 virtual void bindout(const int pos, unsigned long int& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00138
00139 virtual void bindout(const int pos, float& val, bool& isnull) = 0;
00140 virtual void bindout(const int pos, float& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00141 virtual void bindout(const int pos, double& val, bool& isnull) = 0;
00142 virtual void bindout(const int pos, double& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00143 virtual void bindout(const int pos, long double& val, bool& isnull) = 0;
00144 virtual void bindout(const int pos, long double& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00145
00146 virtual void bindout(const int pos, std::string& val, bool& isnull) = 0;
00147 virtual void bindout(const int pos, std::string& val, BindOutInterface::BindOutNotNullConstraint) = 0;
00148
00149
00150
00151
00152 template<class CS>
00153 static typename CS::Impl* newRealCommand(
00154 typename SQLFactory<TM>::databaseType_t a_type
00155 , typename CS::RTC& a_that
00156 , const std::string& a_sql
00157 , SQL::SQLFetcher& fetcher
00158 ) {
00159 switch(a_type) {
00160 #ifdef HAVE_MYSQL
00161 case SQLFactory<TM>::MYSQL :
00162 case SQLFactory<TM>::MYSQLTX :
00163 return new typename CS::template Specialized<fatalmind::ResourceType::mysql>::Impl(a_that, a_sql, fetcher);
00164 break;
00165 #endif
00166 #ifdef HAVE_ORACLE
00167 case SQLFactory<TM>::OCI:
00168 return new typename CS::template Specialized<fatalmind::ResourceType::oracle>::Impl(a_that, a_sql, fetcher);
00169 break;
00170 #endif
00171 default:
00172 std::ostringstream oss;
00173 oss << "Assertaion failure (type=" << a_type << ")";
00174 throw Exception(oss.str());
00175 break;
00176 }
00177 }
00178 };
00179
00180
00181 template<class TM, template<class TM2>class B, class RT, class CW, class RTC>
00182 class RTSQLExecute_SpecializedImplCloneHelper
00183 {
00184 public:
00185 static Clone* DoClone(const Clone * const that) {
00186 throw CloneException(that);
00187 }
00188 };
00189
00190
00191 template<class TM, template<class TM2>class B, class RT, class CW, class RTC>
00192 class RTSQLExecute_SpecializedImpl ;
00193
00194 template<class TM, class RT, class CW, class RTC>
00195 class RTSQLExecute_SpecializedImplCloneHelper<TM, RTSQLExecute_Impl, RT, CW, RTC>
00196 {
00197 public:
00198 typedef RTSQLExecute_SpecializedImpl<TM, RTSQLExecute_Impl, RT, CW, RTC> target;
00199 static Clone* DoClone(const Clone *const that) {
00200 const target *x = dynamic_cast<const target*>(that);
00201 return new target(*x);
00202 }
00203 };
00204
00205
00206 template<class TM, template<class TM2>class B, class RT, class CW, class RTC>
00207 class RTSQLExecute_SpecializedImpl
00208 : public B<TM>
00209 {
00210 public:
00211 RTSQLExecute_SpecializedImpl(RTC& rtc, const std::string& sql)
00212 : sqlExecute_(rtc, sql)
00213 {
00214 }
00215
00216
00217 RTSQLExecute_SpecializedImpl(RTC& rtc, const std::string& sql, SQL::SQLFetcher& fetcher)
00218 : sqlExecute_(rtc, sql, fetcher)
00219 {
00220 }
00221
00222 void bind(const int pos, const char val, bool nul = false) {
00223 sqlExecute_.bind(pos, val, nul);
00224 }
00225 void bind(const int pos, const signed char val, bool nul = false) {
00226 sqlExecute_.bind(pos, val, nul);
00227 }
00228 void bind(const int pos, const unsigned char val, bool nul = false) {
00229 sqlExecute_.bind(pos, val, nul);
00230 }
00231
00232 void bind(const int pos, const short int val, bool nul = false) {
00233 sqlExecute_.bind(pos, val, nul);
00234 }
00235 void bind(const int pos, const int val, bool nul = false) {
00236 sqlExecute_.bind(pos, val, nul);
00237 }
00238 void bind(const int pos, const long int val, bool nul = false) {
00239 sqlExecute_.bind(pos, val, nul);
00240 }
00241
00242 void bind(const int pos, const unsigned short int val, bool nul = false) {
00243 sqlExecute_.bind(pos, val, nul);
00244 }
00245 void bind(const int pos, const unsigned int val, bool nul = false) {
00246 sqlExecute_.bind(pos, val, nul);
00247 }
00248 void bind(const int pos, const unsigned long int val, bool nul = false) {
00249 sqlExecute_.bind(pos, val, nul);
00250 }
00251
00252
00253 void bind(const int pos, const float val, bool nul = false) {
00254 sqlExecute_.bind(pos, val, nul);
00255 }
00256 void bind(const int pos, const double val, bool nul = false) {
00257 sqlExecute_.bind(pos, val, nul);
00258 }
00259 void bind(const int pos, const long double val, bool nul = false) {
00260 sqlExecute_.bind(pos, val, nul);
00261 }
00262
00263 void bind(const int pos, const std::string& val, bool nul = false) {
00264 sqlExecute_.bind(pos, val, nul);
00265 }
00266
00267 void clearParameters() {
00268 sqlExecute_.clearParameters();
00269 }
00270
00271 virtual void execute(SQLResource<TM>& hand) {
00272 sqlExecute_.execute(
00273 dynamic_cast<
00274 SQLResourceSpecialized<TM, typename RT::resource_t>&
00275 >(hand).getRealResource()
00276 );
00277 }
00278
00279 virtual void outputoperator(std::ostream& s) const {
00280 sqlExecute_.outputoperator(s);
00281 }
00282
00283 protected:
00284 virtual Clone* DoClone() const {
00285 return RTSQLExecute_SpecializedImplCloneHelper<TM, B, RT, CW, RTC>::DoClone(this);
00286 }
00287
00288 virtual const Clone* getPlainSpecializedCommand() const {
00289 return &sqlExecute_;
00290 };
00291
00292 CW sqlExecute_;
00293 };
00294
00295
00296 }
00297 }
00298
00299 #endif