⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 otlv4.h

📁 一个利用OTL访问ORACLE数据库的例子
💻 H
📖 第 1 页 / 共 5 页
字号:
    for(size_t i=0;i<sz;++i)strcat(temp_connect_str,"*");       \
    size_t tns_sz=strlen(tnsname);                              \
    if(tns_sz>0){                                               \
      strcat(temp_connect_str,"@");                             \
      strcat(temp_connect_str,tnsname);                         \
    }                                                           \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                    \
    OTL_TRACE_STREAM<<class_name<<"(this=";                     \
    OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                    \
    OTL_TRACE_STREAM<<")::" func_name "(";                      \
    OTL_TRACE_STREAM<<"connect_str=\"";                         \
    OTL_TRACE_STREAM<<temp_connect_str;                         \
    OTL_TRACE_STREAM<<"\", auto_commit=";                       \
    OTL_TRACE_STREAM<<auto_commit <<");";                       \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                    \
  }
#endif

#if !defined(OTL_TRACE_RLOGON_ODBC)&&(defined(OTL_ODBC)||defined(OTL_DB2_CLI))
#define OTL_TRACE_RLOGON_ODBC(level,class_name,func_name,       \
                              tnsname,userid,passwd,            \
                              auto_commit)                      \
  if(OTL_TRACE_LEVEL & level){                                  \
    char temp_connect_str2[2048];                               \
    strcpy(temp_connect_str2,userid);                           \
    strcat(temp_connect_str2,"/");                              \
    size_t sz=strlen(passwd);                                   \
    for(size_t i=0;i<sz;++i)strcat(temp_connect_str2,"*");      \
    size_t tns_sz=strlen(tnsname);                              \
    if(tns_sz>0){                                               \
      strcat(temp_connect_str2,"@");                            \
      strcat(temp_connect_str2,tnsname);                        \
    }                                                           \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                    \
    OTL_TRACE_STREAM<<class_name;                               \
    OTL_TRACE_STREAM<<"(this=";                                 \
    OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                    \
    OTL_TRACE_STREAM<<")::" func_name "(";                      \
    OTL_TRACE_STREAM<<"connect_str=\"";                         \
    OTL_TRACE_STREAM<<temp_connect_str2;                        \
    OTL_TRACE_STREAM<<"\", auto_commit=";                       \
    OTL_TRACE_STREAM<<auto_commit;                              \
    OTL_TRACE_STREAM<<");";                                     \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                    \
  }
#endif

#if !defined(OTL_TRACE_RLOGON_ODBC_W)&& \
    (defined(OTL_ODBC)||defined(OTL_DB2_CLI))
#define OTL_TRACE_RLOGON_ODBC_W(level,class_name,func_name,     \
                              tnsname,userid,passwd,            \
                              auto_commit)                      \
  if(OTL_TRACE_LEVEL & level){                                  \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                    \
    OTL_TRACE_STREAM<<class_name;                               \
    OTL_TRACE_STREAM<<L"(this=";                                \
    OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                    \
    OTL_TRACE_STREAM<<L")::" func_name L"(";                    \
    OTL_TRACE_STREAM<<L"connect_str=\"";                        \
    OTL_TRACE_STREAM<<userid<<L"/***@"<<tnsname;                \
    OTL_TRACE_STREAM<<L"\", auto_commit=";                      \
    OTL_TRACE_STREAM<<auto_commit;                              \
    OTL_TRACE_STREAM<<L");";                                    \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                    \
  }
#endif

#if !defined(OTL_TRACE_FIRST_FETCH)
#define OTL_TRACE_FIRST_FETCH                                                   \
  if(OTL_TRACE_LEVEL & 0x8){                                                    \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                    \
    OTL_TRACE_STREAM<<"otl_stream, fetched the first batch of rows, SQL Stm=";  \
    OTL_TRACE_STREAM<<this->stm_text;                                           \
    OTL_TRACE_STREAM<<", RPC=";                                                 \
    OTL_TRACE_STREAM<<row_count;                                                \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                    \
  }
#endif

#if !defined(OTL_TRACE_NEXT_FETCH)
#define OTL_TRACE_NEXT_FETCH                                                    \
   if(OTL_TRACE_LEVEL & 0x8 && cur_row==0){                                     \
     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                   \
     OTL_TRACE_STREAM<<"otl_stream, fetched the next batch of rows, SQL Stm=" ; \
     OTL_TRACE_STREAM<<this->stm_text;                                          \
     OTL_TRACE_STREAM<<", RPC=";                                                \
     OTL_TRACE_STREAM<<row_count;                                               \
     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                   \
   }
#endif

#if !defined(OTL_TRACE_STREAM_EXECUTION)
#define OTL_TRACE_STREAM_EXECUTION                              \
   if(OTL_TRACE_LEVEL & 0x8){                                   \
     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                   \
     OTL_TRACE_STREAM<<"otl_stream, executing SQL Stm=";        \
     OTL_TRACE_STREAM<<this->stm_text;                          \
     OTL_TRACE_STREAM<<", buffer size=";                        \
     OTL_TRACE_STREAM<<this->array_size;                        \
     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                   \
   }
#endif

#if !defined(OTL_TRACE_STREAM_EXECUTION2)
#define OTL_TRACE_STREAM_EXECUTION2                             \
    if(OTL_TRACE_LEVEL & 0x8){                                  \
      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                  \
      OTL_TRACE_STREAM<<"otl_stream, executing SQL Stm=";       \
      OTL_TRACE_STREAM<<this->stm_text;                         \
      OTL_TRACE_STREAM<<", current batch size=";                \
      OTL_TRACE_STREAM<<(cur_y+1);                              \
      OTL_TRACE_STREAM<<", row offset=";                        \
      OTL_TRACE_STREAM<<rowoff;                                 \
      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                  \
    }
#endif

#if !defined(OTL_TRACE_READ)
#define OTL_TRACE_READ(val,function,type)               \
  if(OTL_TRACE_LEVEL & 0x10){                           \
    otl_var_desc* temp_vdesc=describe_next_in_var();    \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;            \
    OTL_TRACE_STREAM<<"otl_stream(this=";               \
    OTL_TRACE_STREAM<<OTL_RCAST(void*,this);            \
    OTL_TRACE_STREAM<<")::" function "(" type ": ";     \
    OTL_TRACE_STREAM<<"ftype=";                         \
    OTL_TRACE_STREAM<<temp_vdesc->ftype;                \
    OTL_TRACE_STREAM<<", placeholder=";                 \
    OTL_TRACE_STREAM<<temp_vdesc->name;                 \
    OTL_TRACE_STREAM<<", value=";                       \
    OTL_TRACE_STREAM<<val;                              \
    OTL_TRACE_STREAM <<");";                             \
    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;            \
  }
#endif

#if !defined(OTL_TRACE_WRITE)
#define OTL_TRACE_WRITE(val,function,type)              \
   if(OTL_TRACE_LEVEL & 0x10){                          \
     otl_var_desc* temp_vdesc=describe_next_out_var();  \
     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;           \
     OTL_TRACE_STREAM<<"otl_stream(this=";              \
     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);           \
     OTL_TRACE_STREAM<<")::" function "(" type " : ";   \
     OTL_TRACE_STREAM<<"ftype=";                        \
     OTL_TRACE_STREAM<<temp_vdesc->ftype;               \
     OTL_TRACE_STREAM<<", placeholder=";                \
     OTL_TRACE_STREAM<<temp_vdesc->name;                \
     OTL_TRACE_STREAM<<", value=";                      \
     if(this->is_null())                                \
       OTL_TRACE_STREAM<<"NULL";                        \
     else                                               \
       OTL_TRACE_STREAM<<val;                           \
     OTL_TRACE_STREAM<<");";                            \
     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;           \
   }
#endif

#else

#define OTL_TRACE_LINE_PREFIX
#define OTL_TRACE_LINE_SUFFIX
#define OTL_TRACE_DIRECT_EXEC
#define OTL_TRACE_SYNTAX_CHECK
#define OTL_TRACE_FUNC(level,class_name,func_name,args)
#define OTL_TRACE_EXCEPTION(code,msg,stm_text,var_info)
#define OTL_TRACE_RLOGON_ORA7(level,class_name,func_name, \
                              connect_str,auto_commit)
#define OTL_TRACE_RLOGON_ORA8(level,class_name,func_name,       \
                              tnsname,userid,passwd,            \
                              auto_commit)
#define OTL_TRACE_RLOGON_ODBC(level,class_name,func_name,       \
                              tnsname,userid,passwd,            \
                              auto_commit)
#define OTL_TRACE_STREAM_OPEN
#define OTL_TRACE_STREAM_OPEN2
#define OTL_TRACE_FIRST_FETCH
#define OTL_TRACE_NEXT_FETCH
#define OTL_TRACE_STREAM_EXECUTION
#define OTL_TRACE_STREAM_EXECUTION2
#define OTL_TRACE_WRITE(val,function,type)
#define OTL_TRACE_READ(val,function,type)
#define OTL_TRACE_RLOGON_ODBC_W(level,class_name,func_name, \
                              tnsname,userid,passwd,        \
                              auto_commit)
#endif

#if defined(OTL_DB2_CLI)
#define OTL_ODBC
#endif

#if defined(OTL_UNICODE)

#if !defined(OTL_UNICODE_CHAR_TYPE)
#define OTL_UNICODE_CHAR_TYPE wchar_t
#endif

#if !defined(OTL_UNICODE_CHAR_TYPE_TRACE_NAME)
#define OTL_UNICODE_CHAR_TYPE_TRACE_NAME "wchar_t"
#endif

#endif

#if defined(OTL_UNICODE)&& \
    (defined(OTL_ORA8I)|| \
     defined(OTL_ORA9I)|| \
     defined(OTL_ORA10G)||defined(OTL_ORA10G_R2))
#define OTL_ORA_UNICODE
#endif

#if defined(OTL_UNICODE)

#if (defined(OTL_ORA8I)||defined(OTL_ORA9I)||defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)) && defined(OTL_ODBC)
#error OTL_UNICODE is not supported when both OTL_ORAxx and OTL_ODBC/OTL_DB2_CLI are defined
#endif

#if defined(OTL_ORA8I)||defined(OTL_ORA9I)||defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)

#define OTL_CHAR unsigned short
#define OTL_UNICODE_CHAR OTL_CHAR
#define OTL_WCHAR unsigned long

#if defined(OTL_ORA8I)
#define OTL_UNICODE_ID OCI_UCS2ID
#endif

#if defined(OTL_ORA9I )
#define OTL_UNICODE_ID OCI_UTF16ID
#endif

#elif defined(OTL_ODBC)

#define OTL_CHAR unsigned short
#define OTL_UNICODE_CHAR OTL_CHAR
#define OTL_WCHAR OTL_CHAR

#endif

#else

#define OTL_CHAR unsigned char

#endif


#if defined(OTL_ORA7) || defined(OTL_ORA8)
#define OTL_PL_TAB
#endif

const int otl_odbc_adapter=1;
const int otl_ora7_adapter=2;
const int otl_ora8_adapter=3;
const int otl_ibase_adapter=4;

const int otl_inout_binding=1;
const int otl_select_binding=2;

const int otl_unsupported_type=-10000;

#if defined(OTL_ANSI_CPP)

#define OTL_SCAST(_t,_e) static_cast<_t >(_e)
#define OTL_RCAST(_t,_e) reinterpret_cast<_t >(_e)
#define OTL_DCAST(_t,_e) dynamic_cast<_t >(_e)
#define OTL_CCAST(_t,_e) const_cast<_t >(_e)

#define OTL_CONST_EXCEPTION const

#if defined OTL_FUNC_THROW_SPEC_ON
#define OTL_THROWS_OTL_EXCEPTION throw(otl_exception)
#define OTL_NO_THROW throw()
#else
#define OTL_THROWS_OTL_EXCEPTION
#define OTL_NO_THROW
#endif

#define OTL_TYPE_NAME typename

#include <new>

#else

#define OTL_SCAST(_t,_e) ((_t)(_e))
#define OTL_RCAST(_t,_e) ((_t)(_e))
#define OTL_DCAST(_t,_e) ((_t)(_e))
#define OTL_CCAST(_t,_e) ((_t)(_e))
#define OTL_CONST_EXCEPTION
#define OTL_THROWS_OTL_EXCEPTION
#define OTL_NO_THROW
#define OTL_TYPE_NAME class

#endif

#define OTL_PCONV(_to,_from,_val) \
OTL_SCAST(_to,*OTL_RCAST(_from*,OTL_CCAST(void*,_val)))

#if defined(OTL_ACE)

#include <ace/SString.h>
#include <ace/Array.h>
#include <ace/Functor.h>
#include <ace/RB_Tree.h>

#define OTL_USER_DEFINED_STRING_CLASS_ON
#define USER_DEFINED_STRING_CLASS ACE_TString
#define OTL_VALUE_TEMPLATE_ON

const int otl_tmpl_vector_default_size=16;

template<OTL_TYPE_NAME T>
class otl_tmpl_vector: public ACE_Array<T>{
public:

 otl_tmpl_vector(const int init_size=otl_tmpl_vector_default_size)
  : ACE_Array<T>(init_size==0?otl_tmpl_vector_default_size:init_size)
 {
  _length=0;
 }

 ~otl_tmpl_vector(){}

 int capacity(void) const
 {
  return this->max_size();
 }

 int size(void) const
 {
  return _length;
 }

 void clear(void)
 {
  _length=0;
 }

 void resize(const int new_size, const T& t=T())
 {
  ACE_Array<T>::size(new_size);
  if(new_size>_length){
   for(int i=_length;i<new_size;++i)
    (*this)[i]=t;
  }
  _length=new_size;
 }

 void push_back(const T& elem)
 {
  int curr_max_size=this->max_size();
  if(_length==curr_max_size)
   ACE_Array<T>::size(curr_max_size*2);
  ++_length;
  (*this)[_length-1]=elem;
 }

 void pop_back(void)
 {
  if(_length>0)
   --_length;
 }

protected:

 int _length;
 
};

#endif

#if defined(OTL_STLPORT)

#if defined(__STLPORT_STD)
#define OTL_STLPORT_NAMESPACE __STLPORT_STD
#else
#if defined(_STLP_USE_OWN_NAMESPACE)
#define OTL_STLPORT_NAMESPACE _STL
#else
#define OTL_STLPORT_NAMESPACE std
#endif
#endif

#define OTL_STL

#endif

#if defined(OTL_VALUE_TEMPLATE_ON) && !defined(OTL_STL) && !defined(OTL_ACE)
#define STD_NAMESPACE_PREFIX
#if (defined(_MSC_VER)&&(_MSC_VER>=1300))||defined(OTL_ANSI_CPP)
#include <iostream>
using namespace std;
#else
#include <iostream.h>
#endif
#endif

#if defined(OTL_USER_DEFINED_STRING_CLASS_ON)

#if defined(OTL_STL)
#error OTL_STL cannot be used in combination with OTL_USER_DEFINED_STRING_CLASS_ON
#endif

#if defined(USER_DEFINED_STRING_CLASS)
#define OTL_STRING_CONTAINER USER_DEFINED_STRING_CLASS
#define STD_NAMESPACE_PREFIX
#else
#error USER_DEFINED_STRING_CLASS macro needs to be defined before including otlv4.h
#endif

#endif


#if defined(OTL_STL)
#if defined(_MSC_VER)
#if (_MSC_VER >= 1200)
#pragma warning (disable:4786) 
#pragma warning (disable:4290)
#pragma warning (disable:4996)
#endif
#endif

#if defined(OTL_STL_NOSTD_NAMESPACE)
#ifndef OTL_STRING_CONTAINER
#define OTL_STRING_CONTAINER string
#endif
#define STD_NAMESPACE_PREFIX
#else
#ifndef OTL_STRING_CONTAINER

#if defined(OTL_STLPORT)
#define OTL_STRING_CONTAINER OTL_STLPORT_NAMESPACE ::string
#else
#define OTL_STRING_CONTAINER std::string
#endif

#endif

#if defined(OTL_STLPORT)
#define STD_NAMESPACE_PREFIX OTL_STLPORT_NAMESPACE ::
#else
#define STD_NAMESPACE_PREFIX std::
#endif


#endif

#include <string>
#include <iterator>
#include <vector>

#if defined(OTL_UNCAUGHT_EXCEPTION_ON)
#include <exception>
#endif

#ifndef OTL_STL_NOSTD_NAMESPACE
#include <iostream>
#else
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
#include <iostream>
using namespace std;
#else
#include <iostream.h>
#endif
#endif

#endif

// %%%
//#define OTL_DEBUG

//======================= END OF CONFIGURATION ==============================


// ====== COMMON NON-TEMPLATE OBJECTS: CONSTANTS, CLASSES, ETC. ===========

#if defined(OTL_ORA8)
const int otl_var_list_size=1024;
#else
const int otl_var_list_size=512;
#endif

const int otl_error_code_0=32000;
#define otl_error_msg_0 "Incompatible data types in stream operation"

const int otl_error_code_1=32004;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -