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

📄 otlv4.h

📁 一个利用OTL访问ORACLE数据库的例子
💻 H
📖 第 1 页 / 共 5 页
字号:
  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
  OTL_CHAR* bc1=c1;
  ++c1;
  OTL_CHAR* c2=OTL_RCAST(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;
      ++c1; ++c2;
      ++out_size;
    }
    *OTL_RCAST(unsigned short*,bc1)=OTL_SCAST(unsigned short,out_size);
    if(out_size==inp_size-1 && out_size<actual_inp_size)
      overflow=1;
  }else{
    while(*c2&&out_size<inp_size-1){
     *c1=*c2;
     ++c1; ++c2;
     ++out_size;
    }
    *OTL_RCAST(unsigned short*,bc1)=OTL_SCAST(unsigned short,out_size);
    if(*c2&&out_size==inp_size-1)
      overflow=1;
  }
#else
  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
  OTL_CHAR* c2=OTL_RCAST(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;
      ++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;
      ++c1; ++c2;
      ++out_size;
    }
    *c1=0;
    if(*c2&&out_size==inp_size-1)
      overflow=1;
  }
#endif
}

inline char* otl_itoa(int i,char* a)
{
  const char* digits="0123456789";
  int n=i;
  int k;
  char buf[64];
  char* c=buf;
  char *c1=a;
  int klen=0;
  char digit=' ';
  bool negative=false;
  if(n<0){
    n=-n;
    negative=true;
  }
  do{
    if(n>=10)
      k=n%10;
    else
      k=n;
    digit=digits[k];
    *c=digit;
    ++c;
    ++klen;
    n=n/10;
  }while(n!=0);
  *c=0;
  if(negative){
    *c1='-';
    ++c1;
  }
  for(int j=klen-1;j>=0;--j){
    *c1=buf[j];
    ++c1;
  }
  *c1=0;
  return c1;
}

inline void otl_var_info_col
(const int pos,
 const int ftype,
 const int type_code,
 char* var_info)
{
 char buf1[128];
 char buf2[128];
 char name[128];

 otl_itoa(pos,name);
 strcpy(buf1,otl_var_type_name(ftype));
 strcpy(buf2,otl_var_type_name(type_code));
 strcpy(var_info,"Column: ");
 strcat(var_info,name);
 strcat(var_info,"<");
 strcat(var_info,buf1);
 strcat(var_info,">, datatype in operator <</>>: ");
 strcat(var_info,buf2);
}

inline void otl_var_info_col2
(const int pos,
 const int ftype,
 char* var_info)
{
  char buf1[128];
  char name[128];
  
  otl_itoa(pos,name);
  strcpy(buf1,otl_var_type_name(ftype));
  strcpy(var_info,"Column: ");
  strcat(var_info,name);
  strcat(var_info,"<");
  strcat(var_info,buf1);
  strcat(var_info,">");
}

inline void otl_var_info_col3
(const int pos,
 const int ftype,
 const char* col_name,
 char* var_info)
{
  char buf1[128];
  char name[128];
  
  otl_itoa(pos,name);
  strcpy(buf1,otl_var_type_name(ftype));
  strcpy(var_info,"Column: ");
  strcat(var_info,name);
  strcat(var_info," / ");
  strcat(var_info,col_name);
  strcat(var_info," <");
  strcat(var_info,buf1);
  strcat(var_info,">");
}

class otl_pl_tab_generic{
public:

 unsigned char* p_v;
 short* p_null;
 int elem_size;
 int tab_size;
 int tab_len;
 int vtype;

 otl_pl_tab_generic()
 {
  elem_size=0;
  tab_size=0;
  tab_len=0;
  p_v=0;
  p_null=0;
  vtype=0;
 }

 virtual ~otl_pl_tab_generic(){}

 unsigned char* val(int ndx=0)
 {
  return p_v+(ndx*elem_size);
 }

 int is_null(int ndx=0)
 {
  return p_null[ndx]!=0;
 }

 void set_null(int ndx=0)
 {
  p_null[ndx]=1;
 }

 void set_non_null(int ndx=0)
 {
  p_null[ndx]=0;
 }

 void init_generic(void)
 {int i;
  memset(p_v,0,elem_size*tab_len);
  for(i=0;i<tab_len;++i)
   p_null[i]=0;
 }

 int len()
 {
  return tab_len;
 }

 void set_len(int new_len=0)
 {
  tab_len=new_len;
 }

};

#if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
template<OTL_TYPE_NAME T,const int T_type>
inline int otl_numeric_convert_T
(const int ftype,const void* val,T& n)
{
  if(ftype==T_type){
    n=*OTL_RCAST(T*,OTL_CCAST(void*,val));
    return 1;
  }else
    return 0;
}

template<OTL_TYPE_NAME T>
inline int otl_numeric_convert_T2(const int ftype,const void* val,T& n)
{
  int rc=1;
  switch(ftype){
  case otl_var_double:
    n=OTL_PCONV(T,double,val);
    break;
  case otl_var_short:
    n=OTL_PCONV(T,short,val);
    break;
  case otl_var_int:
    n=OTL_PCONV(T,int,val);
    break;
  case otl_var_unsigned_int:
    n=OTL_PCONV(T,unsigned int,val);
    break;
  case otl_var_long_int:
    n=OTL_PCONV(T,long int,val);
    break;
  case otl_var_float:
    n=OTL_PCONV(T,float,val);
    break;
#if defined(OTL_BIGINT)
  case otl_var_bigint:
    n=OTL_PCONV(T,OTL_BIGINT,val);
    break;
#endif
 default:
  rc=0;
  break;
 }
 return rc;  
}

#else
template<OTL_TYPE_NAME T>
inline int otl_numeric_convert_T(const int ftype,const void* val,T& n)
{
  int rc=1;
  switch(ftype){
  case otl_var_double:
    n=OTL_PCONV(T,double,val);
    break;
  case otl_var_short:
    n=OTL_PCONV(T,short,val);
    break;
  case otl_var_int:
    n=OTL_PCONV(T,int,val);
    break;
  case otl_var_unsigned_int:
    n=OTL_PCONV(T,unsigned int,val);
    break;
  case otl_var_long_int:
    n=OTL_PCONV(T,long int,val);
    break;
  case otl_var_float:
    n=OTL_PCONV(T,float,val);
    break;
#if defined(OTL_BIGINT)
  case otl_var_bigint:
    n=OTL_PCONV(T,OTL_BIGINT,val);
    break;
#endif
 default:
  rc=0;
  break;
 }
 return rc;  
}
#endif

#if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)

class otl_ltstr{
public:
 
 bool operator()(const OTL_STRING_CONTAINER& s1, const OTL_STRING_CONTAINER& s2) const
 {
  return strcmp(s1.c_str(), s2.c_str()) < 0;
 }
 
};

const int otl_max_default_pool_size=32;

#endif

#if defined(OTL_ACE)
const int otl_max_default_pool_size=32;
#endif


class otl_stream_shell_generic{
public:

 int should_delete;

 otl_stream_shell_generic()
 {
  should_delete=0;
 }

 virtual ~otl_stream_shell_generic(){}

};

#if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)

#if defined(OTL_STL)
#include <map>
#endif

class otl_stream_pool_entry{
public:

#if defined(OTL_ACE)
 otl_tmpl_vector<otl_stream_shell_generic*> s;
#else
 STD_NAMESPACE_PREFIX vector<otl_stream_shell_generic*> s;
#endif

 int cnt;
 
 otl_stream_pool_entry()
 {
  cnt=0;
 }
 
 otl_stream_pool_entry(const otl_stream_pool_entry& sc)
 {
   copy(sc);
 }
 
 otl_stream_pool_entry& operator=(const otl_stream_pool_entry& sc)
 {
   copy(sc);
   return *this;
 }
 
 virtual ~otl_stream_pool_entry(){}

private:

  void copy(const otl_stream_pool_entry& sc)
  {
    s.clear();
    for(size_t i=0;i<sc.s.size();++i)
      s.push_back(sc.s[i]);
    cnt=sc.cnt;
  }

};

class otl_stream_pool{
public:
 
 typedef otl_stream_pool_entry cache_entry_type;
#if defined(OTL_ACE)
 typedef
 ACE_RB_Tree
   <OTL_STRING_CONTAINER,cache_entry_type,
    ACE_Less_Than<OTL_STRING_CONTAINER>,
    ACE_Null_Mutex> sc_type;
 typedef otl_tmpl_vector<otl_stream_shell_generic*> vec_type;
 typedef ACE_RB_Tree_Node<OTL_STRING_CONTAINER,cache_entry_type> ace_map_entry;
#else
  typedef STD_NAMESPACE_PREFIX
  map<OTL_STRING_CONTAINER,cache_entry_type,otl_ltstr> sc_type;
  typedef STD_NAMESPACE_PREFIX vector<otl_stream_shell_generic*> vec_type;
#endif

  sc_type sc;
  int max_size;
  int size;
 
 otl_stream_pool()
 {
  max_size=otl_max_default_pool_size;
  size=0;
 }

 void init(int amax_size=otl_max_default_pool_size)
 {
  if(size==0&&max_size==0)return;
  if(amax_size<2)
    amax_size=2;
#if defined(OTL_ACE)
  sc_type::iterator elem0=sc.begin();
  sc_type::iterator elemN=sc.end();
  for(sc_type::iterator i=elem0; i!=elemN; ++i){
   cache_entry_type& ce=(*i).item();
   int sz=ce.s.size();
   for(int j=0;j<sz;++j){
    ce.s[j]->should_delete=1;
    delete ce.s[j];
    ce.s[j]=0;
   }
   ce.s.clear();
   ce.cnt=0;
  }
  sc.clear();
#else
  sc_type::iterator elem0=sc.begin();
  sc_type::iterator elemN=sc.end();
  for(sc_type::iterator i=elem0; i!=elemN; ++i){
   cache_entry_type& ce=(*i).second;
   size_t sz=ce.s.size();
   for(size_t j=0;j<sz;++j){
    ce.s[j]->should_delete=1;
    delete ce.s[j];
    ce.s[j]=0;
   }
   ce.s.clear();
   ce.cnt=0;
  }
  sc.clear();
#endif

  size=0;
  max_size=amax_size;

 }

 otl_stream_shell_generic* find(const OTL_STRING_CONTAINER& stmtxt)
 {
  otl_stream_shell_generic* s;
  
#if defined(OTL_ACE)
  ace_map_entry* ce=0;
  int found=sc.find(stmtxt,ce);
  if(found==-1)return 0; // entry not found
  s=ce->item().s[ce->item().s.size()-1];
  ce->item().s.pop_back();
  if(ce->item().s.size()==0){
   sc.unbind(ce);
   --size;
  }
#else
  sc_type::iterator cur=sc.find(stmtxt);
  if(cur==sc.end())
    return 0; // entry not found
  cache_entry_type& ce=(*cur).second;
  s=ce.s[ce.s.size()-1];
  ce.s.pop_back();
  if(ce.s.size()==0){
   sc.erase(cur);
   --size;
  }
#endif

  return s;
 }

 void remove(const otl_stream_shell_generic* s,const OTL_STRING_CONTAINER& stmtxt)
 {
#if defined(OTL_ACE)
  ace_map_entry* cur=0;

⌨️ 快捷键说明

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