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_ORACLE_OCIHANDLE_HH
00025 #define RESOURCEPOOL_ORACLE_OCIHANDLE_HH
00026
00027 #ifndef RESOURCEPOOL_ORACLE_OCIENVHANDLE_HH
00028 #include "OCIEnvHandle.hh"
00029 #endif
00030
00031 #ifndef RESOURCEPOOL_ORACLE_RESOURCEFWD_HH
00032 #include "ResourceFwd.hh"
00033 #endif
00034
00035 #ifndef RESOURCEPOOL_ORACLE_ORACLESTATEMENT_HH
00036 #include "oracleStatement.hh"
00037 #endif
00038
00039 #ifndef OCI_ORACLE
00040 #include <oci.h>
00041 #endif
00042
00043 #include <string>
00044 #include <memory>
00045
00046 namespace fatalmind {
00047 namespace oracle {
00048
00049 template<typename HTYPE, int HCONST>
00050 class OCIHandle {
00051 public:
00052 OCIHandle(const OCIEnv* env);
00053 OCIHandle(const OCIEnvHandle& env);
00054 ~OCIHandle();
00055 inline HTYPE* get() const {
00056 return _h;
00057 };
00058 private:
00059 HTYPE* _h;
00060 };
00061
00062 typedef oracle::OCIHandle<OCIError, OCI_HTYPE_ERROR> OCIErrorHandle;
00063 typedef oracle::OCIHandle<OCIServer, OCI_HTYPE_SERVER> OCIServerHandle;
00064 typedef oracle::OCIHandle<OCISvcCtx, OCI_HTYPE_SVCCTX> OCISvcCtxHandle;
00065 typedef oracle::OCIHandle<OCISession, OCI_HTYPE_SESSION> OCISessionHandle;
00066
00067 class OCIStatementHandle {
00068 public:
00069 OCIStatementHandle(const oracleStatement&);
00070 ~OCIStatementHandle() {
00071 }
00072 bool prepare(oracleHandles&);
00073 OCIStmt* get() const {
00074 return _sth->get();
00075 }
00076 unsigned int getEfficienty() const;
00077
00078 std::string getOraSQL() const;
00079 private:
00080 void force_prepare(oracleHandles&);
00081
00082 oracleStatement _SQL;
00083 typedef OCIHandle<OCIStmt, OCI_HTYPE_STMT> Stmt_t;
00084 std::auto_ptr<Stmt_t> _sth;
00085
00086 unsigned int _prepare;
00087 unsigned int _force_prepare;
00088
00095 bool isCacheable(oracleHandles&) const;
00096
00097 friend
00098 std::ostream& operator<<(std::ostream& s, const OCIStatementHandle&);
00099 };
00100
00101 std::ostream& operator<<(std::ostream& s, const OCIStatementHandle&);
00102
00103 }
00104 }
00105 #endif