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

📄 otlv4.h

📁 通用的数据库访问模板类库
💻 H
📖 第 1 页 / 共 5 页
字号:
const int otl_var_raw=23;const int otl_var_lob_stream=100;const int otl_bigint_str_size=40;class otl_long_string{public:  unsigned char* v;  int length;  int extern_buffer_flag;  int buf_size;  bool this_is_last_piece_;  otl_long_string(const int buffer_size=32760,const int input_length=0):    v(0),    length(0),    extern_buffer_flag(0),    buf_size(0),    this_is_last_piece_(false) {   this_is_last_piece_=false;   if(buffer_size==0){     v=0;     length=0;     extern_buffer_flag=0;   }else{     extern_buffer_flag=0;     length=input_length;     buf_size=buffer_size;     v=new unsigned char[buffer_size+1];     memset(v,0,buffer_size);   } } otl_long_string (const void* external_buffer,  const int buffer_size,  const int input_length=0):    v(OTL_RCAST(unsigned char*, OTL_CCAST(void*, external_buffer))),    length(input_length),    extern_buffer_flag(1),    buf_size(buffer_size),    this_is_last_piece_(false) { }  otl_long_string& operator=(const otl_long_string& s)  {    this_is_last_piece_=s.this_is_last_piece_;    if(s.extern_buffer_flag){      if(!extern_buffer_flag)        delete[] v;      v=s.v;      length=s.length;      extern_buffer_flag=s.extern_buffer_flag;      buf_size=s.buf_size;    }else{      if(extern_buffer_flag){        v=new unsigned char[s.buf_size];        buf_size=s.buf_size;      }else if(buf_size<s.buf_size){        delete[] v;        v=new unsigned char[s.buf_size];        buf_size=s.buf_size;      }      length=s.length;      extern_buffer_flag=s.extern_buffer_flag;      memcpy(v,s.v,length);      if(length<buf_size&&s.v[length]==0)        v[length]=0;    }    return *this;  }  otl_long_string(const otl_long_string& s):    v(0),    length(s.length),    extern_buffer_flag(s.extern_buffer_flag),    buf_size(s.buf_size),    this_is_last_piece_(s.this_is_last_piece_)  {    if(s.extern_buffer_flag)      v=s.v;    else{      v=new unsigned char[buf_size];      memcpy(v,s.v,length);      if(length<buf_size&&s.v[length]==0)        v[length]=0;    }  }    virtual ~otl_long_string()  {   if(!extern_buffer_flag)delete[] v;  }  void set_len(const int alen=0){length=alen;}  int len(void)const {return length;}  void set_last_piece(const bool this_is_last_piece=false)  {    this_is_last_piece_=this_is_last_piece;  }  unsigned char& operator[](int ndx){return v[ndx];}  virtual void null_terminate_string(const int alen)  {    (*this)[alen]=0;  }};#if defined(OTL_UNICODE)class otl_long_unicode_string: public otl_long_string{public:  otl_long_unicode_string(const int buffer_size=32760,const int input_length=0)    : otl_long_string(0,0)  {    extern_buffer_flag=0;    length=input_length;    buf_size=buffer_size;    v=new unsigned char[(buffer_size+1)*sizeof(OTL_WCHAR)];    memset(v,0,buffer_size*sizeof(OTL_WCHAR));  }    otl_long_unicode_string  (const void* external_buffer,    const int buffer_size,   const int input_length=0)    : otl_long_string(external_buffer,buffer_size,input_length)  {    extern_buffer_flag=1;    length=input_length;    buf_size=buffer_size;    v=OTL_RCAST(unsigned char*, OTL_CCAST(void*, external_buffer));  }    virtual ~otl_long_unicode_string(){}    OTL_CHAR& operator[](int ndx)  {    return OTL_RCAST(OTL_CHAR*,v)[ndx];  }  virtual void null_terminate_string(const int alen)  {    (*this)[alen]=0;  }};#endifinline const char* otl_var_type_name(const int ftype){  const char* const_CHAR="CHAR";  const char* const_DOUBLE="DOUBLE";  const char* const_FLOAT="FLOAT";  const char* const_INT="INT";  const char* const_UNSIGNED_INT="UNSIGNED INT";  const char* const_SHORT_INT="SHORT INT";  const char* const_LONG_INT="LONG INT";  const char* const_TIMESTAMP="TIMESTAMP";  const char* const_DB2DATE="DB2DATE";  const char* const_DB2TIME="DB2TIME";  const char* const_TZ_TIMESTAMP="TIMESTAMP WITH TIME ZONE";  const char* const_LTZ_TIMESTAMP="TIMESTAMP WITH LOCAL TIME ZONE";  const char* const_BIGINT="BIGINT";  const char* const_VARCHAR_LONG="VARCHAR LONG";  const char* const_RAW_LONG="RAW LONG";  const char* const_CLOB="CLOB";  const char* const_BLOB="BLOB";  const char* const_RAW="RAW";  const char* const_UNKNOWN="UNKNOWN";  const char* const_LONG_STRING="otl_long_string()";  const char* const_LOB_STREAM="otl_lob_stream*&";  const char* const_USER_DEFINED="User-defined type (object type, VARRAY, Nested Table)";#if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)  const char* const_NCHAR="NCHAR";   const char* const_NCLOB="NCLOB";#endif    switch(ftype){#if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)  case otl_var_nchar:    return const_NCHAR;   case otl_var_nclob:    return const_NCLOB; #endif  case otl_var_char:    return const_CHAR;  case otl_var_double:    return const_DOUBLE;  case otl_var_float:    return const_FLOAT;  case otl_var_int:    return const_INT;  case otl_var_unsigned_int:    return const_UNSIGNED_INT;  case otl_var_short:    return const_SHORT_INT;  case otl_var_long_int:    return const_LONG_INT;  case otl_var_timestamp:    return const_TIMESTAMP;  case otl_var_db2date:    return const_DB2DATE;  case otl_var_db2time:    return const_DB2TIME;  case otl_var_tz_timestamp:    return const_TZ_TIMESTAMP;  case otl_var_ltz_timestamp:    return const_LTZ_TIMESTAMP;  case otl_var_bigint:    return const_BIGINT;  case otl_var_varchar_long:    return const_VARCHAR_LONG;  case otl_var_raw_long:    return const_RAW_LONG;  case otl_var_clob:    return const_CLOB;  case otl_var_blob:    return const_BLOB;  case otl_var_raw:    return const_RAW;  case otl_var_long_string:    return const_LONG_STRING;  case otl_var_lob_stream:    return const_LOB_STREAM;  case 108:    return const_USER_DEFINED; default:  return const_UNKNOWN; }}inline void otl_var_info_var(const char* name, const int ftype, const int type_code, char* var_info,#if defined(_MSC_VER)#if (_MSC_VER >= 1400) // VC++ 8.0 or higher const size_t var_info_sz#else const size_t /*var_info_sz*/#endif#else const size_t /*var_info_sz*/#endif){char buf1[128]; char buf2[128]; OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype)); OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code)); OTL_STRCPY_S(var_info,var_info_sz,"Variable: "); OTL_STRCAT_S(var_info,var_info_sz,name); OTL_STRCAT_S(var_info,var_info_sz,"<"); OTL_STRCAT_S(var_info,var_info_sz,buf1); OTL_STRCAT_S(var_info,var_info_sz,">, datatype in operator <</>>: "); OTL_STRCAT_S(var_info,var_info_sz,buf2);}inline void otl_var_info_var2(const char* name, const int ftype, char* var_info,#if defined(_MSC_VER)#if (_MSC_VER >= 1400) // VC++ 8.0 or higher const size_t var_info_sz#else const size_t /*var_info_sz*/#endif#else const size_t /*var_info_sz*/#endif){char buf1[128]; OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype)); OTL_STRCPY_S(var_info,var_info_sz,"Variable: "); OTL_STRCPY_S(var_info,var_info_sz,name); OTL_STRCAT_S(var_info,var_info_sz,"<"); OTL_STRCAT_S(var_info,var_info_sz,buf1); OTL_STRCAT_S(var_info,var_info_sz,">");}inline void otl_var_info_var3(const char* name, const int ftype, const int type_code, char* var_info,#if defined(_MSC_VER)#if (_MSC_VER >= 1400) // VC++ 8.0 or higher const size_t var_info_sz#else const size_t /*var_info_sz*/#endif#else const size_t /*var_info_sz*/#endif){char buf1[128]; char buf2[128]; OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype)); OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code)); OTL_STRCPY_S(var_info,var_info_sz,"Variable: "); OTL_STRCAT_S(var_info,var_info_sz,name); OTL_STRCAT_S(var_info,var_info_sz,"<"); OTL_STRCAT_S(var_info,var_info_sz,buf1); OTL_STRCAT_S(var_info,              var_info_sz,              ">, datatype in otl_stream_read_iterator::get(): "); OTL_STRCAT_S(var_info,var_info_sz,buf2);}inline void otl_var_info_var4(const char* name, const int ftype, const int type_code, char* var_info,#if defined(_MSC_VER)#if (_MSC_VER >= 1400) // VC++ 8.0 or higher const size_t var_info_sz#else const size_t /*var_info_sz*/#endif#else const size_t /*var_info_sz*/#endif){char buf1[128]; char buf2[128]; OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype)); OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code)); OTL_STRCPY_S(var_info,var_info_sz,"Variable: "); OTL_STRCAT_S(var_info,var_info_sz,name); OTL_STRCAT_S(var_info,var_info_sz,"<"); OTL_STRCAT_S(var_info,var_info_sz,buf1); OTL_STRCAT_S(var_info,              var_info_sz,              ">, datatype in otl_stream_read_iterator::get(): "); OTL_STRCAT_S(var_info,var_info_sz,buf2);}inline void otl_strcpy(  unsigned char* trg,  unsigned char* src,  int& overflow,  const int inp_size=0,  const int actual_inp_size=-1){  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);  const OTL_CHAR* c2=OTL_RCAST(const OTL_CHAR*,src);  int out_size=0;  overflow=0;  if(actual_inp_size!=-1){    while(out_size<inp_size-1 && out_size<actual_inp_size){      *c1++=*c2++;      ++out_size;    }    *c1=0;    if(out_size==inp_size-1 && out_size<actual_inp_size)      overflow=1;  }else{    while(*c2 && out_size<inp_size-1){      *c1++=*c2++;      ++out_size;    }    *c1=0;    if(*c2 && out_size==inp_size-1)      overflow=1;  }}#if defined(OTL_UNICODE) || (defined(_MSC_VER) && (_MSC_VER >= 1400))inline void otl_strcpy (unsigned char* trg,  const unsigned char* src){ OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg); const OTL_CHAR* c2=OTL_RCAST(const OTL_CHAR*,src); while(*c2){  *c1++=*c2++; } *c1=0;}#elseinline void otl_strcpy(unsigned char* trg,const unsigned char* src){  strcpy(OTL_RCAST(char*,trg),OTL_RCAST(const char*,src));}#endifinline void otl_strcat(char* trg,const char* src){  while(*trg)++trg;  while(*src){    *trg=*src;    ++trg;    ++src;  }  *trg=0;}#if defined(OTL_UNICODE) && !defined(OTL_ODBC)inline void otl_strcpy2(  unsigned char* trg,  const unsigned char* src,  const int max_src_len){ OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg); const OTL_CHAR* c2=OTL_RCAST(const OTL_CHAR*,src); int src_len=OTL_SCAST(int,*OTL_SCAST(const unsigned short*,c2)); int len=0; ++c2; while(*c2&&len<max_src_len&&len<src_len){  *c1++=*c2++;  ++len; } *c1=0;#elseinline void otl_strcpy2(  unsigned char* trg,  const unsigned char* src,  const int /* max_src_len */){ otl_strcpy(trg,src);#endif}#if defined(OTL_UNICODE)inline void otl_m

⌨️ 快捷键说明

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