From: <mrj...@us...> - 2007-02-15 03:01:41
|
Revision: 2108 http://svn.sourceforge.net/tora/?rev=2108&view=rev Author: mrjohnson0 Date: 2007-02-14 19:01:41 -0800 (Wed, 14 Feb 2007) Log Message: ----------- update otl. fixes crashing problems with custom types and has better support for 10g Modified Paths: -------------- trunk/tora/ext/otl/otlv4.h Modified: trunk/tora/ext/otl/otlv4.h =================================================================== --- trunk/tora/ext/otl/otlv4.h 2007-02-13 05:53:30 UTC (rev 2107) +++ trunk/tora/ext/otl/otlv4.h 2007-02-15 03:01:41 UTC (rev 2108) @@ -1,6 +1,6 @@ // ============================================================== -// Oracle, ODBC and DB2/CLI Template Library, Version 4.0.131, -// Copyright (C) Sergei Kuchin, 1996,2006 +// Oracle, ODBC and DB2/CLI Template Library, Version 4.0.148, +// Copyright (C) Sergei Kuchin, 1996,2007 // Author: Sergei Kuchin // This library is free software. Permission to use, copy, // modify and redistribute it for any purpose is hereby granted @@ -11,12 +11,8 @@ #ifndef __OTL_H__ #define __OTL_H__ -#if defined(OTL_INCLUDE_0) -#include "otl_include_0.h" -#endif +#define OTL_VERSION_NUMBER (0x040094L) -#define OTL_VERSION_NUMBER (0x040083L) - #if defined(_MSC_VER) #if (_MSC_VER >= 1400) #pragma warning (disable:4996) @@ -34,7 +30,7 @@ //#define OTL_ODBC // Uncomment the following line in order to include the OTL for -// MySQL/MyODBC: +// MySQL/MyODBC for MyODBC 2.5 (pretty old). Otherwise, use OTL_ODBC //#define OTL_ODBC_MYSQL // Uncomment the following line in order to include the OTL for DB2 CLI: @@ -56,7 +52,15 @@ // Oracle 9i: //#define OTL_ORA9I +// Uncomment the following line in order to include the OTL for +// Oracle 10g Release 1: +//#define OTL_ORA10G +// Uncomment the following line in order to include the OTL for +// Oracle 10g Release 2: +//#define OTL_ORA10G_R2 + + // The macro definitions may be also turned on via C++ compiler command line // option, e.g.: -DOTL_ODBC, -DOTL_ORA7, -DOTL_ORA8, -DOTL_ORA8I, -DOTL_ODBC_UNIX // -DOTL_ODBC_MYSQL, -DOTL_DB2_CLI @@ -136,6 +140,7 @@ strcmp(type_arr,"DB2TIME")==0|| \ strcmp(type_arr,"VARCHAR_LONG")==0|| \ strcmp(type_arr,"RAW_LONG")==0|| \ + strcmp(type_arr,"RAW")==0|| \ strcmp(type_arr,"CLOB")==0|| \ strcmp(type_arr,"BLOB")==0|| \ strcmp(type_arr,"NCHAR")==0|| \ @@ -313,6 +318,14 @@ #error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_STRING_TYPE is defined #endif +#if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE_CHAR_TYPE) +#error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_STRING_TYPE is defined +#endif + +#if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE) +#error OTL_UNICODE needs to be defined if OTL_UNICODE_STRING_TYPE is defined +#endif + #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON) && !defined(OTL_UNICODE_CHAR_TYPE) #error OTL_UNICODE_CHAR_TYPEneeds to be defined if OTL_UNICODE_EXCEPTION_AND_RLOGON is defined #endif @@ -424,7 +437,7 @@ OTL_TRACE_STREAM<<"otl_exception, code="; \ OTL_TRACE_STREAM<<code; \ OTL_TRACE_STREAM<<", msg="; \ - char* c=(char*)msg; \ + char* c=OTL_RCAST(char*,msg); \ while(*c && *c!='\n'){ \ OTL_TRACE_STREAM<<*c; \ ++c; \ @@ -442,7 +455,7 @@ connect_str,auto_commit) \ if(OTL_TRACE_LEVEL & level){ \ char temp_connect_str[2048]; \ - const char* c1=(const char*)connect_str; \ + const char* c1=OTL_RCAST(const char*,connect_str); \ char* c2=temp_connect_str; \ while(*c1 && *c1!='/'){ \ *c2=*c1; \ @@ -554,46 +567,107 @@ #endif #if !defined(OTL_TRACE_FIRST_FETCH) +#if defined(OTL_TRACE_ENABLE_STREAM_LABELS) #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="; \ + if(this->stm_label) \ + OTL_TRACE_STREAM<<this->stm_label; \ + else \ + OTL_TRACE_STREAM<<this->stm_text; \ + OTL_TRACE_STREAM<<", RPC="; \ + OTL_TRACE_STREAM<<row_count; \ + OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX; \ + } +#else +#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 +#endif #if !defined(OTL_TRACE_NEXT_FETCH) +#if defined(OTL_TRACE_ENABLE_STREAM_LABELS) #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=" ; \ + if(this->stm_label) \ + OTL_TRACE_STREAM<<this->stm_label; \ + else \ + OTL_TRACE_STREAM<<this->stm_text; \ + OTL_TRACE_STREAM<<", RPC="; \ + OTL_TRACE_STREAM<<row_count; \ + OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX; \ + } +#else +#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 +#endif #if !defined(OTL_TRACE_STREAM_EXECUTION) +#if defined(OTL_TRACE_ENABLE_STREAM_LABELS) #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="; \ + if(this->stm_label) \ + OTL_TRACE_STREAM<<this->stm_label; \ + else \ + OTL_TRACE_STREAM<<this->stm_text; \ + OTL_TRACE_STREAM<<", buffer size="; \ + OTL_TRACE_STREAM<<this->array_size; \ + OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX; \ + } +#else +#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 +#endif #if !defined(OTL_TRACE_STREAM_EXECUTION2) +#if defined(OTL_TRACE_ENABLE_STREAM_LABELS) #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="; \ + if(this->stm_label) \ + OTL_TRACE_STREAM<<this->stm_label; \ + else \ + 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; \ + } +#else +#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); \ @@ -602,6 +676,7 @@ OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX; \ } #endif +#endif #if !defined(OTL_TRACE_READ) #define OTL_TRACE_READ(val,function,type) \ @@ -743,6 +818,8 @@ 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) @@ -762,6 +839,8 @@ #define OTL_TYPE_NAME typename +#include <new> + #else #define OTL_SCAST(_t,_e) ((_t)(_e)) @@ -1060,6 +1139,14 @@ #define otl_error_msg_26 \ "otl_stream_read_iterator: variable name is not recognized " +const int otl_error_code_27=32028; +#define otl_error_msg_27 "Unsupported column data type" + +const int otl_error_code_28=32029; +#define otl_error_msg_28 \ +"RAW value cannot be read with otl_lob_stream, use otl_long_string instead" + + const int otl_oracle_date_size=7; const int otl_explicit_select=0; @@ -1078,53 +1165,81 @@ class otl_select_struct_override{ public: - short int col_ndx[otl_var_list_size]; - short int col_type[otl_var_list_size]; - int col_size[otl_var_list_size]; - int len; + short int* col_ndx; + short int* col_type; + int* col_size; + int len; + + unsigned int all_mask; + bool lob_stream_mode; + + otl_select_struct_override() + { + container_size_=otl_var_list_size; + col_ndx=new short int[container_size_]; + col_type=new short int[container_size_]; + col_size=new int[container_size_]; + reset(); + } - unsigned int all_mask; - bool lob_stream_mode; - - otl_select_struct_override() - { - reset(); - } - void reset(void) { len=0; all_mask=0; lob_stream_mode=false; } - - ~otl_select_struct_override(){} - - void add_override(const int andx, const int atype, const int asize=0) - { - if(len<otl_var_list_size-1){ - ++len; - col_ndx[len-1]=OTL_SCAST(short,andx); - col_type[len-1]=OTL_SCAST(short,atype); - col_size[len-1]=asize; + + ~otl_select_struct_override() + { + delete[] col_ndx; + delete[] col_type; + delete[] col_size; } - } - - int find(const int ndx) - {int i; - for(i=0;i<len;++i) - if(ndx==col_ndx[i]) - return i; - return -1; - } - + + void add_override(const int andx, const int atype, const int asize=0) + { + if(len==otl_var_list_size){ + int temp_container_size=container_size_; + container_size_*=2; + short int* temp_col_ndx=new short int[container_size_]; + short int* temp_col_type=new short int[container_size_]; + int* temp_col_size=new int[container_size_]; + memcpy(temp_col_ndx,col_ndx,sizeof(short int)*temp_container_size); + memcpy(temp_col_type,col_type,sizeof(short int)*temp_container_size); + memcpy(temp_col_size,col_size,sizeof(int)*temp_container_size); + delete[] col_ndx; + delete[] col_type; + delete[] col_size; + col_ndx=temp_col_ndx; + col_type=temp_col_type; + col_size=temp_col_size; + } + ++len; + col_ndx[len-1]=OTL_SCAST(short,andx); + col_type[len-1]=OTL_SCAST(short,atype); + col_size[len-1]=asize; + } + + int find(const int ndx) + { + int i; + for(i=0;i<len;++i) + if(ndx==col_ndx[i]) + return i; + return -1; + } + void set_all_column_types(const unsigned int amask=0) { all_mask=amask; } - + int getLen(void){return len;} +protected: + + int container_size_; + }; inline int otl_decimal_degree(unsigned int num) @@ -1137,6 +1252,12 @@ return n; } +inline bool otl_isspace(char c) +{ + return c==' '||c=='\t'||c=='\n'|| + c=='\r'||c=='\f'||c=='\v'; +} + inline char otl_to_upper(char c) { return OTL_SCAST(char,toupper(c)); @@ -1359,7 +1480,7 @@ name=new char[desc.name_len_]; name_len_=desc.name_len_; strcpy(name,desc.name); - }else if(name_len_<desc.name_len_){ + }else if(name_len_<desc.name_len_ && desc.name!=0){ delete[] name; name=new char[desc.name_len_]; name_len_=desc.name_len_; @@ -1464,6 +1585,7 @@ const int otl_var_nclob=22; #else #endif +const int otl_var_raw=23; const int otl_var_lob_stream=100; const int otl_bigint_str_size=40; @@ -1471,13 +1593,15 @@ class otl_long_string{ public: - unsigned char* v; - int length; - int extern_buffer_flag; - int buf_size; + 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) { + this_is_last_piece_=false; if(buffer_size==0){ v=0; length=0; @@ -1492,18 +1616,20 @@ } otl_long_string - (const void* external_buffer, + (const void* external_buffer, const int buffer_size, const int input_length=0) { - extern_buffer_flag=1; - length=input_length; - buf_size=buffer_size; - v=OTL_RCAST(unsigned char*, OTL_CCAST(void*, external_buffer)); + this_is_last_piece_=false; + extern_buffer_flag=1; + length=input_length; + buf_size=buffer_size; + v=OTL_RCAST(unsigned char*, OTL_CCAST(void*, external_buffer)); } 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; @@ -1531,6 +1657,7 @@ otl_long_string(const otl_long_string& s) { + this_is_last_piece_=s.this_is_last_piece_; length=s.length; extern_buffer_flag=s.extern_buffer_flag; buf_size=s.buf_size; @@ -1552,6 +1679,11 @@ 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) @@ -1622,49 +1754,55 @@ const char* const_RAW_LONG="RAW LONG"; const char* const_CLOB="CLOB"; const char* const_BLOB="BLOB"; - const char* const_UNKNOWN=""; + 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*&"; - - switch(ftype){ - 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_long_string: - return const_LONG_STRING; - case otl_var_lob_stream: - return const_LOB_STREAM; + const char* const_USER_DEFINED="User-defined type (object type, VARRAY, Nested Table)"; + + switch(ftype){ + 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; } @@ -1717,6 +1855,23 @@ strcat(var_info,buf2); } +inline void otl_var_info_var4 +(const char* name, + const int ftype, + const int type_code, + char* var_info) +{char buf1[128]; + char buf2[128]; + strcpy(buf1,otl_var_type_name(ftype)); + strcpy(buf2,otl_var_type_name(type_code)); + strcpy(var_info,"Variable: "); + strcat(var_info,name); + strcat(var_info,"<"); + strcat(var_info,buf1); + strcat(var_info,">, datatype in otl_stream_read_iterator::get(): "); + strcat(var_info,buf2); +} + inline void otl_strcpy( unsigned char* trg, unsigned char* src, @@ -1731,8 +1886,7 @@ overflow=0; if(actual_inp_size!=-1){ while(out_size<inp_size-1 && out_size<actual_inp_size){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *c1=0; @@ -1740,8 +1894,7 @@ overflow=1; }else{ while(*c2 && out_size<inp_size-1){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *c1=0; @@ -1758,8 +1911,7 @@ OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg); OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src); while(*c2){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; } *c1=0; } @@ -1783,9 +1935,7 @@ int len=0; ++c2; while(*c2&&len<max_src_len&&len<src_len){ - *c1=*c2; - ++c1; - ++c2; + *c1++=*c2++; ++len; } *c1=0; @@ -1808,21 +1958,18 @@ const int ftype ) { - - if(ftype==otl_var_raw_long){ + if(ftype==otl_var_raw_long||ftype==otl_var_raw){ memcpy(trg,src,src_len); return; } - OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg); - OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src); - int len=0; - while(len<src_len){ - *c1=*c2; - ++c1; - ++c2; - ++len; - } + OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg); + OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src); + int len=0; + while(len<src_len){ + *c1++=*c2++; + ++len; + } #else inline void otl_memcpy( @@ -1853,8 +2000,7 @@ int out_size=0; overflow=0; while(len<src_len&&len<max_src_len&&out_size<inp_size-1){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; ++len; } @@ -1875,8 +2021,7 @@ int out_size=0; overflow=0; while(*c2&&out_size<inp_size-1){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *c1=0; @@ -1902,8 +2047,7 @@ overflow=0; if(actual_inp_size!=-1){ while(out_size<inp_size-1 && out_size<actual_inp_size){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *OTL_RCAST(unsigned short*,bc1)=OTL_SCAST(unsigned short,out_size); @@ -1911,8 +2055,7 @@ overflow=1; }else{ while(*c2&&out_size<inp_size-1){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *OTL_RCAST(unsigned short*,bc1)=OTL_SCAST(unsigned short,out_size); @@ -1926,8 +2069,7 @@ overflow=0; if(actual_inp_size!=-1){ while(out_size<inp_size-1 && out_size<actual_inp_size){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *c1=0; @@ -1935,8 +2077,7 @@ overflow=1; }else{ while(*c2&&out_size<inp_size-1){ - *c1=*c2; - ++c1; ++c2; + *c1++=*c2++; ++out_size; } *c1=0; @@ -2011,16 +2152,36 @@ const int ftype, char* var_info) { - char buf1[128]; - char name[128]; + 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,">"); +} - 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{ @@ -2603,24 +2764,38 @@ template <OTL_TYPE_NAME T> class otl_auto_array_ptr{ public: + + T* ptr; + int arr_size_; + + otl_auto_array_ptr() + { + ptr=0; + arr_size_=0; + } + + otl_auto_array_ptr(const int arr_size) + { + ptr=new T[arr_size]; + arr_size_=arr_size; + } + + void double_size(void) + { + int old_arr_size=arr_size_; + arr_size_*=2; + T* temp_ptr=new T[arr_size_]; + for(int i=0;i<old_arr_size;++i) + temp_ptr[i]=ptr[i]; + delete[] ptr; + ptr=temp_ptr; + } + + virtual ~otl_auto_array_ptr() + { + delete[] ptr; + } - T* ptr; - - otl_auto_array_ptr() - { - ptr=0; - } - - otl_auto_array_ptr(const int arr_size) - { - ptr=new T[arr_size]; - } - - virtual ~otl_auto_array_ptr() - { - delete[] ptr; - } - }; template <OTL_TYPE_NAME T> @@ -2679,34 +2854,39 @@ class otl_Tptr{ public: - T* ptr; - - otl_Tptr() - { - ptr=0; + T* ptr; + + bool do_not_destroy; + + otl_Tptr() + { + ptr=0; + do_not_destroy=false; + } + + void assign(T* var) + { + ptr=var; } - - void assign(T* var) - { - ptr=var; + + void disconnect(void) + { + ptr=0; + } + + void destroy(void) + { + if(do_not_destroy) + return; + delete ptr; + ptr=0; } + + ~otl_Tptr() + { + destroy(); + } - void disconnect(void) - { - ptr=0; - } - - void destroy(void) - { - delete ptr; - ptr=0; - } - - ~otl_Tptr() - { - destroy(); - } - }; @@ -2984,7 +3164,7 @@ v=new T[tab_size]; null_flag=new short[tab_size]; p_null=null_flag; - p_v=(unsigned char*)v; + p_v=OTL_RCAST(unsigned char*,v); elem_size=sizeof(T); for(i=0;i<atab_size;++i) null_flag[i]=0; @@ -3571,11 +3751,16 @@ var_struct.set_not_null(ndx,elem_size); } - void set_len(int len, int ndx=0) - { - var_struct.set_len(len,ndx); - } + void bulk_set_not_null(int aarray_size) + { + var_struct.bulk_set_not_null(elem_size,aarray_size); + } + void set_len(int len, int ndx=0) + { + var_struct.set_len(len,ndx); + } + int get_len(int ndx=0) { return var_struct.get_len(ndx); @@ -3623,6 +3808,11 @@ column_ndx); } + static int int2ext(int int_type) + { + return TVariableStruct::int2ext(int_type); + } + }; template <OTL_TYPE_NAME TExceptionStruct, @@ -4005,180 +4195,191 @@ def=3 }; - char* hv[otl_var_list_size]; - short inout[otl_var_list_size]; - int pl_tab_size[otl_var_list_size]; + char** hv; + short* inout; + int* pl_tab_size; int array_size; + int prev_array_size; short vst[4]; int len; char* stm_text_; char* stm_label_; + int container_size_; otl_tmpl_ext_hv_decl(char* stm, int arr_size=1, char* label=0, otl_select_struct_override** select_override=0, OTL_TMPL_CONNECT* adb=0) - {int j; - array_size=arr_size; + { + container_size_=otl_var_list_size; + hv=new char*[container_size_]; + inout=new short[container_size_]; + pl_tab_size=new int[container_size_]; - stm_text_=stm; - stm_label_=label; - int i=0; - short in_str=0; - bool in_comment=false; - bool in_one_line_comment=false; - char *c=stm; - - hv[i]=0; - while(*c){ - switch(*c){ - case '\'': - if(!in_comment&&!in_one_line_comment){ - if(!in_str) - in_str=1; - else{ - if(c[1]=='\'') - ++c; - else - in_str=0; + int j; + array_size=arr_size; + prev_array_size=arr_size; + stm_text_=stm; + stm_label_=label; + int i=0; + short in_str=0; + bool in_comment=false; + bool in_one_line_comment=false; + char *c=stm; + + hv[i]=0; + while(*c){ + switch(*c){ + case '\'': + if(!in_comment&&!in_one_line_comment){ + if(!in_str) + in_str=1; + else{ + if(c[1]=='\'') + ++c; + else + in_str=0; + } } + break; + case '/': + if(c[1]=='*'&&!in_str){ + in_comment=true; + ++c; + } + break; + case '-': + if(c[1]=='-'&&!in_str){ + in_one_line_comment=true; + ++c; + } + break; + case '*': + if(c[1]=='/'&&in_comment){ + in_comment=false; + ++c; + } + break; + case '\n': + if(in_one_line_comment) + in_one_line_comment=false; + break; } - break; - case '/': - if(c[1]=='*'&&!in_str){ - in_comment=true; - ++c; - } - break; - case '-': - if(c[1]=='-'&&!in_str){ - in_one_line_comment=true; - ++c; - } - break; - case '*': - if(c[1]=='/'&&in_comment){ - in_comment=false; - ++c; - } - break; - case '\n': - if(in_one_line_comment) - in_one_line_comment=false; - break; - } - if(*c==':' && !in_str && !in_comment && !in_one_line_comment && - (c>stm && *(c-1)!='\\' || c==stm)){ - char* bind_var_ptr=c; - short in_out=def; - int apl_tab_size=0; - char var[64]; - char* v=var; - *v++=*c++; - while(is_id(*c)) + if(*c==':' && !in_str && !in_comment && !in_one_line_comment && + (c>stm && *(c-1)!='\\' || c==stm)){ + char* bind_var_ptr=c; + short in_out=def; + int apl_tab_size=0; + char var[64]; + char* v=var; *v++=*c++; - while(isspace(*c)&&*c) - ++c; - if(*c=='<'){ - *c=' '; - while(*c!='>'&&*c!=','&&*c){ - *v++=*c; - *c++=' '; - } - if(*c==','){ - *c++=' '; - if(otl_to_upper(*c)=='I'){ - if(otl_to_upper(c[2])=='O') - in_out=io; - else - in_out=in; - }else if(otl_to_upper(*c)=='O') - in_out=out; - while(*c!='>'&&*c&&(*c!='[' && *c!='(')) + while(is_id(*c)) + *v++=*c++; + while(otl_isspace(*c)&&*c) + ++c; + if(*c=='<'){ + *c=' '; + while(*c!='>'&&*c!=','&&*c){ + *v++=*c; *c++=' '; - if(*c=='[' || *c=='('){ - char tmp[32]; - char *t=tmp; + } + if(*c==','){ *c++=' '; - while((*c!=']' && *c!=')')&&*c!='>'&&*c){ - *t++=*c; + if(otl_to_upper(*c)=='I'){ + if(otl_to_upper(c[2])=='O') + in_out=io; + else + in_out=in; + }else if(otl_to_upper(*c)=='O') + in_out=out; + while(*c!='>'&&*c&&(*c!='[' && *c!='(')) *c++=' '; + if(*c=='[' || *c=='('){ + char tmp[32]; + char *t=tmp; + *c++=' '; + while((*c!=']' && *c!=')')&&*c!='>'&&*c){ + *t++=*c; + *c++=' '; + } + *t='\0'; + apl_tab_size=atoi(tmp); + while(*c!='>'&&*c) + *c++=' '; } - *t='\0'; - apl_tab_size=atoi(tmp); - while(*c!='>'&&*c) - *c++=' '; } + if(*c)*c=' '; + *v='\0'; + if(select_override!=0 && bind_var_ptr[1]=='#'){ + char* c4=bind_var_ptr+2; + char col_num[64]; + char* col_num_ptr=col_num; + while(is_num(*c4) && *c4){ + *col_num_ptr=*c4; + ++col_num_ptr; + ++c4; + } + *col_num_ptr=0; + int col_ndx=atoi(col_num); + if(col_ndx>0){ + if(*select_override==0){ + *select_override=new otl_select_struct_override(); + } + int data_type=otl_var_none; + int data_len=0; + char name[128]; + parse_var + (adb, + var, + data_type, + data_len, + name); + (*select_override)->add_override + (col_ndx, + data_type, + data_len); + } + c4=bind_var_ptr; + while(*c4 && *c4!=' '){ + *c4=' '; + ++c4; + } + }else + add_var(i,var,in_out,apl_tab_size); } - if(*c)*c=' '; - *v='\0'; - if(select_override!=0 && bind_var_ptr[1]=='#'){ - char* c4=bind_var_ptr+2; - char col_num[64]; - char* col_num_ptr=col_num; - while(is_num(*c4) && *c4){ - *col_num_ptr=*c4; - ++col_num_ptr; - ++c4; - } - *col_num_ptr=0; - int col_ndx=atoi(col_num); - if(col_ndx>0){ - if(*select_override==0){ - *select_override=new otl_select_struct_override(); - } - int data_type=otl_var_none; - int data_len=0; - char name[128]; - parse_var - (adb, - var, - data_type, - data_len, - name); - (*select_override)->add_override - (col_ndx, - data_type, - data_len); - } - c4=bind_var_ptr; - while(*c4 && *c4!=' '){ - *c4=' '; - ++c4; - } - }else - add_var(i,var,in_out,apl_tab_size); } + if(*c)++c; } - if(*c)++c; - } - for(j=0;j<4;++j)vst[j]=0; - i=0; - while(hv[i]){ - switch(inout[i]){ - case in: - ++vst[0]; - break; - case out: - ++vst[1]; - break; - case io: - ++vst[2]; - break; - case def: - ++vst[3]; - break; + for(j=0;j<4;++j)vst[j]=0; + i=0; + while(hv[i]){ + switch(inout[i]){ + case in: + ++vst[0]; + break; + case out: + ++vst[1]; + break; + case io: + ++vst[2]; + break; + case def: + ++vst[3]; + break; + } + ++i; } - ++i; - } - len=i; + len=i; } virtual ~otl_tmpl_ext_hv_decl() {int i; for(i=0;hv[i]!=0;++i) delete[] hv[i]; + delete[] hv; + delete[] inout; + delete[] pl_tab_size; } @@ -4207,6 +4408,22 @@ strcpy(hv[n],v); inout[n]=in_out; pl_tab_size[n]=apl_tab_size; + if(n==container_size_-1){ + int temp_container_size=container_size_; + container_size_*=2; + char** temp_hv=new char*[container_size_]; + short* temp_inout=new short[container_size_]; + int* temp_pl_tab_size=new int[container_size_]; + memcpy(temp_hv,hv,sizeof(char*)*temp_container_size); + memcpy(temp_inout,inout,sizeof(short)*temp_container_size); + memcpy(temp_pl_tab_size,pl_tab_size,sizeof(int)*temp_container_size); + delete[] hv; + delete[] inout; + delete[] pl_tab_size; + hv=temp_hv; + inout=temp_inout; + pl_tab_size=temp_pl_tab_size; + } hv[++n]=0; inout[n]=def; pl_tab_size[n]=0; @@ -4256,7 +4473,7 @@ t3=otl_to_upper(c1[2]); t4=otl_to_upper(c1[3]); } - if(type=='C'&&t2=='H'){ + if(type=='C'&&t2=='H'||type=='R'&&t2=='A'&&t3=='W'&&(t4=='['||t4=='(')){ char tmp[32]; char *t=tmp; while((*c1!='[' && *c1!='(')&&*c1) @@ -4280,7 +4497,7 @@ ++c1; while((*c1!=']' && *c1!=')')&&*c1) *t++=*c1++; - *t='\0'; + *t=0; size=atoi(tmp); #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE) size+=1; @@ -4429,263 +4646,277 @@ OTL_TMPL_CONNECT& adb, const int apl_tab_size=0) { - char name[128]; + char name[128]; #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON) - char type_arr[256]; + char type_arr[256]; #endif - char type=' '; - char t2=' '; - char t3=' '; - char t4=' '; - char t5=' '; - - int size=0; - - char *c=name,*c1=s; - while(*c1!=' '&&*c1) - *c++=*c1++; - *c='\0'; - while(*c1==' '&&*c1) - ++c1; - + char type=' '; + char t2=' '; + char t3=' '; + char t4=' '; + char t5=' '; + + int size=0; + + char *c=name,*c1=s; + while(*c1!=' '&&*c1) + *c++=*c1++; + *c=0; + while(*c1==' '&&*c1) + ++c1; + #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON) - char* ct=c1; - char* tac=type_arr; - size_t ta_len=0; - while(*ct && (*ct!='[' && *ct!='(') && ta_len<sizeof(type_arr)){ - *tac=otl_to_upper(*ct); - ++ct; - ++tac; - ++ta_len; - } - *tac=0; + char* ct=c1; + char* tac=type_arr; + size_t ta_len=0; + while(*ct && (*ct!='[' && *ct!='(') && ta_len<sizeof(type_arr)){ + *tac=otl_to_upper(*ct); + ++ct; + ++tac; + ++ta_len; + } + *tac=0; #endif - size_t clen=strlen(c1); - if(clen>=3){ - type=otl_to_upper(c1[0]); - t2=otl_to_upper(c1[1]); - t3=otl_to_upper(c1[2]); - t4=otl_to_upper(c1[3]); - } - if(clen>4) - t5=otl_to_upper(c1[4]); - if(type=='C'&&t2=='H'){ - char tmp[32]; - char *t=tmp; - while((*c1!='[' && *c1!='(')&&*c1) - ++c1; - if(*c1)++c1; - while((*c1!=']' && *c1!=')')&&*c1) - *t++=*c1++; - *t=0; - size=atoi(tmp); + size_t clen=strlen(c1); + if(clen>=3){ + type=otl_to_upper(c1[0]); + t2=otl_to_upper(c1[1]); + t3=otl_to_upper(c1[2]); + t4=otl_to_upper(c1[3]); + } + if(clen>4) + t5=otl_to_upper(c1[4]); + if(type=='C'&&t2=='H'||type=='R'&&t2=='A'&&t3=='W'&&(t4=='['||t4=='(')){ + char tmp[32]; + char *t=tmp; + while((*c1!='[' && *c1!='(')&&*c1) + ++c1; + if(*c1)++c1; + while((*c1!=']' && *c1!=')')&&*c1) + *t++=*c1++; + *t=0; + if(*tmp==0) + // declaration <char> is invalid + return 0; + size=atoi(tmp); #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE) - size+=1; + if(type=='C')size+=1; #endif - } - + if(size<2) + // minimum size of <char[XXX]> should be at 2 + return 0; + } + #if defined(OTL_ORA_UNICODE) - if(type=='N'&&t2=='C'&&t3=='H'){ - char tmp[32]; - char *t=tmp; - while((*c1!='[' && *c1!='(')&&*c1) - ++c1; - if(*c1)++c1; - while((*c1!=']' && *c1!=')')&&*c1) - *t++=*c1++; - *t=0; - size=atoi(tmp); + if(type=='N'&&t2=='C'&&t3=='H'){ + char tmp[32]; + char *t=tmp; + while((*c1!='[' && *c1!='(')&&*c1) + ++c1; + if(*c1)++c1; + while((*c1!=']' && *c1!=')')&&*c1) + *t++=*c1++; + *t=0; + if(*tmp==0) + return 0; + size=atoi(tmp); #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE) - size+=1; + size+=1; #endif - } + } #endif - - - if(status==in && (vstat==in||vstat==io)) - ; - else if(status==out && (vstat==out||vstat==io||vstat==def)) - ; - else if(status==def) - ; - else - return 0; - - OTL_CHECK_BIND_VARS - - int pl_tab_flag=0; - - if(apl_tab_size){ - array_size=apl_tab_size; - pl_tab_flag=1; - } - - otl_tmpl_variable<TVariableStruct>* v= - new otl_tmpl_variable<TVariableStruct>; - v->copy_name(name); - switch(type){ - case 'B': - if(t2=='L') - v->init(otl_var_blob, - adb.get_max_long_size(), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct); + + + if(status==in && (vstat==in||vstat==io)) + ; + else if(status==out && (vstat==out||vstat==io||vstat==def)) + ; + else if(status==def) + ; + else + return 0; + + OTL_CHECK_BIND_VARS + + int pl_tab_flag=0; + + if(apl_tab_size){ + array_size=apl_tab_size; + pl_tab_flag=1; + }else + array_size=prev_array_size; + + otl_tmpl_variable<TVariableStruct>* v= + new otl_tmpl_variable<TVariableStruct>; + v->copy_name(name); + switch(type){ + case 'B': + if(t2=='L') + v->init(otl_var_blob, + adb.get_max_long_size(), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct); #if defined(OTL_BIGINT) && (defined(OTL_ODBC)||defined(OTL_DB2_CLI)) - else if(t2=='I') - v->init(otl_var_bigint,sizeof(OTL_BIGINT), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); + else if(t2=='I') + v->init(otl_var_bigint,sizeof(OTL_BIGINT), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); #elif (defined(OTL_ORA7)||defined(OTL_ORA8)|| \ defined(OTL_ORA8I)||defined(OTL_ORA9I)) && \ defined(OTL_BIGINT) - else if(t2=='I') - v->init(otl_var_char, - otl_bigint_str_size, - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct, - pl_tab_flag); + else if(t2=='I') + v->init(otl_var_char, + otl_bigint_str_size, + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct, + pl_tab_flag); #endif - break; + break; #if defined(OTL_ORA_UNICODE) - case 'N': - if(t2=='C' && (t3=='L'||t3=='H')){ - if(t3=='L'){ - v->init(otl_var_nclob, - adb.get_max_long_size(), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct); - v->ftype=otl_var_clob; - }else if(t3=='H'){ - v->init(otl_var_nchar, - size, - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - v->ftype=otl_var_char; - } - }else{ - delete v; - v=0; - } - break; + case 'N': + if(t2=='C' && (t3=='L'||t3=='H')){ + if(t3=='L'){ + v->init(otl_var_nclob, + adb.get_max_long_size(), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct); + v->ftype=otl_var_clob; + }else if(t3=='H'){ + v->init(otl_var_nchar, + size, + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + v->ftype=otl_var_char; + } + }else{ + delete v; + v=0; + } + break; #endif - case 'C': - if(t2=='H'){ - v->init(otl_var_char, - size, - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - if(t5=='Z') - v->var_struct.charz_flag=true; - }else if(t2=='L') - v->init(otl_var_clob, - adb.get_max_long_size(), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct); - else{ - delete v; - v=0; - } - break; - case 'D': - if(t2=='O') - v->init(otl_var_double,sizeof(double), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - else if(t2=='B'&&t3=='2'){ - if(t4=='T') - v->init(otl_var_db2time,sizeof(TTimestampStruct), + case 'C': + if(t2=='H'){ + v->init(otl_var_char, + size, + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + if(t5=='Z') + v->var_struct.charz_flag=true; + }else if(t2=='L') + v->init(otl_var_clob, + adb.get_max_long_size(), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct); + else{ + delete v; + v=0; + } + break; + case 'D': + if(t2=='O') + v->init(otl_var_double,sizeof(double), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else if(t2=='B'&&t3=='2'){ + if(t4=='T') + v->init(otl_var_db2time,sizeof(TTimestampStruct), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else if(t4=='D') + v->init(otl_var_db2date,sizeof(TTimestampStruct), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else{ + delete v; + v=0; + } + }else{ + delete v; + v=0; + } + break; + case 'F': + v->init(otl_var_float, + sizeof(float), OTL_SCAST(const otl_stream_buffer_size_type,array_size), &adb.connect_struct,pl_tab_flag); - else if(t4=='D') - v->init(otl_var_db2date,sizeof(TTimestampStruct), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - else{ + break; + case 'I': + v->init(otl_var_int, + sizeof(int), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + break; + case 'U': + v->init(otl_var_unsigned_int, + sizeof(unsigned), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + break; + case 'R': + if(t2=='E'&&t3=='F') + v->init(otl_var_refcur, + 1, + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,0); + else if(t2=='A'&&t3=='W'&&(t4=='['||t4=='(')) + v->init(otl_var_raw, + size, + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else if(t2=='A'&&t3=='W') + v->init(otl_var_raw_long, + adb.get_max_long_size(), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct); + break; + case 'S': + v->init(otl_var_short, + sizeof(short), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + break; + case 'L': + if(t2=='O'&&t3=='N') + v->init(otl_var_long_int, + sizeof(long), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else if(t2=='T'&&t3=='Z') + v->init(otl_var_ltz_timestamp, + sizeof(TTimestampStruct), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else{ + delete v; + v=0; + } + break; + case 'T': + if(t2=='Z') + v->init(otl_var_tz_timestamp,sizeof(TTimestampStruct), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else if(t2=='I' && t3=='M') + v->init(otl_var_timestamp,sizeof(TTimestampStruct), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct,pl_tab_flag); + else{ + delete v; + v=0; + } + break; + case 'V': + v->init(otl_var_varchar_long,adb.get_max_long_size(), + OTL_SCAST(const otl_stream_buffer_size_type,array_size), + &adb.connect_struct); + break; + default: delete v; v=0; - } - }else{ - delete v; - v=0; + break; } - break; - case 'F': - v->init(otl_var_float, - sizeof(float), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - break; - case 'I': - v->init(otl_var_int, - sizeof(int), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - break; - case 'U': - v->init(otl_var_unsigned_int, - sizeof(unsigned), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - break; - case 'R': - if(t2=='E'&&t3=='F') - v->init(otl_var_refcur, - 1, - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,0); - else if(t2=='A'&&t3=='W') - v->init(otl_var_raw_long, - adb.get_max_long_size(), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct); - break; - case 'S': - v->init(otl_var_short, - sizeof(short), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - break; - case 'L': - if(t2=='O'&&t3=='N') - v->init(otl_var_long_int, - sizeof(long), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - else if(t2=='T'&&t3=='Z') - v->init(otl_var_ltz_timestamp, - sizeof(TTimestampStruct), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - else{ - delete v; - v=0; - } - break; - case 'T': - if(t2=='Z') - v->init(otl_var_tz_timestamp,sizeof(TTimestampStruct), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - else if(t2=='I' && t3=='M') - v->init(otl_var_timestamp,sizeof(TTimestampStruct), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct,pl_tab_flag); - else{ - delete v; - v=0; - } - break; - case 'V': - v->init(otl_var_varchar_long,adb.get_max_long_size(), - OTL_SCAST(const otl_stream_buffer_size_type,array_size), - &adb.connect_struct); - break; - default: - delete v; - v=0; - break; - } - return v; + return v; } void alloc_host_var_list @@ -4700,7 +4931,9 @@ vl=0; return; } - otl_tmpl_variable<TVariableStruct>* tmp_vl[otl_var_list_size]; + otl_auto_array_ptr<otl_tmpl_variable<TVariableStruct>*> + loc_ptr(container_size_); + otl_tmpl_variable<TVariableStruct>** tmp_vl=loc_ptr.ptr; int i=0; while(hv[i]){ otl_tmpl_variable<TVariableStruct>* vp= @@ -4886,6 +5119,12 @@ virtual void set_len(const int new_len=0) = 0; virtual otl_lob_stream_generic& operator<<(const otl_long_string& s) = 0; virtual otl_lob_stream_generic& operator>>(otl_long_string& s) = 0; +#if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_UNICODE) + virtual otl_lob_stream_generic& operator<<(const OTL_STRING_CONTAINER& s) = 0; + virtual otl_lob_stream_generic& operator>>(OTL_STRING_CONTAINER& s) = 0; + virtual void setStringBuffer(const int chunk_size) = 0; +#endif + virtual int eof(void) = 0; virtual int len(void) = 0; virtual void close(void) = 0; @@ -4895,10 +5134,10 @@ #endif #if defined(__GNUC__) || defined(__SUNPRO_CC) || \ - (defined(_MSC_VER) &&(_MSC_VER <= 1200)) + (defined(_MSC_VER) &&(_MSC_VER <= 1300)) // Enable the kludge for compilers that do not support template // member functions at all, or have bugs: g++, Forte C++ (Solaris), - // Visual C++ 6.0, etc. + // Visual C++ 6.0, Visual C++ 7.0, etc. #define OTL_NO_TMPL_MEMBER_FUNC_SUPPORT #endif @@ -4947,62 +5186,63 @@ const int implicit_select=otl_explicit_select, const char* sqlstm_label=0) : OTL_TMPL_SELECT_CURSOR(pdb,arr_size,sqlstm_label) - {int i; - this->select_cursor_struct.set_select_type(implicit_select); - sl=0; - sl_len=0; - _rfc=0; - null_fetched=0; - lob_stream_mode=aoverride->lob_stream_mode; - this->retcode=0; - sl_desc=0; - executed=0; - cur_in=0; - this->stm_text=0; - eof_status=1; - override=aoverride; - - { - size_t len=strlen(sqlstm)+1; - this->stm_text=new char[len]; - strcpy(this->stm_text,sqlstm); - otl_select_struct_override* temp_local_override=&this->local_override; - otl_tmpl_ext_hv_decl - <TVariableStruct,TTimestampStruct,TExceptionStruct, - TConnectStruct,TCursorStruct> hvd + { + int i; + this->select_cursor_struct.set_select_type(implicit_select); + sl=0; + sl_len=0; + _rfc=0; + null_fetched=0; + lob_stream_mode=aoverride->lob_stream_mode; + this->retcode=0; + sl_desc=0; + executed=0; + cur_in=0; + this->stm_text=0; + eof_status=1; + override=aoverride; + + { + size_t len=strlen(sqlstm)+1; + this->stm_text=new char[len]; + strcpy(this->stm_text,sqlstm); + otl_select_struct_override* temp_local_override=&this->local_override; + otl_tmpl_ext_hv_decl + <TVariableStruct,TTimestampStruct,TExceptionStruct, + TConnectStruct,TCursorStruct> hvd (this->stm_text, 1, this->stm_label, &temp_local_override, &pdb - ); - hvd.alloc_host_var_list(this->vl,this->vl_len,pdb); - } - - try{ - this->parse(); - if(!this->select_cursor_struct.implicit_cursor){ - get_select_list(); - bind_all(); - }else{ - for(i=0;i<this->vl_len;++i) - this->bind(*this->vl[i]); + ); + hvd.alloc_host_var_list(this->vl,this->vl_len,pdb); } - if(this->vl_len==0){ - rewind(); - null_fetched=0; + + try{ + this->parse(); + if(!this->select_cursor_struct.implicit_cursor){ + get_select_list(); + bind_all(); + }else{ + for(i=0;i<this->vl_len;++i) + this->bind(*this->vl[i]); + } + if(this->vl_len==0){ + rewind(); + null_fetched=0; + } + }catch(OTL_CONST_EXCEPTION OTL_TMPL_EXCEPTION&){ + cleanup(); + if(this->adb)this->adb->throw_count++; + throw; } - }catch(OTL_CONST_EXCEPTION OTL_TMPL_EXCEPTION&){ - cleanup(); - if(this->adb)this->adb->throw_count++; - throw; - } } void rewind(void) { - OTL_TRACE_STREAM_EXECUTION + OTL_TRACE_STREAM_EXECUTION int i; _rfc=0; if(!this->select_cursor_struct.close_select(this->cursor_struct)){ @@ -5073,50 +5313,70 @@ } void get_select_list(void) - {int j; - - otl_auto_array_ptr<otl_column_desc> loc_ptr(otl_var_list_size); - otl_column_desc* sl_desc_tmp=loc_ptr.ptr; - int sld_tmp_len=0; - int ftype,elem_size,i; - for(i=1;this->describe_column(sl_desc_tmp[i-1],i);++i) - ++sld_tmp_len; - sl_len=sld_tmp_len; - if(sl){ - delete[] sl; - sl=0; - } - sl=new otl_tmpl_variable<TVariableStruct>[sl_len==0?1:sl_len]; - int max_long_size=this->adb->get_max_long_size(); - for(j=0;j<sl_len;++j){ - otl_tmpl_variable<TVariableStruct>::map_ftype - (sl_desc_tmp[j], - max_long_size, - ftype, - elem_size, - this->local_override.getLen()>0?this->local_override:*override, - j+1); - sl[j].copy_pos(j+1); + { + int j; + otl_auto_array_ptr<otl_column_desc> loc_ptr(otl_var_list_size); + otl_column_desc* sl_desc_tmp=loc_ptr.ptr; + int sld_tmp_len=0; + int ftype,elem_size,i; + for(i=1;this->describe_column(sl_desc_tmp[i-1],i);++i){ + if(otl_tmpl_variable<TVariableStruct>::int2ext + (sl_desc_tmp[i-1].dbtype)==otl_unsupported_type){ + otl_var_info_col3 + (i-1, + sl_desc_tmp[i-1].dbtype, + sl_desc_tmp[i-1].name, + this->var_info); + throw OTL_TMPL_EXCEPTION + (otl_error_msg_27, + otl_error_code_27, + this->stm_label? + this->stm_label: + this->stm_text, + this->var_info); + } + ++sld_tmp_len; + if(sld_tmp_len==loc_ptr.arr_size_){ + loc_ptr.double_size(); + sl_desc_tmp=loc_ptr.ptr; + } + } + sl_len=sld_tmp_len; + if(sl){ + delete[] sl; + sl=0; + } + sl=new otl_tmpl_variable<TVariableStruct>[sl_len==0?1:sl_len]; + int max_long_size=this->adb->get_max_long_size(); + for(j=0;j<sl_len;++j){ + otl_tmpl_variable<TVariableStruct>::map_ftype + (sl_desc_tmp[j], + max_long_size, + ftype, + elem_size, + this->local_override.getLen()>0?this->local_override:*override, + j+1); + sl[j].copy_pos(j+1); #if defined(OTL_ORA_UNICODE) - if(sl_desc_tmp[j].charset_form==2) - sl[j].var_struct.nls_flag=true; + if(sl_desc_tmp[j].charset_form==2) + sl[j].var_struct.nls_flag=true; #endif - sl[j].init(ftype, - elem_size, - OTL_SCAST(otl_stream_buffer_size_type,(this->array_size)), - &this->adb->connect_struct - ); - sl[j].var_struct.lob_stream_mode=this->lob_stream_mode; - } - if(sl_desc){ - delete[] sl_desc; - sl_desc=0; - } - sl_desc=new otl_column_desc[sl_len==0?1:sl_len]; - for(j=0;j<sl_len;++j) - sl_desc[j]=sl_desc_tmp[j]; + sl[j].init(ftype, + elem_size, + OTL_SCAST(otl_stream_buffer_size_type,(this->array_size)), + &this->adb->connect_struct + ); + sl[j].var_struct.lob_stream_mode=this->lob_stream_mode; + } + if(sl_desc){ + delete[] sl_desc; + sl_desc=0; + } + sl_desc=new otl_column_desc[sl_len==0?1:sl_len]; + for(j=0;j<sl_len;++j) + sl_desc[j]=sl_desc_tmp[j]; } - + void check_if_executed_throw(void) { if(this->adb)this->adb->throw_count++; @@ -5280,9 +5540,9 @@ #if (defined(OTL_USER_DEFINED_STRING_CLASS_ON) || defined(OTL_STL)) \ && !defined(OTL_ACE) - s.assign((char*)c,len); + s.assign(OTL_RCAST(char*,c),len); #elif defined(OTL_ACE) - s.set((char*)c,len,1); + s.set(OTL_RCAST(char*,c),len,1); #endif look_ahead(); } @@ -5312,9 +5572,9 @@ } #if (defined(OTL_USER_DEFINED_STRING_CLASS_ON) || \ defined(OTL_STL)) && !defined(OTL_ACE) - s.assign((char*)temp_buf,len); + s.assign(OTL_RCAST(char*,temp_buf),len); #elif defined(OTL_ACE) - s.set((char*)temp_buf,len,1); + s.set(OTL_RCAST(char*,temp_buf),len,1); #endif look_ahead(); } @@ -5397,8 +5657,18 @@ #if defined(OTL_ODBC) || defined(DB2_CLI) s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row)); #else - s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row))+1; + +#if defined(OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR) + OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST + (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row)); + OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR(s,temp_s+1,*temp_s); +#else + OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST + (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row)); + s.assign(temp_s+1,*temp_s); #endif + +#endif look_ahead(); } break; @@ -5541,60 +5811,92 @@ OTL_TMPL_SELECT_STREAM& operator>>(otl_long_string& s) { - check_if_executed(); - if(eof_intern())return *this; - get_next(); - if((sl[cur_col].ftype==otl_var_varchar_long|| - sl[cur_col].ftype==otl_var_raw_long)&& - !eof_intern()){ - unsigned char* c= - OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row)); - int len2=sl[cur_col].get_len(this->cur_row); - if(len2>s.buf_size)len2=s.buf_size; - otl_memcpy(s.v,c,len2,sl[cur_col].ftype); - s.null_terminate_string(len2); - s.set_len(len2); - look_ahead(); - }else if((sl[cur_col].ftype==otl_var_blob|| - sl[cur_col].ftype==otl_var_clob)&& - !eof_intern()){ - int len=0; - int rc=sl[cur_col].var_struct.get_blob(this->cur_row,s.v,s.buf_size,len); - if(rc==0){ - if(this->adb)this->adb->throw_count++; - if(this->adb&&this->adb->throw_count>1)return *this; + check_if_executed(); + if(eof_intern())return *this; + get_next(); + switch(sl[cur_col].ftype){ + case otl_var_varchar_long: + case otl_var_raw_long: + { + if(!eof_intern()){ + unsigned char* c= + OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row)); + int len2=sl[cur_col].get_len(this->cur_row); + if(len2>s.buf_size)len2=s.buf_size; + otl_memcpy(s.v,c,len2,sl[cur_col].ftype); + if(sl[cur_col].ftype==otl_var_varchar_long) + s.null_terminate_string(len2); + s.set_len(len2); + look_ahead(); + } + } + break; + case otl_var_raw: + { + if(!eof_intern()){ + unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row)); + if(sl[cur_col].var_struct.otl_adapter==otl_ora7_adapter|| + sl[cur_col].var_struct.otl_adapter==otl_ora8_adapter){ + int len2=OTL_SCAST(int,*OTL_RCAST(unsigned short*,c)); + otl_memcpy(s.v,c+sizeof(short int),len2,sl[cur_col].ftype); + s.set_len(len2); + }else{ + int len2=sl[cur_col].get_len(this->cur_row); + if(len2>s.buf_size)len2=s.buf_size; + otl_memcpy(s.v,c,len2,sl[cur_col].ftype); + s.set_len(len2); + } + look_ahead(); + } + } + break; + case otl_var_blob: + case otl_var_clob: + { + if(!eof_intern()){ + int len=0; + int rc=sl[cur_col].var_struct.get_blob(this->cur_row,s.v,s.buf_size,len); + if(rc==0){ + if(this->adb)this->adb->throw_count++; + if(this->adb&&this->adb->throw_count>1)return *this; #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON) - if(STD_NAMESPACE_PREFIX uncaught_exception())return *this; + if(STD_NAMESPACE_PREFIX uncaught_exception())return *this; #endif - throw OTL_TMPL_EXCEPTION - (this->adb->connect_struct, - this->stm_label?this->stm_label: - this->stm_text); - } - if(len>s.buf_size)len=s.buf_size; - s.set_len(len); - s.null_terminate_string(len); - look_ahead(); - }else{ - char tmp_var_info[256]; - otl_var_info_col - (sl[cur_col].pos, - sl[cur_col].ftype, - otl_var_long_string, - tmp_var_info); - if(this->adb)this->adb->throw_count+... [truncated message content] |