1 /**********************************************************
2  * Version $Id: otlv4.h 1100 2011-06-17 00:47:16Z johanvdw $
3  *********************************************************/
4 // =================================================================================
5 // ORACLE, ODBC and DB2/CLI Template Library, Version 4.0.210,
6 // Copyright (C) 1996-2010, Sergei Kuchin (skuchin@gmail.com)
7 //
8 // This library is free software. Permission to use, copy, modify,
9 // and/or distribute this software for any purpose with or without fee
10 // is hereby granted, provided that the above copyright notice and
11 // this permission notice appear in all copies.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 //
21 // a.k.a. as Open BSD license
22 // (http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/share/misc/license.template
23 // =================================================================================
24 
25 #ifndef __OTL_H__
26 #define __OTL_H__
27 
28 #if defined(OTL_INCLUDE_0)
29 #include "otl_include_0.h"
30 #endif
31 
32 #define OTL_VERSION_NUMBER (0x0400D2L)
33 
34 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
35 #pragma warning (disable:4351)
36 #pragma warning (disable:4290)
37 #define OTL_STRCAT_S(dest,dest_sz,src) strcat_s(dest,dest_sz,src)
38 #define OTL_STRCPY_S(dest,dest_sz,src) strcpy_s(dest,dest_sz,src)
39 #define OTL_STRNCPY_S(dest,dest_sz,src,count) strncpy_s(dest,dest_sz,src,count)
40 #else
41 #define OTL_STRCAT_S(dest,dest_sz,src) strcat(dest,src)
42 #define OTL_STRCPY_S(dest,dest_sz,src) strcpy(dest,src)
43 #define OTL_STRNCPY_S(dest,dest_sz,src,count) strncpy(dest,src,count)
44 #endif
45 
46 #include <string.h>
47 #include <ctype.h>
48 #include <stdlib.h>
49 #include <stdio.h>
50 #include <stddef.h>
51 
52 //======================= CONFIGURATION #DEFINEs ===========================
53 
54 // Uncomment the following line in order to include the OTL for ODBC:
55 //#define OTL_ODBC
56 
57 // Uncomment the following line in order to include the OTL for
58 // MySQL/MyODBC for MyODBC 2.5 (pretty old). Otherwise, use OTL_ODBC
59 //#define OTL_ODBC_MYSQL
60 
61 // Uncomment the following line in order to include the OTL for DB2 CLI:
62 //#define OTL_DB2_CLI
63 
64 // Uncomment the following line in order to include the OTL for
65 // Oracle 7:
66 //#define OTL_ORA7
67 
68 // Uncomment the following line in order to include the OTL for
69 // Oracle 8:
70 //#define OTL_ORA8
71 
72 // Uncomment the following line in order to include the OTL for
73 // Oracle 8i:
74 //#define OTL_ORA8I
75 
76 // Uncomment the following line in order to include the OTL for
77 // Oracle 9i:
78 //#define OTL_ORA9I
79 
80 // Uncomment the following line in order to include the OTL for
81 // Oracle 10g Release 1:
82 //#define OTL_ORA10G
83 
84 // Uncomment the following line in order to include the OTL for
85 // Oracle 10g Release 2:
86 //#define OTL_ORA10G_R2
87 
88 // Uncomment the following line in order to include the OTL for
89 // Oracle 11g Release 1
90 //#define OTL_ORA11G
91 
92 
93 // The macro definitions may be also turned on via C++ compiler command line
94 // option, e.g.: -DOTL_ODBC, -DOTL_ORA7, -DOTL_ORA8, -DOTL_ORA8I, -DOTL_ODBC_UNIX
95 // -DOTL_ODBC_MYSQL, -DOTL_DB2_CLI
96 
97 // this becomes the default from version 4.0.162 and on.
98 // the #define is not enabled for vc++ 6.0 in version 4.0.167 and higher.
99 #if !defined(OTL_UNCAUGHT_EXCEPTION_ON) && !(defined(_MSC_VER)&&(_MSC_VER==1200))
100 #define OTL_UNCAUGHT_EXCEPTION_ON
101 #endif
102 
103 #if !defined(OTL_TRACE_LEVEL)
104 
105 #define OTL_TRACE_FORMAT_TZ_DATETIME(s)
106 #define OTL_TRACE_FORMAT_DATETIME(s)
107 
108 #else
109 
110 #if !defined(OTL_TRACE_FORMAT_DATETIME)
111 
112 #define OTL_TRACE_FORMAT_TZ_DATETIME(s)                         \
113 s.month<<"/"<<s.day<<"/"<<s.year                                \
114 <<" "<<s.hour<<":"<<s.minute<<":"<<s.second<<"."<<s.fraction    \
115 <<" "<<s.tz_hour<<":"<<s.tz_minute
116 
117 #define OTL_TRACE_FORMAT_DATETIME(s)                            \
118 s.month<<"/"<<s.day<<"/"<<s.year                                \
119 <<" "<<s.hour<<":"<<s.minute<<":"<<s.second<<"."<<s.fraction
120 
121 #endif
122 #endif
123 
124 #if defined(OTL_ORA11G)
125 #define OTL_ORA10G_R2
126 #endif
127 
128 #if defined(OTL_ORA11G_R2)
129 #define OTL_ORA10G_R2
130 #endif
131 
132 #if defined(OTL_STREAM_LEGACY_BUFFER_SIZE_TYPE)
133 typedef short int otl_stream_buffer_size_type;
134 #else
135 typedef int otl_stream_buffer_size_type;
136 #endif
137 
138 
139 #if defined(OTL_ODBC_MULTI_MODE)
140 #define OTL_ODBC
141 #define OTL_ODBC_SQL_EXTENDED_FETCH_ON
142 #endif
143 
144 #if defined(OTL_ODBC_MSSQL_2005)
145 #define OTL_ODBC
146 #endif
147 
148 #if defined(OTL_ODBC_MSSQL_2008)
149 #define OTL_ODBC
150 #define OTL_ODBC_MSSQL_2005
151 #endif
152 
153 #if defined(OTL_IODBC_BSD)
154 #define OTL_ODBC
155 #define OTL_ODBC_UNIX
156 #endif
157 
158 #if defined(OTL_ODBC_TIMESTEN_WIN)
159 #define OTL_ODBC_TIMESTEN
160 #define OTL_ODBC
161 #define OTL_ODBC_SQL_EXTENDED_FETCH_ON
162 #define ODBCVER 0x0250
163 #include <timesten.h>
164 #endif
165 
166 #if defined(OTL_ODBC_TIMESTEN_UNIX)
167 #define OTL_ODBC_TIMESTEN
168 #define OTL_ODBC
169 #define OTL_ODBC_UNIX
170 #define OTL_ODBC_SQL_EXTENDED_FETCH_ON
171 #include <timesten.h>
172 #endif
173 
174 #if defined(OTL_ODBC_ENTERPRISEDB)
175 #define OTL_ODBC_POSTGRESQL
176 #endif
177 
178 #if defined(OTL_ODBC_POSTGRESQL)
179 #define OTL_ODBC
180 #endif
181 
182 // Comment out this #define when using pre-ANSI C++ compiler
183 #if !defined(OTL_ODBC_zOS) && !defined (OTL_ANSI_CPP)
184 #define OTL_ANSI_CPP
185 #endif
186 
187 #if defined(OTL_ODBC_zOS)
188 #define OTL_ODBC_UNIX
189 #define OTL_ODBC_SQL_EXTENDED_FETCH_ON
190 #endif
191 
192 #if defined(OTL_ORA8I)
193 #define OTL_ORA8
194 #define OTL_ORA8_8I_REFCUR
195 #define OTL_ORA8_8I_DESC_COLUMN_SCALE
196 #endif
197 
198 #if defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)
199 #define  OTL_ORA9I
200 #define OTL_ORA_NATIVE_TYPES
201 #endif
202 
203 #if defined(OTL_ORA9I)
204 #define OTL_ORA8
205 #define OTL_ORA8_8I_REFCUR
206 #define OTL_ORA8_8I_DESC_COLUMN_SCALE
207 #endif
208 
209 #if defined(OTL_ODBC_MYSQL)
210 #define OTL_ODBC
211 #endif
212 
213 #if defined(OTL_ODBC_XTG_IBASE6)
214 #define OTL_ODBC
215 #endif
216 
217 #define OTL_VALUE_TEMPLATE
218 //#define OTL_ODBC_SQL_EXTENDED_FETCH_ON
219 
220 #if defined(OTL_ODBC_UNIX) && !defined(OTL_ODBC)
221 #define OTL_ODBC
222 #endif
223 
224 #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON)
225 #define OTL_CHECK_BIND_VARS                     \
226   if(strcmp(type_arr,"INT")==0||                \
227      strcmp(type_arr,"UNSIGNED")==0||           \
228      strcmp(type_arr,"SHORT")==0||              \
229      strcmp(type_arr,"LONG")==0||               \
230      strcmp(type_arr,"FLOAT")==0||              \
231      strcmp(type_arr,"DOUBLE")==0||             \
232      strcmp(type_arr,"TIMESTAMP")==0||          \
233      strcmp(type_arr,"TZ_TIMESTAMP")==0||       \
234      strcmp(type_arr,"LTZ_TIMESTAMP")==0||      \
235      strcmp(type_arr,"BIGINT")==0||             \
236      strcmp(type_arr,"CHAR")==0||               \
237      strcmp(type_arr,"CHARZ")==0||              \
238      strcmp(type_arr,"DB2DATE")==0||            \
239      strcmp(type_arr,"DB2TIME")==0||            \
240      strcmp(type_arr,"VARCHAR_LONG")==0||       \
241      strcmp(type_arr,"RAW_LONG")==0||           \
242      strcmp(type_arr,"RAW")==0||                \
243      strcmp(type_arr,"CLOB")==0||               \
244      strcmp(type_arr,"BLOB")==0||               \
245      strcmp(type_arr,"NCHAR")==0||              \
246      strcmp(type_arr,"NCLOB")==0||              \
247      strcmp(type_arr,"REFCUR")==0)              \
248     ;                                           \
249   else                                          \
250     return 0;
251 #else
252 #define OTL_CHECK_BIND_VARS
253 #endif
254 
255 // ------------------- Namespace generation ------------------------
256 #if defined(OTL_EXPLICIT_NAMESPACES)
257 
258 #if defined(OTL_DB2_CLI)
259 #define OTL_ODBC_NAMESPACE_BEGIN namespace db2 {
260 #define OTL_ODBC_NAMESPACE_PREFIX db2::
261 #define OTL_ODBC_NAMESPACE_END }
262 #else
263 #define OTL_ODBC_NAMESPACE_BEGIN namespace odbc {
264 #define OTL_ODBC_NAMESPACE_PREFIX odbc::
265 #define OTL_ODBC_NAMESPACE_END }
266 #endif
267 
268 #define OTL_ORA7_NAMESPACE_BEGIN namespace oracle {
269 #define OTL_ORA7_NAMESPACE_PREFIX oracle::
270 #define OTL_ORA7_NAMESPACE_END }
271 
272 #define OTL_ORA8_NAMESPACE_BEGIN namespace oracle {
273 #define OTL_ORA8_NAMESPACE_PREFIX oracle::
274 #define OTL_ORA8_NAMESPACE_END }
275 
276 #else
277 
278 // Only one OTL is being intantiated
279 #if defined(OTL_ODBC)&&!defined(OTL_ORA8)&& \
280     !defined(OTL_ORA7)&&!defined(OTL_DB2_CLI) \
281  || !defined(OTL_ODBC)&&defined(OTL_ORA8)&& \
282     !defined(OTL_ORA7)&&!defined(OTL_DB2_CLI) \
283  || !defined(OTL_ODBC)&&!defined(OTL_ORA8)&& \
284     defined(OTL_ORA7)&&!defined(OTL_DB2_CLI) \
285  || !defined(OTL_ODBC)&&!defined(OTL_ORA8)&& \
286     !defined(OTL_ORA7)&&defined(OTL_DB2_CLI)
287 
288 #define OTL_ODBC_NAMESPACE_BEGIN
289 #define OTL_ODBC_NAMESPACE_PREFIX
290 #define OTL_ODBC_NAMESPACE_END
291 
292 #define OTL_ORA7_NAMESPACE_BEGIN
293 #define OTL_ORA7_NAMESPACE_PREFIX
294 #define OTL_ORA7_NAMESPACE_END
295 
296 #define OTL_ORA8_NAMESPACE_BEGIN
297 #define OTL_ORA8_NAMESPACE_PREFIX
298 #define OTL_ORA8_NAMESPACE_END
299 
300 #endif
301 
302 // ================ Combinations of two OTLs =========================
303 #if defined(OTL_ODBC) && defined(OTL_ORA7) && \
304     !defined(OTL_ORA8) && !defined(OTL_DB2_CLI)
305 
306 #define OTL_ODBC_NAMESPACE_BEGIN namespace odbc{
307 #define OTL_ODBC_NAMESPACE_PREFIX odbc::
308 #define OTL_ODBC_NAMESPACE_END }
309 
310 #define OTL_ORA7_NAMESPACE_BEGIN namespace oracle {
311 #define OTL_ORA7_NAMESPACE_PREFIX oracle::
312 #define OTL_ORA7_NAMESPACE_END }
313 
314 #define OTL_ORA8_NAMESPACE_BEGIN
315 #define OTL_ORA8_NAMESPACE_PREFIX
316 #define OTL_ORA8_NAMESPACE_END
317 
318 #endif
319 
320 #if defined(OTL_ODBC) && !defined(OTL_ORA7) && \
321     defined(OTL_ORA8) && !defined(OTL_DB2_CLI)
322 
323 #define OTL_ODBC_NAMESPACE_BEGIN namespace odbc{
324 #define OTL_ODBC_NAMESPACE_PREFIX odbc::
325 #define OTL_ODBC_NAMESPACE_END }
326 
327 #define OTL_ORA8_NAMESPACE_BEGIN namespace oracle {
328 #define OTL_ORA8_NAMESPACE_PREFIX oracle::
329 #define OTL_ORA8_NAMESPACE_END }
330 
331 #define OTL_ORA7_NAMESPACE_BEGIN
332 #define OTL_ORA7_NAMESPACE_PREFIX
333 #define OTL_ORA7_NAMESPACE_END
334 
335 
336 #endif
337 
338 #if !defined(OTL_ODBC) && defined(OTL_ORA7) && \
339     !defined(OTL_ORA8) && defined(OTL_DB2_CLI)
340 
341 #define OTL_ORA7_NAMESPACE_BEGIN namespace oracle {
342 #define OTL_ORA7_NAMESPACE_PREFIX oracle::
343 #define OTL_ORA7_NAMESPACE_END }
344 
345 #define OTL_ORA8_NAMESPACE_BEGIN
346 #define OTL_ORA8_NAMESPACE_PREFIX
347 #define OTL_ORA8_NAMESPACE_END
348 
349 #define OTL_ODBC_NAMESPACE_BEGIN namespace db2 {
350 #define OTL_ODBC_NAMESPACE_PREFIX db2::
351 #define OTL_ODBC_NAMESPACE_END }
352 
353 
354 #endif
355 
356 #if !defined(OTL_ODBC) && !defined(OTL_ORA7) && \
357     defined(OTL_ORA8) && defined(OTL_DB2_CLI)
358 
359 #define OTL_ORA8_NAMESPACE_BEGIN namespace oracle {
360 #define OTL_ORA8_NAMESPACE_PREFIX oracle::
361 #define OTL_ORA8_NAMESPACE_END }
362 
363 #define OTL_ORA7_NAMESPACE_BEGIN
364 #define OTL_ORA7_NAMESPACE_PREFIX
365 #define OTL_ORA7_NAMESPACE_END
366 
367 #define OTL_ODBC_NAMESPACE_BEGIN namespace db2 {
368 #define OTL_ODBC_NAMESPACE_PREFIX db2::
369 #define OTL_ODBC_NAMESPACE_END }
370 
371 
372 #endif
373 
374 #endif
375 
376 // -------------------- End of namespace generation -------------------
377 
378 // --------------------- Invalid combinations --------------------------
379 
380 #if (defined(OTL_ORA7_TIMESTAMP_TO_STRING)||defined(OTL_ORA7_STRING_TO_TIMESTAMP)) \
381   && defined(OTL_ORA_TIMESTAMP)
382 #error Invalid combination: OTL_ORA_TIMESTAMP and \
383 OTL_ORA7_TIMESTAMP_TO_STRING/OTL_ORA7_STRING_TO_TIMESTAMP
384 #endif
385 
386 #if defined(OTL_ORA_MAP_BIGINT_TO_LONG) && \
387     defined(OTL_BIGINT_TO_STR) && \
388     defined(OTL_STR_TO_BIGINT)
389 #error OTL_ORA_MAP_BIGINT_TO_LONG cannot be used when \
390 OTL_BIGINT_TO_STR and OTL_STR_TO_BIGINT are defined
391 #endif
392 
393 #if defined(OTL_STL) && defined(OTL_UNICODE_STRING_TYPE)
394 #error Invalid combination: OTL_STL and OTL_UNICODE_STRING_TYPE
395 #endif
396 
397 #if defined(OTL_ORA_UTF8) && !defined(OTL_ORA10G) && \
398     !defined(OTL_ORA_10G_R2) && !defined(OTL_ORA9I)
399 #error Invalid combination: OTL_ORA_UTF8 can only be used with OTL_ORA9I or higher
400 #endif
401 
402 #if defined(OTL_ORA_UTF8) && defined(OTL_UNICODE)
403 #error Invalid combination: OTL_ORA_UTF8 and OTL_UNICODE are mutually exclusive
404 #endif
405 
406 #if defined(OTL_ODBC) && defined(OTL_DB2_CLI)
407 #error Invalid combination: OTL_ODBC && OTL_DB2_CLI together
408 #endif
409 
410 #if defined(OTL_ORA7) && defined(OTL_ORA8)
411 #error Invalid combination: OTL_ORA7 && OTL_ORA8(I) together
412 #endif
413 
414 #if (defined(OTL_ORA7) || defined(OTL_ORA8) ||          \
415      defined(OTL_ORA8I) || defined(OTL_ORA9I) ) &&      \
416      defined(OTL_BIGINT) &&                             \
417      (defined(OTL_ODBC) || defined(OTL_DB2_CLI))
418 #error OTL_BIGINT is not supported when OTL_ORAXX and OTL_ODBC \
419 (or OTL_DB2_CLI) are defined together
420 #endif
421 
422 #if defined (OTL_ORA7) && defined(OTL_ORA8)
423 #error Invalid combination: OTL_ORA7 && OTL_ORA8(I) together
424 #endif
425 
426 #if defined(OTL_ORA_OCI_ENV_CREATE) && \
427     (!defined(OTL_ORA8I) && !defined(OTL_ORA9I) && \
428      !defined(OTL_ORA10G) && !defined(OTL_ORA10G_R2))
429 #error OTL_ORA_OCI_ENV_CREATE can be only defined when OTL_ORA8I, OTL_ORA9I, OTL_ORA10G, OTL_ORA10G_R2, or OTL_ORA11G is defined
430 #endif
431 // --------------------------------------------------------------------
432 
433 #if defined(OTL_TRACE_LEVEL)
434 
435 #if !defined(OTL_TRACE_LINE_PREFIX)
436 #define OTL_TRACE_LINE_PREFIX "OTL TRACE ==> "
437 #endif
438 
439 #if defined(OTL_UNICODE_CHAR_TYPE) && !defined(OTL_UNICODE)
440 #error OTL_UNICODE needs to be defined if OTL_UNICODE_CHAR_TYPE is defined
441 #endif
442 
443 #if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE_CHAR_TYPE)
444 #error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_STRING_TYPE is defined
445 #endif
446 
447 #if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE_CHAR_TYPE)
448 #error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_STRING_TYPE is defined
449 #endif
450 
451 #if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE)
452 #error OTL_UNICODE needs to be defined if OTL_UNICODE_STRING_TYPE is defined
453 #endif
454 
455 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON) && !defined(OTL_UNICODE_CHAR_TYPE)
456 #error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_EXCEPTION_AND_RLOGON is defined
457 #endif
458 
459 
460 #if !defined(OTL_TRACE_LINE_SUFFIX)
461 #if defined(OTL_UNICODE)
462 #define OTL_TRACE_LINE_SUFFIX L"\n"
463 #else
464 #define OTL_TRACE_LINE_SUFFIX "\n"
465 #endif
466 #endif
467 
468 #if !defined(OTL_TRACE_STREAM_OPEN)
469 #define OTL_TRACE_STREAM_OPEN                   \
470   if(OTL_TRACE_LEVEL & 0x4){                    \
471     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;    \
472     OTL_TRACE_STREAM<<"otl_stream(this=";       \
473     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);    \
474     OTL_TRACE_STREAM<<")::open(buffer_size=";   \
475     OTL_TRACE_STREAM<<arr_size;                 \
476     OTL_TRACE_STREAM<<", sqlstm=";              \
477     OTL_TRACE_STREAM<<sqlstm;                   \
478     OTL_TRACE_STREAM<<", connect=";             \
479     OTL_TRACE_STREAM<<OTL_RCAST(void*,&db);     \
480     OTL_TRACE_STREAM<<", implicit_select=";     \
481     OTL_TRACE_STREAM<<implicit_select;          \
482     if(sqlstm_label){                           \
483       OTL_TRACE_STREAM<<", label=";             \
484       OTL_TRACE_STREAM<<sqlstm_label;           \
485     }                                           \
486     OTL_TRACE_STREAM<<");";                     \
487     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;    \
488   }
489 #endif
490 
491 #if !defined(OTL_TRACE_STREAM_OPEN2)
492 #define OTL_TRACE_STREAM_OPEN2                          \
493   if(OTL_TRACE_LEVEL & 0x4){                            \
494     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;            \
495     OTL_TRACE_STREAM<<"otl_stream(this=";               \
496     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);            \
497     OTL_TRACE_STREAM<<")::open(buffer_size=";           \
498     OTL_TRACE_STREAM<<arr_size;                         \
499     OTL_TRACE_STREAM<<", sqlstm=";                      \
500     OTL_TRACE_STREAM<<sqlstm;                           \
501     OTL_TRACE_STREAM<<", connect=";                     \
502     OTL_TRACE_STREAM<<OTL_RCAST(void*,&db);             \
503     if(ref_cur_placeholder){                            \
504       OTL_TRACE_STREAM<<", ref_cur_placeholder=";       \
505       OTL_TRACE_STREAM<<ref_cur_placeholder;            \
506     }                                                   \
507     if(sqlstm_label){                                   \
508       OTL_TRACE_STREAM<<", label=";                     \
509       OTL_TRACE_STREAM<<sqlstm_label;                   \
510     }                                                   \
511     OTL_TRACE_STREAM<<");";                             \
512     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;            \
513   }
514 #endif
515 
516 #if !defined(OTL_TRACE_DIRECT_EXEC)
517 #define OTL_TRACE_DIRECT_EXEC                             \
518   if(OTL_TRACE_LEVEL & 0x2){                              \
519     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;              \
520     OTL_TRACE_STREAM<<"otl_cursor::direct_exec(connect="; \
521     OTL_TRACE_STREAM<<OTL_RCAST(void*,&connect);          \
522     OTL_TRACE_STREAM<<",sqlstm=\"";                       \
523     OTL_TRACE_STREAM<<sqlstm;                             \
524     OTL_TRACE_STREAM<<"\",exception_enabled=";            \
525     OTL_TRACE_STREAM<<exception_enabled;                  \
526     OTL_TRACE_STREAM<<");";                               \
527     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;              \
528   }
529 #endif
530 
531 #if !defined(OTL_TRACE_SYNTAX_CHECK)
532 #define OTL_TRACE_SYNTAX_CHECK                             \
533   if(OTL_TRACE_LEVEL & 0x2){                               \
534     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;               \
535     OTL_TRACE_STREAM<<"otl_cursor::syntax_check(connect="; \
536     OTL_TRACE_STREAM<<OTL_RCAST(void*,&connect);           \
537     OTL_TRACE_STREAM<<",sqlstm=\"";                        \
538     OTL_TRACE_STREAM<<sqlstm;                              \
539     OTL_TRACE_STREAM<<"\"";                                \
540     OTL_TRACE_STREAM<<");";                                \
541     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;               \
542   }
543 #endif
544 
545 #if !defined(OTL_TRACE_FUNC)
546 #define OTL_TRACE_FUNC(level,class_name,func_name,args) \
547   if(OTL_TRACE_LEVEL & level){                          \
548     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;            \
549     OTL_TRACE_STREAM<<class_name;                       \
550     OTL_TRACE_STREAM<<"(this=";                         \
551     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);            \
552     OTL_TRACE_STREAM<<")::" func_name "(";              \
553     OTL_TRACE_STREAM<<args;                             \
554     OTL_TRACE_STREAM<<");";                             \
555     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;            \
556   }
557 #endif
558 
559 #if !defined(OTL_TRACE_EXCEPTION)
560 #define OTL_TRACE_EXCEPTION(code,msg,stm_text,var_info) \
561   if(OTL_TRACE_LEVEL & 0x20){                           \
562     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;            \
563     OTL_TRACE_STREAM<<"otl_exception, code=";           \
564     OTL_TRACE_STREAM<<code;                             \
565     OTL_TRACE_STREAM<<", msg=";                         \
566     char* c=OTL_RCAST(char*,msg);                       \
567     while(*c && *c!='\n'){                              \
568       OTL_TRACE_STREAM<<*c;                             \
569       ++c;                                              \
570     }                                                   \
571     OTL_TRACE_STREAM<<", stm_text=";                    \
572     OTL_TRACE_STREAM<<stm_text;                         \
573     OTL_TRACE_STREAM<<", var_info=";                    \
574     OTL_TRACE_STREAM<<var_info;                         \
575     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;            \
576   }
577 #endif
578 
579 #if !defined(OTL_TRACE_RLOGON_ORA7) && defined(OTL_ORA7)
580 #define OTL_TRACE_RLOGON_ORA7(level,class_name,func_name,       \
581                               connect_str,auto_commit)          \
582   if(OTL_TRACE_LEVEL & level){                                  \
583     char temp_connect_str[2048];                                \
584     const char* c1=OTL_RCAST(const char*,connect_str);          \
585     char* c2=temp_connect_str;                                  \
586     while(*c1 && *c1!='/'){                                     \
587       *c2=*c1;                                                  \
588       ++c1; ++c2;                                               \
589     }                                                           \
590     if(*c1=='/'){                                               \
591       *c2=*c1;                                                  \
592       ++c1; ++c2;                                               \
593       while(*c1 && *c1!='@'){                                   \
594         *c2='*';                                                \
595         ++c1; ++c2;                                             \
596       }                                                         \
597       if(*c1=='@'){                                             \
598         while(*c1){                                             \
599           *c2=*c1;                                              \
600           ++c1; ++c2;                                           \
601         }                                                       \
602       }                                                         \
603     }                                                           \
604     *c2=0;                                                      \
605     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                    \
606     OTL_TRACE_STREAM<<class_name;                               \
607     OTL_TRACE_STREAM<<"(this=";                                 \
608     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                    \
609     OTL_TRACE_STREAM<<")::" func_name "(";                      \
610     OTL_TRACE_STREAM<<"connect_str=\"";                         \
611     OTL_TRACE_STREAM<<temp_connect_str;                         \
612     OTL_TRACE_STREAM<<"\", auto_commit=";                       \
613     OTL_TRACE_STREAM<<auto_commit;                              \
614     OTL_TRACE_STREAM<<");";                                     \
615     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                    \
616   }
617 #endif
618 
619 #if !defined(OTL_TRACE_RLOGON_ORA8) && defined(OTL_ORA8)
620 #define OTL_TRACE_RLOGON_ORA8(level,class_name,func_name,               \
621                               tnsname,userid,passwd,                    \
622                               auto_commit)                              \
623   if(OTL_TRACE_LEVEL & level){                                          \
624     char temp_connect_str[2048];                                        \
625     OTL_STRCPY_S(temp_connect_str,sizeof(temp_connect_str),userid);     \
626     OTL_STRCAT_S(temp_connect_str,sizeof(temp_connect_str),"/");        \
627     size_t sz=strlen(passwd);                                           \
628     for(size_t i=0;i<sz;++i)                                            \
629       OTL_STRCAT_S(temp_connect_str,sizeof(temp_connect_str),"*");      \
630     size_t tns_sz=strlen(tnsname);                                      \
631     if(tns_sz>0){                                                       \
632       OTL_STRCAT_S(temp_connect_str,sizeof(temp_connect_str),"@");      \
633       OTL_STRCAT_S(temp_connect_str,sizeof(temp_connect_str),tnsname);  \
634     }                                                                   \
635     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                            \
636     OTL_TRACE_STREAM<<class_name<<"(this=";                             \
637     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                            \
638     OTL_TRACE_STREAM<<")::" func_name "(";                              \
639     OTL_TRACE_STREAM<<"connect_str=\"";                                 \
640     OTL_TRACE_STREAM<<temp_connect_str;                                 \
641     OTL_TRACE_STREAM<<"\", auto_commit=";                               \
642     OTL_TRACE_STREAM<<auto_commit <<");";                               \
643     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                            \
644   }
645 #endif
646 
647 #if !defined(OTL_TRACE_RLOGON_ODBC)&&(defined(OTL_ODBC)||defined(OTL_DB2_CLI))
648 #define OTL_TRACE_RLOGON_ODBC(level,class_name,func_name,                       \
649                               tnsname,userid,passwd,                            \
650                               auto_commit)                                      \
651   if(OTL_TRACE_LEVEL & level){                                                  \
652     char temp_connect_str2[2048];                                               \
653     OTL_STRCPY_S(temp_connect_str2,sizeof(temp_connect_str2),userid);           \
654     OTL_STRCAT_S(temp_connect_str2,sizeof(temp_connect_str2),"/");              \
655     size_t sz=strlen(passwd);                                                   \
656     for(size_t i=0;i<sz;++i)                                                    \
657       OTL_STRCAT_S(temp_connect_str2,sizeof(temp_connect_str2),"*");            \
658     size_t tns_sz=strlen(tnsname);                                              \
659     if(tns_sz>0){                                                               \
660       OTL_STRCAT_S(temp_connect_str2,sizeof(temp_connect_str2),"@");            \
661       OTL_STRCAT_S(temp_connect_str2,sizeof(temp_connect_str2),tnsname);        \
662     }                                                                           \
663     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                    \
664     OTL_TRACE_STREAM<<class_name;                                               \
665     OTL_TRACE_STREAM<<"(this=";                                                 \
666     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                                    \
667     OTL_TRACE_STREAM<<")::" func_name "(";                                      \
668     OTL_TRACE_STREAM<<"connect_str=\"";                                         \
669     OTL_TRACE_STREAM<<temp_connect_str2;                                        \
670     OTL_TRACE_STREAM<<"\", auto_commit=";                                       \
671     OTL_TRACE_STREAM<<auto_commit;                                              \
672     OTL_TRACE_STREAM<<");";                                                     \
673     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                    \
674   }
675 #endif
676 
677 #if !defined(OTL_TRACE_RLOGON_ODBC_W)&& \
678     (defined(OTL_ODBC)||defined(OTL_DB2_CLI))
679 #define OTL_TRACE_RLOGON_ODBC_W(level,class_name,func_name,     \
680                               tnsname,userid,passwd,            \
681                               auto_commit)                      \
682   if(OTL_TRACE_LEVEL & level){                                  \
683     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                    \
684     OTL_TRACE_STREAM<<class_name;                               \
685     OTL_TRACE_STREAM<<L"(this=";                                \
686     OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                    \
687     OTL_TRACE_STREAM<<L")::" func_name L"(";                    \
688     OTL_TRACE_STREAM<<L"connect_str=\"";                        \
689     OTL_TRACE_STREAM<<userid<<L"/***@"<<tnsname;                \
690     OTL_TRACE_STREAM<<L"\", auto_commit=";                      \
691     OTL_TRACE_STREAM<<auto_commit;                              \
692     OTL_TRACE_STREAM<<L");";                                    \
693     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                    \
694   }
695 #endif
696 
697 #if !defined(OTL_TRACE_FIRST_FETCH)
698 #if defined(OTL_TRACE_ENABLE_STREAM_LABELS)
699 #define OTL_TRACE_FIRST_FETCH                                                   \
700   if(OTL_TRACE_LEVEL & 0x8){                                                    \
701     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                    \
702     OTL_TRACE_STREAM<<"otl_stream(this=";                                       \
703     OTL_TRACE_STREAM<<this->master_stream_ptr_;                                 \
704     OTL_TRACE_STREAM<<"), ";                                                    \
705     OTL_TRACE_STREAM<<"fetched the first batch of rows, SQL Stm=";              \
706     if(this->stm_label)                                                         \
707       OTL_TRACE_STREAM<<this->stm_label;                                        \
708     else                                                                        \
709       OTL_TRACE_STREAM<<this->stm_text;                                         \
710     OTL_TRACE_STREAM<<", RPC=";                                                 \
711     OTL_TRACE_STREAM<<row_count;                                                \
712     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                    \
713   }
714 #else
715 #define OTL_TRACE_FIRST_FETCH                                                   \
716   if(OTL_TRACE_LEVEL & 0x8){                                                    \
717     OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                    \
718     OTL_TRACE_STREAM<<"otl_stream(this=";                                       \
719     OTL_TRACE_STREAM<<this->master_stream_ptr_;                                 \
720     OTL_TRACE_STREAM<<"), ";                                                    \
721     OTL_TRACE_STREAM<<"fetched the first batch of rows, SQL Stm=";              \
722     OTL_TRACE_STREAM<<this->stm_text;                                           \
723     OTL_TRACE_STREAM<<", RPC=";                                                 \
724     OTL_TRACE_STREAM<<row_count;                                                \
725     OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                    \
726   }
727 #endif
728 #endif
729 
730 #if !defined(OTL_TRACE_NEXT_FETCH)
731 #if defined(OTL_TRACE_ENABLE_STREAM_LABELS)
732 #define OTL_TRACE_NEXT_FETCH                                                    \
733    if(OTL_TRACE_LEVEL & 0x8 && cur_row==0){                                     \
734      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                   \
735      OTL_TRACE_STREAM<<"otl_stream(this=";                                      \
736      OTL_TRACE_STREAM<<this->master_stream_ptr_;                                \
737      OTL_TRACE_STREAM<<"), ";                                                   \
738      OTL_TRACE_STREAM<<"fetched the next batch of rows, SQL Stm=" ;             \
739      if(this->stm_label)                                                        \
740        OTL_TRACE_STREAM<<this->stm_label;                                       \
741      else                                                                       \
742        OTL_TRACE_STREAM<<this->stm_text;                                        \
743      OTL_TRACE_STREAM<<", RPC=";                                                \
744      OTL_TRACE_STREAM<<row_count;                                               \
745      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                   \
746    }
747 #define OTL_TRACE_NEXT_FETCH2                                                   \
748    if(OTL_TRACE_LEVEL & 0x8 && cur_row==1){                                     \
749      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                   \
750      OTL_TRACE_STREAM<<"otl_stream(this=";                                      \
751      OTL_TRACE_STREAM<<this->master_stream_ptr_;                                \
752      OTL_TRACE_STREAM<<"), ";                                                   \
753      OTL_TRACE_STREAM<<"fetched the next batch of rows, SQL Stm=" ;             \
754      if(this->stm_label)                                                        \
755        OTL_TRACE_STREAM<<this->stm_label;                                       \
756      else                                                                       \
757        OTL_TRACE_STREAM<<this->stm_text;                                        \
758      OTL_TRACE_STREAM<<", RPC=";                                                \
759      OTL_TRACE_STREAM<<row_count;                                               \
760      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                   \
761    }
762 #else
763 #define OTL_TRACE_NEXT_FETCH                                                    \
764    if(OTL_TRACE_LEVEL & 0x8 && cur_row==0){                                     \
765      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                   \
766      OTL_TRACE_STREAM<<"otl_stream(this=";                                      \
767      OTL_TRACE_STREAM<<this->master_stream_ptr_;                                \
768      OTL_TRACE_STREAM<<"), ";                                                   \
769      OTL_TRACE_STREAM<<"fetched the next batch of rows, SQL Stm=" ;             \
770      OTL_TRACE_STREAM<<this->stm_text;                                          \
771      OTL_TRACE_STREAM<<", RPC=";                                                \
772      OTL_TRACE_STREAM<<row_count;                                               \
773      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                   \
774    }
775 #define OTL_TRACE_NEXT_FETCH2                                                   \
776    if(OTL_TRACE_LEVEL & 0x8 && cur_row==1){                                     \
777      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                                   \
778      OTL_TRACE_STREAM<<"otl_stream(this=";                                      \
779      OTL_TRACE_STREAM<<this->master_stream_ptr_;                                \
780      OTL_TRACE_STREAM<<"), ";                                                   \
781      OTL_TRACE_STREAM<<"fetched the next batch of rows, SQL Stm=" ;             \
782      OTL_TRACE_STREAM<<this->stm_text;                                          \
783      OTL_TRACE_STREAM<<", RPC=";                                                \
784      OTL_TRACE_STREAM<<row_count;                                               \
785      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                                   \
786    }
787 #endif
788 #endif
789 
790 #if !defined(OTL_TRACE_STREAM_EXECUTION)
791 #if defined(OTL_TRACE_ENABLE_STREAM_LABELS)
792 #define OTL_TRACE_STREAM_EXECUTION                              \
793    if(OTL_TRACE_LEVEL & 0x8){                                   \
794      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                   \
795      OTL_TRACE_STREAM<<"otl_stream(this=";                      \
796      OTL_TRACE_STREAM<<override->get_master_stream_ptr();       \
797      OTL_TRACE_STREAM<<"), executing SQL Stm=";                 \
798      if(this->stm_label)                                        \
799        OTL_TRACE_STREAM<<this->stm_label;                       \
800      else                                                       \
801        OTL_TRACE_STREAM<<this->stm_text;                        \
802      OTL_TRACE_STREAM<<", buffer size=";                        \
803      OTL_TRACE_STREAM<<this->array_size;                        \
804      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                   \
805    }
806 #else
807 #define OTL_TRACE_STREAM_EXECUTION                              \
808    if(OTL_TRACE_LEVEL & 0x8){                                   \
809      OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                   \
810      OTL_TRACE_STREAM<<"otl_stream(this=";                      \
811      OTL_TRACE_STREAM<<override->get_master_stream_ptr();       \
812      OTL_TRACE_STREAM<<"), executing SQL Stm=";                 \
813      OTL_TRACE_STREAM<<this->stm_text;                          \
814      OTL_TRACE_STREAM<<", buffer size=";                        \
815      OTL_TRACE_STREAM<<this->array_size;                        \
816      OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                   \
817    }
818 #endif
819 #endif
820 
821 #if !defined(OTL_TRACE_STREAM_EXECUTION2)
822 #if defined(OTL_TRACE_ENABLE_STREAM_LABELS)
823 #define OTL_TRACE_STREAM_EXECUTION2                             \
824     if(OTL_TRACE_LEVEL & 0x8){                                  \
825       OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                  \
826       OTL_TRACE_STREAM<<"otl_stream(this=";                     \
827       OTL_TRACE_STREAM<<this->master_stream_ptr_;               \
828       OTL_TRACE_STREAM<<"), executing SQL Stm=";                \
829      if(this->stm_label)                                        \
830        OTL_TRACE_STREAM<<this->stm_label;                       \
831      else                                                       \
832        OTL_TRACE_STREAM<<this->stm_text;                        \
833       OTL_TRACE_STREAM<<", current batch size=";                \
834       OTL_TRACE_STREAM<<(cur_y+1);                              \
835       OTL_TRACE_STREAM<<", row offset=";                        \
836       OTL_TRACE_STREAM<<rowoff;                                 \
837       OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                  \
838     }
839 #else
840 #define OTL_TRACE_STREAM_EXECUTION2                             \
841     if(OTL_TRACE_LEVEL & 0x8){                                  \
842       OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                  \
843       OTL_TRACE_STREAM<<"otl_stream(this=";                     \
844       OTL_TRACE_STREAM<<this->master_stream_ptr_;               \
845       OTL_TRACE_STREAM<<"), executing SQL Stm=";                \
846       OTL_TRACE_STREAM<<this->stm_text;                         \
847       OTL_TRACE_STREAM<<", current batch size=";                \
848       OTL_TRACE_STREAM<<(cur_y+1);                              \
849       OTL_TRACE_STREAM<<", row offset=";                        \
850       OTL_TRACE_STREAM<<rowoff;                                 \
851       OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                  \
852     }
853 #endif
854 #endif
855 
856 #if !defined(OTL_TRACE_READ)
857 
858 #define OTL_TRACE_READ(val,function,type)                       \
859   if(OTL_TRACE_LEVEL & 0x10){                                   \
860     otl_var_desc* temp_vdesc=describe_next_in_var();            \
861     if(temp_vdesc){                                             \
862       OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                  \
863       OTL_TRACE_STREAM<<"otl_stream(this=";                     \
864       OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                  \
865       OTL_TRACE_STREAM<<")::" function "(" type ": ";           \
866       OTL_TRACE_STREAM<<"ftype=";                               \
867       OTL_TRACE_STREAM<<temp_vdesc->ftype;                      \
868       OTL_TRACE_STREAM<<", placeholder=";                       \
869       OTL_TRACE_STREAM<<temp_vdesc->name;                       \
870       OTL_TRACE_STREAM<<", value=";                             \
871       OTL_TRACE_STREAM<<val;                                    \
872       OTL_TRACE_STREAM <<");";                                  \
873       OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                  \
874     }else{                                                      \
875       OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                  \
876       OTL_TRACE_STREAM<<"loading superfluous input variable";   \
877       OTL_TRACE_STREAM<<"::" function "(" type ": ";            \
878       OTL_TRACE_STREAM<<", value=";                             \
879       OTL_TRACE_STREAM<<val;                                    \
880       OTL_TRACE_STREAM<<");";                                   \
881       OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                  \
882     }                                                           \
883   }
884 #endif
885 
886 #if !defined(OTL_TRACE_WRITE)
887 #define OTL_TRACE_WRITE(val,function,type)                      \
888    if(OTL_TRACE_LEVEL & 0x10){                                  \
889      otl_var_desc* temp_vdesc=describe_next_out_var();          \
890      if (temp_vdesc){                                           \
891        OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                 \
892        OTL_TRACE_STREAM<<"otl_stream(this=";                    \
893        OTL_TRACE_STREAM<<OTL_RCAST(void*,this);                 \
894        OTL_TRACE_STREAM<<")::" function "(" type " : ";         \
895        OTL_TRACE_STREAM<<"ftype=";                              \
896        OTL_TRACE_STREAM<<temp_vdesc->ftype;                     \
897        OTL_TRACE_STREAM<<", placeholder=";                      \
898        OTL_TRACE_STREAM<<temp_vdesc->name;                      \
899        OTL_TRACE_STREAM<<", value=";                            \
900        if(this->is_null())                                      \
901          OTL_TRACE_STREAM<<"NULL";                              \
902        else                                                     \
903          OTL_TRACE_STREAM<<val;                                 \
904        OTL_TRACE_STREAM<<");";                                  \
905        OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                 \
906      }else{                                                     \
907        OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;                 \
908        OTL_TRACE_STREAM<<"writing superfluous output variable"; \
909        OTL_TRACE_STREAM<<"::" function "(" type " : ";          \
910        OTL_TRACE_STREAM<<", value=";                            \
911        if(this->is_null())                                      \
912          OTL_TRACE_STREAM<<"NULL";                              \
913        else                                                     \
914          OTL_TRACE_STREAM<<val;                                 \
915        OTL_TRACE_STREAM<<");";                                  \
916        OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;                 \
917      }                                                          \
918    }
919 #endif
920 
921 #else
922 
923 #define OTL_TRACE_LINE_PREFIX
924 #define OTL_TRACE_LINE_SUFFIX
925 #define OTL_TRACE_DIRECT_EXEC
926 #define OTL_TRACE_SYNTAX_CHECK
927 #define OTL_TRACE_FUNC(level,class_name,func_name,args)
928 #define OTL_TRACE_EXCEPTION(code,msg,stm_text,var_info)
929 #define OTL_TRACE_RLOGON_ORA7(level,class_name,func_name, \
930                               connect_str,auto_commit)
931 #define OTL_TRACE_RLOGON_ORA8(level,class_name,func_name,       \
932                               tnsname,userid,passwd,            \
933                               auto_commit)
934 #define OTL_TRACE_RLOGON_ODBC(level,class_name,func_name,       \
935                               tnsname,userid,passwd,            \
936                               auto_commit)
937 #define OTL_TRACE_STREAM_OPEN
938 #define OTL_TRACE_STREAM_OPEN2
939 #define OTL_TRACE_FIRST_FETCH
940 #define OTL_TRACE_NEXT_FETCH
941 #define OTL_TRACE_NEXT_FETCH2
942 #define OTL_TRACE_STREAM_EXECUTION
943 #define OTL_TRACE_STREAM_EXECUTION2
944 #define OTL_TRACE_WRITE(val,function,type)
945 #define OTL_TRACE_READ(val,function,type)
946 #define OTL_TRACE_RLOGON_ODBC_W(level,class_name,func_name, \
947                               tnsname,userid,passwd,        \
948                               auto_commit)
949 #endif
950 
951 #if defined(OTL_DB2_CLI)
952 #define OTL_ODBC
953 #endif
954 
955 #if defined(OTL_UNICODE)
956 
957 #if !defined(OTL_UNICODE_CHAR_TYPE)
958 #define OTL_UNICODE_CHAR_TYPE wchar_t
959 #endif
960 
961 #if !defined(OTL_UNICODE_CHAR_TYPE_TRACE_NAME)
962 #define OTL_UNICODE_CHAR_TYPE_TRACE_NAME "wchar_t"
963 #endif
964 
965 #endif
966 
967 #if defined(OTL_UNICODE)&& \
968     (defined(OTL_ORA8I)|| \
969      defined(OTL_ORA9I)|| \
970      defined(OTL_ORA10G)||defined(OTL_ORA10G_R2))
971 #define OTL_ORA_UNICODE
972 #endif
973 
974 #if defined(OTL_UNICODE)
975 
976 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I)||defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)) && defined(OTL_ODBC)
977 #error OTL_UNICODE is not supported when both OTL_ORAxx and OTL_ODBC/OTL_DB2_CLI are defined
978 #endif
979 
980 #if defined(OTL_ORA8I)||defined(OTL_ORA9I)||defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)
981 
982 #define OTL_CHAR unsigned short
983 #define OTL_UNICODE_CHAR OTL_CHAR
984 #define OTL_WCHAR unsigned long
985 
986 #if defined(OTL_ORA8I)
987 #define OTL_UNICODE_ID OCI_UCS2ID
988 #endif
989 
990 #if defined(OTL_ORA9I)
991 #define OTL_UNICODE_ID OCI_UTF16ID
992 #endif
993 
994 #elif defined(OTL_ODBC)
995 
996 #define OTL_CHAR unsigned short
997 #define OTL_UNICODE_CHAR OTL_CHAR
998 #define OTL_WCHAR OTL_CHAR
999 
1000 #endif
1001 
1002 #else
1003 
1004 #define OTL_CHAR unsigned char
1005 
1006 #endif
1007 
1008 
1009 #if defined(OTL_ORA7) || defined(OTL_ORA8)
1010 #define OTL_PL_TAB
1011 #endif
1012 
1013 const int otl_odbc_adapter=1;
1014 const int otl_ora7_adapter=2;
1015 const int otl_ora8_adapter=3;
1016 
1017 const int otl_inout_binding=1;
1018 const int otl_select_binding=2;
1019 
1020 const int otl_unsupported_type=-10000;
1021 
1022 #if defined(OTL_ANSI_CPP)
1023 
1024 #define OTL_SCAST(_t,_e) static_cast<_t >(_e)
1025 #define OTL_RCAST(_t,_e) reinterpret_cast<_t >(_e)
1026 #define OTL_DCAST(_t,_e) dynamic_cast<_t >(_e)
1027 #define OTL_CCAST(_t,_e) const_cast<_t >(_e)
1028 
1029 #define OTL_CONST_EXCEPTION const
1030 
1031 #if defined(OTL_FUNC_THROW_SPEC_ON)
1032 #define OTL_THROWS_OTL_EXCEPTION throw(otl_exception)
1033 #define OTL_NO_THROW throw()
1034 #else
1035 #define OTL_THROWS_OTL_EXCEPTION
1036 #define OTL_NO_THROW
1037 #endif
1038 
1039 #define OTL_TYPE_NAME typename
1040 
1041 #include <new>
1042 
1043 #else
1044 
1045 #define OTL_SCAST(_t,_e) ((_t)(_e))
1046 #define OTL_RCAST(_t,_e) ((_t)(_e))
1047 #define OTL_DCAST(_t,_e) ((_t)(_e))
1048 #define OTL_CCAST(_t,_e) ((_t)(_e))
1049 #define OTL_CONST_EXCEPTION
1050 #define OTL_THROWS_OTL_EXCEPTION
1051 #define OTL_NO_THROW
1052 #define OTL_TYPE_NAME class
1053 
1054 #endif
1055 
1056 #define OTL_PCONV(_to,_from,_val) \
1057 OTL_SCAST(_to,*OTL_RCAST(_from*,OTL_CCAST(void*,_val)))
1058 
1059 #if defined(OTL_ACE)
1060 
1061 #include <ace/SString.h>
1062 #include <ace/Array.h>
1063 #include <ace/Null_Mutex.h>
1064 #include <ace/Functor.h>
1065 #include <ace/RB_Tree.h>
1066 
1067 #define OTL_USER_DEFINED_STRING_CLASS_ON
1068 #define USER_DEFINED_STRING_CLASS ACE_TString
1069 #define OTL_VALUE_TEMPLATE_ON
1070 
1071 const int otl_tmpl_vector_default_size=16;
1072 
1073 template<OTL_TYPE_NAME T>
1074 class otl_tmpl_vector: public ACE_Array<T>{
1075 public:
1076 
1077  otl_tmpl_vector(const int init_size=otl_tmpl_vector_default_size)
1078   : ACE_Array<T>(init_size==0?otl_tmpl_vector_default_size:init_size)
1079  {
1080    length_=0;
1081  }
1082 
~otl_tmpl_vector()1083  ~otl_tmpl_vector(){}
1084 
capacity(void)1085  int capacity(void) const
1086  {
1087   return this->max_size();
1088  }
1089 
size(void)1090  int size(void) const
1091  {
1092   return length_;
1093  }
1094 
clear(void)1095  void clear(void)
1096  {
1097   length_=0;
1098  }
1099 
1100  void resize(const int new_size, const T& t=T())
1101  {
1102   ACE_Array<T>::size(new_size);
1103   if(new_size>length_){
1104    for(int i=length_;i<new_size;++i)
1105     (*this)[i]=t;
1106   }
1107   length_=new_size;
1108  }
1109 
push_back(const T & elem)1110  void push_back(const T& elem)
1111  {
1112    int curr_max_size=OTL_SCAST(int,this->max_size());
1113    if(length_==curr_max_size)
1114      ACE_Array<T>::size(curr_max_size*2);
1115    ++length_;
1116    (*this)[length_-1]=elem;
1117  }
1118 
pop_back(void)1119  void pop_back(void)
1120  {
1121   if(length_>0)
1122    --length_;
1123  }
1124 
1125 private:
1126 
1127  int length_;
1128 
1129 };
1130 
1131 #endif
1132 
1133 #if defined(OTL_UNCAUGHT_EXCEPTION_ON)
1134 #include <exception>
1135 #if !defined(OTL_STLPORT)
otl_uncaught_exception()1136 inline bool otl_uncaught_exception()
1137 {
1138   return std::uncaught_exception();
1139 }
1140 #else
otl_uncaught_exception()1141 inline bool otl_uncaught_exception()
1142 {
1143   return __std_alias::uncaught_exception();
1144 }
1145 #endif
1146 #else
otl_uncaught_exception()1147 inline bool otl_uncaught_exception()
1148 {
1149   return false;
1150 }
1151 #endif
1152 
1153 #if defined(OTL_STLPORT)
1154 #if defined(__STLPORT_STD)
1155 #define OTL_STLPORT_NAMESPACE __STLPORT_STD
1156 #else
1157 #if defined(_STLP_USE_OWN_NAMESPACE)
1158 #define OTL_STLPORT_NAMESPACE _STL
1159 #else
1160 #define OTL_STLPORT_NAMESPACE std
1161 #endif
1162 #endif
1163 
1164 #define OTL_STL
1165 
1166 #endif
1167 
1168 
1169 #if defined(OTL_VALUE_TEMPLATE_ON) && !defined(OTL_STL) && !defined(OTL_ACE)
1170 #define STD_NAMESPACE_PREFIX
1171 #if (defined(_MSC_VER)&&(_MSC_VER>=1300))||defined(OTL_ANSI_CPP)
1172 #include <iostream>
1173 using namespace std;
1174 #else
1175 #include <iostream.h>
1176 #endif
1177 #endif
1178 
1179 #if defined(OTL_USER_DEFINED_STRING_CLASS_ON)
1180 
1181 #if defined(OTL_STL)
1182 #error OTL_STL cannot be used in combination with OTL_USER_DEFINED_STRING_CLASS_ON
1183 #endif
1184 
1185 #if defined(USER_DEFINED_STRING_CLASS)
1186 #define OTL_STRING_CONTAINER USER_DEFINED_STRING_CLASS
1187 #define STD_NAMESPACE_PREFIX
1188 #else
1189 #error USER_DEFINED_STRING_CLASS macro needs to be defined before including otlv4.h
1190 #endif
1191 
1192 #endif
1193 
1194 
1195 #if defined(OTL_STL)
1196 #if defined(_MSC_VER)
1197 #if (_MSC_VER >= 1200)
1198 #pragma warning (disable:4786)
1199 #pragma warning (disable:4290)
1200 #pragma warning (disable:4996)
1201 #endif
1202 #endif
1203 
1204 #if defined(OTL_STL_NOSTD_NAMESPACE)
1205 #ifndef OTL_STRING_CONTAINER
1206 #define OTL_STRING_CONTAINER string
1207 #endif
1208 #define STD_NAMESPACE_PREFIX
1209 #else
1210 #ifndef OTL_STRING_CONTAINER
1211 
1212 #if defined(OTL_STLPORT)
1213 #define OTL_STRING_CONTAINER OTL_STLPORT_NAMESPACE ::string
1214 #else
1215 #define OTL_STRING_CONTAINER std::string
1216 #endif
1217 
1218 #endif
1219 
1220 #if defined(OTL_STLPORT)
1221 #define STD_NAMESPACE_PREFIX OTL_STLPORT_NAMESPACE ::
1222 #else
1223 #define STD_NAMESPACE_PREFIX std::
1224 #endif
1225 
1226 
1227 #endif
1228 
1229 #include <string>
1230 #include <iterator>
1231 #include <vector>
1232 
1233 #ifndef OTL_STL_NOSTD_NAMESPACE
1234 #include <iostream>
1235 #else
1236 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
1237 #include <iostream>
1238 using namespace std;
1239 #else
1240 #include <iostream.h>
1241 #endif
1242 #endif
1243 
1244 #endif
1245 
1246 //======================= END OF CONFIGURATION ==============================
1247 
1248 
1249 // ====== COMMON NON-TEMPLATE OBJECTS: CONSTANTS, CLASSES, ETC. ===========
1250 
1251 #if defined(OTL_ORA8)
1252 const int otl_var_list_size=1024;
1253 #else
1254 const int otl_var_list_size=512;
1255 #endif
1256 
1257 const int otl_error_code_0=32000;
1258 #define otl_error_msg_0 "Incompatible data types in stream operation"
1259 
1260 const int otl_error_code_1=32004;
1261 #define otl_error_msg_1 "No input variables have been defined in SQL statement"
1262 
1263 const int otl_error_code_2=32003;
1264 #define otl_error_msg_2 "Not all input variables have been initialized"
1265 
1266 const int otl_error_code_3=32001;
1267 #define otl_error_msg_3 "Row must be full for flushing output stream"
1268 
1269 const int otl_error_code_4=32005;
1270 #define otl_error_msg_4 "Input string value is too large to fit into the buffer"
1271 
1272 const int otl_error_code_5=32006;
1273 #define otl_error_msg_5 "Input otl_long_string is too large to fit into the buffer"
1274 
1275 const int otl_error_code_6=32007;
1276 #define otl_error_msg_6 "PL/SQL table size is too large (>32767)"
1277 
1278 const int otl_error_code_7=32008;
1279 #define otl_error_msg_7 "Writing CLOB/BLOB in stream mode: actual size is greater than specified"
1280 
1281 const int otl_error_code_8=32009;
1282 #define otl_error_msg_8 "Closing CLOB/BLOB in stream mode: actual size is not equal to specified size"
1283 
1284 const int otl_error_code_9=32010;
1285 #define otl_error_msg_9 "CLOB/BLOB stream is not open for writing"
1286 
1287 const int otl_error_code_10=32011;
1288 #define otl_error_msg_10 "CLOB/BLOB stream is not open for reading"
1289 
1290 const int otl_error_code_11=32012;
1291 #define otl_error_msg_11 "First session must be started with session_begin()"
1292 
1293 const int otl_error_code_12=32013;
1294 #define otl_error_msg_12 "Invalid bind variable declaration"
1295 
1296 const int otl_error_code_13=32014;
1297 #define otl_error_msg_13 "No stored procedure was found"
1298 
1299 const int otl_error_code_14=32015;
1300 #define otl_error_msg_14 "Unsupported data type: "
1301 
1302 const int otl_error_code_15=32016;
1303 #define otl_error_msg_15 "Unsupported procedure type"
1304 
1305 const int otl_error_code_16=32017;
1306 #define otl_error_msg_16 "Stream buffer size can't be > 1 in this case"
1307 
1308 const int otl_error_code_17=32018;
1309 #define otl_error_msg_17                                        \
1310 "ODBC / DB2 CLI function name is not recognized. "              \
1311 "It should be one of the following: SQLTables, SQLColumns, "    \
1312 "SQLProcedures, SQLColumnPrivileges, SQLTablePrivileges, "      \
1313 "SQLPrimaryKeys, SQLProcedureColumns, SQLForeignKeys"
1314 
1315 const int otl_error_code_18=32019;
1316 #define otl_error_msg_18                                \
1317 "otl_stream::operator>>() should have been called "     \
1318 "before otl_stream::operator int()"
1319 
1320 const int otl_error_code_19=32020;
1321 #define otl_error_msg_19                                \
1322 "otl_stream_read_iterator: otl_stream is not open"
1323 
1324 const int otl_error_code_20=32021;
1325 #define otl_error_msg_20                                \
1326 "otl_stream_read_iterator: PL/SQL table and 'refcur' "  \
1327 "parameters are not supported"
1328 
1329 const int otl_error_code_21=32022;
1330 #define otl_error_msg_21                                        \
1331 "otl_stream_read_iterator: otl_stream cannot be described"
1332 
1333 const int otl_error_code_22=32023;
1334 #define otl_error_msg_22                                \
1335 "otl_stream_read_iterator: position is out of range"
1336 
1337 const int otl_error_code_23=32024;
1338 #define otl_error_msg_23                        \
1339 "otl_stream_read_iterator: incompatible types in get()"
1340 
1341 const int otl_error_code_24=32025;
1342 #define otl_error_msg_24 \
1343 "otl_stream::operator int() is not supported in the LOB stream mode"
1344 
1345 const int otl_error_code_25=32026;
1346 #define otl_error_msg_25                                                     \
1347 "otl_stream_read_iterator: get(otl_lob_stream*&) function "                  \
1348 "can only be used if otl_stream::set_lob_stream_mode(true) had been called " \
1349 "before the iterator was attached to the stream"
1350 
1351 const int otl_error_code_26=32027;
1352 #define otl_error_msg_26                                \
1353 "otl_stream_read_iterator: variable name is not recognized "
1354 
1355 const int otl_error_code_27=32028;
1356 #define otl_error_msg_27 "Unsupported column data type"
1357 
1358 const int otl_error_code_28=32029;
1359 #define otl_error_msg_28 \
1360 "RAW value cannot be read with otl_lob_stream, use otl_long_string instead"
1361 
1362 const int otl_error_code_29=32030;
1363 #define otl_error_msg_29 \
1364 "otl_stream is already open"
1365 
1366 const int otl_error_code_30=32031;
1367 #define otl_error_msg_30 \
1368 "otl_connect is already connected"
1369 
1370 const int otl_error_code_31=32032;
1371 #define otl_error_msg_31 \
1372 "SELECT otl_stream buffer size for TimesTen should be in [0..128] range"
1373 
1374 const int otl_error_code_32=32033;
1375 #define otl_error_msg_32 \
1376 "otl_connect object needs to be connected to DB before using otl_subscriber"
1377 
1378 const int otl_error_code_33=32034;
1379 #define otl_error_msg_33 \
1380 "otl_stream buffer size should be 1 when refcur or plsql table is used"
1381 
1382 const int otl_error_code_34=32035;
1383 #define otl_error_msg_34 "END-OF-ROW check failed"
1384 
1385 const int otl_oracle_date_size=7;
1386 
1387 const int otl_explicit_select=0;
1388 const int otl_implicit_select=1;
1389 
1390 const int otl_input_param=0;
1391 const int otl_output_param=1;
1392 const int otl_inout_param=2;
1393 
1394 const unsigned int otl_all_num2str=1;
1395 const unsigned int otl_all_date2str=2;
1396 
1397 const int otl_num_str_size=60;
1398 const int otl_date_str_size=60;
1399 
1400 class otl_select_struct_override{
1401 public:
1402 
otl_select_struct_override()1403   otl_select_struct_override():
1404     col_ndx(new short int[otl_var_list_size]),
1405     col_type(new short int[otl_var_list_size]),
1406     col_size(new int[otl_var_list_size]),
1407     len(0),
1408     all_mask(0),
1409     lob_stream_mode(false),
1410     container_size_(otl_var_list_size),
1411     master_stream_ptr_(0)
1412   {
1413   }
1414 
~otl_select_struct_override()1415   ~otl_select_struct_override()
1416   {
1417     delete[] col_ndx;
1418     delete[] col_type;
1419     delete[] col_size;
1420   }
1421 
set_master_stream_ptr(void * stream_ptr)1422   void set_master_stream_ptr(void* stream_ptr)
1423   {
1424     master_stream_ptr_=stream_ptr;
1425   }
1426 
get_master_stream_ptr()1427   void* get_master_stream_ptr(){return master_stream_ptr_;}
1428 
reset(void)1429   void reset(void)
1430   {
1431     len=0;
1432     all_mask=0;
1433     lob_stream_mode=false;
1434   }
1435 
1436   void add_override(const int andx, const int atype, const int asize=0)
1437   {
1438     if(len==otl_var_list_size){
1439       int temp_container_size=container_size_;
1440       container_size_*=2;
1441       short int* temp_col_ndx=new short int[container_size_];
1442       short int* temp_col_type=new short int[container_size_];
1443       int* temp_col_size=new int[container_size_];
1444       memcpy(temp_col_ndx,col_ndx,sizeof(short int)*temp_container_size);
1445       memcpy(temp_col_type,col_type,sizeof(short int)*temp_container_size);
1446       memcpy(temp_col_size,col_size,sizeof(int)*temp_container_size);
1447       delete[] col_ndx;
1448       delete[] col_type;
1449       delete[] col_size;
1450       col_ndx=temp_col_ndx;
1451       col_type=temp_col_type;
1452       col_size=temp_col_size;
1453     }
1454     ++len;
1455     col_ndx[len-1]=OTL_SCAST(short,andx);
1456     col_type[len-1]=OTL_SCAST(short,atype);
1457     col_size[len-1]=asize;
1458   }
1459 
find(const int ndx)1460   int find(const int ndx) const
1461   {
1462     int i;
1463     for(i=0;i<len;++i)
1464       if(ndx==col_ndx[i])
1465         return i;
1466     return -1;
1467   }
1468 
1469   void set_all_column_types(const unsigned int amask=0)
1470   {
1471     all_mask=amask;
1472   }
1473 
getLen(void)1474   int getLen(void) const
1475   {
1476     return len;
1477   }
1478 
get_all_mask()1479   unsigned int get_all_mask() const
1480   {
1481     return all_mask;
1482   }
1483 
get_col_type(int ndx)1484   short int get_col_type(int ndx) const
1485   {
1486     return col_type[ndx];
1487   }
1488 
get_col_size(int ndx)1489   int get_col_size(int ndx) const
1490   {
1491     return col_size[ndx];
1492   }
1493 
setLen(const int alen)1494   void setLen(const int alen)
1495   {
1496     len=alen;
1497   }
1498 
get_lob_stream_mode()1499   bool get_lob_stream_mode() const
1500   {
1501     return lob_stream_mode;
1502   }
1503 
set_lob_stream_mode(const bool alobs_tream_mode)1504   void set_lob_stream_mode(const bool alobs_tream_mode)
1505   {
1506     lob_stream_mode=alobs_tream_mode;
1507   }
1508 
1509 private:
1510 
1511   short int* col_ndx;
1512   short int* col_type;
1513   int* col_size;
1514   int len;
1515 
1516   unsigned int all_mask;
1517   bool lob_stream_mode;
1518 
1519   int container_size_;
1520   void* master_stream_ptr_;
1521 
1522 // this class is not meant to be copied: copy constructor and
1523 // operator= are declared private
1524 
otl_select_struct_override(const otl_select_struct_override &)1525   otl_select_struct_override(const otl_select_struct_override&):
1526     col_ndx(0),
1527     col_type(0),
1528     col_size(0),
1529     len(0),
1530     all_mask(0),
1531     lob_stream_mode(false),
1532     container_size_(0),
1533     master_stream_ptr_(0)
1534   {
1535   }
1536 
1537   otl_select_struct_override& operator=(const otl_select_struct_override&)
1538   {
1539     return *this;
1540   }
1541 
1542 };
1543 
otl_decimal_degree(unsigned int num)1544 inline int otl_decimal_degree(unsigned int num)
1545 {
1546   int n=0;
1547   while(num!=0){
1548     ++n;
1549     num/=10;
1550   }
1551   return n;
1552 }
1553 
otl_isspace(char c)1554 inline bool otl_isspace(char c)
1555 {
1556   return c==' '||c=='\t'||c=='\n'||
1557          c=='\r'||c=='\f'||c=='\v';
1558 }
1559 
otl_to_upper(char c)1560 inline char otl_to_upper(char c)
1561 {
1562  return OTL_SCAST(char,toupper(c));
1563 }
1564 
otl_str_case_insensitive_equal(const char * s1,const char * s2)1565 inline bool otl_str_case_insensitive_equal(const char* s1, const char* s2)
1566 {
1567   while(*s1 && *s2){
1568     if(otl_to_upper(*s1)!=otl_to_upper(*s2))
1569       return false;
1570     ++s1;
1571     ++s2;
1572   }
1573   if(*s1==0 && *s2==0)
1574     return true;
1575   else
1576     return false;
1577 }
1578 
otl_to_fraction(unsigned int fraction,int frac_prec)1579 inline unsigned int otl_to_fraction
1580 (unsigned int fraction,int frac_prec)
1581 {
1582   if(fraction==0||frac_prec==0)return fraction;
1583   int fraction_degree=otl_decimal_degree(fraction);
1584   if(fraction_degree>frac_prec){
1585     // in case if the actual fraction value is beyond the "fraction
1586     // precision" range, truncate the value
1587     int excess_decimal_digits=fraction_degree-frac_prec;
1588     for(int iter=1;iter<=excess_decimal_digits;++iter)
1589       fraction/=10;
1590   }
1591   int degree_diff=9-frac_prec;
1592   for(int i=0;i<degree_diff;++i)
1593     fraction*=10;
1594   return fraction;
1595 }
1596 
otl_from_fraction(unsigned int fraction,int frac_prec)1597 inline unsigned int otl_from_fraction
1598 (unsigned int fraction,int frac_prec)
1599 {
1600   if(fraction==0||frac_prec==0)return fraction;
1601   int degree_diff=9-frac_prec;
1602   for(int i=0;i<degree_diff;++i)
1603     fraction/=10;
1604   return fraction;
1605 }
1606 
1607 #define OTL_NO_STM_TEXT "#No Stm Text available#"
1608 
1609 class otl_datetime{
1610 public:
1611 
1612   int year;
1613   int month;
1614   int day;
1615   int hour;
1616   int minute;
1617   int second;
1618   unsigned long fraction;
1619   int frac_precision;
1620 
1621 #if defined(OTL_ORA_TIMESTAMP) || defined(OTL_ODBC_TIME_ZONE)
1622   short int tz_hour;
1623   short int tz_minute;
1624 #endif
1625 
otl_datetime()1626   otl_datetime():
1627     year(1900),
1628     month(1),
1629     day(1),
1630     hour(0),
1631     minute(0),
1632     second(0),
1633     fraction(0),
1634     frac_precision(0)
1635 #if defined(OTL_ORA_TIMESTAMP) || defined(OTL_ODBC_TIME_ZONE)
1636     ,tz_hour(0),
1637     tz_minute(0)
1638 #endif
1639  {
1640  }
1641 
1642  otl_datetime
1643  (const int ayear,
1644   const int amonth,
1645   const int aday,
1646   const int ahour,
1647   const int aminute,
1648   const int asecond,
1649   const unsigned long afraction=0,
1650   const int afrac_precision=0
1651 #if defined(OTL_ORA_TIMESTAMP)||defined(OTL_ODBC_TIME_ZONE)
1652   ,
1653   const short int atz_hour=0,
1654   const short int atz_minute=0
1655 #endif
1656    ):
year(ayear)1657    year(ayear),
1658    month(amonth),
1659    day(aday),
1660    hour(ahour),
1661    minute(aminute),
1662    second(asecond),
1663    fraction(afraction),
1664    frac_precision(afrac_precision)
1665 #if defined(OTL_ORA_TIMESTAMP)||defined(OTL_ODBC_TIME_ZONE)
1666    ,tz_hour(atz_hour),
1667    tz_minute(atz_minute)
1668 #endif
1669  {
1670  }
1671 
otl_datetime(const otl_datetime & dt)1672   otl_datetime(const otl_datetime& dt):
1673     year(dt.year),
1674     month(dt.month),
1675     day(dt.day),
1676     hour(dt.hour),
1677     minute(dt.minute),
1678     second(dt.second),
1679     fraction(dt.fraction),
1680     frac_precision(dt.frac_precision)
1681 #if defined(OTL_ORA_TIMESTAMP)||defined(OTL_ODBC_TIME_ZONE)
1682     ,tz_hour(dt.tz_hour),
1683     tz_minute(dt.tz_minute)
1684 #endif
1685  {
1686  }
1687 
~otl_datetime()1688  ~otl_datetime(){}
1689 
1690  otl_datetime& operator=(const otl_datetime& dt)
1691  {
1692    copy(dt);
1693    return *this;
1694  }
1695 
1696 private:
1697 
copy(const otl_datetime & dt)1698   void copy(const otl_datetime& dt)
1699   {
1700     year=dt.year;
1701     month=dt.month;
1702     day=dt.day;
1703     hour=dt.hour;
1704     minute=dt.minute;
1705     second=dt.second;
1706     fraction=dt.fraction;
1707     frac_precision=dt.frac_precision;
1708 #if defined(OTL_ORA_TIMESTAMP)||defined(OTL_ODBC_TIME_ZONE)
1709     tz_hour=dt.tz_hour;
1710     tz_minute=dt.tz_minute;
1711 #endif
1712   }
1713 
1714 };
1715 
1716 struct otl_oracle_date{
1717 
1718  unsigned char century;
1719  unsigned char year;
1720  unsigned char month;
1721  unsigned char day;
1722  unsigned char hour;
1723  unsigned char minute;
1724  unsigned char second;
1725 
otl_oracle_dateotl_oracle_date1726   otl_oracle_date():
1727     century(0),
1728     year(0),
1729     month(0),
1730     day(0),
1731     hour(0),
1732     minute(0),
1733     second(0)
1734   {
1735   }
1736 
~otl_oracle_dateotl_oracle_date1737  ~otl_oracle_date(){}
1738 
1739 };
1740 
convert_date(otl_datetime & t,const otl_oracle_date & s)1741 inline void convert_date(otl_datetime& t,const otl_oracle_date& s)
1742 {
1743  t.year=(OTL_SCAST(int, s.century-100)*100+(OTL_SCAST(int, s.year-100)));
1744  t.month=s.month;
1745  t.day=s.day;
1746  t.hour=s.hour-1;
1747  t.minute=s.minute-1;
1748  t.second=s.second-1;
1749 }
1750 
convert_date(otl_oracle_date & t,const otl_datetime & s)1751 inline void convert_date(otl_oracle_date& t,const otl_datetime& s)
1752 {
1753  t.year=OTL_SCAST(unsigned char, ((s.year%100)+100));
1754  t.century=OTL_SCAST(unsigned char, ((s.year/100)+100));
1755  t.month=OTL_SCAST(unsigned char, s.month);
1756  t.day=OTL_SCAST(unsigned char, s.day);
1757  t.hour=OTL_SCAST(unsigned char, (s.hour+1));
1758  t.minute=OTL_SCAST(unsigned char, (s.minute+1));
1759  t.second=OTL_SCAST(unsigned char, (s.second+1));
1760 }
1761 
1762 class otl_null{
1763 public:
1764 
otl_null()1765  otl_null(){}
~otl_null()1766  ~otl_null(){}
1767 
1768 private:
1769 
1770 #if (defined(_MSC_VER)&&(_MSC_VER==1200))
1771  int dummy; // this is to fix a compiler bug in VC++ 6.0
1772 #endif
1773 
1774 };
1775 
1776 class otl_column_desc{
1777 public:
1778 
1779   char* name;
1780   int  dbtype;
1781   int  otl_var_dbtype;
1782 #if defined(_WIN64)
1783   __int64 dbsize;
1784 #else
1785   int  dbsize;
1786 #endif
1787   int  scale;
1788 #if defined(_WIN64)
1789   __int64 prec;
1790 #else
1791   int  prec;
1792 #endif
1793   int  nullok;
1794 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
1795   int charset_form;
1796   int char_size;
1797 #endif
1798 
otl_column_desc()1799   otl_column_desc():
1800     name(0),
1801     dbtype(0),
1802     otl_var_dbtype(0),
1803     dbsize(0),
1804     scale(0),
1805     prec(0),
1806     nullok(0),
1807 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
1808     charset_form(0),
1809     char_size(0),
1810 #endif
1811     name_len_(0)
1812   {
1813   }
1814 
~otl_column_desc()1815   ~otl_column_desc()
1816   {
1817     delete[] name;
1818   }
1819 
1820   otl_column_desc& operator=(const otl_column_desc& desc)
1821   {
1822     if(name_len_>=desc.name_len_)
1823       OTL_STRCPY_S(name,name_len_,desc.name);
1824     else if(name==0 && desc.name!=0){
1825       name=new char[desc.name_len_];
1826       name_len_=desc.name_len_;
1827       OTL_STRCPY_S(name,name_len_,desc.name);
1828     }else if(name_len_<desc.name_len_ && desc.name!=0){
1829       delete[] name;
1830       name=new char[desc.name_len_];
1831       name_len_=desc.name_len_;
1832       OTL_STRCPY_S(name,name_len_,desc.name);
1833     }
1834     dbtype=desc.dbtype;
1835     otl_var_dbtype=desc.otl_var_dbtype;
1836     dbsize=desc.dbsize;
1837     scale=desc.scale;
1838     prec=desc.prec;
1839     nullok=desc.nullok;
1840 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
1841     charset_form=desc.charset_form;
1842     char_size=desc.char_size;
1843 #endif
1844 
1845     return *this;
1846   }
1847 
1848   void set_name(const char* aname,const int aname_len=0)
1849   {
1850     int len;
1851     if(aname_len==0)
1852       len=OTL_SCAST(int,strlen(aname))+1;
1853     else
1854       len=aname_len+1;
1855     if(name_len_<len){
1856       if(name)delete[] name;
1857       name=new char[len];
1858       name_len_=len;
1859       for(int i=0;i<len-1;++i)
1860         name[i]=aname[i];
1861       name[len-1]=0;
1862     }
1863   }
1864 
1865 private:
1866 
1867   int name_len_;
1868 
otl_column_desc(const otl_column_desc &)1869   otl_column_desc(const otl_column_desc&):
1870     name(0),
1871     dbtype(0),
1872     otl_var_dbtype(0),
1873     dbsize(0),
1874     scale(0),
1875     prec(0),
1876     nullok(0),
1877 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
1878     charset_form(0),
1879     char_size(0),
1880 #endif
1881     name_len_(0)
1882   {
1883   }
1884 
1885 };
1886 
1887 class otl_var_desc{
1888 public:
1889 
1890   int  param_type;
1891   int  ftype;
1892   int  elem_size;
1893   int  array_size;
1894   int  pos;
1895   int  name_pos;
1896   char name[128];
1897   int  pl_tab_flag;
1898 
otl_var_desc()1899   otl_var_desc():
1900     param_type(0),
1901     ftype(0),
1902     elem_size(0),
1903     array_size(0),
1904     pos(0),
1905     name_pos(0),
1906     name(),
1907     pl_tab_flag(0)
1908  {
1909    name[0]=0;
1910  }
1911 
~otl_var_desc()1912  ~otl_var_desc(){}
1913 
copy_name(const char * nm)1914  void copy_name(const char* nm)
1915  {
1916   if(!nm)
1917    name[0]=0;
1918   else{
1919 #if defined(_MSC_VER)
1920 #if (_MSC_VER >= 1400)
1921    OTL_STRNCPY_S(name,sizeof(name),nm,sizeof(name)-1);
1922    name[sizeof(name)-1]=0;
1923 #else
1924    strncpy(name,nm,sizeof(name));
1925    name[sizeof(name)-1]=0;
1926 #endif
1927 #else
1928    strncpy(name,nm,sizeof(name));
1929    name[sizeof(name)-1]=0;
1930 #endif
1931   }
1932  }
1933 
1934 };
1935 
1936 const int otl_var_none=0;
1937 const int otl_var_char=1;
1938 const int otl_var_double=2;
1939 const int otl_var_float=3;
1940 const int otl_var_int=4;
1941 const int otl_var_unsigned_int=5;
1942 const int otl_var_short=6;
1943 const int otl_var_long_int=7;
1944 const int otl_var_timestamp=8;
1945 const int otl_var_varchar_long=9;
1946 const int otl_var_raw_long=10;
1947 const int otl_var_clob=11;
1948 const int otl_var_blob=12;
1949 const int otl_var_refcur=13;
1950 const int otl_var_long_string=15;
1951 const int otl_var_db2time=16;
1952 const int otl_var_db2date=17;
1953 const int otl_var_tz_timestamp=18;
1954 const int otl_var_ltz_timestamp=19;
1955 const int otl_var_bigint=20;
1956 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
1957 const int otl_var_nchar=21;
1958 const int otl_var_nclob=22;
1959 #else
1960 #endif
1961 const int otl_var_raw=23;
1962 const int otl_var_lob_stream=100;
1963 
1964 const int otl_bigint_str_size=40;
1965 
1966 const int otl_sql_exec_from_cursor_class=0;
1967 const int otl_sql_exec_from_select_cursor_class=1;
1968 
1969 class otl_long_string{
1970 public:
1971 
1972   unsigned char* v;
1973 
1974   otl_long_string(const int buffer_size=32760,const int input_length=0):
1975     v(0),
1976     length(0),
1977     extern_buffer_flag(0),
1978     buf_size(0),
1979     this_is_last_piece_(false)
1980  {
1981    this_is_last_piece_=false;
1982    if(buffer_size==0){
1983      v=0;
1984      length=0;
1985      extern_buffer_flag=0;
1986    }else{
1987      extern_buffer_flag=0;
1988      length=input_length;
1989      buf_size=buffer_size;
1990      v=new unsigned char[buffer_size+1];
1991      memset(v,0,buffer_size);
1992    }
1993  }
1994 
1995  otl_long_string
1996  (const void* external_buffer,
1997   const int buffer_size,
1998   const int input_length=0):
v(OTL_RCAST (unsigned char *,OTL_CCAST (void *,external_buffer)))1999     v(OTL_RCAST(unsigned char*, OTL_CCAST(void*, external_buffer))),
2000     length(input_length),
2001     extern_buffer_flag(1),
2002     buf_size(buffer_size),
2003     this_is_last_piece_(false)
2004  {
2005  }
2006 
2007   otl_long_string& operator=(const otl_long_string& s)
2008   {
2009     this_is_last_piece_=s.this_is_last_piece_;
2010     if(s.extern_buffer_flag){
2011       if(!extern_buffer_flag)
2012         delete[] v;
2013       v=s.v;
2014       length=s.length;
2015       extern_buffer_flag=s.extern_buffer_flag;
2016       buf_size=s.buf_size;
2017     }else{
2018       if(extern_buffer_flag){
2019         v=new unsigned char[s.buf_size+1];
2020         buf_size=s.buf_size;
2021       }else if(buf_size<s.buf_size){
2022         delete[] v;
2023         v=new unsigned char[s.buf_size+1];
2024         buf_size=s.buf_size;
2025       }
2026       length=s.length;
2027       extern_buffer_flag=s.extern_buffer_flag;
2028       memcpy(v,s.v,length);
2029       if(length<buf_size&&s.v[length]==0)
2030         v[length]=0;
2031     }
2032     return *this;
2033   }
2034 
otl_long_string(const otl_long_string & s)2035   otl_long_string(const otl_long_string& s):
2036     v(0),
2037     length(s.length),
2038     extern_buffer_flag(s.extern_buffer_flag),
2039     buf_size(s.buf_size),
2040     this_is_last_piece_(s.this_is_last_piece_)
2041   {
2042     if(s.extern_buffer_flag)
2043       v=s.v;
2044     else{
2045       v=new unsigned char[buf_size+1];
2046       memcpy(v,s.v,length);
2047       if(length<buf_size&&s.v[length]==0)
2048         v[length]=0;
2049     }
2050   }
2051 
~otl_long_string()2052   virtual ~otl_long_string()
2053   {
2054    if(!extern_buffer_flag)delete[] v;
2055   }
2056 
2057   void set_len(const int alen=0){length=alen;}
len(void)2058   int len(void)const {return length;}
2059 
2060   void set_last_piece(const bool this_is_last_piece=false)
2061   {
2062     this_is_last_piece_=this_is_last_piece;
2063   }
2064 
is_last_piece()2065   bool is_last_piece() const
2066   {
2067     return this_is_last_piece_;
2068   }
2069 
2070   unsigned char& operator[](int ndx)
2071   {
2072     return v[ndx];
2073   }
2074 
null_terminate_string(const int alen)2075   virtual void null_terminate_string(const int alen)
2076   {
2077     (*this)[alen]=0;
2078   }
2079 
get_buf_size()2080   int get_buf_size() const
2081   {
2082     return buf_size;
2083   }
2084 
get_extern_buffer_flag()2085   int get_extern_buffer_flag() const
2086   {
2087     return extern_buffer_flag;
2088   }
2089 
2090 protected:
2091 
2092   int length;
2093   int extern_buffer_flag;
2094   int buf_size;
2095   bool this_is_last_piece_;
2096 
2097 };
2098 
2099 #if defined(OTL_UNICODE)
2100 class otl_long_unicode_string: public otl_long_string{
2101 public:
2102 
2103   otl_long_unicode_string(const int buffer_size=32760,const int input_length=0)
2104     : otl_long_string(0,0)
2105   {
2106     extern_buffer_flag=0;
2107     length=input_length;
2108     buf_size=buffer_size;
2109     v=new unsigned char[(buffer_size+1)*sizeof(OTL_WCHAR)];
2110     memset(v,0,buffer_size*sizeof(OTL_WCHAR));
2111   }
2112 
2113   otl_long_unicode_string
2114   (const void* external_buffer,
2115    const int buffer_size,
2116    const int input_length=0)
otl_long_string(external_buffer,buffer_size,input_length)2117     : otl_long_string(external_buffer,buffer_size,input_length)
2118   {
2119     extern_buffer_flag=1;
2120     length=input_length;
2121     buf_size=buffer_size;
2122     v=OTL_RCAST(unsigned char*, OTL_CCAST(void*, external_buffer));
2123   }
2124 
otl_long_unicode_string(const otl_long_unicode_string & s)2125   otl_long_unicode_string(const otl_long_unicode_string& s) : otl_long_string(0,0)
2126   {
2127     this->buf_size=s.buf_size;
2128     this->this_is_last_piece_=s.this_is_last_piece_;
2129     this->extern_buffer_flag=s.extern_buffer_flag;
2130     this->v=0;
2131     this->length=s.length;
2132     if(s.extern_buffer_flag)
2133       v=s.v;
2134     else{
2135       v=new unsigned char[(buf_size+1)*sizeof(OTL_WCHAR)];
2136       memcpy(v,s.v,length*sizeof(OTL_WCHAR));
2137       if(length<buf_size&&s.v[length]==0)
2138         (*this)[length]=0;
2139     }
2140   }
2141 
2142   otl_long_unicode_string& operator=(const otl_long_unicode_string& s)
2143   {
2144     this_is_last_piece_=s.this_is_last_piece_;
2145     if(s.extern_buffer_flag){
2146       if(!extern_buffer_flag)
2147         delete[] v;
2148       v=s.v;
2149       length=s.length;
2150       extern_buffer_flag=s.extern_buffer_flag;
2151       buf_size=s.buf_size;
2152     }else{
2153       if(extern_buffer_flag){
2154         v=new unsigned char[(s.buf_size+1)*sizeof(OTL_WCHAR)];
2155         buf_size=s.buf_size;
2156       }else if(buf_size<s.buf_size){
2157         delete[] v;
2158         v=new unsigned char[(s.buf_size+1)*sizeof(OTL_WCHAR)];
2159         buf_size=s.buf_size;
2160       }
2161       length=s.length;
2162       extern_buffer_flag=s.extern_buffer_flag;
2163       memcpy(v,s.v,length*sizeof(OTL_WCHAR));
2164       if(length<buf_size&&s.v[length]==0)
2165         (*this)[length]=0;
2166     }
2167     return *this;
2168   }
2169 
~otl_long_unicode_string()2170   virtual ~otl_long_unicode_string(){}
2171 
2172   OTL_CHAR& operator[](int ndx)
2173   {
2174     return OTL_RCAST(OTL_CHAR*,v)[ndx];
2175   }
2176 
null_terminate_string(const int alen)2177   virtual void null_terminate_string(const int alen)
2178   {
2179     (*this)[alen]=0;
2180   }
2181 
2182 };
2183 
2184 #endif
2185 
otl_var_type_name(const int ftype)2186 inline const char* otl_var_type_name(const int ftype)
2187 {
2188   const char* const_CHAR="CHAR";
2189   const char* const_DOUBLE="DOUBLE";
2190   const char* const_FLOAT="FLOAT";
2191   const char* const_INT="INT";
2192   const char* const_UNSIGNED_INT="UNSIGNED INT";
2193   const char* const_SHORT_INT="SHORT INT";
2194   const char* const_LONG_INT="LONG INT";
2195   const char* const_TIMESTAMP="TIMESTAMP";
2196   const char* const_DB2DATE="DB2DATE";
2197   const char* const_DB2TIME="DB2TIME";
2198   const char* const_TZ_TIMESTAMP="TIMESTAMP WITH TIME ZONE";
2199   const char* const_LTZ_TIMESTAMP="TIMESTAMP WITH LOCAL TIME ZONE";
2200   const char* const_BIGINT="BIGINT";
2201   const char* const_VARCHAR_LONG="VARCHAR LONG";
2202   const char* const_RAW_LONG="RAW LONG";
2203   const char* const_CLOB="CLOB";
2204   const char* const_BLOB="BLOB";
2205   const char* const_RAW="RAW";
2206   const char* const_UNKNOWN="UNKNOWN";
2207   const char* const_LONG_STRING="otl_long_string()";
2208   const char* const_LOB_STREAM="otl_lob_stream*&";
2209   const char* const_USER_DEFINED="User-defined type (object type, VARRAY, Nested Table)";
2210 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
2211   const char* const_NCHAR="NCHAR";
2212   const char* const_NCLOB="NCLOB";
2213 #endif
2214 
2215   switch(ftype){
2216 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
2217   case otl_var_nchar:
2218     return const_NCHAR;
2219   case otl_var_nclob:
2220     return const_NCLOB;
2221 #endif
2222   case otl_var_char:
2223     return const_CHAR;
2224   case otl_var_double:
2225     return const_DOUBLE;
2226   case otl_var_float:
2227     return const_FLOAT;
2228   case otl_var_int:
2229     return const_INT;
2230   case otl_var_unsigned_int:
2231     return const_UNSIGNED_INT;
2232   case otl_var_short:
2233     return const_SHORT_INT;
2234   case otl_var_long_int:
2235     return const_LONG_INT;
2236   case otl_var_timestamp:
2237     return const_TIMESTAMP;
2238   case otl_var_db2date:
2239     return const_DB2DATE;
2240   case otl_var_db2time:
2241     return const_DB2TIME;
2242   case otl_var_tz_timestamp:
2243     return const_TZ_TIMESTAMP;
2244   case otl_var_ltz_timestamp:
2245     return const_LTZ_TIMESTAMP;
2246   case otl_var_bigint:
2247     return const_BIGINT;
2248   case otl_var_varchar_long:
2249     return const_VARCHAR_LONG;
2250   case otl_var_raw_long:
2251     return const_RAW_LONG;
2252   case otl_var_clob:
2253     return const_CLOB;
2254   case otl_var_blob:
2255     return const_BLOB;
2256   case otl_var_raw:
2257     return const_RAW;
2258   case otl_var_long_string:
2259     return const_LONG_STRING;
2260   case otl_var_lob_stream:
2261     return const_LOB_STREAM;
2262   case 108:
2263     return const_USER_DEFINED;
2264  default:
2265   return const_UNKNOWN;
2266  }
2267 }
2268 
otl_var_info_var(const char * name,const int ftype,const int type_code,char * var_info,const size_t var_info_sz)2269 inline void otl_var_info_var
2270 (const char* name,
2271  const int ftype,
2272  const int type_code,
2273  char* var_info,
2274 #if defined(_MSC_VER)
2275 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2276  const size_t var_info_sz
2277 #else
2278  const size_t /*var_info_sz*/
2279 #endif
2280 #else
2281  const size_t /*var_info_sz*/
2282 #endif
2283 )
2284 {char buf1[128];
2285  char buf2[128];
2286  OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2287  OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code));
2288  OTL_STRCPY_S(var_info,var_info_sz,"Variable: ");
2289  OTL_STRCAT_S(var_info,var_info_sz,name);
2290  OTL_STRCAT_S(var_info,var_info_sz,"<");
2291  OTL_STRCAT_S(var_info,var_info_sz,buf1);
2292  OTL_STRCAT_S(var_info,var_info_sz,">, datatype in operator <</>>: ");
2293  OTL_STRCAT_S(var_info,var_info_sz,buf2);
2294 }
2295 
otl_var_info_var2(const char * name,const int ftype,char * var_info,const size_t var_info_sz)2296 inline void otl_var_info_var2
2297 (const char* name,
2298  const int ftype,
2299  char* var_info,
2300 #if defined(_MSC_VER)
2301 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2302  const size_t var_info_sz
2303 #else
2304  const size_t /*var_info_sz*/
2305 #endif
2306 #else
2307  const size_t /*var_info_sz*/
2308 #endif
2309 )
2310 {char buf1[128];
2311  OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2312  OTL_STRCPY_S(var_info,var_info_sz,"Variable: ");
2313  OTL_STRCPY_S(var_info,var_info_sz,name);
2314  OTL_STRCAT_S(var_info,var_info_sz,"<");
2315  OTL_STRCAT_S(var_info,var_info_sz,buf1);
2316  OTL_STRCAT_S(var_info,var_info_sz,">");
2317 }
2318 
otl_var_info_var3(const char * name,const int ftype,const int type_code,char * var_info,const size_t var_info_sz)2319 inline void otl_var_info_var3
2320 (const char* name,
2321  const int ftype,
2322  const int type_code,
2323  char* var_info,
2324 #if defined(_MSC_VER)
2325 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2326  const size_t var_info_sz
2327 #else
2328  const size_t /*var_info_sz*/
2329 #endif
2330 #else
2331  const size_t /*var_info_sz*/
2332 #endif
2333 )
2334 {char buf1[128];
2335  char buf2[128];
2336  OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2337  OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code));
2338  OTL_STRCPY_S(var_info,var_info_sz,"Variable: ");
2339  OTL_STRCAT_S(var_info,var_info_sz,name);
2340  OTL_STRCAT_S(var_info,var_info_sz,"<");
2341  OTL_STRCAT_S(var_info,var_info_sz,buf1);
2342  OTL_STRCAT_S(var_info,
2343               var_info_sz,
2344               ">, datatype in otl_stream_read_iterator::get(): ");
2345  OTL_STRCAT_S(var_info,var_info_sz,buf2);
2346 }
2347 
otl_var_info_var4(const char * name,const int ftype,const int type_code,char * var_info,const size_t var_info_sz)2348 inline void otl_var_info_var4
2349 (const char* name,
2350  const int ftype,
2351  const int type_code,
2352  char* var_info,
2353 #if defined(_MSC_VER)
2354 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2355  const size_t var_info_sz
2356 #else
2357  const size_t /*var_info_sz*/
2358 #endif
2359 #else
2360  const size_t /*var_info_sz*/
2361 #endif
2362 )
2363 {char buf1[128];
2364  char buf2[128];
2365  OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2366  OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code));
2367  OTL_STRCPY_S(var_info,var_info_sz,"Variable: ");
2368  OTL_STRCAT_S(var_info,var_info_sz,name);
2369  OTL_STRCAT_S(var_info,var_info_sz,"<");
2370  OTL_STRCAT_S(var_info,var_info_sz,buf1);
2371  OTL_STRCAT_S(var_info,
2372               var_info_sz,
2373               ">, datatype in otl_stream_read_iterator::get(): ");
2374  OTL_STRCAT_S(var_info,var_info_sz,buf2);
2375 }
2376 
2377 inline void otl_strcpy(
2378   unsigned char* trg,
2379   unsigned char* src,
2380   int& overflow,
2381   const int inp_size=0,
2382   const int actual_inp_size=-1
2383 )
2384 {
2385   OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2386   const OTL_CHAR* c2=OTL_RCAST(const OTL_CHAR*,src);
2387   int out_size=0;
2388   overflow=0;
2389   if(actual_inp_size!=-1){
2390     while(out_size<inp_size-1 && out_size<actual_inp_size){
2391       *c1++=*c2++;
2392       ++out_size;
2393     }
2394     *c1=0;
2395     if(out_size==inp_size-1 && out_size<actual_inp_size)
2396       overflow=1;
2397   }else{
2398     while(*c2 && out_size<inp_size-1){
2399       *c1++=*c2++;
2400       ++out_size;
2401     }
2402     *c1=0;
2403     if(*c2 && out_size==inp_size-1)
2404       overflow=1;
2405   }
2406 }
2407 
2408 #if defined(OTL_UNICODE) || (defined(_MSC_VER) && (_MSC_VER >= 1400))
otl_strcpy(unsigned char * trg,const unsigned char * src)2409 inline void otl_strcpy
2410  (unsigned char* trg,
2411   const unsigned char* src)
2412 {
2413  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2414  const OTL_CHAR* c2=OTL_RCAST(const OTL_CHAR*,src);
2415  while(*c2){
2416   *c1++=*c2++;
2417  }
2418  *c1=0;
2419 }
2420 #else
otl_strcpy(unsigned char * trg,const unsigned char * src)2421 inline void otl_strcpy(unsigned char* trg,const unsigned char* src)
2422 {
2423   strcpy(OTL_RCAST(char*,trg),OTL_RCAST(const char*,src));
2424 }
2425 #endif
2426 
otl_strcat(char * trg,const char * src)2427 inline void otl_strcat(char* trg,const char* src)
2428 {
2429   while(*trg)++trg;
2430   while(*src){
2431     *trg=*src;
2432     ++trg;
2433     ++src;
2434   }
2435   *trg=0;
2436 }
2437 
2438 #if defined(OTL_UNICODE) && !defined(OTL_ODBC)
otl_strcpy2(unsigned char * trg,const unsigned char * src,const int max_src_len)2439 inline void otl_strcpy2(
2440   unsigned char* trg,
2441   const unsigned char* src,
2442   const int max_src_len
2443 )
2444 {
2445  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2446  const OTL_CHAR* c2=OTL_RCAST(const OTL_CHAR*,src);
2447  int src_len=OTL_SCAST(int,*OTL_SCAST(const unsigned short*,c2));
2448  int len=0;
2449  ++c2;
2450  while(*c2&&len<max_src_len&&len<src_len){
2451   *c1++=*c2++;
2452   ++len;
2453  }
2454  *c1=0;
2455 #else
2456 inline void otl_strcpy2(
2457   unsigned char* trg,
2458   const unsigned char* src,
2459   const int /* max_src_len */
2460 )
2461 {
2462  otl_strcpy(trg,src);
2463 #endif
2464 }
2465 
2466 #if defined(OTL_UNICODE)
2467 inline void otl_memcpy(
2468   unsigned char* trg,
2469   unsigned char* src,
2470   const int src_len,
2471   const int ftype
2472 )
2473 {
2474   if(ftype==otl_var_raw_long||ftype==otl_var_raw){
2475     memcpy(trg,src,src_len);
2476     return;
2477   }
2478 
2479   OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2480   OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src);
2481   int len=0;
2482   while(len<src_len){
2483     *c1++=*c2++;
2484     ++len;
2485   }
2486 
2487 #else
2488 inline void otl_memcpy(
2489   unsigned char* trg,
2490   unsigned char* src,
2491   const int src_len,
2492   const int /* ftype */
2493 )
2494 {
2495  memcpy(trg,src,src_len);
2496 #endif
2497 }
2498 
2499 #if defined(OTL_UNICODE) && !defined(OTL_ODBC)
2500 inline void otl_strcpy3(
2501   unsigned char* trg,
2502   unsigned char* src,
2503   const int max_src_len,
2504   int& overflow,
2505   const int inp_size=0
2506 )
2507 {
2508  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2509  OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src);
2510  int len=0;
2511  int src_len=OTL_SCAST(int,*OTL_RCAST(unsigned short*,c2));
2512  ++c2;
2513  int out_size=0;
2514  overflow=0;
2515  while(len<src_len&&len<max_src_len&&out_size<inp_size-1){
2516   *c1++=*c2++;
2517   ++out_size;
2518   ++len;
2519  }
2520  *c1=0;
2521  if(len<src_len&&out_size==inp_size-1)
2522   overflow=1;
2523 #else
2524 inline void otl_strcpy3(
2525   unsigned char* trg,
2526   unsigned char* src,
2527   const int /* max_src_len */,
2528   int& overflow,
2529   const int inp_size=0
2530 )
2531 {
2532  OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2533  OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src);
2534  int out_size=0;
2535  overflow=0;
2536  while(*c2&&out_size<inp_size-1){
2537   *c1++=*c2++;
2538   ++out_size;
2539  }
2540  *c1=0;
2541  if(*c2&&out_size==inp_size-1)
2542   overflow=1;
2543 #endif
2544 }
2545 
2546 inline void otl_strcpy4(
2547   unsigned char* trg,
2548   unsigned char* src,
2549   int& overflow,
2550   const int inp_size=0,
2551   const int actual_inp_size=-1
2552 )
2553 {
2554 #if  defined(OTL_UNICODE) && !defined(OTL_ODBC)
2555   OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2556   OTL_CHAR* bc1=c1;
2557   ++c1;
2558   OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src);
2559   int out_size=0;
2560   overflow=0;
2561   if(actual_inp_size!=-1){
2562     while(out_size<inp_size-1 && out_size<actual_inp_size){
2563       *c1++=*c2++;
2564       ++out_size;
2565     }
2566     *OTL_RCAST(unsigned short*,bc1)=OTL_SCAST(unsigned short,out_size);
2567     if(out_size==inp_size-1 && out_size<actual_inp_size)
2568       overflow=1;
2569   }else{
2570     while(*c2&&out_size<inp_size-1){
2571      *c1++=*c2++;
2572      ++out_size;
2573     }
2574     *OTL_RCAST(unsigned short*,bc1)=OTL_SCAST(unsigned short,out_size);
2575     if(*c2&&out_size==inp_size-1)
2576       overflow=1;
2577   }
2578 #else
2579   OTL_CHAR* c1=OTL_RCAST(OTL_CHAR*,trg);
2580   OTL_CHAR* c2=OTL_RCAST(OTL_CHAR*,src);
2581   int out_size=0;
2582   overflow=0;
2583   if(actual_inp_size!=-1){
2584     while(out_size<inp_size-1 && out_size<actual_inp_size){
2585       *c1++=*c2++;
2586       ++out_size;
2587     }
2588     *c1=0;
2589     if(out_size==inp_size-1 && out_size<actual_inp_size)
2590       overflow=1;
2591   }else{
2592     while(*c2&&out_size<inp_size-1){
2593       *c1++=*c2++;
2594       ++out_size;
2595     }
2596     *c1=0;
2597     if(*c2&&out_size==inp_size-1)
2598       overflow=1;
2599   }
2600 #endif
2601 }
2602 
2603 inline char* otl_itoa(int i,char* a)
2604 {
2605   const char* digits="0123456789";
2606   int n=i;
2607   int k;
2608   char buf[64];
2609   char* c=buf;
2610   char *c1=a;
2611   int klen=0;
2612   char digit=' ';
2613   bool negative=false;
2614   if(n<0){
2615     n=-n;
2616     negative=true;
2617   }
2618   do{
2619     if(n>=10)
2620       k=n%10;
2621     else
2622       k=n;
2623     digit=digits[k];
2624     *c=digit;
2625     ++c;
2626     ++klen;
2627     n=n/10;
2628   }while(n!=0);
2629   *c=0;
2630   if(negative){
2631     *c1='-';
2632     ++c1;
2633   }
2634   for(int j=klen-1;j>=0;--j){
2635     *c1=buf[j];
2636     ++c1;
2637   }
2638   *c1=0;
2639   return c1;
2640 }
2641 
2642 inline void otl_var_info_col
2643 (const int pos,
2644  const int ftype,
2645  const int type_code,
2646  char* var_info,
2647 #if defined(_MSC_VER)
2648 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2649  const size_t var_info_sz
2650 #else
2651  const size_t /*var_info_sz*/
2652 #endif
2653 #else
2654  const size_t /*var_info_sz*/
2655 #endif
2656 )
2657 {
2658  char buf1[128];
2659  char buf2[128];
2660  char name[128];
2661 
2662  otl_itoa(pos,name);
2663  OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2664  OTL_STRCPY_S(buf2,sizeof(buf2),otl_var_type_name(type_code));
2665  OTL_STRCPY_S(var_info,var_info_sz,"Column: ");
2666  OTL_STRCAT_S(var_info,var_info_sz,name);
2667  OTL_STRCAT_S(var_info,var_info_sz,"<");
2668  OTL_STRCAT_S(var_info,var_info_sz,buf1);
2669  OTL_STRCAT_S(var_info,
2670               var_info_sz,
2671               ">, datatype in operator <</>>: ");
2672  OTL_STRCAT_S(var_info,var_info_sz,buf2);
2673 }
2674 
2675 inline void otl_var_info_col2
2676 (const int pos,
2677  const int ftype,
2678  char* var_info,
2679 #if defined(_MSC_VER)
2680 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2681  const size_t var_info_sz
2682 #else
2683  const size_t /*var_info_sz*/
2684 #endif
2685 #else
2686  const size_t /*var_info_sz*/
2687 #endif
2688 )
2689 {
2690   char buf1[128];
2691   char name[128];
2692 
2693   otl_itoa(pos,name);
2694   OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2695   OTL_STRCPY_S(var_info,var_info_sz,"Column: ");
2696   OTL_STRCAT_S(var_info,var_info_sz,name);
2697   OTL_STRCAT_S(var_info,var_info_sz,"<");
2698   OTL_STRCAT_S(var_info,var_info_sz,buf1);
2699   OTL_STRCAT_S(var_info,var_info_sz,">");
2700 }
2701 
2702 inline void otl_var_info_col3
2703 (const int pos,
2704  const int ftype,
2705  const char* col_name,
2706  char* var_info,
2707 #if defined(_MSC_VER)
2708 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
2709  const size_t var_info_sz
2710 #else
2711  const size_t /*var_info_sz*/
2712 #endif
2713 #else
2714  const size_t /*var_info_sz*/
2715 #endif
2716 )
2717 {
2718   char buf1[128];
2719   char name[128];
2720 
2721   otl_itoa(pos,name);
2722   OTL_STRCPY_S(buf1,sizeof(buf1),otl_var_type_name(ftype));
2723   OTL_STRCPY_S(var_info,var_info_sz,"Column: ");
2724   OTL_STRCAT_S(var_info,var_info_sz,name);
2725   OTL_STRCAT_S(var_info,var_info_sz," / ");
2726   OTL_STRCAT_S(var_info,var_info_sz,col_name);
2727   OTL_STRCAT_S(var_info,var_info_sz," <");
2728   OTL_STRCAT_S(var_info,var_info_sz,buf1);
2729   OTL_STRCAT_S(var_info,var_info_sz,">");
2730 }
2731 
2732 class otl_pl_tab_generic{
2733 public:
2734 
2735   otl_pl_tab_generic():
2736     p_v(0),
2737     p_null(0),
2738     elem_size(0),
2739     tab_size(0),
2740     tab_len(0),
2741     vtype(0)
2742  {
2743  }
2744 
2745  virtual ~otl_pl_tab_generic(){}
2746 
2747  unsigned char* val(int ndx=0)
2748  {
2749   return p_v+(ndx*elem_size);
2750  }
2751 
2752  int is_null(int ndx=0)
2753  {
2754   return p_null[ndx]!=0;
2755  }
2756 
2757  void set_null(int ndx=0)
2758  {
2759   p_null[ndx]=1;
2760  }
2761 
2762  void set_non_null(int ndx=0)
2763  {
2764   p_null[ndx]=0;
2765  }
2766 
2767  void init_generic(void)
2768  {int i;
2769   memset(p_v,0,elem_size*tab_len);
2770   for(i=0;i<tab_len;++i)
2771    p_null[i]=0;
2772  }
2773 
2774  int len()
2775  {
2776   return tab_len;
2777  }
2778 
2779  void set_len(int new_len=0)
2780  {
2781   tab_len=new_len;
2782  }
2783 
2784   int get_vtype() const
2785   {
2786     return vtype;
2787   }
2788 
2789   int get_elem_size() const
2790   {
2791     return elem_size;
2792   }
2793 
2794   int get_tab_size() const
2795   {
2796     return tab_size;
2797   }
2798 
2799   unsigned char* get_p_v()
2800   {
2801     return p_v;
2802   }
2803 
2804 protected:
2805 
2806  unsigned char* p_v;
2807  short* p_null;
2808  int elem_size;
2809  int tab_size;
2810  int tab_len;
2811  int vtype;
2812 
2813 private:
2814 
2815   otl_pl_tab_generic(const otl_pl_tab_generic&):
2816     p_v(0),
2817     p_null(0),
2818     elem_size(0),
2819     tab_size(0),
2820     tab_len(0),
2821     vtype(0)
2822  {
2823  }
2824 
2825   otl_pl_tab_generic& operator=(const otl_pl_tab_generic&)
2826   {
2827     return *this;
2828   }
2829 
2830 };
2831 
2832 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
2833 template<OTL_TYPE_NAME T,const int T_type>
2834 inline int otl_numeric_convert_T
2835 (const int ftype,const void* val,T& n)
2836 {
2837   if(ftype==T_type){
2838     n=*OTL_RCAST(T*,OTL_CCAST(void*,val));
2839     return 1;
2840   }else
2841     return 0;
2842 }
2843 
2844 template<OTL_TYPE_NAME T>
2845 inline int otl_numeric_convert_T2(const int ftype,const void* val,T& n)
2846 {
2847   int rc=1;
2848   switch(ftype){
2849   case otl_var_double:
2850     n=OTL_PCONV(T,double,val);
2851     break;
2852   case otl_var_short:
2853     n=OTL_PCONV(T,short,val);
2854     break;
2855   case otl_var_int:
2856     n=OTL_PCONV(T,int,val);
2857     break;
2858   case otl_var_unsigned_int:
2859     n=OTL_PCONV(T,unsigned int,val);
2860     break;
2861   case otl_var_long_int:
2862     n=OTL_PCONV(T,long int,val);
2863     break;
2864   case otl_var_float:
2865     n=OTL_PCONV(T,float,val);
2866     break;
2867 #if defined(OTL_BIGINT)
2868   case otl_var_bigint:
2869     n=OTL_PCONV(T,OTL_BIGINT,val);
2870     break;
2871 #endif
2872  default:
2873   rc=0;
2874   break;
2875  }
2876  return rc;
2877 }
2878 
2879 #else
2880 template<OTL_TYPE_NAME T>
2881 inline int otl_numeric_convert_T(const int ftype,const void* val,T& n)
2882 {
2883   int rc=1;
2884   switch(ftype){
2885   case otl_var_double:
2886     n=OTL_PCONV(T,double,val);
2887     break;
2888   case otl_var_short:
2889     n=OTL_PCONV(T,short,val);
2890     break;
2891   case otl_var_int:
2892     n=OTL_PCONV(T,int,val);
2893     break;
2894   case otl_var_unsigned_int:
2895     n=OTL_PCONV(T,unsigned int,val);
2896     break;
2897   case otl_var_long_int:
2898     n=OTL_PCONV(T,long int,val);
2899     break;
2900   case otl_var_float:
2901     n=OTL_PCONV(T,float,val);
2902     break;
2903 #if defined(OTL_BIGINT)
2904   case otl_var_bigint:
2905     n=OTL_PCONV(T,OTL_BIGINT,val);
2906     break;
2907 #endif
2908  default:
2909   rc=0;
2910   break;
2911  }
2912  return rc;
2913 }
2914 #endif
2915 
2916 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
2917 
2918 class otl_ltstr{
2919 public:
2920 
2921  bool operator()(const OTL_STRING_CONTAINER& s1, const OTL_STRING_CONTAINER& s2) const
2922  {
2923   return strcmp(s1.c_str(), s2.c_str()) < 0;
2924  }
2925 
2926 };
2927 
2928 const int otl_max_default_pool_size=32;
2929 
2930 #endif
2931 
2932 #if defined(OTL_ACE)
2933 const int otl_max_default_pool_size=32;
2934 #endif
2935 
2936 
2937 class otl_stream_shell_generic{
2938 public:
2939 
2940   otl_stream_shell_generic():
2941     should_delete(0)
2942  {
2943  }
2944 
2945  virtual ~otl_stream_shell_generic(){}
2946 
2947   int get_should_delete() const
2948   {
2949     return should_delete;
2950   }
2951 
2952   void set_should_delete(const int ashould_delete)
2953   {
2954     should_delete=ashould_delete;
2955   }
2956 
2957 protected:
2958 
2959  int should_delete;
2960 
2961 };
2962 
2963 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
2964 
2965 #if defined(OTL_STL)
2966 #include <map>
2967 #endif
2968 
2969 class otl_stream_pool;
2970 
2971 class otl_stream_pool_entry{
2972 public:
2973 
2974   friend class otl_stream_pool;
2975 
2976 #if defined(OTL_ACE)
2977  otl_tmpl_vector<otl_stream_shell_generic*> s;
2978 #else
2979  STD_NAMESPACE_PREFIX vector<otl_stream_shell_generic*> s;
2980 #endif
2981 
2982   otl_stream_pool_entry():
2983     s(),
2984     cnt(0)
2985  {
2986  }
2987 
2988   otl_stream_pool_entry(const otl_stream_pool_entry& sc):
2989     s(),
2990     cnt(0)
2991  {
2992    copy(sc);
2993  }
2994 
2995  otl_stream_pool_entry& operator=(const otl_stream_pool_entry& sc)
2996  {
2997    copy(sc);
2998    return *this;
2999  }
3000 
3001  virtual ~otl_stream_pool_entry(){}
3002 
3003   int get_cnt() const
3004   {
3005     return cnt;
3006   }
3007 
3008   void set_cnt(const int acnt)
3009   {
3010     cnt=acnt;
3011   }
3012 
3013 private:
3014 
3015  int cnt;
3016 
3017   void copy(const otl_stream_pool_entry& sc)
3018   {
3019     s.clear();
3020 #if defined(OTL_ACE)
3021     for(int i=0;i<sc.s.size();++i)
3022 #else
3023     for(size_t i=0;i<sc.s.size();++i)
3024 #endif
3025       s.push_back(sc.s[i]);
3026     cnt=sc.cnt;
3027   }
3028 
3029 };
3030 
3031 class otl_stream_pool{
3032 public:
3033 
3034  typedef otl_stream_pool_entry cache_entry_type;
3035 #if defined(OTL_ACE)
3036  typedef
3037  ACE_RB_Tree
3038    <OTL_STRING_CONTAINER,cache_entry_type,
3039     ACE_Less_Than<OTL_STRING_CONTAINER>,
3040     ACE_Null_Mutex> sc_type;
3041  typedef otl_tmpl_vector<otl_stream_shell_generic*> vec_type;
3042  typedef ACE_RB_Tree_Node<OTL_STRING_CONTAINER,cache_entry_type> ace_map_entry;
3043 #else
3044   typedef STD_NAMESPACE_PREFIX
3045   map<OTL_STRING_CONTAINER,cache_entry_type,otl_ltstr> sc_type;
3046   typedef STD_NAMESPACE_PREFIX vector<otl_stream_shell_generic*> vec_type;
3047 #endif
3048 
3049 protected:
3050 
3051   sc_type sc;
3052   int max_size;
3053   int size;
3054 
3055 public:
3056 
3057   otl_stream_pool():
3058     sc(),
3059     max_size(otl_max_default_pool_size),
3060     size(0)
3061  {
3062  }
3063 
3064  void init(int amax_size=otl_max_default_pool_size)
3065  {
3066   if(size==0&&max_size==0)return;
3067   if(amax_size<2)
3068     amax_size=2;
3069 #if defined(OTL_ACE)
3070   sc_type::iterator elem0=sc.begin();
3071   sc_type::iterator elemN=sc.end();
3072   for(sc_type::iterator i=elem0; i!=elemN; ++i){
3073    cache_entry_type& ce=(*i).item();
3074    int sz=ce.s.size();
3075    for(int j=0;j<sz;++j){
3076      ce.s[j]->set_should_delete(1);
3077     delete ce.s[j];
3078     ce.s[j]=0;
3079    }
3080    ce.s.clear();
3081    ce.cnt=0;
3082   }
3083   sc.clear();
3084 #else
3085   sc_type::iterator elem0=sc.begin();
3086   sc_type::iterator elemN=sc.end();
3087   for(sc_type::iterator i=elem0; i!=elemN; ++i){
3088    cache_entry_type& ce=(*i).second;
3089    size_t sz=ce.s.size();
3090    for(size_t j=0;j<sz;++j){
3091      ce.s[j]->set_should_delete(1);
3092      delete ce.s[j];
3093      ce.s[j]=0;
3094    }
3095    ce.s.clear();
3096    ce.set_cnt(0);
3097   }
3098   sc.clear();
3099 #endif
3100 
3101   size=0;
3102   max_size=amax_size;
3103 
3104  }
3105 
3106  otl_stream_shell_generic* find(const OTL_STRING_CONTAINER& stmtxt)
3107  {
3108   otl_stream_shell_generic* s;
3109 
3110 #if defined(OTL_ACE)
3111   ace_map_entry* ce=0;
3112   int found=sc.find(stmtxt,ce);
3113   if(found==-1)return 0; // entry not found
3114   s=ce->item().s[ce->item().s.size()-1];
3115   ce->item().s.pop_back();
3116   if(ce->item().s.size()==0){
3117    sc.unbind(ce);
3118    --size;
3119   }
3120 #else
3121   sc_type::iterator cur=sc.find(stmtxt);
3122   if(cur==sc.end())
3123     return 0; // entry not found
3124   cache_entry_type& ce=(*cur).second;
3125   s=ce.s[ce.s.size()-1];
3126   ce.s.pop_back();
3127   if(ce.s.size()==0){
3128    sc.erase(cur);
3129    --size;
3130   }
3131 #endif
3132 
3133   return s;
3134  }
3135 
3136  void remove(const otl_stream_shell_generic* s,const OTL_STRING_CONTAINER& stmtxt)
3137  {
3138 #if defined(OTL_ACE)
3139   ace_map_entry* cur=0;
3140   int found=sc.find(stmtxt,cur);
3141   if(found==-1)
3142    return;
3143   cache_entry_type& ce=(*cur).item();
3144   for(int i=0;i<ce.s.size();++i)
3145    if(ce.s[i]==s){
3146     if(ce.s.size()>1 && i!=ce.s.size()-1){
3147      otl_stream_shell_generic* temp_s=ce.s[i];
3148      ce.s[i]=ce.s[ce.s.size()-1];
3149      ce.s[ce.s.size()-1]=temp_s;
3150     }
3151     ce.s.pop_back();
3152     --size;
3153     return;
3154    }
3155 #else
3156   sc_type::iterator cur=sc.find(stmtxt);
3157   if(cur==sc.end())
3158    return;
3159   cache_entry_type& ce=(*cur).second;
3160   vec_type::iterator bgn=ce.s.begin();
3161   vec_type::iterator end=ce.s.end();
3162   for(vec_type::iterator i=bgn;i!=end;++i)
3163    if((*i)==s){
3164     ce.s.erase(i);
3165     --size;
3166     return;
3167    }
3168 #endif
3169  }
3170 
3171   int get_max_size() const
3172   {
3173     return max_size;
3174   }
3175 
3176  void add(otl_stream_shell_generic* s,const char* stm_text)
3177  {
3178   OTL_STRING_CONTAINER stmtxt(stm_text);
3179 
3180 #if defined(OTL_ACE)
3181 
3182   ace_map_entry* cur=0;
3183   int found_in_map=sc.find(stmtxt,cur);
3184   if(found_in_map==0){ // entry found
3185    bool found=false;
3186    cache_entry_type& ce=(*cur).item();
3187    int sz=ce.s.size();
3188    for(int i=0;i<sz;++i){
3189     if(s==ce.s[i]){
3190      found=true;
3191      break;
3192     }
3193    }
3194    if(!found)
3195      ce.s.push_back(s);
3196    ++ce.cnt;
3197   }else{ // entry not found
3198    if(size<max_size-1){ // add new entry
3199     cache_entry_type ce;
3200     ce.s.push_back(s);
3201     ce.cnt=1;
3202     sc.bind(stmtxt,ce);
3203     ++size;
3204    }else{ // erase the least used entry and add new one
3205 
3206     sc_type::iterator elem0=sc.begin();
3207     sc_type::iterator elemN=sc.end();
3208     int min_cnt=0;
3209     ace_map_entry* min_entry=0;
3210 
3211     for(sc_type::iterator i=elem0;i!=elemN;++i){
3212      if(i==elem0){ // first element
3213       min_entry=&(*i);
3214       min_cnt=(*i).item().cnt;
3215      }
3216      if(min_cnt>(*i).item().cnt){ // found less used entry
3217       min_entry=&(*i);
3218       min_cnt=(*i).item().cnt;
3219      }
3220     }
3221     cache_entry_type& me=(*min_entry).item();
3222     int sz=me.s.size();
3223     for(int n=0;n<sz;++n){
3224       me.s[n]->set_should_delete(1);
3225       otl_stream_shell_generic* tmp=me.s[n];
3226       delete tmp;
3227     }
3228     me.s.clear();
3229     sc.unbind(min_entry);
3230     cache_entry_type ce;
3231     ce.cnt=1;
3232     ce.s.push_back(s);
3233     sc.bind(stmtxt,ce);
3234    }
3235   }
3236 
3237 #else
3238 
3239   sc_type::iterator cur=sc.find(stmtxt);
3240 
3241   if(cur!=sc.end()){ // entry found
3242    bool found=false;
3243    cache_entry_type& ce=(*cur).second;
3244    size_t sz=ce.s.size();
3245    for(size_t i=0;i<sz;++i){
3246     if(s==ce.s[i]){
3247      found=true;
3248      break;
3249     }
3250    }
3251    if(!found)ce.s.push_back(s);
3252    ce.set_cnt(ce.get_cnt()+1);
3253   }else{ // entry not found
3254    if(size<max_size-1){ // add new entry
3255     cache_entry_type ce;
3256     ce.s.push_back(s);
3257     ce.set_cnt(1);
3258     sc[stmtxt]=ce;
3259     ++size;
3260    }else{ // erase the least used entry and add new one
3261 
3262     sc_type::iterator elem0=sc.begin();
3263     sc_type::iterator elemN=sc.end();
3264     int min_cnt=0;
3265     sc_type::iterator min_entry;
3266 
3267     for(sc_type::iterator i=elem0;i!=elemN;++i){
3268      if(i==elem0){ // first element
3269       min_entry=i;
3270       min_cnt=(*i).second.get_cnt();
3271      }
3272      if(min_cnt>(*i).second.get_cnt()){ // found less used entry
3273       min_entry=i;
3274       min_cnt=(*i).second.get_cnt();
3275      }
3276     }
3277     cache_entry_type& me=(*min_entry).second;
3278     size_t sz=me.s.size();
3279     for(size_t n=0;n<sz;++n){
3280       me.s[n]->set_should_delete(1);
3281      otl_stream_shell_generic* tmp=me.s[n];
3282      delete tmp;
3283     }
3284     me.s.clear();
3285     sc.erase(min_entry);
3286     cache_entry_type ce;
3287     ce.set_cnt(1);
3288     ce.s.push_back(s);
3289     sc[stmtxt]=ce;
3290    }
3291   }
3292 #endif
3293  }
3294 
3295  virtual ~otl_stream_pool()
3296  {
3297   init();
3298  }
3299 
3300 private:
3301 
3302   otl_stream_pool(const otl_stream_pool&):
3303     sc(),
3304     max_size(0),
3305     size(0)
3306  {
3307  }
3308 
3309  otl_stream_pool& operator=(const otl_stream_pool&)
3310  {
3311    return *this;
3312  }
3313 
3314 };
3315 
3316 #endif
3317 
3318 
3319 // =========================== COMMON TEMPLATES  ============================
3320 
3321 
3322 #if (defined(OTL_STL)||defined(OTL_VALUE_TEMPLATE_ON)) && defined(OTL_VALUE_TEMPLATE)
3323 
3324 template <OTL_TYPE_NAME TData>
3325 class otl_value{
3326 public:
3327 
3328  TData v;
3329  bool ind;
3330 
3331   otl_value():
3332     v(),
3333    ind(true)
3334  {
3335  }
3336 
3337  virtual ~otl_value(){}
3338 
3339  otl_value(const otl_value<TData>& var):
3340    v(var.v),
3341    ind(var.ind)
3342  {
3343  }
3344 
3345   otl_value(const TData& var):
3346    v(var),
3347    ind(false)
3348  {
3349  }
3350 
3351   otl_value(const otl_null&):
3352    v(),
3353    ind(true)
3354  {
3355  }
3356 
3357  otl_value<TData>& operator=(const otl_value<TData>& var)
3358  {
3359   v=var.v;
3360   ind=var.ind;
3361   return *this;
3362  }
3363 
3364  otl_value<TData>& operator=(const TData& var)
3365  {
3366   v=var;
3367   ind=false;
3368   return *this;
3369  }
3370 
3371  otl_value<TData>& operator=(const otl_null&)
3372  {
3373   ind=true;
3374   return *this;
3375  }
3376 
3377  bool is_null(void)const {return ind;}
3378  void set_null(void){ind=true;}
3379  void set_non_null(void){ind=false;}
3380 
3381 };
3382 
3383 template <OTL_TYPE_NAME TData>
3384 STD_NAMESPACE_PREFIX ostream& operator<<
3385   (STD_NAMESPACE_PREFIX ostream& s,
3386    const otl_value<TData>& var)
3387 {
3388  if(var.ind)
3389   s<<"NULL";
3390  else
3391   s<<var.v;
3392  return s;
3393 }
3394 
3395 #if defined(OTL_DISABLE_OPERATOR_GT_GT_FOR_OTL_VALUE_OTL_DATETIME)
3396 #else
3397 inline STD_NAMESPACE_PREFIX ostream& operator<<(
3398  STD_NAMESPACE_PREFIX ostream& s,
3399  const otl_value<otl_datetime>& var)
3400 {
3401  if(var.ind)
3402    s<<"NULL";
3403  else{
3404 #if !defined(OTL_TRACE_LEVEL)
3405    s<<var.v.month<<"/"<<var.v.day<<"/"<<var.v.year
3406     <<" "<<var.v.hour<<":"<<var.v.minute
3407     <<":"<<var.v.second<<"."<<var.v.fraction;
3408 #else
3409    s<<OTL_TRACE_FORMAT_DATETIME(var.v);
3410 #endif
3411  }
3412  return s;
3413 }
3414 #endif
3415 
3416 #endif
3417 
3418 template <OTL_TYPE_NAME T>
3419 class otl_auto_array_ptr{
3420 public:
3421 
3422   otl_auto_array_ptr():
3423     ptr(0),
3424     arr_size_(0)
3425   {
3426   }
3427 
3428   otl_auto_array_ptr(const int arr_size):
3429     ptr(new T[arr_size]),
3430     arr_size_(arr_size)
3431   {
3432   }
3433 
3434   void double_size(void)
3435   {
3436     int old_arr_size=arr_size_;
3437     arr_size_*=2;
3438     T* temp_ptr=new T[arr_size_];
3439     for(int i=0;i<old_arr_size;++i)
3440       temp_ptr[i]=ptr[i];
3441     delete[] ptr;
3442     ptr=temp_ptr;
3443   }
3444 
3445   virtual ~otl_auto_array_ptr()
3446   {
3447     delete[] ptr;
3448   }
3449 
3450   T* get_ptr()
3451   {
3452     return ptr;
3453   }
3454 
3455   int get_arr_size() const
3456   {
3457     return arr_size_;
3458   }
3459 
3460 private:
3461 
3462   T* ptr;
3463   int arr_size_;
3464 
3465   otl_auto_array_ptr(const otl_auto_array_ptr<T>&):
3466     ptr(0),
3467     arr_size_(0)
3468   {
3469   }
3470 
3471   otl_auto_array_ptr<T>& operator=(const otl_auto_array_ptr<T>&)
3472   {
3473     return *this;
3474   }
3475 
3476 };
3477 
3478 template <OTL_TYPE_NAME T>
3479 class otl_ptr{
3480 public:
3481 
3482   otl_ptr():
3483     ptr(0),
3484     arr_flag(0)
3485  {
3486  }
3487 
3488  void assign(T** var)
3489  {
3490   ptr=var;
3491   arr_flag=0;
3492  }
3493 
3494  void assign_array(T** var)
3495  {
3496   ptr=var;
3497   arr_flag=1;
3498  }
3499 
3500 
3501  void disconnect(void)
3502  {
3503   if(ptr!=0)
3504    *ptr=0;
3505   ptr=0;
3506  }
3507 
3508  void destroy(void)
3509  {
3510   if(ptr==0)return;
3511   if(*ptr!=0){
3512    if(arr_flag)
3513     delete[] *ptr;
3514    else
3515     delete *ptr;
3516    *ptr=0;
3517   }
3518  }
3519 
3520  ~otl_ptr()
3521  {
3522   destroy();
3523  }
3524 
3525 protected:
3526 
3527  T** ptr;
3528  int arr_flag;
3529 
3530 private:
3531 
3532   otl_ptr(const otl_ptr&):
3533     ptr(0),
3534     arr_flag(0)
3535   {
3536   }
3537 
3538   otl_ptr& operator=(const otl_ptr&)
3539   {
3540     return *this;
3541   }
3542 
3543 };
3544 
3545 template <OTL_TYPE_NAME T>
3546 class otl_Tptr{
3547 public:
3548 
3549  otl_Tptr():
3550     ptr(0),
3551     do_not_destroy(false)
3552   {
3553   }
3554 
3555   void assign(T* var)
3556   {
3557     ptr=var;
3558  }
3559 
3560   void disconnect(void)
3561   {
3562     ptr=0;
3563   }
3564 
3565   void destroy(void)
3566   {
3567     if(do_not_destroy)
3568       return;
3569     delete ptr;
3570     ptr=0;
3571  }
3572 
3573   ~otl_Tptr()
3574   {
3575     destroy();
3576   }
3577 
3578   otl_Tptr& operator=(const otl_Tptr& src)
3579   {
3580     ptr=src.ptr;
3581     do_not_destroy=src.do_not_destroy;
3582     return *this;
3583   }
3584 
3585   void set_do_not_destroy(const bool ado_not_destroy)
3586   {
3587     do_not_destroy=ado_not_destroy;
3588   }
3589 
3590   T* get_ptr()
3591   {
3592     return ptr;
3593   }
3594 
3595 protected:
3596 
3597   T* ptr;
3598   bool do_not_destroy;
3599 
3600 private:
3601 
3602   otl_Tptr(const otl_Tptr&):
3603     ptr(0),
3604     do_not_destroy(false)
3605   {
3606   }
3607 
3608 };
3609 
3610 template <OTL_TYPE_NAME OTLStream,
3611           OTL_TYPE_NAME OTLConnect,
3612           OTL_TYPE_NAME otl_exception>
3613 class otl_tmpl_nocommit_stream: public OTLStream{
3614 public:
3615 
3616  otl_tmpl_nocommit_stream() OTL_NO_THROW
3617    : OTLStream()
3618  {
3619   OTLStream::set_commit(0);
3620  }
3621 
3622  otl_tmpl_nocommit_stream
3623  (const otl_stream_buffer_size_type arr_size,
3624   const char* sqlstm,
3625   OTLConnect& pdb,
3626   const char* ref_cur_placeholder=0)
3627    OTL_THROWS_OTL_EXCEPTION
3628   : OTLStream(arr_size,sqlstm,pdb,ref_cur_placeholder)
3629  {
3630   OTLStream::set_commit(0);
3631  }
3632 
3633  void open
3634  (otl_stream_buffer_size_type arr_size,
3635   const char* sqlstm,
3636   OTLConnect& db,
3637   const char* ref_cur_placeholder=0)
3638    OTL_THROWS_OTL_EXCEPTION
3639  {
3640   OTLStream::open(arr_size,sqlstm,db,ref_cur_placeholder);
3641   OTLStream::set_commit(0);
3642  }
3643 
3644 };
3645 
3646 #if defined(OTL_STL)
3647 
3648 class otl_pl_vec_generic{
3649 public:
3650 
3651  typedef STD_NAMESPACE_PREFIX vector<bool> null_flag_type;
3652 
3653 
3654  otl_pl_vec_generic():
3655    p_v(0),
3656    null_flag(),
3657    vtype(0),
3658    elem_size(0)
3659  {
3660  }
3661 
3662  virtual int len(void) const
3663  {
3664   return 0;
3665  }
3666 
3667   virtual void set_len(const int /*new_len*/=0,
3668                        const bool /*set_all_to_null*/=true)
3669 
3670  {
3671  }
3672 
3673  bool is_null(const int ndx=0) const
3674  {
3675   return null_flag[ndx];
3676  }
3677 
3678  void set_null(const int ndx=0)
3679  {
3680   null_flag[ndx]=true;
3681  }
3682 
3683  void set_non_null(const int ndx=0)
3684  {
3685   null_flag[ndx]=false;
3686  }
3687 
3688  virtual ~otl_pl_vec_generic(){}
3689 
3690   int get_vtype() const
3691   {
3692     return vtype;
3693   }
3694 
3695   int get_elem_size() const
3696   {
3697     return elem_size;
3698   }
3699 
3700   void* get_p_v()
3701   {
3702     return p_v;
3703   }
3704 
3705 protected:
3706 
3707  void* p_v;
3708  null_flag_type null_flag;
3709  int vtype;
3710  int elem_size;
3711 
3712 private:
3713 
3714  otl_pl_vec_generic(const otl_pl_vec_generic&):
3715    p_v(0),
3716    null_flag(),
3717    vtype(0),
3718    elem_size(0)
3719  {
3720  }
3721 
3722  otl_pl_vec_generic& operator=(const otl_pl_vec_generic&)
3723  {
3724    return *this;
3725  }
3726 
3727 };
3728 
3729 template<OTL_TYPE_NAME T,const int type_code,const int T_sz>
3730 class otl_T_vec: public otl_pl_vec_generic{
3731 public:
3732 
3733  STD_NAMESPACE_PREFIX vector<T> v;
3734 
3735  otl_T_vec():
3736     v()
3737  {
3738   this->p_v=OTL_RCAST(void*,&v);
3739   this->vtype=type_code;
3740   this->elem_size=T_sz;
3741  }
3742 
3743  virtual ~otl_T_vec(){}
3744 
3745  virtual void set_len
3746    (const int new_len=0,
3747     const bool set_all_to_null=true)
3748  {int i,vsize;
3749 
3750   v.resize(new_len);
3751   this->null_flag.resize(new_len);
3752   vsize=OTL_SCAST(int,v.size());
3753   if(set_all_to_null)
3754     for(i=0;i<vsize;++i)
3755       this->null_flag[i]=true;
3756  }
3757 
3758  virtual int len(void) const
3759  {
3760   return OTL_SCAST(int,v.size());
3761  }
3762 
3763  T& operator[](int ndx)
3764  {
3765   return v[ndx];
3766  }
3767 
3768 private:
3769 
3770  otl_T_vec(const otl_T_vec&):
3771     v()
3772  {
3773  }
3774 
3775  otl_T_vec& operator=(const otl_T_vec&)
3776  {
3777    return *this;
3778  }
3779 
3780 };
3781 
3782 typedef otl_T_vec<double,otl_var_double,sizeof(double)> otl_double_vec;
3783 typedef otl_T_vec<float,otl_var_float,sizeof(float)> otl_float_vec;
3784 typedef otl_T_vec<int,otl_var_int,sizeof(int)> otl_int_vec;
3785 typedef otl_T_vec<short,otl_var_short,sizeof(short)> otl_short_vec;
3786 typedef otl_T_vec<long,otl_var_long_int,sizeof(long)> otl_long_int_vec;
3787 typedef otl_T_vec<otl_datetime,otl_var_timestamp,
3788                   sizeof(otl_oracle_date)> otl_datetime_vec;
3789 typedef otl_T_vec<OTL_STRING_CONTAINER,otl_var_char,1> otl_string_vec;
3790 
3791 #endif
3792 
3793 template <OTL_TYPE_NAME T,const int atab_size,const int avtype>
3794 class otl_tmpl_pl_tab: public otl_pl_tab_generic{
3795 public:
3796 
3797  T v[atab_size];
3798 
3799  void init(void)
3800  {int i;
3801   tab_len=0;
3802   vtype=avtype;
3803   tab_size=atab_size;
3804   p_null=null_flag;
3805   p_v=OTL_RCAST(unsigned char*,v);
3806   elem_size=sizeof(T);
3807   for(i=0;i<atab_size;++i)
3808    null_flag[i]=0;
3809   memset(v,0,sizeof(v));
3810  }
3811 
3812  otl_tmpl_pl_tab():
3813    v(),
3814    null_flag()
3815  {
3816   init();
3817  }
3818 
3819  virtual ~otl_tmpl_pl_tab(){}
3820 
3821 private:
3822 
3823  short null_flag[atab_size];
3824 
3825  otl_tmpl_pl_tab& operator=(const otl_tmpl_pl_tab&)
3826  {
3827    return *this;
3828  }
3829 
3830   otl_tmpl_pl_tab(const otl_tmpl_pl_tab&):
3831    v(),
3832    null_flag()
3833  {
3834  }
3835 
3836 };
3837 
3838 template <const int atab_size>
3839 class otl_int_tab: public otl_tmpl_pl_tab<int,atab_size,otl_var_int>{
3840 public:
3841  otl_int_tab():otl_tmpl_pl_tab<int,atab_size,otl_var_int>(){}
3842 };
3843 
3844 template <const int atab_size>
3845 class otl_double_tab: public otl_tmpl_pl_tab<double,atab_size,otl_var_double>{
3846 public:
3847  otl_double_tab():otl_tmpl_pl_tab<double,atab_size,otl_var_double>(){}
3848 };
3849 
3850 template <const int atab_size>
3851 class otl_float_tab: public otl_tmpl_pl_tab<float,atab_size,otl_var_float>{
3852 public:
3853  otl_float_tab():otl_tmpl_pl_tab<float,atab_size,otl_var_float>(){}
3854 };
3855 
3856 template <const int atab_size>
3857 class otl_unsigned_tab: public otl_tmpl_pl_tab<unsigned,atab_size,otl_var_unsigned_int>{
3858 public:
3859  otl_unsigned_tab():otl_tmpl_pl_tab<unsigned,atab_size,otl_var_unsigned_int>(){}
3860 };
3861 
3862 template <const int atab_size>
3863 class otl_short_tab: public otl_tmpl_pl_tab<short,atab_size,otl_var_short>{
3864 public:
3865  otl_short_tab():otl_tmpl_pl_tab<short,atab_size,otl_var_short>(){}
3866 };
3867 
3868 template <const int atab_size>
3869 class otl_long_int_tab: public otl_tmpl_pl_tab<long,atab_size,otl_var_long_int>{
3870 public:
3871  otl_long_int_tab():otl_tmpl_pl_tab<long,atab_size,otl_var_long_int>(){}
3872 };
3873 
3874 template <const int atab_size,const int str_size>
3875 class otl_cstr_tab: public otl_pl_tab_generic{
3876 public:
3877  typedef unsigned char T[str_size];
3878  T v[atab_size];
3879 
3880  void init(void)
3881  {int i;
3882   tab_len=0;
3883   vtype=otl_var_char;
3884   tab_size=atab_size;
3885   p_null=null_flag;
3886   p_v=OTL_RCAST(unsigned char*,v);
3887   elem_size=sizeof(T);
3888   for(i=0;i<atab_size;++i)
3889    null_flag[i]=0;
3890   memset(v,0,sizeof(v));
3891  }
3892 
3893   otl_cstr_tab():
3894     v(),
3895     null_flag()
3896  {
3897   init();
3898  }
3899 
3900  virtual ~otl_cstr_tab(){}
3901 
3902 private:
3903 
3904  short null_flag[atab_size];
3905 
3906   otl_cstr_tab(const otl_cstr_tab&):
3907     v(),
3908     null_flag()
3909  {
3910  }
3911 
3912  otl_cstr_tab& operator=(const otl_cstr_tab&)
3913  {
3914    return *this;
3915  }
3916 
3917 };
3918 
3919 template <const int atab_size>
3920 class otl_datetime_tab: public otl_pl_tab_generic{
3921 public:
3922 
3923  typedef otl_datetime T;
3924 
3925  T v[atab_size];
3926 
3927  void init(void)
3928  {int i;
3929   tab_len=0;
3930   vtype=otl_var_timestamp;
3931   tab_size=atab_size;
3932   p_null=null_flag;
3933   p_v=OTL_RCAST(unsigned char*,v);
3934   elem_size=sizeof(otl_oracle_date);
3935   for(i=0;i<atab_size;++i)
3936    null_flag[i]=0;
3937  }
3938 
3939   otl_datetime_tab():
3940     v(),
3941     null_flag()
3942  {
3943   init();
3944  }
3945 
3946  virtual ~otl_datetime_tab(){}
3947 
3948 private:
3949 
3950  short null_flag[atab_size];
3951 
3952 };
3953 
3954 template <OTL_TYPE_NAME T,const int avtype>
3955 class otl_tmpl_dyn_pl_tab: public otl_pl_tab_generic{
3956 public:
3957  T* v;
3958 
3959  void init(const int atab_size=1)
3960  {int i;
3961   tab_len=0;
3962   vtype=avtype;
3963   tab_size=atab_size;
3964   v=new T[tab_size];
3965   null_flag=new short[tab_size];
3966   p_null=null_flag;
3967   p_v=OTL_RCAST(unsigned char*,v);
3968   elem_size=sizeof(T);
3969   for(i=0;i<atab_size;++i)
3970    null_flag[i]=0;
3971   memset(v,0,elem_size*tab_size);
3972  }
3973 
3974   otl_tmpl_dyn_pl_tab(const int atab_size=1):
3975     v(0),
3976     null_flag(0)
3977  {
3978   init(atab_size);
3979  }
3980 
3981  virtual ~otl_tmpl_dyn_pl_tab()
3982  {
3983   delete[] v;
3984   delete[] null_flag;
3985  }
3986 
3987 private:
3988 
3989   short* null_flag;
3990 
3991   otl_tmpl_dyn_pl_tab(const otl_tmpl_dyn_pl_tab<T,avtype>&):
3992     v(0),
3993     null_flag(0)
3994   {
3995   }
3996 
3997   otl_tmpl_dyn_pl_tab<T,avtype>& operator=(const otl_tmpl_dyn_pl_tab<T,avtype>&)
3998   {
3999     return *this;
4000   }
4001 
4002 };
4003 
4004 class otl_dynamic_int_tab: public otl_tmpl_dyn_pl_tab<int,otl_var_int>{
4005 public:
4006  otl_dynamic_int_tab(const int atab_size=1)
4007   :otl_tmpl_dyn_pl_tab<int,otl_var_int>(atab_size){}
4008 };
4009 
4010 class otl_dynamic_double_tab: public otl_tmpl_dyn_pl_tab<double,otl_var_double>{
4011 public:
4012  otl_dynamic_double_tab(const int atab_size=1)
4013   :otl_tmpl_dyn_pl_tab<double,otl_var_double>(atab_size){}
4014 };
4015 
4016 class otl_dynamic_float_tab: public otl_tmpl_dyn_pl_tab<float,otl_var_float>{
4017 public:
4018  otl_dynamic_float_tab(const int atab_size=1)
4019   :otl_tmpl_dyn_pl_tab<float,otl_var_float>(atab_size){}
4020 };
4021 
4022 class otl_dynamic_unsigned_tab: public
4023 otl_tmpl_dyn_pl_tab<unsigned,otl_var_unsigned_int>{
4024 public:
4025  otl_dynamic_unsigned_tab(const int atab_size=1)
4026   :otl_tmpl_dyn_pl_tab<unsigned,otl_var_unsigned_int>(atab_size){}
4027 };
4028 
4029 class otl_dynamic_short_tab: public otl_tmpl_dyn_pl_tab<short,otl_var_short>{
4030 public:
4031  otl_dynamic_short_tab(const int atab_size=1)
4032   :otl_tmpl_dyn_pl_tab<short,otl_var_short>(atab_size){}
4033 };
4034 
4035 class otl_dynamic_long_int_tab: public otl_tmpl_dyn_pl_tab<long,otl_var_long_int>{
4036 public:
4037  otl_dynamic_long_int_tab(const int atab_size=1)
4038   :otl_tmpl_dyn_pl_tab<long,otl_var_long_int>(atab_size){}
4039 };
4040 
4041 template <const int str_size>
4042 class otl_dynamic_cstr_tab: public otl_pl_tab_generic{
4043 public:
4044  typedef unsigned char T[str_size];
4045  T* v;
4046 
4047  void init(const int atab_size=1)
4048  {int i;
4049   tab_len=0;
4050   vtype=otl_var_char;
4051   tab_size=atab_size;
4052   v=new T[tab_size];
4053   null_flag=new short[tab_size];
4054   p_null=null_flag;
4055   p_v=OTL_RCAST(unsigned char*,v);
4056   elem_size=sizeof(T);
4057   for(i=0;i<atab_size;++i)
4058    null_flag[i]=0;
4059   memset(v,0,elem_size*tab_size);
4060  }
4061 
4062   otl_dynamic_cstr_tab(const int atab_size=1):
4063     v(0),
4064     null_flag(0)
4065  {
4066   init(atab_size);
4067  }
4068 
4069  virtual ~otl_dynamic_cstr_tab()
4070  {
4071   delete[] v;
4072   delete[] null_flag;
4073  }
4074 
4075 private:
4076 
4077   short* null_flag;
4078 
4079   otl_dynamic_cstr_tab(const otl_dynamic_cstr_tab&):
4080     v(0),
4081     null_flag(0)
4082  {
4083  }
4084 
4085   otl_dynamic_cstr_tab& operator=(const otl_dynamic_cstr_tab&)
4086   {
4087     return *this;
4088   }
4089 
4090 };
4091 
4092 class otl_dynamic_datetime_tab: public otl_pl_tab_generic{
4093 public:
4094 
4095  typedef otl_datetime T;
4096 
4097  T* v;
4098 
4099  void init(const int atab_size=1)
4100  {int i;
4101   tab_len=0;
4102   vtype=otl_var_timestamp;
4103   tab_size=atab_size;
4104   v=new T[tab_size];
4105   null_flag=new short[tab_size];
4106   p_null=null_flag;
4107   p_v=OTL_RCAST(unsigned char*,v);
4108   elem_size=sizeof(otl_oracle_date);
4109   for(i=0;i<atab_size;++i)
4110    null_flag[i]=0;
4111  }
4112 
4113  otl_dynamic_datetime_tab(const int atab_size=1):
4114    otl_pl_tab_generic(),
4115    v(0),
4116    null_flag(0)
4117  {
4118   init(atab_size);
4119  }
4120 
4121  virtual ~otl_dynamic_datetime_tab()
4122  {
4123   delete[] v;
4124   delete[] null_flag;
4125  }
4126 
4127 private:
4128 
4129  short* null_flag;
4130 
4131  otl_dynamic_datetime_tab(const otl_dynamic_datetime_tab&):
4132    otl_pl_tab_generic(),
4133    v(0),
4134    null_flag(0)
4135  {
4136  }
4137 
4138  otl_dynamic_datetime_tab& operator=(const otl_dynamic_datetime_tab&)
4139  {
4140    return *this;
4141  }
4142 
4143 };
4144 
4145 #define OTL_TMPL_EXCEPTION   \
4146   otl_tmpl_exception         \
4147     <TExceptionStruct,       \
4148      TConnectStruct,         \
4149      TCursorStruct>
4150 
4151 #define OTL_TMPL_CONNECT  \
4152   otl_tmpl_connect        \
4153    <TExceptionStruct,     \
4154     TConnectStruct,       \
4155     TCursorStruct>
4156 
4157 #define OTL_TMPL_CURSOR                   \
4158     otl_tmpl_cursor                       \
4159    <TExceptionStruct,TConnectStruct,      \
4160     TCursorStruct,TVariableStruct>
4161 
4162 #define OTL_TMPL_OUT_STREAM            \
4163   otl_tmpl_out_stream                  \
4164    <TExceptionStruct,TConnectStruct,   \
4165     TCursorStruct,TVariableStruct,     \
4166     TTimestampStruct>
4167 
4168 #define OTL_TMPL_SELECT_CURSOR                          \
4169  otl_tmpl_select_cursor                                 \
4170   <TExceptionStruct,TConnectStruct,                     \
4171    TCursorStruct,TVariableStruct,TSelectCursorStruct>
4172 
4173 #define OTL_TMPL_INOUT_STREAM             \
4174   otl_tmpl_inout_stream                   \
4175    <TExceptionStruct,TConnectStruct,      \
4176     TCursorStruct,TVariableStruct,        \
4177     TTimestampStruct>
4178 
4179 #define OTL_TMPL_SELECT_STREAM                      \
4180  otl_tmpl_select_stream                             \
4181    <TExceptionStruct,TConnectStruct,TCursorStruct,  \
4182     TVariableStruct,TSelectCursorStruct,            \
4183     TTimestampStruct>
4184 
4185 #if defined(OTL_EXCEPTION_IS_DERIVED_FROM_STD_EXCEPTION)
4186 #if defined(OTL_EXCEPTION_DERIVED_FROM)
4187 #error OTL_EXCEPTION_DERIVED_FROM is already defined. \
4188 OTL_EXCEPTION_IS_DERIVED_FROM_STD_EXCEPTION cannot be used
4189 #endif
4190 #define OTL_EXCEPTION_DERIVED_FROM std::exception
4191 #define OTL_EXCEPTION_HAS_MEMBERS                       \
4192   virtual const char* what() const throw()              \
4193   {                                                     \
4194     return reinterpret_cast<const char*>(this->msg);    \
4195   }
4196 
4197 #endif
4198 
4199 template <OTL_TYPE_NAME TExceptionStruct,
4200           OTL_TYPE_NAME TConnectStruct,
4201           OTL_TYPE_NAME TCursorStruct>
4202 #if defined(OTL_EXCEPTION_DERIVED_FROM)
4203 class otl_tmpl_exception:
4204   public OTL_EXCEPTION_DERIVED_FROM,
4205   public TExceptionStruct{
4206 #else
4207 class otl_tmpl_exception: public TExceptionStruct{
4208 #endif
4209 public:
4210 
4211 #if defined(OTL_EXCEPTION_HAS_MEMBERS)
4212   OTL_EXCEPTION_HAS_MEMBERS
4213 #endif
4214 
4215 #if defined(OTL_EXCEPTION_STM_TEXT_SIZE)
4216   char stm_text[OTL_EXCEPTION_STM_TEXT_SIZE];
4217 #else
4218   char stm_text[2048];
4219 #endif
4220   char var_info[256];
4221 
4222   otl_tmpl_exception()
4223 #if defined(__GNUC__) && (__GNUC__>=3)
4224     throw()
4225 #else
4226     OTL_NO_THROW
4227 #endif
4228  {
4229   stm_text[0]=0;
4230   var_info[0]=0;
4231  }
4232 
4233  otl_tmpl_exception(TConnectStruct& conn_struct, const char* sqlstm=0)
4234 #if defined(__GNUC__) && (__GNUC__>=3)
4235     throw()
4236 #else
4237     OTL_NO_THROW
4238 #endif
4239  {
4240   stm_text[0]=0;
4241   var_info[0]=0;
4242   if(sqlstm){
4243    OTL_STRNCPY_S(OTL_RCAST(char*,stm_text),
4244                  sizeof(stm_text),
4245                  sqlstm,
4246                  sizeof(stm_text)-1);
4247    stm_text[sizeof(stm_text)-1]=0;
4248   }
4249   conn_struct.error(OTL_SCAST(TExceptionStruct&,*this));
4250   OTL_TRACE_EXCEPTION(this->code,this->msg,this->stm_text,this->var_info)
4251  }
4252 
4253  otl_tmpl_exception(TCursorStruct& cursor_struct, const char* sqlstm=0)
4254 #if defined(__GNUC__) && (__GNUC__>=3)
4255     throw()
4256 #else
4257     OTL_NO_THROW
4258 #endif
4259  {
4260   stm_text[0]=0;
4261   var_info[0]=0;
4262   if(sqlstm){
4263    OTL_STRNCPY_S(OTL_RCAST(char*,stm_text),
4264                  sizeof(stm_text),
4265                  sqlstm,
4266                  sizeof(stm_text)-1);
4267    stm_text[sizeof(stm_text)-1]=0;
4268   }
4269   cursor_struct.error(OTL_SCAST(TExceptionStruct&,*this));
4270   OTL_TRACE_EXCEPTION(this->code,this->msg,this->stm_text,this->var_info)
4271  }
4272 
4273  otl_tmpl_exception
4274  (const char* amsg,
4275   const int acode,
4276   const char* sqlstm=0,
4277   const char* varinfo=0)
4278 #if defined(__GNUC__) && (__GNUC__>=3)
4279     throw()
4280 #else
4281     OTL_NO_THROW
4282 #endif
4283  {
4284   stm_text[0]=0;
4285   var_info[0]=0;
4286   if(sqlstm){
4287 #if defined(_MSC_VER)
4288 #if (_MSC_VER >= 1400)
4289     OTL_STRCPY_S(OTL_RCAST(char*,stm_text),sizeof(stm_text),sqlstm);
4290 #else
4291     strncpy(OTL_RCAST(char*,stm_text),sqlstm,sizeof(stm_text));
4292     stm_text[sizeof(stm_text)-1]=0;
4293 #endif
4294 #else
4295     strncpy(OTL_RCAST(char*,stm_text),sqlstm,sizeof(stm_text));
4296     stm_text[sizeof(stm_text)-1]=0;
4297 #endif
4298   }
4299   if(varinfo)
4300     OTL_STRCPY_S(OTL_RCAST(char*,var_info),sizeof(var_info),varinfo);
4301   TExceptionStruct::init(amsg,acode);
4302   OTL_TRACE_EXCEPTION(this->code,this->msg,this->stm_text,this->var_info)
4303  }
4304 
4305  virtual ~otl_tmpl_exception()
4306 #if defined(__GNUC__) && (__GNUC__>=3)
4307     throw()
4308 #else
4309     OTL_NO_THROW
4310 #endif
4311  {
4312  }
4313 
4314 };
4315 
4316 template <OTL_TYPE_NAME TExceptionStruct,
4317           OTL_TYPE_NAME TConnectStruct,
4318           OTL_TYPE_NAME TCursorStruct>
4319 class otl_tmpl_connect{
4320 protected:
4321 
4322  TConnectStruct connect_struct;
4323  int long_max_size;
4324  int retcode;
4325  int throw_count;
4326 
4327 public:
4328 
4329   void set_retcode(const int aretcode)
4330   {
4331     retcode=aretcode;
4332   }
4333 
4334   int get_retcode() const
4335   {
4336     return retcode;
4337   }
4338 
4339   void reset_throw_count(void)
4340   {
4341     throw_count=0;
4342   }
4343 
4344   void increment_throw_count()
4345   {
4346     throw_count++;
4347   }
4348 
4349   int get_throw_count() const
4350   {
4351     return throw_count;
4352   }
4353 
4354   TConnectStruct& get_connect_struct()
4355   {
4356     return connect_struct;
4357   }
4358 
4359  int connected;
4360 
4361  void set_max_long_size(const int amax_size)
4362  {
4363   reset_throw_count();
4364 #if defined(OTL_UNICODE)
4365 #if defined(OTL_ORA8I)||defined(OTL_ORA9I)||defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)
4366   long_max_size=amax_size*sizeof(OTL_WCHAR);
4367 #else
4368   long_max_size=amax_size;
4369 #endif
4370 #else
4371   long_max_size=amax_size;
4372 #endif
4373  }
4374 
4375  int get_max_long_size(void)
4376  {
4377   reset_throw_count();
4378   return long_max_size;
4379  }
4380 
4381  void set_timeout(const int atimeout=0)
4382  {
4383   reset_throw_count();
4384   connect_struct.set_timeout(atimeout);
4385  }
4386 
4387  void set_cursor_type(const int acursor_type=0)
4388  {
4389   reset_throw_count();
4390   connect_struct.set_cursor_type(acursor_type);
4391  }
4392 
4393   otl_tmpl_connect():
4394     connect_struct(),
4395     long_max_size(32760),
4396     retcode(1),
4397     throw_count(0),
4398     connected(0)
4399  {
4400  }
4401 
4402   otl_tmpl_connect(const char* connect_str,const int auto_commit=0):
4403     connect_struct(),
4404     long_max_size(32760),
4405     retcode(1),
4406     throw_count(0),
4407     connected(0)
4408  {
4409   rlogon(connect_str,auto_commit);
4410  }
4411 
4412  virtual ~otl_tmpl_connect()
4413  {
4414   logoff();
4415  }
4416 
4417  static int otl_initialize(const int threaded_mode=0)
4418  {
4419   return TConnectStruct::initialize(threaded_mode);
4420  }
4421 
4422  void rlogon(const char* connect_str,const int auto_commit=0)
4423  {
4424   throw_count=0;
4425   retcode=connect_struct.rlogon(connect_str,auto_commit);
4426   if(retcode)
4427    connected=1;
4428   else{
4429    connected=0;
4430    increment_throw_count();
4431   if(get_throw_count()>1)return;
4432    if(otl_uncaught_exception()) return;
4433    OTL_TMPL_EXCEPTION ex(connect_struct);
4434    connect_struct.cleanup();
4435    throw ex;
4436   }
4437  }
4438 
4439  void logoff(void)
4440  {
4441   if(!connected)return;
4442   OTL_TRACE_FUNC(0x1,"otl_connect","logoff","")
4443   retcode=connect_struct.logoff();
4444   connected=0;
4445   if(retcode)return;
4446   if(get_throw_count()>0)
4447    return;
4448   increment_throw_count();
4449   if(otl_uncaught_exception()) return;
4450   throw OTL_TMPL_EXCEPTION(connect_struct);
4451  }
4452 
4453  void commit(void)
4454  {
4455   if(!connected)return;
4456   OTL_TRACE_FUNC(0x1,"otl_connect","commit","")
4457   reset_throw_count();
4458   retcode=connect_struct.commit();
4459   if(retcode)return;
4460   increment_throw_count();
4461   if(get_throw_count()>1)return;
4462    if(otl_uncaught_exception()) return;
4463   throw OTL_TMPL_EXCEPTION(connect_struct);
4464  }
4465 
4466  void auto_commit_on(void)
4467  {
4468   if(!connected)return;
4469   OTL_TRACE_FUNC(0x1,"otl_connect","auto_commit_on","")
4470   reset_throw_count();
4471   retcode=connect_struct.auto_commit_on();
4472   if(retcode)return;
4473   increment_throw_count();
4474   if(get_throw_count()>1)return;
4475    if(otl_uncaught_exception()) return;
4476   throw OTL_TMPL_EXCEPTION(connect_struct);
4477  }
4478 
4479  void auto_commit_off(void)
4480  {
4481   if(!connected)return;
4482   OTL_TRACE_FUNC(0x1,"otl_connect","auto_commit_off","")
4483   reset_throw_count();
4484   retcode=connect_struct.auto_commit_off();
4485   if(retcode)return;
4486   increment_throw_count();
4487   if(get_throw_count()>1)return;
4488    if(otl_uncaught_exception()) return;
4489   throw OTL_TMPL_EXCEPTION(connect_struct);
4490  }
4491 
4492  void rollback(void)
4493  {
4494   if(!connected)return;
4495   OTL_TRACE_FUNC(0x1,"otl_connect","rollback","")
4496   reset_throw_count();
4497   retcode=connect_struct.rollback();
4498   if(retcode)return;
4499   increment_throw_count();
4500   if(get_throw_count()>1)return;
4501    if(otl_uncaught_exception()) return;
4502   throw OTL_TMPL_EXCEPTION(connect_struct);
4503  }
4504 
4505 private:
4506 
4507   otl_tmpl_connect(const otl_tmpl_connect&):
4508     connected(0),
4509     connect_struct(),
4510     long_max_size(32760),
4511     retcode(1),
4512     throw_count(0)
4513  {
4514  }
4515 
4516  otl_tmpl_connect& operator=(const otl_tmpl_connect&)
4517  {
4518    return *this;
4519  }
4520 
4521 };
4522 
4523 template <OTL_TYPE_NAME TVariableStruct>
4524 class otl_tmpl_variable{
4525 protected:
4526 
4527  int param_type;
4528  int ftype;
4529  int elem_size;
4530  int array_size;
4531  char* name;
4532  int pos;
4533  int name_pos;
4534  int bound;
4535 
4536  int pl_tab_flag;
4537 
4538  TVariableStruct var_struct;
4539 
4540 public:
4541 
4542   TVariableStruct& get_var_struct(){return var_struct;}
4543   const TVariableStruct& get_const_var_struct() const {return var_struct;}
4544   int get_bound() const {return bound;}
4545   int get_param_type() const {return param_type;}
4546   int get_ftype() const {return ftype;}
4547   int get_name_pos() const {return name_pos;}
4548   int get_elem_size() const {return elem_size;}
4549   int get_pl_tab_flag() const {return pl_tab_flag;}
4550   int get_pos() const {return pos;}
4551   int get_array_size() const {return array_size;}
4552   const char* get_name() const {return name;}
4553 
4554   void set_pos(const int apos)
4555   {
4556     this->pos=apos;
4557   }
4558 
4559   void set_bound(const int abound)
4560   {
4561     this->bound=abound;
4562   }
4563 
4564   void set_name_pos(const int aname_pos)
4565   {
4566     this->name_pos=aname_pos;
4567   }
4568 
4569   void set_ftype(const int aftype)
4570   {
4571     this->ftype=aftype;
4572   }
4573 
4574 
4575  int actual_elem_size(void)
4576  {
4577   return var_struct.actual_elem_size();
4578  }
4579 
4580  void copy_var_desc(otl_var_desc& v)
4581  {
4582   v.param_type=param_type;
4583   v.ftype=ftype;
4584   v.elem_size=elem_size;
4585   v.array_size=array_size;
4586   v.pos=pos;
4587   v.name_pos=name_pos;
4588   if(name){
4589    OTL_STRNCPY_S(v.name,sizeof(v.name),name,sizeof(v.name)-1);
4590    v.name[sizeof(v.name)-1]=0;
4591   }else
4592    v.name[0]=0;
4593   v.pl_tab_flag=pl_tab_flag;
4594  }
4595 
4596   otl_tmpl_variable():
4597     param_type(0),
4598     ftype(0),
4599     elem_size(0),
4600     array_size(0),
4601     name(0),
4602     pos(0),
4603     name_pos(0),
4604     bound(0),
4605     pl_tab_flag(0),
4606     var_struct()
4607  {
4608  }
4609 
4610  virtual ~otl_tmpl_variable()
4611  {
4612   delete[] name;
4613  }
4614 
4615  otl_tmpl_variable
4616  (const int column_num,
4617   const int aftype,
4618   const int aelem_size,
4619   const short aarray_size):
4620     param_type(0),
4621     ftype(0),
4622     elem_size(0),
4623     array_size(0),
4624     name(0),
4625     pos(0),
4626     name_pos(0),
4627     bound(0),
4628     pl_tab_flag(0),
4629     var_struct()
4630  {
4631   copy_pos(column_num);
4632   init(aftype,aelem_size,aarray_size);
4633  }
4634 
4635  otl_tmpl_variable
4636  (const char* aname,
4637   const int aftype,
4638   const int aelem_size,
4639   const short aarray_size,
4640   const int apl_tab_flag=0)
4641  {
4642   copy_name(aname);
4643   init
4644    (aftype,
4645     aelem_size,
4646     aarray_size,
4647     0,
4648     apl_tab_flag);
4649  }
4650 
4651  void init
4652  (const bool select_stm_flag,
4653   const int aftype,
4654   const int aelem_size,
4655   const otl_stream_buffer_size_type aarray_size,
4656   const void* connect_struct=0,
4657   const int apl_tab_flag=0)
4658  {
4659   ftype=aftype;
4660 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
4661   if(ftype==otl_var_nchar)
4662     ftype=otl_var_char;
4663   else if(ftype==otl_var_nclob)
4664     ftype=otl_var_clob;
4665 #endif
4666   elem_size=aelem_size;
4667   array_size=aarray_size;
4668   pl_tab_flag=apl_tab_flag;
4669   bound=0;
4670   var_struct.init(select_stm_flag,
4671                   aftype,
4672                   elem_size,
4673                   aarray_size,
4674                   connect_struct,
4675                   pl_tab_flag);
4676  }
4677 
4678  void set_param_type(const int aparam_type=otl_input_param)
4679  {
4680   param_type=aparam_type;
4681  }
4682 
4683  int get_param_type(void)
4684  {
4685   return param_type;
4686  }
4687 
4688  void copy_name(const char* aname)
4689  {
4690   pos=0;
4691   if(name==aname)return;
4692   if(name)delete[] name;
4693   size_t len=strlen(aname)+1;
4694   name=new char[len];
4695   OTL_STRCPY_S(name,len,aname);
4696  }
4697 
4698  void copy_pos(const int apos)
4699  {
4700   if(name){
4701    delete[] name;
4702    name=0;
4703    name_pos=0;
4704   }
4705   pos=apos;
4706  }
4707 
4708 
4709  void set_null(int ndx)
4710  {
4711   var_struct.set_null(ndx);
4712  }
4713 
4714  void set_not_null(int ndx)
4715  {
4716   var_struct.set_not_null(ndx,elem_size);
4717  }
4718 
4719   void set_len(int len, int ndx=0)
4720   {
4721     var_struct.set_len(len,ndx);
4722   }
4723 
4724  int get_len(int ndx=0)
4725  {
4726   return var_struct.get_len(ndx);
4727  }
4728 
4729  int get_pl_tab_len(void)
4730  {
4731   return this->var_struct.get_pl_tab_len();
4732  }
4733 
4734  int get_max_pl_tab_len(void)
4735  {
4736   return this->var_struct.get_max_pl_tab_len();
4737  }
4738 
4739  void set_pl_tab_len(const int pl_tab_len)
4740  {
4741   this->var_struct.set_pl_tab_len(pl_tab_len);
4742  }
4743 
4744  int is_null(int ndx)
4745  {
4746   return var_struct.is_null(ndx);
4747  }
4748 
4749  void* val(int ndx=0)
4750  {
4751   return var_struct.val(ndx,elem_size);
4752  }
4753 
4754  static void map_ftype
4755  (otl_column_desc& desc,
4756   const int max_long_size,
4757   int& aftype,
4758   int& aelem_size,
4759   otl_select_struct_override& override,
4760   const int column_ndx,
4761   const int connection_type)
4762  {
4763   TVariableStruct::map_ftype
4764     (desc,
4765      max_long_size,
4766      aftype,
4767      aelem_size,
4768      override,
4769      column_ndx,
4770      connection_type);
4771  }
4772 
4773  static int int2ext(int int_type)
4774  {
4775    return TVariableStruct::int2ext(int_type);
4776  }
4777 
4778 private:
4779 
4780   otl_tmpl_variable(const otl_tmpl_variable&):
4781     param_type(0),
4782     ftype(0),
4783     elem_size(0),
4784     array_size(0),
4785     name(0),
4786     pos(0),
4787     name_pos(0),
4788     bound(0),
4789     pl_tab_flag(0),
4790     var_struct()
4791  {
4792  }
4793 
4794  otl_tmpl_variable& operator=(const otl_tmpl_variable&)
4795  {
4796    return *this;
4797  }
4798 
4799 };
4800 
4801 template <OTL_TYPE_NAME TExceptionStruct,
4802           OTL_TYPE_NAME TConnectStruct,
4803           OTL_TYPE_NAME TCursorStruct,
4804           OTL_TYPE_NAME TVariableStruct>
4805 class otl_tmpl_cursor{
4806 protected:
4807 
4808   int connected;
4809   char* stm_text;
4810   char* stm_label;
4811 
4812  TCursorStruct cursor_struct;
4813  int vl_len;
4814  otl_tmpl_variable<TVariableStruct>** vl;
4815  OTL_TMPL_CONNECT* adb;
4816  int eof_data;
4817  int eof_desc;
4818  int retcode;
4819  long _rpc;
4820  int in_destructor;
4821 
4822 public:
4823 
4824   OTL_TMPL_CONNECT* get_adb(){return adb;}
4825   void set_adb(OTL_TMPL_CONNECT* aadb)
4826   {
4827     adb=aadb;
4828   }
4829 
4830   TCursorStruct& get_cursor_struct_ref(){return cursor_struct;}
4831 
4832   otl_tmpl_variable<TVariableStruct>** get_vl(){return vl;}
4833   int get_vl_len() const {return vl_len;}
4834 
4835   const char* get_stm_label() const
4836   {
4837     return stm_label;
4838   }
4839 
4840   const char* get_stm_text() const
4841   {
4842     return stm_text;
4843   }
4844 
4845   void set_connected(const int aconnected)
4846   {
4847     connected=aconnected;
4848   }
4849 
4850   int& get_eof_data_ref()
4851   {
4852     return eof_data;
4853   }
4854 
4855   TCursorStruct& get_cursor_struct()
4856   {
4857     return cursor_struct;
4858   }
4859 
4860   int get_connected() const
4861   {
4862     return connected;
4863   }
4864 
4865   otl_tmpl_cursor():
4866     connected(0),
4867     stm_text(0),
4868     stm_label(0),
4869     cursor_struct(),
4870     vl_len(0),
4871     vl(0),
4872     adb(0),
4873     eof_data(),
4874     eof_desc(),
4875     retcode(1),
4876     _rpc(0),
4877     in_destructor(0)
4878  {
4879  }
4880 
4881   otl_tmpl_cursor(OTL_TMPL_CONNECT& connect):
4882     connected(0),
4883     stm_text(0),
4884     stm_label(0),
4885     cursor_struct(),
4886     vl_len(0),
4887     vl(0),
4888     adb(&connect),
4889     eof_data(),
4890     eof_desc(),
4891     retcode(1),
4892     _rpc(0),
4893     in_destructor(0)
4894  {
4895   open(connect);
4896  }
4897 
4898  otl_tmpl_cursor
4899  (OTL_TMPL_CONNECT& connect,
4900   TVariableStruct* var):
4901     connected(0),
4902     stm_text(0),
4903     stm_label(0),
4904     cursor_struct(),
4905     vl_len(0),
4906     vl(0),
4907     adb(&connect),
4908     eof_data(),
4909     eof_desc(),
4910     retcode(1),
4911     _rpc(0),
4912     in_destructor(0)
4913  {
4914   open(connect,var);
4915  }
4916 
4917  virtual ~otl_tmpl_cursor()
4918  {
4919   in_destructor=1;
4920   close();
4921   delete[] stm_label;
4922   stm_label=0;
4923   delete[] stm_text;
4924   stm_text=0;
4925  }
4926 
4927  void open
4928  (OTL_TMPL_CONNECT& connect,
4929   TVariableStruct* var=0)
4930  {
4931   in_destructor=0;
4932   eof_data=0;
4933   eof_desc=0;
4934   retcode=1;
4935   adb=&connect;
4936   _rpc=0;
4937   if(var==0)
4938     retcode=cursor_struct.open(connect.get_connect_struct());
4939   else
4940     retcode=cursor_struct.open(connect.get_connect_struct(),var);
4941   if(retcode){
4942    connected=1;
4943    return;
4944   }
4945   if(this->adb)this->adb->increment_throw_count();
4946   if(this->adb&&this->adb->get_throw_count()>1)return;
4947    if(otl_uncaught_exception()) return;
4948   throw OTL_TMPL_EXCEPTION(cursor_struct);
4949  }
4950 
4951  virtual void close(void)
4952  {_rpc=0;
4953   if(!connected)return;
4954   if(!this->adb)return;
4955   if(!adb->connected){
4956    connected=0;
4957    adb=0;
4958    retcode=1;
4959    return;
4960   }
4961   connected=0;
4962   retcode=cursor_struct.close();
4963   if(retcode){
4964    adb=0;
4965    return;
4966   }
4967   if(this->adb->get_throw_count()>0){
4968    adb=0;
4969    return;
4970   }
4971   this->adb->increment_throw_count();
4972   adb=0;
4973    if(otl_uncaught_exception()) return;
4974   throw OTL_TMPL_EXCEPTION(cursor_struct);
4975  }
4976 
4977  void parse(void)
4978  {_rpc=0;
4979   if(!connected)return;
4980   retcode=cursor_struct.parse(stm_text);
4981   switch(retcode){
4982   case 0:
4983     if(this->adb)this->adb->increment_throw_count();
4984     if(this->adb&&this->adb->get_throw_count()>1)return;
4985     if(otl_uncaught_exception()) return;
4986     throw OTL_TMPL_EXCEPTION(cursor_struct,stm_label?stm_label:stm_text);
4987   case 2:
4988     if(this->adb)this->adb->increment_throw_count();
4989     if(this->adb&&this->adb->get_throw_count()>1)return;
4990     if(otl_uncaught_exception()) return;
4991     char var_info[1];
4992     var_info[0]=0;
4993     throw OTL_TMPL_EXCEPTION
4994      (otl_error_msg_17,
4995       otl_error_code_17,
4996       this->stm_label?this->stm_label:this->stm_text,
4997       var_info);
4998   }
4999  }
5000 
5001  void parse(const char* sqlstm)
5002  {
5003   if(!connected)return;
5004   if(stm_text){
5005    delete[] stm_text;
5006    stm_text=0;
5007   }
5008   size_t len=strlen(sqlstm)+1;
5009   stm_text=new char[len];
5010   OTL_STRCPY_S(stm_text,len,sqlstm);
5011   parse();
5012  }
5013 
5014  long get_rpc()
5015  {
5016   return _rpc;
5017  }
5018 
5019   void exec(const int iters/*=1*/,
5020             const int rowoff/*=0*/,
5021             const int otl_sql_exec_from_class/*=otl_sql_exec_from_cursor_class*/)
5022  {
5023   if(!connected)return;
5024   retcode=cursor_struct.exec(iters,rowoff,otl_sql_exec_from_class);
5025   _rpc=cursor_struct.get_rpc();
5026   if(retcode)return;
5027   if(this->adb)this->adb->increment_throw_count();
5028   if(this->adb&&this->adb->get_throw_count()>1)return;
5029   if(otl_uncaught_exception()) return;
5030   throw OTL_TMPL_EXCEPTION(cursor_struct,stm_label?stm_label:stm_text);
5031  }
5032 
5033   virtual bool valid_binding
5034   (const otl_tmpl_variable<TVariableStruct>& v,
5035    const int binding_type)
5036   {
5037     bool rc=true;
5038     if(((v.get_ftype()==otl_var_varchar_long||v.get_ftype()==otl_var_raw_long) &&
5039         (v.get_const_var_struct().get_otl_adapter()==otl_ora7_adapter||
5040          v.get_const_var_struct().get_otl_adapter()==otl_ora8_adapter) &&
5041         v.get_array_size()>1) ||
5042        ((v.get_ftype()==otl_var_blob||v.get_ftype()==otl_var_clob)&&
5043         v.get_const_var_struct().get_otl_adapter()==otl_ora8_adapter&&
5044         v.get_array_size()>1 &&
5045         binding_type==otl_inout_binding))
5046       rc=false;
5047     return rc;
5048   }
5049 
5050  virtual void bind
5051  (const char* name,
5052   otl_tmpl_variable<TVariableStruct>& v)
5053  {
5054   if(!connected)return;
5055   if(v.get_bound())return;
5056   v.copy_name(name);
5057   if(!valid_binding(v,otl_inout_binding)){
5058     char var_info[256];
5059     otl_var_info_var2
5060       (v.get_name(),
5061        v.get_ftype(),
5062        var_info,
5063        sizeof(var_info));
5064     if(this->adb)this->adb->increment_throw_count();
5065     if(this->adb&&this->adb->get_throw_count()>1)return;
5066     if(otl_uncaught_exception()) return;
5067     throw OTL_TMPL_EXCEPTION
5068      (otl_error_msg_16,
5069       otl_error_code_16,
5070       stm_label?stm_label:stm_text,
5071       var_info);
5072   }
5073   retcode=cursor_struct.bind
5074    (name,
5075     v.get_var_struct(),
5076     v.get_elem_size(),
5077     v.get_ftype(),
5078     v.get_param_type(),
5079     v.get_name_pos(),
5080     this->adb->get_connect_struct().get_connection_type(),
5081     v.get_pl_tab_flag());
5082   if(retcode){
5083     v.set_bound(1);
5084    return;
5085   }
5086   if(this->adb)this->adb->increment_throw_count();
5087   if(this->adb&&this->adb->get_throw_count()>1)return;
5088   if(otl_uncaught_exception()) return;
5089   throw OTL_TMPL_EXCEPTION(cursor_struct,stm_label?stm_label:stm_text);
5090  }
5091 
5092  virtual void bind
5093  (const int column_num,
5094   otl_tmpl_variable<TVariableStruct>& v)
5095  {
5096   if(!connected)return;
5097   v.copy_pos(column_num);
5098   if(!valid_binding(v,otl_select_binding)){
5099     char var_info[256];
5100     otl_var_info_col2
5101       (v.get_pos(),
5102        v.get_ftype(),
5103        var_info,
5104        sizeof(var_info));
5105     if(this->adb)this->adb->increment_throw_count();
5106     if(this->adb&&this->adb->get_throw_count()>1)return;
5107     if(otl_uncaught_exception()) return;
5108     throw OTL_TMPL_EXCEPTION
5109      (otl_error_msg_16,
5110       otl_error_code_16,
5111       stm_label?stm_label:stm_text,
5112       var_info);
5113   }
5114   retcode=cursor_struct.bind
5115    (column_num,
5116     v.get_var_struct(),
5117     v.get_elem_size(),
5118     v.get_ftype(),
5119     v.get_param_type());
5120   if(retcode)return;
5121   if(this->adb)this->adb->increment_throw_count();
5122   if(this->adb&&this->adb->get_throw_count()>1)return;
5123   if(otl_uncaught_exception()) return;
5124   throw OTL_TMPL_EXCEPTION(cursor_struct,stm_label?stm_label:stm_text);
5125  }
5126 
5127  virtual void bind(otl_tmpl_variable<TVariableStruct>& v)
5128  {
5129   if(!connected)return;
5130   if(v.get_name()) bind(v.get_name(),v);
5131   if(v.get_pos()) bind(v.get_pos(),v);
5132  }
5133 
5134 
5135   static long direct_exec
5136   (OTL_TMPL_CONNECT& connect,
5137    const char* sqlstm,
5138    const int exception_enabled=1)
5139 #if defined(OTL_ANSI_CPP) && defined(OTL_FUNC_THROW_SPEC_ON)
5140     throw(OTL_TMPL_EXCEPTION)
5141 #endif
5142   {
5143     connect.reset_throw_count();
5144     OTL_TRACE_DIRECT_EXEC
5145       try{
5146         OTL_TMPL_CURSOR cur(connect);
5147         cur.cursor_struct.set_direct_exec(1);
5148         cur.parse(sqlstm);
5149         cur.exec(1,0,otl_sql_exec_from_cursor_class);
5150         return cur.cursor_struct.get_rpc();
5151       }catch(OTL_CONST_EXCEPTION OTL_TMPL_EXCEPTION&){
5152         if(exception_enabled){
5153           connect.increment_throw_count();
5154           throw;
5155         }
5156       }
5157     return -1;
5158   }
5159 
5160   static void syntax_check
5161   (OTL_TMPL_CONNECT& connect,
5162    const char* sqlstm)
5163 #if defined(OTL_ANSI_CPP) && defined(OTL_FUNC_THROW_SPEC_ON)
5164     throw(OTL_TMPL_EXCEPTION)
5165 #endif
5166   {
5167     connect.reset_throw_count();
5168     OTL_TRACE_SYNTAX_CHECK
5169     OTL_TMPL_CURSOR cur(connect);
5170     cur.cursor_struct.set_direct_exec(1);
5171     cur.cursor_struct.set_parse_only(1);
5172     cur.parse(sqlstm);
5173   }
5174 
5175  int eof(void){return eof_data;}
5176 
5177  int describe_column
5178  (otl_column_desc& col,
5179   const int column_num)
5180  {
5181   if(!connected)return 0;
5182   retcode=cursor_struct.describe_column
5183    (col,column_num,eof_desc);
5184   if(eof_desc)return 0;
5185   if(retcode)return 1;
5186   if(this->adb)this->adb->increment_throw_count();
5187   if(this->adb&&this->adb->get_throw_count()>1)return 0;
5188   if(otl_uncaught_exception()) return 0;
5189   throw OTL_TMPL_EXCEPTION(cursor_struct,stm_label?stm_label:stm_text);
5190  }
5191 
5192 private:
5193 
5194   otl_tmpl_cursor(const otl_tmpl_cursor&):
5195     connected(0),
5196     stm_text(0),
5197     stm_label(0),
5198     cursor_struct(),
5199     vl_len(0),
5200     vl(0),
5201     adb(0),
5202     eof_data(),
5203     eof_desc(),
5204     retcode(1),
5205     _rpc(0),
5206     in_destructor(0)
5207  {
5208  }
5209 
5210   otl_tmpl_cursor& operator=(const otl_tmpl_cursor&)
5211   {
5212     return *this;
5213   }
5214 
5215 
5216 };
5217 
5218 inline int is_num(char c)
5219 {
5220   return c>='0' && c<='9';
5221 }
5222 
5223 template <OTL_TYPE_NAME TVariableStruct,
5224           OTL_TYPE_NAME TTimestampStruct,
5225           OTL_TYPE_NAME TExceptionStruct,
5226           OTL_TYPE_NAME TConnectStruct,
5227           OTL_TYPE_NAME TCursorStruct>
5228 class otl_tmpl_ext_hv_decl{
5229 private:
5230 
5231   char** hv;
5232   short int* inout;
5233   int* pl_tab_size;
5234   int array_size;
5235   int prev_array_size;
5236   short int vst[4];
5237   int len;
5238   char* stm_text_;
5239   char* stm_label_;
5240   int container_size_;
5241   bool has_plsql_tabs_or_refcur_;
5242 
5243 public:
5244 
5245   bool has_plsql_tabs_or_refcur() const {return has_plsql_tabs_or_refcur_;}
5246   short int get_vst(const int ndx) const {return vst[ndx];}
5247   int get_len() const {return len;}
5248   short int get_inout(const int ndx) const {return inout[ndx];}
5249   int get_pl_tab_size(const int ndx) const {return pl_tab_size[ndx];}
5250   const char* stm_label() const {return stm_label_;}
5251   const char* stm_text() const {return stm_text_;}
5252 
5253   enum var_status{
5254     in=0,
5255     out=1,
5256     io=2,
5257     def=3
5258   };
5259 
5260  otl_tmpl_ext_hv_decl(char* stm,
5261                       int arr_size=1,
5262                       char* label=0,
5263                       otl_select_struct_override** select_override=0,
5264                       OTL_TMPL_CONNECT* adb=0):
5265    hv(0),
5266    inout(0),
5267    pl_tab_size(0),
5268    array_size(0),
5269    prev_array_size(0),
5270    vst(),
5271    len(0),
5272    stm_text_(0),
5273    stm_label_(0),
5274    container_size_(0),
5275    has_plsql_tabs_or_refcur_(0)
5276   {
5277     container_size_=otl_var_list_size;
5278     hv=new char*[container_size_];
5279     inout=new short[container_size_];
5280     pl_tab_size=new int[container_size_];
5281     has_plsql_tabs_or_refcur_=false;
5282 
5283     int j;
5284     array_size=arr_size;
5285     prev_array_size=arr_size;
5286     stm_text_=stm;
5287     stm_label_=label;
5288     int i=0;
5289     short in_str=0;
5290     bool in_comment=false;
5291     bool in_one_line_comment=false;
5292     char *c=stm;
5293     bool in_comment_column_override=false;
5294     hv[i]=0;
5295     while(*c){
5296       switch(*c){
5297       case '\'':
5298         if(!in_comment&&!in_one_line_comment){
5299           if(!in_str)
5300             in_str=1;
5301           else{
5302             if(c[1]=='\'')
5303               ++c;
5304             else
5305               in_str=0;
5306           }
5307         }
5308         break;
5309       case '/':
5310         if(c[1]=='*' && !in_str && c[2]==':' && c[3]=='#'){
5311           in_comment_column_override=true;
5312           *c=' ';
5313           ++c;
5314           *c=' ';
5315           ++c;
5316         }else if(c[1]=='*'&&!in_str){
5317           in_comment=true;
5318           ++c;
5319         }
5320         break;
5321       case '-':
5322         if(c[1]=='-'&&!in_str){
5323           in_one_line_comment=true;
5324           ++c;
5325         }
5326         break;
5327       case '*':
5328         if(c[1]=='/' && in_comment){
5329           in_comment=false;
5330           ++c;
5331         }else if(c[1]=='/' && in_comment_column_override){
5332           *c=' ';
5333           ++c;
5334           *c=' ';
5335         }
5336         break;
5337       case '\n':
5338         if(in_one_line_comment)
5339           in_one_line_comment=false;
5340         break;
5341       }
5342       if(*c==':' && !in_str && !in_comment && !in_one_line_comment &&
5343          ((c>stm && *(c-1)!='\\') || c==stm)){
5344         char* bind_var_ptr=c;
5345         short in_out=def;
5346         int apl_tab_size=0;
5347         char var[64];
5348         char* v=var;
5349         *v++=*c++;
5350         while(is_id(*c))
5351           *v++=*c++;
5352         while(otl_isspace(*c)&&*c)
5353           ++c;
5354         if(*c=='<' || (*c=='/' && c[1]=='*')){
5355           if(*c=='<')
5356             *c=' ';
5357           else if(*c=='/'&&c[1]=='*'){
5358             *c=' ';
5359             ++c;
5360             *c=' ';
5361           }
5362           while(*c!='>' && *c!=',' && *c!='*' && *c){
5363             *v++=*c;
5364             *c++=' ';
5365           }
5366           if(*c==','){
5367             *c++=' ';
5368             if(otl_to_upper(*c)=='I'){
5369               if(otl_to_upper(c[2])=='O')
5370                 in_out=io;
5371               else
5372                 in_out=in;
5373             }else if(otl_to_upper(*c)=='O')
5374               in_out=out;
5375             while(*c!='>' && *c && *c!='*' && (*c!='[' && *c!='(') )
5376               *c++=' ';
5377             if(*c=='*'){
5378               *c=' ';
5379               ++c;
5380               *c=' ';
5381             }
5382             if(*c=='[' || *c=='('){
5383               char tmp[32];
5384               char *t=tmp;
5385               *c++=' ';
5386               while((*c!=']' && *c!=')') && *c!='>' && *c!='*' && *c){
5387                 *t++=*c;
5388                 *c++=' ';
5389               }
5390               if(*c=='*'){
5391                 *c=' ';
5392                 ++c;
5393                 *c=' ';
5394               }
5395               *t='\0';
5396               apl_tab_size=atoi(tmp);
5397               while(*c!='>' && *c!='*' && *c)
5398                 *c++=' ';
5399               if(*c=='*'){
5400                 *c=' ';
5401                 ++c;
5402                 *c=' ';
5403               }
5404             }
5405           }else if(*c=='*' && c[1]=='/'){
5406             *c=' ';
5407             ++c;
5408             *c=' ';
5409           }
5410           if(*c)*c=' ';
5411           *v='\0';
5412           if(select_override!=0 && bind_var_ptr[1]=='#'){
5413             char* c4=bind_var_ptr+2;
5414             char col_num[64];
5415             char* col_num_ptr=col_num;
5416             while(is_num(*c4) && *c4){
5417               *col_num_ptr=*c4;
5418               ++col_num_ptr;
5419               ++c4;
5420             }
5421             *col_num_ptr=0;
5422             int col_ndx=atoi(col_num);
5423             if(col_ndx>0){
5424               if(*select_override==0){
5425                 *select_override=new otl_select_struct_override();
5426               }
5427               int data_type=otl_var_none;
5428               int data_len=0;
5429               char name[128];
5430               parse_var
5431                 (adb,
5432                  var,
5433                  data_type,
5434                  data_len,
5435                  name);
5436               (*select_override)->add_override
5437                 (col_ndx,
5438                  data_type,
5439                  data_len);
5440             }
5441             c4=bind_var_ptr;
5442             while(*c4 && *c4!=' '){
5443               *c4=' ';
5444               ++c4;
5445             }
5446           }else
5447             add_var(i,var,in_out,apl_tab_size);
5448         }
5449       }
5450       if(*c)++c;
5451     }
5452     for(j=0;j<4;++j)vst[j]=0;
5453     i=0;
5454     while(hv[i]){
5455       switch(inout[i]){
5456       case in:
5457         ++vst[0];
5458         break;
5459       case out:
5460         ++vst[1];
5461         break;
5462       case io:
5463         ++vst[2];
5464         break;
5465       case def:
5466         ++vst[3];
5467         break;
5468       }
5469       ++i;
5470     }
5471     len=i;
5472  }
5473 
5474  virtual ~otl_tmpl_ext_hv_decl()
5475  {int i;
5476   for(i=0;hv[i]!=0;++i)
5477    delete[] hv[i];
5478   delete[] hv;
5479   delete[] inout;
5480   delete[] pl_tab_size;
5481  }
5482 
5483 
5484   char* operator[](int ndx){return hv[ndx];}
5485   short v_status(int ndx){return inout[ndx];}
5486   int is_id(char c){return isalnum(c)||c=='_'||c=='#';}
5487 
5488  int name_comp(char* n1,char* n2)
5489  {
5490   while(*n1!=' '&&*n1!='\0'&&*n2!=' '&&*n2!='\0'){
5491    if(otl_to_upper(*n1)!=otl_to_upper(*n2))return 0;
5492    ++n1;
5493    ++n2;
5494   }
5495   if((*n1==' '&&*n2!=' ')||(*n2==' '&&*n1!=' '))
5496    return 0;
5497   return 1;
5498  }
5499 
5500  void add_var(int &n,char* v,short in_out,int apl_tab_size=0)
5501  {int i;
5502   for(i=0;i<n;++i)
5503    if(name_comp(hv[i],v))
5504     return;
5505   char *c=v;
5506   bool is_space=false;
5507   while(*c){
5508     is_space=otl_isspace(*c);
5509     if(is_space) break;
5510     ++c;
5511   }
5512   if(is_space && otl_str_case_insensitive_equal((c+1),"REFCUR")){
5513     has_plsql_tabs_or_refcur_=true;
5514     if(apl_tab_size==0)
5515       apl_tab_size=1;
5516   }
5517   if(apl_tab_size>0)
5518     has_plsql_tabs_or_refcur_=true;
5519   size_t v_len=strlen(v)+1;
5520   hv[n]=new char[v_len];
5521   OTL_STRCPY_S(hv[n],v_len,v);
5522   inout[n]=in_out;
5523   pl_tab_size[n]=apl_tab_size;
5524   if(n==container_size_-1){
5525     int temp_container_size=container_size_;
5526     container_size_*=2;
5527     char** temp_hv=new char*[container_size_];
5528     short* temp_inout=new short[container_size_];
5529     int* temp_pl_tab_size=new int[container_size_];
5530     memcpy(temp_hv,hv,sizeof(char*)*temp_container_size);
5531     memcpy(temp_inout,inout,sizeof(short)*temp_container_size);
5532     memcpy(temp_pl_tab_size,pl_tab_size,sizeof(int)*temp_container_size);
5533     delete[] hv;
5534     delete[] inout;
5535     delete[] pl_tab_size;
5536     hv=temp_hv;
5537     inout=temp_inout;
5538     pl_tab_size=temp_pl_tab_size;
5539   }
5540   hv[++n]=0;
5541   inout[n]=def;
5542   pl_tab_size[n]=0;
5543  }
5544 
5545  int parse_var
5546  (OTL_TMPL_CONNECT* pdb,
5547   char* s,
5548   int& data_type,
5549   int& data_len,
5550   char* name)
5551  {
5552    data_type=otl_var_none;
5553    data_len=0;
5554 #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON)
5555   char type_arr[256];
5556 #endif
5557   char type=' ';
5558   char t2=' ';
5559   char t3=' ';
5560   char t4=' ';
5561   int size=0;
5562 
5563   char *c=name,*c1=s;
5564   while(*c1!=' '&&*c1)
5565    *c++=*c1++;
5566   *c=0;
5567   while(*c1==' '&&*c1)
5568    ++c1;
5569 
5570 #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON)
5571   char* ct=c1;
5572   char* tac=type_arr;
5573   size_t ta_len=0;
5574   while(*ct && (*ct!='[' && *ct!='(') && ta_len<sizeof(type_arr)){
5575     *tac=otl_to_upper(*ct);
5576     ++ct;
5577     ++tac;
5578     ++ta_len;
5579   }
5580   *tac=0;
5581 #endif
5582   size_t clen=strlen(c1);
5583   if(clen>=3){
5584     type=otl_to_upper(c1[0]);
5585     t2=otl_to_upper(c1[1]);
5586     t3=otl_to_upper(c1[2]);
5587     t4=otl_to_upper(c1[3]);
5588   }
5589   if((type=='C'&&t2=='H')||(type=='R'&&t2=='A'&&t3=='W'&&(t4=='['||t4=='('))){
5590    char tmp[32];
5591    char *t=tmp;
5592    while((*c1!='[' && *c1!='(')&&*c1)
5593     ++c1;
5594    ++c1;
5595    while((*c1!=']' && *c1!=')')&&*c1)
5596     *t++=*c1++;
5597    *t=0;
5598    size=atoi(tmp);
5599 #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE)
5600    size+=1;
5601 #endif
5602   }
5603 
5604 #if defined(OTL_ORA_UNICODE)
5605   if(type=='N'&&t2=='C'&&t3=='H'){
5606    char tmp[32];
5607    char *t=tmp;
5608    while((*c1!='[' && *c1!='(')&&*c1)
5609     ++c1;
5610    ++c1;
5611    while((*c1!=']' && *c1!=')')&&*c1)
5612     *t++=*c1++;
5613    *t=0;
5614    size=atoi(tmp);
5615 #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE)
5616    size+=1;
5617 #endif
5618   }
5619 #endif
5620 
5621   OTL_CHECK_BIND_VARS
5622 
5623   int rc=1;
5624   switch(type){
5625   case 'B':
5626     if(t2=='L'){
5627       data_type=otl_var_blob;
5628       if(pdb)
5629         data_len=pdb->get_max_long_size();
5630       else
5631         data_len=0;
5632     }
5633 #if defined(OTL_BIGINT) && \
5634     (defined(OTL_ODBC)||defined(OTL_DB2_CLI)||\
5635      (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
5636       !defined(OTL_BIGINT_TO_STR)))
5637     else if(t2=='I'){
5638       data_type=otl_var_bigint;
5639       data_len=sizeof(OTL_BIGINT);
5640     }
5641 #elif (defined(OTL_ORA7)||defined(OTL_ORA8)|| \
5642        defined(OTL_ORA8I)||defined(OTL_ORA9I)) && \
5643   defined(OTL_BIGINT) && defined(OTL_ORA_MAP_BIGINT_TO_LONG)
5644     else if(t2=='I'){
5645       data_type=otl_var_long_int;
5646       data_len=sizeof(long);
5647     }
5648 #elif (defined(OTL_ORA7)||defined(OTL_ORA8)|| \
5649        defined(OTL_ORA8I)||defined(OTL_ORA9I)) && \
5650        defined(OTL_BIGINT)
5651     else if(t2=='I'){
5652       data_type=otl_var_char;
5653       data_len=otl_bigint_str_size;
5654     }
5655 #endif
5656     break;
5657   case 'C':
5658     if(t2=='H'){
5659       data_type=otl_var_char;
5660       data_len=size;
5661     }else if(t2=='L'){
5662       data_type=otl_var_clob;
5663       if(pdb)
5664         data_len=pdb->get_max_long_size();
5665       else
5666         data_len=0;
5667     }else
5668       rc=0;
5669     break;
5670   case 'D':
5671     if(t2=='O'){
5672       data_type=otl_var_double;
5673       data_len=sizeof(double);
5674     }
5675     else if(t2=='B'&&t3=='2'){
5676       if(t4=='T'){
5677         data_type=otl_var_db2time;
5678         data_len=sizeof(TTimestampStruct);
5679       }
5680       else if(t4=='D'){
5681         data_type=otl_var_db2date;
5682         data_len=sizeof(TTimestampStruct);
5683       }else
5684         rc=0;
5685    }else
5686      rc=0;
5687    break;
5688 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
5689   case 'N':
5690     if(t2=='C'){
5691       if(t3=='L'){
5692         data_type=otl_var_nclob;
5693         if(pdb)
5694           data_len=pdb->get_max_long_size();
5695         else
5696           data_len=0;
5697       }else if(t3=='H'){
5698         data_type=otl_var_nchar;
5699         data_len=size;
5700       }
5701     }
5702    break;
5703 #endif
5704   case 'F':
5705     data_type=otl_var_float;
5706     data_len=sizeof(float);
5707     break;
5708   case 'I':
5709     data_type=otl_var_int;
5710     data_len=sizeof(int);
5711     break;
5712   case 'U':
5713     data_type=otl_var_unsigned_int;
5714     data_len=sizeof(unsigned);
5715    break;
5716   case 'R':
5717     if(t2=='E'&&t3=='F'){
5718       data_type=otl_var_refcur;
5719       data_len=1;
5720     }else if(t2=='A'&&t3=='W'&&t4!='_'){
5721       data_type=otl_var_raw;
5722       data_len=size;
5723     }else if(t2=='A'&&t3=='W'&&t4=='_'){
5724       data_type=otl_var_raw_long;
5725       if(pdb)
5726         data_len=pdb->get_max_long_size();
5727       else
5728         data_len=0;
5729     }
5730     break;
5731   case 'S':
5732     data_type=otl_var_short;
5733     data_len=sizeof(short);
5734     break;
5735   case 'L':
5736     if(t2=='O'&&t3=='N'){
5737       data_type=otl_var_long_int;
5738       data_len=sizeof(long);
5739     }else if(t2=='T'&&t3=='Z'){
5740       data_type=otl_var_ltz_timestamp;
5741       data_len=sizeof(TTimestampStruct);
5742     }else
5743       rc=0;
5744     break;
5745   case 'T':
5746     if(t2=='Z'){
5747       data_type=otl_var_tz_timestamp;
5748       data_len=sizeof(TTimestampStruct);
5749     }else if(t2=='I' && t3=='M'){
5750       data_type=otl_var_timestamp;
5751       data_len=sizeof(TTimestampStruct);
5752     }else
5753       rc=0;
5754     break;
5755   case 'V':
5756     data_type=otl_var_varchar_long;
5757     if(pdb)
5758       data_len=pdb->get_max_long_size();
5759     else
5760       data_len=0;
5761    break;
5762   default:
5763     return 0;
5764   }
5765   return rc;
5766  }
5767 
5768  otl_tmpl_variable<TVariableStruct>* alloc_var
5769  (char* s,
5770   const int vstat,
5771   const int status,
5772   OTL_TMPL_CONNECT& adb,
5773   const int apl_tab_size=0)
5774  {
5775    char name[128];
5776 #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON)
5777    char type_arr[256];
5778 #endif
5779    char type=' ';
5780    char t2=' ';
5781    char t3=' ';
5782    char t4=' ';
5783    char t5=' ';
5784 
5785    int size=0;
5786 
5787    char *c=name,*c1=s;
5788    while(*c1!=' '&&*c1)
5789      *c++=*c1++;
5790    *c=0;
5791    while(*c1==' '&&*c1)
5792      ++c1;
5793 
5794 #if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON)
5795    char* ct=c1;
5796    char* tac=type_arr;
5797    size_t ta_len=0;
5798    while(*ct && (*ct!='[' && *ct!='(') && ta_len<sizeof(type_arr)){
5799      *tac=otl_to_upper(*ct);
5800      ++ct;
5801      ++tac;
5802      ++ta_len;
5803    }
5804    *tac=0;
5805 #endif
5806    size_t clen=strlen(c1);
5807    if(clen>=3){
5808      type=otl_to_upper(c1[0]);
5809      t2=otl_to_upper(c1[1]);
5810      t3=otl_to_upper(c1[2]);
5811      t4=otl_to_upper(c1[3]);
5812    }
5813    if(clen>4)
5814      t5=otl_to_upper(c1[4]);
5815    if((type=='C'&&t2=='H')||(type=='R'&&t2=='A'&&t3=='W'&&(t4=='['||t4=='('))){
5816      char tmp[32];
5817      char *t=tmp;
5818      while((*c1!='[' && *c1!='(')&&*c1)
5819        ++c1;
5820      if(*c1)++c1;
5821      while((*c1!=']' && *c1!=')')&&*c1)
5822        *t++=*c1++;
5823      *t=0;
5824      if(*tmp==0)
5825        // declaration <char> is invalid
5826        return 0;
5827      size=atoi(tmp);
5828 #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE)
5829      if(type=='C')size+=1;
5830 #endif
5831      if(size<2)
5832        // minimum size of <char[XXX]> should be at 2
5833        return 0;
5834    }
5835 
5836 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
5837    if(type=='N'&&t2=='C'&&t3=='H'){
5838      char tmp[32];
5839      char *t=tmp;
5840      while((*c1!='[' && *c1!='(')&&*c1)
5841        ++c1;
5842      if(*c1)++c1;
5843      while((*c1!=']' && *c1!=')')&&*c1)
5844        *t++=*c1++;
5845      *t=0;
5846      if(*tmp==0)
5847        return 0;
5848      size=atoi(tmp);
5849 #if defined(OTL_ADD_NULL_TERMINATOR_TO_STRING_SIZE)
5850      size+=1;
5851 #endif
5852    }
5853 #endif
5854 
5855 
5856    if(status==in && (vstat==in||vstat==io))
5857      ;
5858    else if(status==out && (vstat==out||vstat==io||vstat==def))
5859      ;
5860    else if(status==def)
5861      ;
5862    else
5863      return 0;
5864 
5865    OTL_CHECK_BIND_VARS
5866 
5867      int pl_tab_flag=0;
5868 
5869    if(apl_tab_size){
5870      array_size=apl_tab_size;
5871      pl_tab_flag=1;
5872    }else
5873      array_size=prev_array_size;
5874 
5875    otl_tmpl_variable<TVariableStruct>* v=
5876      new otl_tmpl_variable<TVariableStruct>;
5877    v->copy_name(name);
5878    switch(type){
5879    case 'B':
5880      if(t2=='L')
5881        v->init(false,
5882                otl_var_blob,
5883                adb.get_max_long_size(),
5884                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5885                &adb.get_connect_struct());
5886 #if defined(OTL_BIGINT) && \
5887   (defined(OTL_ODBC)||defined(OTL_DB2_CLI)||\
5888    (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
5889       !defined(OTL_BIGINT_TO_STR)))
5890      else if(t2=='I')
5891        v->init(false,
5892                otl_var_bigint,sizeof(OTL_BIGINT),
5893                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5894                &adb.get_connect_struct(),pl_tab_flag);
5895 #elif (defined(OTL_ORA7)||defined(OTL_ORA8)|| \
5896        defined(OTL_ORA8I)||defined(OTL_ORA9I)) && \
5897        defined(OTL_BIGINT) && defined(OTL_ORA_MAP_BIGINT_TO_LONG)
5898      else if(t2=='I')
5899        v->init(false,
5900                otl_var_long_int,
5901                sizeof(long),
5902                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5903                &adb.get_connect_struct(),
5904                pl_tab_flag);
5905 #elif (defined(OTL_ORA7)||defined(OTL_ORA8)|| \
5906        defined(OTL_ORA8I)||defined(OTL_ORA9I)) && \
5907        defined(OTL_BIGINT)
5908      else if(t2=='I')
5909        v->init(false,
5910                otl_var_char,
5911                otl_bigint_str_size,
5912                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5913                &adb.get_connect_struct(),
5914                pl_tab_flag);
5915 #endif
5916      break;
5917 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
5918    case 'N':
5919      if(t2=='C' && (t3=='L'||t3=='H')){
5920        if(t3=='L'){
5921          v->init(false,otl_var_nclob,
5922                  adb.get_max_long_size(),
5923                  OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5924                  &adb.get_connect_struct());
5925          v->set_ftype(otl_var_clob);
5926        }else if(t3=='H'){
5927          v->init(false,otl_var_nchar,
5928                  size,
5929                  OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5930                  &adb.get_connect_struct(),pl_tab_flag);
5931          v->set_ftype(otl_var_char);
5932        }
5933      }else{
5934        delete v;
5935        v=0;
5936      }
5937      break;
5938 #endif
5939    case 'C':
5940      if(t2=='H'){
5941        v->init(false,otl_var_char,
5942                size,
5943                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5944                &adb.get_connect_struct(),pl_tab_flag);
5945        if(t5=='Z')
5946          v->get_var_struct().set_charz_flag(true);
5947      }else if(t2=='L')
5948        v->init(false,otl_var_clob,
5949                adb.get_max_long_size(),
5950                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5951                &adb.get_connect_struct());
5952      else{
5953        delete v;
5954        v=0;
5955      }
5956      break;
5957    case 'D':
5958      if(t2=='O')
5959        v->init(false,otl_var_double,sizeof(double),
5960                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5961                &adb.get_connect_struct(),pl_tab_flag);
5962      else if(t2=='B'&&t3=='2'){
5963        if(t4=='T')
5964          v->init(false,otl_var_db2time,sizeof(TTimestampStruct),
5965                  OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5966                  &adb.get_connect_struct(),pl_tab_flag);
5967        else if(t4=='D')
5968          v->init(false,otl_var_db2date,sizeof(TTimestampStruct),
5969                  OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5970                  &adb.get_connect_struct(),pl_tab_flag);
5971        else{
5972          delete v;
5973          v=0;
5974        }
5975      }else{
5976        delete v;
5977        v=0;
5978      }
5979      break;
5980    case 'F':
5981      v->init(false,otl_var_float,
5982              sizeof(float),
5983              OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5984              &adb.get_connect_struct(),pl_tab_flag);
5985      break;
5986    case 'I':
5987      v->init(false,otl_var_int,
5988              sizeof(int),
5989              OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5990              &adb.get_connect_struct(),pl_tab_flag);
5991      break;
5992    case 'U':
5993      v->init(false,otl_var_unsigned_int,
5994              sizeof(unsigned),
5995              OTL_SCAST(const otl_stream_buffer_size_type,array_size),
5996              &adb.get_connect_struct(),pl_tab_flag);
5997      break;
5998    case 'R':
5999      if(t2=='E'&&t3=='F')
6000        v->init(false,otl_var_refcur,
6001                1,
6002                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6003                &adb.get_connect_struct(),0);
6004      else if(t2=='A'&&t3=='W'&&(t4=='['||t4=='('))
6005        v->init(false,otl_var_raw,
6006                size,
6007                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6008                &adb.get_connect_struct(),pl_tab_flag);
6009      else if(t2=='A'&&t3=='W')
6010        v->init(false,otl_var_raw_long,
6011                adb.get_max_long_size(),
6012                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6013                &adb.get_connect_struct());
6014      break;
6015    case 'S':
6016      v->init(false,otl_var_short,
6017              sizeof(short),
6018              OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6019              &adb.get_connect_struct(),pl_tab_flag);
6020      break;
6021    case 'L':
6022      if(t2=='O'&&t3=='N')
6023        v->init(false,otl_var_long_int,
6024                sizeof(long),
6025                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6026                &adb.get_connect_struct(),pl_tab_flag);
6027      else if(t2=='T'&&t3=='Z')
6028        v->init(false,otl_var_ltz_timestamp,
6029                sizeof(TTimestampStruct),
6030                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6031                &adb.get_connect_struct(),pl_tab_flag);
6032      else{
6033        delete v;
6034        v=0;
6035      }
6036      break;
6037    case 'T':
6038      if(t2=='Z')
6039        v->init(false,otl_var_tz_timestamp,sizeof(TTimestampStruct),
6040                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6041                &adb.get_connect_struct(),pl_tab_flag);
6042      else if(t2=='I' && t3=='M')
6043        v->init(false,otl_var_timestamp,sizeof(TTimestampStruct),
6044                OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6045                &adb.get_connect_struct(),pl_tab_flag);
6046      else{
6047        delete v;
6048        v=0;
6049      }
6050      break;
6051    case 'V':
6052      v->init(false,otl_var_varchar_long,adb.get_max_long_size(),
6053              OTL_SCAST(const otl_stream_buffer_size_type,array_size),
6054              &adb.get_connect_struct());
6055      break;
6056    default:
6057      delete v;
6058      v=0;
6059      break;
6060    }
6061    return v;
6062  }
6063 
6064  void alloc_host_var_list
6065  (otl_tmpl_variable<TVariableStruct>** &vl,
6066   int& vl_len,
6067   OTL_TMPL_CONNECT& adb,
6068   const int status=def)
6069  {
6070   int j;
6071   vl_len=0;
6072   if(!hv[0]){
6073    vl=0;
6074    return;
6075   }
6076   otl_auto_array_ptr<otl_tmpl_variable<TVariableStruct>*>
6077     loc_ptr(container_size_);
6078   otl_tmpl_variable<TVariableStruct>** tmp_vl=loc_ptr.get_ptr();
6079   int i=0;
6080   while(hv[i]){
6081     otl_tmpl_variable<TVariableStruct>* vp=
6082       alloc_var(hv[i],inout[i],status,adb,pl_tab_size[i]);
6083     if(vp==0){
6084       int j2;
6085       for(j2=0;j2<vl_len;++j2)
6086         delete tmp_vl[j2];
6087       vl_len=0;
6088       throw OTL_TMPL_EXCEPTION
6089         (otl_error_msg_12,
6090          otl_error_code_12,
6091          stm_label_?stm_label_:stm_text_,
6092          hv[i]);
6093     }
6094     vp->set_name_pos(i+1);
6095     if(vp){
6096       ++vl_len;
6097       tmp_vl[vl_len-1]=vp;
6098     }
6099     ++i;
6100   }
6101   if(vl_len>0){
6102    vl=new otl_tmpl_variable<TVariableStruct>*[vl_len];
6103    for(j=0;j<vl_len;++j)
6104     vl[j]=tmp_vl[j];
6105   }
6106  }
6107 
6108 private:
6109 
6110  otl_tmpl_ext_hv_decl
6111  (const otl_tmpl_ext_hv_decl
6112   <TVariableStruct,
6113    TTimestampStruct,
6114    TExceptionStruct,
6115    TConnectStruct,
6116    TCursorStruct>&):
6117    hv(0),
6118    inout(0),
6119    pl_tab_size(0),
6120    array_size(0),
6121    prev_array_size(0),
6122    vst(),
6123    len(0),
6124    stm_text_(0),
6125    stm_label_(0),
6126    container_size_(0),
6127    has_plsql_tabs_or_refcur_(0)
6128  {
6129  }
6130 
6131 otl_tmpl_ext_hv_decl
6132   <TVariableStruct,
6133    TTimestampStruct,
6134    TExceptionStruct,
6135    TConnectStruct,
6136    TCursorStruct>&
6137 operator=
6138 (const otl_tmpl_ext_hv_decl
6139   <TVariableStruct,
6140    TTimestampStruct,
6141    TExceptionStruct,
6142    TConnectStruct,
6143    TCursorStruct>&)
6144  {
6145    return *this;
6146  }
6147 
6148 };
6149 
6150 template <OTL_TYPE_NAME TExceptionStruct,
6151           OTL_TYPE_NAME TConnectStruct,
6152           OTL_TYPE_NAME TCursorStruct,
6153           OTL_TYPE_NAME TVariableStruct,
6154           OTL_TYPE_NAME TSelectCursorStruct>
6155 class otl_tmpl_select_cursor: public OTL_TMPL_CURSOR{
6156 
6157 protected:
6158 
6159   int cur_row;
6160   int cur_size;
6161   int row_count;
6162   int array_size;
6163   int prefetch_array_size;
6164 
6165   TSelectCursorStruct select_cursor_struct;
6166   otl_select_struct_override local_override;
6167   void* master_stream_ptr_;
6168 
6169 public:
6170 
6171  otl_tmpl_select_cursor
6172  (OTL_TMPL_CONNECT& pdb,
6173   void* master_stream_ptr,
6174   const otl_stream_buffer_size_type arr_size=1,
6175   const char* sqlstm_label=0):
6176    OTL_TMPL_CURSOR(pdb),
6177    cur_row(-1),
6178    cur_size(0),
6179    row_count(0),
6180    array_size(0),
6181    prefetch_array_size(0),
6182    select_cursor_struct(),
6183    local_override(),
6184    master_stream_ptr_(master_stream_ptr)
6185  {
6186    local_override.reset();
6187    if(sqlstm_label!=0){
6188      if(this->stm_label!=0){
6189        delete[] this->stm_label;
6190        this->stm_label=0;
6191      }
6192      size_t len=strlen(sqlstm_label)+1;
6193      this->stm_label=new char[len];
6194      OTL_STRCPY_S(this->stm_label,len,sqlstm_label);
6195    }
6196    select_cursor_struct.set_arr_size
6197      (arr_size,
6198       array_size,
6199       prefetch_array_size);
6200    select_cursor_struct.init(array_size);
6201  }
6202 
6203  otl_tmpl_select_cursor()
6204    : OTL_TMPL_CURSOR(),
6205      master_stream_ptr_(0)
6206  {
6207  }
6208 
6209  void open
6210  (OTL_TMPL_CONNECT& db,
6211   otl_stream_buffer_size_type  arr_size=1)
6212  {
6213    local_override.reset();
6214    cur_row=-1;
6215    row_count=0;
6216    cur_size=0;
6217    array_size=arr_size;
6218    OTL_TMPL_CURSOR::open(db);
6219  }
6220 
6221  void close(void)
6222  {
6223    local_override.reset();
6224    OTL_TMPL_CURSOR::close();
6225  }
6226 
6227  int first(void)
6228  {
6229   if(!OTL_TMPL_CURSOR::connected)return 0;
6230   select_cursor_struct.set_prefetch_size(prefetch_array_size);
6231   int rc=select_cursor_struct.first
6232    (this->cursor_struct,
6233     cur_row,cur_size,
6234     row_count,
6235     this->eof_data,
6236     array_size);
6237   OTL_TRACE_FIRST_FETCH
6238   if(!rc){
6239    if(this->adb)this->adb->increment_throw_count();
6240    if(this->adb&&this->adb->get_throw_count()>1)return 0;
6241    if(otl_uncaught_exception()) return 0;
6242    throw OTL_TMPL_EXCEPTION
6243      (this->cursor_struct,
6244       this->stm_label?
6245       this->stm_label:
6246       this->stm_text);
6247   }
6248   return cur_size!=0;
6249  }
6250 
6251   int next_throw(void)
6252   {
6253     if(this->adb)this->adb->increment_throw_count();
6254     if(this->adb&&this->adb->get_throw_count()>1)return 0;
6255     if(otl_uncaught_exception()) return 0;
6256 
6257     throw OTL_TMPL_EXCEPTION
6258       (this->cursor_struct,
6259        this->stm_label?
6260        this->stm_label:
6261        this->stm_text);
6262   }
6263 
6264  int next(void)
6265  {
6266   if(!this->connected)return 0;
6267   if(cur_row==-1)return first();
6268   int rc=select_cursor_struct.next
6269    (this->cursor_struct,
6270     cur_row,cur_size,
6271     row_count,
6272     this->eof_data,
6273     array_size);
6274   if(!rc){
6275     return next_throw();
6276   }
6277   OTL_TRACE_NEXT_FETCH
6278   return cur_size!=0;
6279  }
6280 
6281 private:
6282 
6283  otl_tmpl_select_cursor
6284  (const otl_tmpl_select_cursor&):
6285    OTL_TMPL_CURSOR(),
6286    cur_row(-1),
6287    cur_size(0),
6288    row_count(0),
6289    array_size(0),
6290    prefetch_array_size(0),
6291    select_cursor_struct(),
6292    local_override()
6293  {
6294  }
6295 
6296  otl_tmpl_select_cursor& operator=
6297  (const otl_tmpl_select_cursor&)
6298  {
6299    return *this;
6300  }
6301 
6302 };
6303 
6304 #if defined(OTL_ORA8)||defined(OTL_ODBC)
6305 
6306 const int otl_lob_stream_read_mode=1;
6307 const int otl_lob_stream_write_mode=2;
6308 const int otl_lob_stream_zero_mode=3;
6309 
6310 const int otl_lob_stream_first_piece=1;
6311 const int otl_lob_stream_next_piece=2;
6312 const int otl_lob_stream_last_piece=3;
6313 
6314 class otl_lob_stream_generic{
6315 protected:
6316 
6317  int mode;
6318  int retcode;
6319  int ndx;
6320  int offset;
6321  int lob_len;
6322  int in_destructor;
6323  int eof_flag;
6324  int lob_is_null;
6325  bool ora_lob;
6326 
6327 public:
6328 
6329   int get_ora_lob() const {return ora_lob;}
6330 
6331 
6332   otl_lob_stream_generic(const bool aora_lob=true):
6333     mode(0),
6334     retcode(0),
6335     ndx(0),
6336     offset(0),
6337     lob_len(0),
6338     in_destructor(0),
6339     eof_flag(0),
6340     lob_is_null(0),
6341     ora_lob(aora_lob)
6342  {
6343  }
6344 
6345  virtual ~otl_lob_stream_generic(){}
6346 
6347  virtual void init
6348  (void* avar,void* aconnect,void* acursor,int andx,
6349   int amode,const int alob_is_null=0) = 0;
6350  virtual void set_len(const int new_len=0) = 0;
6351  virtual otl_lob_stream_generic& operator<<(const otl_long_string& s) = 0;
6352  virtual otl_lob_stream_generic& operator>>(otl_long_string& s) = 0;
6353 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_UNICODE)
6354   virtual otl_lob_stream_generic& operator<<(const OTL_STRING_CONTAINER& s) = 0;
6355   virtual otl_lob_stream_generic& operator>>(OTL_STRING_CONTAINER& s) = 0;
6356   virtual  void setStringBuffer(const int chunk_size) = 0;
6357 #endif
6358 
6359  virtual int eof(void) = 0;
6360  virtual int len(void) = 0;
6361  virtual bool is_initialized(void) = 0;
6362  virtual void close(void) = 0;
6363 
6364 private:
6365 
6366   otl_lob_stream_generic(const otl_lob_stream_generic&):
6367     mode(0),
6368     retcode(0),
6369     ndx(0),
6370     offset(0),
6371     lob_len(0),
6372     in_destructor(0),
6373     eof_flag(0),
6374     lob_is_null(0),
6375     ora_lob(false)
6376   {
6377   }
6378 
6379   otl_lob_stream_generic& operator=(const otl_lob_stream_generic&)
6380   {
6381     return *this;
6382   }
6383 
6384 };
6385 
6386 #endif
6387 
6388 #if defined(__GNUC__) || defined(__SUNPRO_CC) ||   \
6389     (defined(_MSC_VER) && (_MSC_VER <= 1300)) ||   \
6390      defined(__HP_aCC) || defined(__BORLANDC__) || \
6391     ((defined(__IBMC__) || defined(__IBMCPP__)) && defined(__xlC__))
6392   // Enable the kludge for compilers that do not support template
6393   // member functions at all, or have bugs: g++, Forte C++ (Solaris),
6394   // Visual C++ 6.0, Visual C++ 7.0, xlC v6, etc.
6395 #if !defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
6396 #define OTL_NO_TMPL_MEMBER_FUNC_SUPPORT
6397 #endif
6398 #endif
6399 
6400 template <OTL_TYPE_NAME TExceptionStruct,
6401           OTL_TYPE_NAME TConnectStruct,
6402           OTL_TYPE_NAME TCursorStruct,
6403           OTL_TYPE_NAME TVariableStruct,
6404           OTL_TYPE_NAME TSelectCursorStruct,
6405           OTL_TYPE_NAME TTimestampStruct>
6406 class otl_tmpl_select_stream: public OTL_TMPL_SELECT_CURSOR{
6407 
6408 protected:
6409 
6410  otl_column_desc* sl_desc;
6411  otl_tmpl_variable<TVariableStruct>* sl;
6412  int sl_len;
6413  int null_fetched;
6414  int cur_col;
6415  int cur_in;
6416  int executed;
6417  int eof_status;
6418  char var_info[256];
6419  otl_select_struct_override* override;
6420  int delay_next;
6421  bool lob_stream_mode;
6422  long _rfc;
6423 
6424 public:
6425 
6426   int get_select_row_count() const
6427   {
6428     return this->cur_row==-1?0:this->cur_size-this->cur_row;
6429   }
6430 
6431   int get_prefetched_row_count() const {return this->row_count;}
6432   int get_row_count() const {return this->row_count;}
6433   int get_sl_len() const {return sl_len;}
6434   otl_tmpl_variable<TVariableStruct>* get_sl(){return sl;}
6435   otl_column_desc* get_sl_desc(){return sl_desc;}
6436   long get_rfc() const {return _rfc;}
6437 
6438  void cleanup(void)
6439  {int i;
6440   delete[] sl;
6441   for(i=0;i<this->vl_len;++i)
6442    delete this->vl[i];
6443   delete[] this->vl;
6444   delete[] sl_desc;
6445  }
6446 
6447  virtual ~otl_tmpl_select_stream()
6448  {
6449   cleanup();
6450  }
6451 
6452  otl_tmpl_select_stream
6453  (otl_select_struct_override* aoverride,
6454   const otl_stream_buffer_size_type arr_size,
6455   const char* sqlstm,
6456   OTL_TMPL_CONNECT& pdb,
6457   const int implicit_select=otl_explicit_select,
6458   const char* sqlstm_label=0)
6459    : OTL_TMPL_SELECT_CURSOR
6460      (pdb,
6461       aoverride->get_master_stream_ptr(),
6462       arr_size,sqlstm_label),
6463      sl_desc(0),
6464      sl(0),
6465      sl_len(0),
6466      null_fetched(0),
6467      cur_col(0),
6468      cur_in(0),
6469      executed(0),
6470      eof_status(0),
6471      var_info(),
6472      override(0),
6473      delay_next(0),
6474      lob_stream_mode(false),
6475      _rfc(0)
6476  {
6477    int i;
6478    this->select_cursor_struct.set_select_type(implicit_select);
6479    sl=0;
6480    sl_len=0;
6481    _rfc=0;
6482    null_fetched=0;
6483    lob_stream_mode=aoverride->get_lob_stream_mode();
6484    this->retcode=0;
6485    sl_desc=0;
6486    executed=0;
6487    cur_in=0;
6488    this->stm_text=0;
6489    eof_status=1;
6490    override=aoverride;
6491 
6492    {
6493      size_t len=strlen(sqlstm)+1;
6494      this->stm_text=new char[len];
6495      OTL_STRCPY_S(this->stm_text,len,sqlstm);
6496      otl_select_struct_override* temp_local_override=&this->local_override;
6497      otl_tmpl_ext_hv_decl
6498        <TVariableStruct,TTimestampStruct,TExceptionStruct,
6499        TConnectStruct,TCursorStruct> hvd
6500        (this->stm_text,
6501         1,
6502         this->stm_label,
6503         &temp_local_override,
6504         &pdb
6505          );
6506      hvd.alloc_host_var_list(this->vl,this->vl_len,pdb);
6507    }
6508 
6509    try{
6510      this->parse();
6511      if(!this->select_cursor_struct.get_implicit_cursor()){
6512        get_select_list();
6513        bind_all();
6514      }else{
6515        for(i=0;i<this->vl_len;++i)
6516          this->bind(*this->vl[i]);
6517      }
6518      if(this->vl_len==0){
6519        rewind();
6520        null_fetched=0;
6521      }
6522    }catch(OTL_CONST_EXCEPTION OTL_TMPL_EXCEPTION&){
6523      cleanup();
6524      if(this->adb)this->adb->increment_throw_count();
6525      throw;
6526    }
6527 
6528  }
6529 
6530  void rewind(void)
6531  {
6532   OTL_TRACE_STREAM_EXECUTION
6533   int i;
6534   _rfc=0;
6535   if(!this->select_cursor_struct.close_select(this->cursor_struct)){
6536    throw OTL_TMPL_EXCEPTION
6537     (this->cursor_struct,
6538      this->stm_label?this->stm_label:this->stm_text);
6539   }
6540   if(this->select_cursor_struct.get_implicit_cursor()){
6541     this->exec(1,0,otl_sql_exec_from_select_cursor_class);
6542    if(sl){
6543     delete[] sl;
6544     sl=0;
6545    }
6546    get_select_list();
6547    for(i=0;i<sl_len;++i)this->bind(sl[i]);
6548   }
6549   eof_status=this->first();
6550   null_fetched=0;
6551   cur_col=-1;
6552   cur_in=0;
6553   executed=1;
6554   delay_next=0;
6555  }
6556 
6557   void clean(void)
6558   {
6559     _rfc=0;
6560     this->cursor_struct.set_canceled(false);
6561     null_fetched=0;
6562     cur_col=-1;
6563     cur_in=0;
6564     executed=0;
6565     eof_status=0;
6566     delay_next=0;
6567     this->cur_row=-1;
6568     this->row_count=0;
6569     this->cur_size=0;
6570     if(!this->select_cursor_struct.close_select(this->cursor_struct)){
6571       throw OTL_TMPL_EXCEPTION
6572         (this->cursor_struct,
6573          this->stm_label?this->stm_label:this->stm_text);
6574     }
6575   }
6576 
6577  int is_null(void)
6578  {
6579   return null_fetched;
6580  }
6581 
6582  int eof(void)
6583  {
6584   if(delay_next){
6585    look_ahead();
6586    delay_next=0;
6587   }
6588   return !eof_status;
6589  }
6590 
6591  int eof_intern(void)
6592  {
6593   return !eof_status;
6594  }
6595 
6596 
6597  void skip_to_end_of_row()
6598  {
6599    check_if_executed();
6600    if(eof_intern())return;
6601    while(cur_col<sl_len-1){
6602      ++cur_col;
6603      null_fetched=sl[cur_col].is_null(this->cur_row);
6604    }
6605    eof_status=this->next();
6606    cur_col=0;
6607    if(!eof_intern())
6608      cur_col=-1;
6609   ++_rfc;
6610  }
6611 
6612  void bind_all(void)
6613  {int i;
6614   for(i=0;i<this->vl_len;++i)this->bind(*this->vl[i]);
6615   for(i=0;i<sl_len;++i)this->bind(sl[i]);
6616  }
6617 
6618  void get_select_list(void)
6619  {
6620    int j;
6621    otl_auto_array_ptr<otl_column_desc> loc_ptr(otl_var_list_size);
6622    otl_column_desc* sl_desc_tmp=loc_ptr.get_ptr();
6623    int sld_tmp_len=0;
6624    int ftype,elem_size,i;
6625    for(i=1;this->describe_column(sl_desc_tmp[i-1],i);++i){
6626      int temp_code_type=
6627        otl_tmpl_variable<TVariableStruct>::int2ext
6628        (sl_desc_tmp[i-1].dbtype);
6629      if(temp_code_type==otl_unsupported_type){
6630        otl_var_info_col3
6631          (i-1,
6632           sl_desc_tmp[i-1].dbtype,
6633           sl_desc_tmp[i-1].name,
6634           this->var_info,
6635           sizeof(this->var_info));
6636        throw OTL_TMPL_EXCEPTION
6637          (otl_error_msg_27,
6638           otl_error_code_27,
6639           this->stm_label?
6640           this->stm_label:
6641           this->stm_text,
6642           this->var_info);
6643      }
6644      ++sld_tmp_len;
6645      if(sld_tmp_len==loc_ptr.get_arr_size()){
6646        loc_ptr.double_size();
6647        sl_desc_tmp=loc_ptr.get_ptr();
6648      }
6649    }
6650    sl_len=sld_tmp_len;
6651    if(sl){
6652      delete[] sl;
6653      sl=0;
6654    }
6655    sl=new otl_tmpl_variable<TVariableStruct>[sl_len==0?1:sl_len];
6656    int max_long_size=this->adb->get_max_long_size();
6657    for(j=0;j<sl_len;++j){
6658      otl_tmpl_variable<TVariableStruct>::map_ftype
6659        (sl_desc_tmp[j],
6660         max_long_size,
6661         ftype,
6662         elem_size,
6663         this->local_override.getLen()>0?this->local_override:*override,
6664         j+1,
6665         this->adb->get_connect_struct().get_connection_type());
6666      sl[j].copy_pos(j+1);
6667 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
6668      if(sl_desc_tmp[j].charset_form==2)
6669        sl[j].get_var_struct().set_nls_flag(true);
6670 #endif
6671      sl[j].init(true,
6672                 ftype,
6673                 elem_size,
6674                 OTL_SCAST(otl_stream_buffer_size_type,(this->array_size)),
6675                 &this->adb->get_connect_struct()
6676                 );
6677      sl[j].get_var_struct().set_lob_stream_mode(this->lob_stream_mode);
6678    }
6679    if(sl_desc){
6680      delete[] sl_desc;
6681      sl_desc=0;
6682    }
6683    sl_desc=new otl_column_desc[sl_len==0?1:sl_len];
6684    for(j=0;j<sl_len;++j)
6685      sl_desc[j]=sl_desc_tmp[j];
6686  }
6687 
6688   void check_if_executed_throw(void)
6689   {
6690     if(this->adb)this->adb->increment_throw_count();
6691     if(this->adb&&this->adb->get_throw_count()>1)return;
6692     if(otl_uncaught_exception()) return;
6693     throw OTL_TMPL_EXCEPTION
6694       (otl_error_msg_2,
6695        otl_error_code_2,
6696        this->stm_label?
6697        this->stm_label:
6698        this->stm_text,
6699        0);
6700   }
6701 
6702  void check_if_executed(void)
6703  {
6704   if(!executed){
6705     check_if_executed_throw();
6706   }
6707  }
6708 
6709   int check_type_throw(int type_code,int actual_data_type)
6710   {
6711    int out_type_code;
6712    if(actual_data_type!=0)
6713      out_type_code=actual_data_type;
6714    else
6715      out_type_code=type_code;
6716    otl_var_info_col
6717      (sl[cur_col].get_pos(),
6718       sl[cur_col].get_ftype(),
6719       out_type_code,
6720       var_info,
6721       sizeof(var_info));
6722    if(this->adb)this->adb->increment_throw_count();
6723    if(this->adb&&this->adb->get_throw_count()>1)return 0;
6724   if(otl_uncaught_exception()) return 0;
6725    throw OTL_TMPL_EXCEPTION
6726      (otl_error_msg_0,
6727       otl_error_code_0,
6728       this->stm_label?
6729       this->stm_label:
6730       this->stm_text,
6731       var_info);
6732   }
6733 
6734 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
6735   void strict_check_throw(int type_code)
6736   {
6737    otl_var_info_col
6738      (sl[cur_col].get_pos(),
6739       sl[cur_col].get_ftype(),
6740       type_code,
6741       var_info,
6742       sizeof(var_info));
6743    if(this->adb)this->adb->increment_throw_count();
6744    if(this->adb&&this->adb->get_throw_count()>1)return;
6745    if(otl_uncaught_exception()) return;
6746    throw OTL_TMPL_EXCEPTION
6747      (otl_error_msg_0,
6748       otl_error_code_0,
6749       this->stm_label?
6750       this->stm_label:
6751       this->stm_text,
6752       var_info);
6753   }
6754 #endif
6755 
6756  int check_type(int type_code,int actual_data_type=0)
6757  {
6758    switch(sl[cur_col].get_ftype()){
6759    case otl_var_timestamp:
6760    case otl_var_tz_timestamp:
6761    case otl_var_ltz_timestamp:
6762      if(type_code==otl_var_timestamp)
6763        return 1;
6764    default:
6765      if(sl[cur_col].get_ftype()==type_code)
6766        return 1;
6767    }
6768    return check_type_throw(type_code,actual_data_type);
6769  }
6770 
6771  void get_next(void)
6772  {
6773   if(cur_col<sl_len-1){
6774    ++cur_col;
6775    null_fetched=sl[cur_col].is_null(this->cur_row);
6776   }else{
6777    eof_status=this->next();
6778    cur_col=0;
6779   }
6780  }
6781 
6782  void look_ahead(void)
6783  {
6784   if(cur_col==sl_len-1){
6785    eof_status=this->next();
6786    cur_col=-1;
6787    ++_rfc;
6788   }
6789  }
6790 
6791   OTL_TMPL_SELECT_STREAM& operator>>(char& c)
6792  {
6793   check_if_executed();
6794   if(eof_intern())return *this;
6795   get_next();
6796   if(check_type(otl_var_char)&&!eof_intern()){
6797    c=*OTL_RCAST(char*,sl[cur_col].val(this->cur_row));
6798    look_ahead();
6799   }
6800   return *this;
6801  }
6802 
6803   OTL_TMPL_SELECT_STREAM& operator>>(unsigned char& c)
6804  {
6805   check_if_executed();
6806   if(eof_intern())return *this;
6807   get_next();
6808   if(check_type(otl_var_char)&&!eof_intern()){
6809    c=*OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row));
6810    look_ahead();
6811   }
6812   return *this;
6813  }
6814 
6815 
6816 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
6817   OTL_TMPL_SELECT_STREAM& operator>>(OTL_STRING_CONTAINER& s)
6818  {
6819   check_if_executed();
6820   if(eof_intern())return *this;
6821   get_next();
6822 
6823   switch(sl[cur_col].get_ftype()){
6824   case otl_var_char:
6825     if(!eof_intern()){
6826 #if defined(OTL_ACE)
6827       s.set(OTL_RCAST(char*,sl[cur_col].val(this->cur_row)),1);
6828 #else
6829       s=OTL_RCAST(char*,sl[cur_col].val(this->cur_row));
6830 #endif
6831       look_ahead();
6832     }
6833     break;
6834 #if defined(OTL_USER_DEFINED_STRING_CLASS_ON) || \
6835     defined(OTL_STL) || defined(OTL_ACE)
6836   case otl_var_varchar_long:
6837   case otl_var_raw_long:
6838     if(!eof_intern()){
6839       unsigned char* c=OTL_RCAST(unsigned char*,
6840                                  sl[cur_col].val(this->cur_row));
6841       int len=sl[cur_col].get_len(this->cur_row);
6842       int buf_sz=sl[cur_col].get_elem_size();
6843       if(len>buf_sz)len=buf_sz;
6844 
6845 #if (defined(OTL_USER_DEFINED_STRING_CLASS_ON) || defined(OTL_STL)) \
6846      && !defined(OTL_ACE)
6847       s.assign(OTL_RCAST(char*,c),len);
6848 #elif defined(OTL_ACE)
6849       s.set(OTL_RCAST(char*,c),len,1);
6850 #endif
6851       look_ahead();
6852     }
6853     break;
6854   case otl_var_blob:
6855   case otl_var_clob:
6856     if(!eof_intern()){
6857       int len=0;
6858       int max_long_sz=this->adb->get_max_long_size();
6859       otl_auto_array_ptr<unsigned char> loc_ptr(max_long_sz);
6860       unsigned char* temp_buf=loc_ptr.get_ptr();
6861       int rc=sl[cur_col].get_var_struct().get_blob
6862         (this->cur_row,
6863          temp_buf,
6864          max_long_sz,
6865          len);
6866       if(rc==0){
6867         if(this->adb)this->adb->increment_throw_count();
6868         if(this->adb&&this->adb->get_throw_count()>1)return *this;
6869         if(otl_uncaught_exception()) return *this;
6870         throw OTL_TMPL_EXCEPTION
6871           (this->adb->get_connect_struct(),
6872            this->stm_label?this->stm_label:
6873            this->stm_text);
6874       }
6875 #if (defined(OTL_USER_DEFINED_STRING_CLASS_ON) || \
6876      defined(OTL_STL)) && !defined(OTL_ACE)
6877       s.assign(OTL_RCAST(char*,temp_buf),len);
6878 #elif defined(OTL_ACE)
6879       s.set(OTL_RCAST(char*,temp_buf),len,1);
6880 #endif
6881       look_ahead();
6882     }
6883     break;
6884 #endif
6885   default:
6886     check_type(otl_var_char);
6887   } // switch
6888   return *this;
6889  }
6890 #endif
6891 
6892   OTL_TMPL_SELECT_STREAM& operator>>(char* s)
6893   {
6894     check_if_executed();
6895     if(eof_intern())return *this;
6896     get_next();
6897     if(check_type(otl_var_char)&&!eof_intern()){
6898       otl_strcpy(OTL_RCAST(unsigned char*,s),
6899                  OTL_RCAST(const unsigned char*,sl[cur_col].val(this->cur_row))
6900                  );
6901       look_ahead();
6902     }
6903     return *this;
6904   }
6905 
6906 #if defined(OTL_UNICODE_STRING_TYPE)
6907   OTL_TMPL_SELECT_STREAM& operator<<(const OTL_UNICODE_STRING_TYPE& s)
6908   {
6909     check_in_var();
6910     if(check_in_type(otl_var_char,1)){
6911 
6912       int overflow;
6913       otl_strcpy4
6914         (OTL_RCAST(unsigned char*,this->vl[cur_in]->val()),
6915          OTL_RCAST(unsigned char*,
6916                    OTL_CCAST(OTL_UNICODE_CHAR_TYPE*,s.c_str())),
6917          overflow,
6918          this->vl[cur_in]->get_elem_size(),
6919          OTL_SCAST(int,s.length())
6920         );
6921       if(overflow){
6922         char temp_var_info[256];
6923         otl_var_info_var
6924           (this->vl[cur_in]->get_name(),
6925            this->vl[cur_in]->get_ftype(),
6926            otl_var_char,
6927            temp_var_info,
6928            sizeof(temp_var_info));
6929         if(this->adb)this->adb->increment_throw_count();
6930         if(this->adb&&this->adb->get_throw_count()>1)return *this;
6931         if(otl_uncaught_exception()) return *this;
6932         throw OTL_TMPL_EXCEPTION
6933           (otl_error_msg_4,
6934            otl_error_code_4,
6935            this->stm_label?this->stm_label:
6936            this->stm_text,
6937       temp_var_info);
6938       }
6939       this->vl[cur_in]->set_not_null(0);
6940     }
6941     get_in_next();
6942     return *this;
6943   }
6944 
6945 #endif
6946 
6947 #if defined(OTL_UNICODE_STRING_TYPE)
6948   OTL_TMPL_SELECT_STREAM& operator>>(OTL_UNICODE_STRING_TYPE& s)
6949   {
6950     check_if_executed();
6951     if(eof_intern())return *this;
6952     get_next();
6953     switch(sl[cur_col].get_ftype()){
6954     case otl_var_char:
6955       if(!eof_intern()){
6956 #if defined(OTL_ODBC) || defined(DB2_CLI)
6957         s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
6958 #else
6959 
6960 #if defined(OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR)
6961         OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
6962           (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
6963         OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR(s,temp_s+1,*temp_s);
6964 #else
6965         OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
6966           (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
6967         s.assign(temp_s+1,*temp_s);
6968 #endif
6969 
6970 #endif
6971         look_ahead();
6972       }
6973       break;
6974     case otl_var_varchar_long:
6975       if(!eof_intern()){
6976         s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
6977         look_ahead();
6978       }
6979       break;
6980     case otl_var_clob:
6981       if(!eof_intern()){
6982         int len=0;
6983         int max_long_sz=this->adb->get_max_long_size();
6984         otl_auto_array_ptr<unsigned short> loc_ptr(max_long_sz);
6985         unsigned char* temp_buf=OTL_RCAST(unsigned char*,loc_ptr.get_ptr());
6986 
6987         int rc=sl[cur_col].get_var_struct().get_blob
6988           (this->cur_row,
6989            temp_buf,
6990            max_long_sz,
6991            len);
6992         if(rc==0){
6993           if(this->adb)this->adb->increment_throw_count();
6994           if(this->adb&&this->adb->get_throw_count()>1)return *this;
6995           if(otl_uncaught_exception()) return *this;
6996           throw OTL_TMPL_EXCEPTION
6997             (this->adb->get_connect_struct(),
6998              this->stm_label?this->stm_label:
6999              this->stm_text);
7000         }
7001         s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,temp_buf);
7002         look_ahead();
7003       }
7004       break;
7005     default:
7006       check_type(otl_var_char);
7007     }
7008     return *this;
7009   }
7010 #endif
7011 
7012   OTL_TMPL_SELECT_STREAM& operator>>(unsigned char* s)
7013   {
7014     check_if_executed();
7015     if(eof_intern())return *this;
7016     get_next();
7017     if(check_type(otl_var_char)&&!eof_intern()){
7018       otl_strcpy2(OTL_RCAST(unsigned char*,s),
7019                   OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row)),
7020                   sl[cur_col].get_len(this->cur_row)
7021                   );
7022       look_ahead();
7023     }
7024     return *this;
7025   }
7026 
7027 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
7028 #define OTL_D1(T,T_type)                                        \
7029   OTL_TMPL_SELECT_STREAM& operator>>(T& n)                      \
7030   {                                                             \
7031     check_if_executed();                                        \
7032     if(eof_intern())return *this;                               \
7033     get_next();                                                 \
7034     if(!eof_intern()){                                          \
7035       int match_found=otl_numeric_convert_T<T,T_type>           \
7036         (sl[cur_col].get_ftype(),                               \
7037          sl[cur_col].val(this->cur_row),                        \
7038          n);                                                    \
7039       if(!match_found)                                          \
7040         strict_check_throw(T_type);                             \
7041         look_ahead();                                           \
7042     }                                                           \
7043     return *this;                                               \
7044   }
7045 #else
7046 #define OTL_D1(T,T_type)                                        \
7047   OTL_TMPL_SELECT_STREAM& operator>>(T& n)                      \
7048   {                                                             \
7049     check_if_executed();                                        \
7050     if(eof_intern())return *this;                               \
7051     get_next();                                                 \
7052     if(!eof_intern()){                                          \
7053       int match_found=otl_numeric_convert_T                     \
7054         (sl[cur_col].get_ftype(),                               \
7055          sl[cur_col].val(this->cur_row),                        \
7056          n);                                                    \
7057       if(!match_found){                                         \
7058         if(check_type(otl_var_double,T_type))                   \
7059         n=OTL_PCONV(T,double,sl[cur_col].val(this->cur_row));   \
7060       }                                                         \
7061       look_ahead();                                             \
7062    }                                                            \
7063    return *this;                                                \
7064   }
7065 #endif
7066 
7067 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
7068 
7069   OTL_D1(int,otl_var_int)
7070 #if defined(OTL_BIGINT)
7071   OTL_D1(OTL_BIGINT,otl_var_bigint)
7072 #endif
7073   OTL_D1(unsigned,otl_var_unsigned_int)
7074   OTL_D1(long,otl_var_long_int)
7075   OTL_D1(short,otl_var_short)
7076   OTL_D1(float,otl_var_float)
7077   OTL_D1(double,otl_var_double)
7078 
7079 #else
7080   template<OTL_TYPE_NAME T,const int T_type> OTL_D1(T,T_type)
7081 #endif
7082 
7083   OTL_TMPL_SELECT_STREAM& operator>>(TTimestampStruct& t)
7084  {
7085   check_if_executed();
7086   if(eof_intern())return *this;
7087   get_next();
7088   if(check_type(otl_var_timestamp)&&!eof_intern()){
7089    TTimestampStruct* tm=
7090     OTL_RCAST(TTimestampStruct*,sl[cur_col].val(this->cur_row));
7091    int rc=sl[cur_col].get_var_struct().read_dt
7092      (&t,tm,sizeof(TTimestampStruct));
7093    if(rc==0){
7094      if(this->adb)this->adb->increment_throw_count();
7095      if(this->adb&&this->adb->get_throw_count()>1)return *this;
7096      if(otl_uncaught_exception()) return *this;
7097      throw OTL_TMPL_EXCEPTION
7098        (this->adb->get_connect_struct(),
7099         this->stm_label?this->stm_label:
7100         this->stm_text);
7101    }
7102    look_ahead();
7103   }
7104   return *this;
7105  }
7106 
7107   OTL_TMPL_SELECT_STREAM& operator>>(otl_long_string& s)
7108  {
7109    check_if_executed();
7110    if(eof_intern())return *this;
7111    get_next();
7112    switch(sl[cur_col].get_ftype()){
7113    case otl_var_raw_long:
7114    {
7115        if(!eof_intern()){
7116          unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row));
7117          int len2=sl[cur_col].get_len(this->cur_row);
7118          if(len2>s.get_buf_size())
7119            len2=s.get_buf_size();
7120          otl_memcpy(s.v,c,len2,sl[cur_col].get_ftype());
7121          s.set_len(len2);
7122          look_ahead();
7123        }
7124      }
7125      break;
7126    case otl_var_varchar_long:
7127    {
7128        if(!eof_intern()){
7129          if(sl[cur_col].get_var_struct().get_otl_adapter()==otl_ora8_adapter){
7130 #if defined(OTL_UNICODE)
7131            int len2=0;
7132            OTL_CHAR* source=OTL_RCAST(OTL_CHAR*,sl[cur_col].val(this->cur_row));
7133            OTL_CHAR* target=OTL_RCAST(OTL_CHAR*,s.v);
7134            while(*source && len2<s.get_buf_size()){
7135              *target++=*source++;
7136              ++len2;
7137            }
7138            s.null_terminate_string(len2);
7139            s.set_len(len2);
7140            look_ahead();
7141 #else
7142            unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row));
7143            int len2=sl[cur_col].get_len(this->cur_row);
7144            if(len2>s.get_buf_size())
7145              len2=s.get_buf_size();
7146            otl_memcpy(s.v,c,len2,sl[cur_col].get_ftype());
7147            s.null_terminate_string(len2);
7148            s.set_len(len2);
7149            look_ahead();
7150 #endif
7151          }else{
7152            unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row));
7153            int len2=sl[cur_col].get_len(this->cur_row);
7154            if(len2>s.get_buf_size())
7155              len2=s.get_buf_size();
7156            otl_memcpy(s.v,c,len2,sl[cur_col].get_ftype());
7157            s.null_terminate_string(len2);
7158            s.set_len(len2);
7159            look_ahead();
7160          }
7161        }
7162      }
7163      break;
7164    case otl_var_raw:
7165      {
7166        if(!eof_intern()){
7167          unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row));
7168          if(sl[cur_col].get_var_struct().get_otl_adapter()==otl_ora7_adapter||
7169             sl[cur_col].get_var_struct().get_otl_adapter()==otl_ora8_adapter){
7170            int len2=OTL_SCAST(int,*OTL_RCAST(unsigned short*,c));
7171            otl_memcpy(s.v,c+sizeof(short int),len2,sl[cur_col].get_ftype());
7172            s.set_len(len2);
7173          }else{
7174            int len2=sl[cur_col].get_len(this->cur_row);
7175            if(len2>s.get_buf_size())
7176              len2=s.get_buf_size();
7177            otl_memcpy(s.v,c,len2,sl[cur_col].get_ftype());
7178            s.set_len(len2);
7179          }
7180          look_ahead();
7181        }
7182      }
7183      break;
7184    case otl_var_blob:
7185    case otl_var_clob:
7186      {
7187        if(!eof_intern()){
7188          int len=0;
7189          int rc=sl[cur_col].get_var_struct().get_blob
7190            (this->cur_row,s.v,s.get_buf_size(),len);
7191          if(rc==0){
7192            if(this->adb)this->adb->increment_throw_count();
7193            if(this->adb&&this->adb->get_throw_count()>1)return *this;
7194            if(otl_uncaught_exception()) return *this;
7195            throw OTL_TMPL_EXCEPTION
7196              (this->adb->get_connect_struct(),
7197               this->stm_label?this->stm_label:
7198               this->stm_text);
7199          }
7200          if(len>s.get_buf_size())
7201            len=s.get_buf_size();
7202          s.set_len(len);
7203          if(sl[cur_col].get_ftype()==otl_var_clob)
7204            s.null_terminate_string(len);
7205          look_ahead();
7206        }
7207      }
7208      break;
7209    default:
7210      {
7211        char tmp_var_info[256];
7212        otl_var_info_col
7213          (sl[cur_col].get_pos(),
7214           sl[cur_col].get_ftype(),
7215           otl_var_long_string,
7216           tmp_var_info,
7217           sizeof(tmp_var_info));
7218        if(this->adb)this->adb->increment_throw_count();
7219        if(this->adb&&this->adb->get_throw_count()>1)return *this;
7220        if(otl_uncaught_exception()) return *this;
7221        throw OTL_TMPL_EXCEPTION
7222          (otl_error_msg_0,
7223           otl_error_code_0,
7224           this->stm_label?this->stm_label:
7225           this->stm_text,
7226           tmp_var_info);
7227      }
7228    }
7229    return *this;
7230  }
7231 
7232 #if defined(OTL_ORA8)||defined(OTL_ODBC)
7233   OTL_TMPL_SELECT_STREAM& operator>>
7234   (otl_lob_stream_generic& s)
7235  {
7236   check_if_executed();
7237   if(eof_intern())return *this;
7238   get_next();
7239   if(s.get_ora_lob() &&
7240      (sl[cur_col].get_ftype()==otl_var_blob||
7241       sl[cur_col].get_ftype()==otl_var_clob)&&
7242      !eof_intern()){
7243    s.init
7244      (OTL_RCAST(void*,&sl[cur_col]),
7245       OTL_RCAST(void*,this->adb),
7246       OTL_RCAST(void*,this),
7247       this->cur_row,
7248       otl_lob_stream_read_mode,
7249       this->is_null());
7250    delay_next=1;
7251   }else if((sl[cur_col].get_ftype()==otl_var_varchar_long||
7252             sl[cur_col].get_ftype()==otl_var_raw_long)&&
7253            !eof_intern()){
7254    s.init
7255     (OTL_RCAST(void*,&sl[cur_col]),
7256      OTL_RCAST(void*,this->adb),
7257      OTL_RCAST(void*,this),
7258      this->cur_row,
7259      otl_lob_stream_read_mode);
7260    delay_next=1;
7261   }else{
7262    char tmp_var_info[256];
7263    otl_var_info_col
7264      (sl[cur_col].get_pos(),
7265       sl[cur_col].get_ftype(),
7266       otl_var_long_string,
7267       tmp_var_info,
7268       sizeof(tmp_var_info));
7269    if(this->adb)this->adb->increment_throw_count();
7270    if(this->adb&&this->adb->get_throw_count()>1)return *this;
7271    if(otl_uncaught_exception()) return *this;
7272    throw OTL_TMPL_EXCEPTION
7273     (otl_error_msg_0,
7274      otl_error_code_0,
7275      this->stm_label?this->stm_label:
7276      this->stm_text,
7277      tmp_var_info);
7278   }
7279   return *this;
7280  }
7281 #endif
7282 
7283   int check_in_type_throw(int type_code)
7284   {
7285     otl_var_info_var
7286       (this->vl[cur_in]->get_name(),
7287        this->vl[cur_in]->get_ftype(),
7288        type_code,
7289        var_info,
7290        sizeof(var_info));
7291     if(this->adb)this->adb->increment_throw_count();
7292     if(this->adb&&this->adb->get_throw_count()>1)return 0;
7293     if(otl_uncaught_exception()) return 0;
7294     throw OTL_TMPL_EXCEPTION
7295       (otl_error_msg_0,
7296        otl_error_code_0,
7297        this->stm_label?this->stm_label:
7298        this->stm_text,
7299        var_info);
7300   }
7301 
7302   int check_in_type(int type_code,int tsize)
7303   {
7304     switch(this->vl[cur_in]->get_ftype()){
7305     case otl_var_char:
7306       if(type_code==otl_var_char)
7307         return 1;
7308     case otl_var_db2date:
7309     case otl_var_db2time:
7310     case otl_var_timestamp:
7311     case otl_var_tz_timestamp:
7312     case otl_var_ltz_timestamp:
7313       if(type_code==otl_var_timestamp)
7314         return 1;
7315     default:
7316       if(this->vl[cur_in]->get_ftype()==type_code &&
7317          this->vl[cur_in]->get_elem_size()==tsize)
7318         return 1;
7319     }
7320     return check_in_type_throw(type_code);
7321   }
7322 
7323   void check_in_var_throw(void)
7324   {
7325     if(this->adb)this->adb->increment_throw_count();
7326     if(this->adb&&this->adb->get_throw_count()>1)return;
7327    if(otl_uncaught_exception()) return;
7328     throw OTL_TMPL_EXCEPTION
7329       (otl_error_msg_1,
7330        otl_error_code_1,
7331        this->stm_label?this->stm_label:
7332        this->stm_text,
7333        0);
7334   }
7335 
7336   void check_in_var(void)
7337   {
7338     if(this->vl_len==0)
7339       check_in_var_throw();
7340   }
7341 
7342  void get_in_next(void)
7343  {
7344   if(cur_in==this->vl_len-1)
7345    rewind();
7346   else{
7347    ++cur_in;
7348    executed=0;
7349   }
7350  }
7351 
7352   OTL_TMPL_SELECT_STREAM& operator<<(const otl_null& /* n */)
7353  {
7354   check_in_var();
7355   this->vl[cur_in]->set_null(0);
7356   get_in_next();
7357   return *this;
7358  }
7359 
7360  OTL_TMPL_SELECT_STREAM& operator<<(const char c)
7361  {
7362   check_in_var();
7363   if(check_in_type(otl_var_char,1)){
7364    char* tmp=OTL_RCAST(char*,this->vl[cur_in]->val());
7365    tmp[0]=c;
7366    tmp[1]=0;
7367    this->vl[cur_in]->set_not_null(0);
7368   }
7369   get_in_next();
7370   return *this;
7371  }
7372 
7373   OTL_TMPL_SELECT_STREAM& operator<<(const unsigned char c)
7374  {
7375   check_in_var();
7376   if(check_in_type(otl_var_char,1)){
7377    unsigned char* tmp=
7378     OTL_RCAST(unsigned char*,this->vl[cur_in]->val());
7379    tmp[0]=c;
7380    tmp[1]=0;
7381    this->vl[cur_in]->set_not_null(0);
7382   }
7383   get_in_next();
7384   return *this;
7385  }
7386 
7387  OTL_TMPL_SELECT_STREAM& operator<<(const char* s)
7388  {
7389   check_in_var();
7390   if(check_in_type(otl_var_char,1)){
7391 
7392    int overflow;
7393    otl_strcpy
7394     (OTL_RCAST(unsigned char*,this->vl[cur_in]->val()),
7395      OTL_RCAST(unsigned char*,OTL_CCAST(char*,s)),
7396      overflow,
7397      this->vl[cur_in]->get_elem_size()
7398     );
7399    if(overflow){
7400     char tmp_var_info[256];
7401     otl_var_info_var
7402       (this->vl[cur_in]->get_name(),
7403        this->vl[cur_in]->get_ftype(),
7404        otl_var_char,
7405        tmp_var_info,
7406        sizeof(tmp_var_info));
7407     if(this->adb)this->adb->increment_throw_count();
7408     if(this->adb&&this->adb->get_throw_count()>1)return *this;
7409     if(otl_uncaught_exception()) return *this;
7410     throw OTL_TMPL_EXCEPTION
7411      (otl_error_msg_4,
7412       otl_error_code_4,
7413       this->stm_label?this->stm_label:
7414       this->stm_text,
7415       tmp_var_info);
7416    }
7417 
7418    this->vl[cur_in]->set_not_null(0);
7419 
7420   }
7421   get_in_next();
7422   return *this;
7423  }
7424 
7425  OTL_TMPL_SELECT_STREAM& operator<<(const otl_long_string& s)
7426  {
7427   check_in_var();
7428   switch(this->vl[cur_in]->get_ftype()){
7429   case otl_var_varchar_long:
7430     {
7431       unsigned char* c=OTL_RCAST(unsigned char*,this->vl[cur_in]->val(0));
7432       int len=OTL_CCAST(otl_long_string*,&s)->len();
7433       this->vl[cur_in]->set_not_null(0);
7434       if(len>this->vl[cur_in]->actual_elem_size()){
7435         otl_var_info_var
7436           (this->vl[cur_in]->get_name(),
7437            this->vl[cur_in]->get_ftype(),
7438            otl_var_long_string,
7439            var_info,
7440            sizeof(var_info));
7441         if(this->adb)this->adb->increment_throw_count();
7442         if(this->adb&&this->adb->get_throw_count()>1)return *this;
7443         if(otl_uncaught_exception()) return *this;
7444         throw OTL_TMPL_EXCEPTION
7445           (otl_error_msg_5,
7446            otl_error_code_5,
7447            this->stm_label?this->stm_label:
7448            this->stm_text,
7449            var_info);
7450       }
7451       otl_memcpy(c,s.v,len,this->vl[cur_in]->get_ftype());
7452       this->vl[cur_in]->set_len(len,0);
7453     }
7454     break;
7455   case otl_var_raw_long:
7456     {
7457       unsigned char* c=OTL_RCAST(unsigned char*,this->vl[cur_in]->val(0));
7458       int len=OTL_CCAST(otl_long_string*,&s)->len();
7459       if(len>this->vl[cur_in]->actual_elem_size()){
7460         otl_var_info_var
7461           (this->vl[cur_in]->get_name(),
7462            this->vl[cur_in]->get_ftype(),
7463            otl_var_char,
7464            var_info,
7465            sizeof(var_info));
7466         if(this->adb)this->adb->increment_throw_count();
7467         if(this->adb&&this->adb->get_throw_count()>1)return *this;
7468         if(otl_uncaught_exception()) return *this;
7469         throw OTL_TMPL_EXCEPTION
7470           (otl_error_msg_5,
7471            otl_error_code_5,
7472            this->stm_label?this->stm_label:
7473            this->stm_text,
7474            var_info);
7475       }
7476       this->vl[cur_in]->set_not_null(0);
7477       otl_memcpy(c,s.v,len,this->vl[cur_in]->get_ftype());
7478       this->vl[cur_in]->set_len(len,0);
7479     }
7480     break;
7481   case otl_var_raw:
7482     {
7483       unsigned char* c=OTL_RCAST(unsigned char*,this->vl[cur_in]->val(0));
7484       int len=OTL_CCAST(otl_long_string*,&s)->len();
7485       if(len>this->vl[cur_in]->actual_elem_size()){
7486         otl_var_info_var
7487           (this->vl[cur_in]->get_name(),
7488            this->vl[cur_in]->get_ftype(),
7489            otl_var_raw,
7490            var_info,
7491            sizeof(var_info));
7492         if(this->adb)this->adb->increment_throw_count();
7493         if(this->adb&&this->adb->get_throw_count()>1)return *this;
7494         if(otl_uncaught_exception()) return *this;
7495         throw OTL_TMPL_EXCEPTION
7496           (otl_error_msg_5,
7497            otl_error_code_5,
7498            this->stm_label?this->stm_label:
7499            this->stm_text,
7500            var_info);
7501       }
7502       this->vl[cur_in]->set_not_null(0);
7503       if((this->vl[cur_in]->get_var_struct().get_otl_adapter()==otl_ora7_adapter||
7504           this->vl[cur_in]->get_var_struct().get_otl_adapter()==otl_ora8_adapter) &&
7505          this->vl[cur_in]->get_ftype()==otl_var_raw){
7506         otl_memcpy
7507           (c+sizeof(unsigned short),
7508            s.v,
7509            len,
7510            this->vl[cur_in]->get_ftype());
7511         *OTL_RCAST(unsigned short*,
7512                    this->vl[cur_in]->val(0))=OTL_SCAST(unsigned short,len);
7513         this->vl[cur_in]->set_len(len,0);
7514       }else{
7515         otl_memcpy(c,s.v,len,this->vl[cur_in]->get_ftype());
7516         this->vl[cur_in]->set_len(len,0);
7517       }
7518     }
7519     break;
7520   }
7521   get_in_next();
7522   return *this;
7523  }
7524 
7525 
7526 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
7527   OTL_TMPL_SELECT_STREAM& operator<<(const OTL_STRING_CONTAINER& s)
7528   {
7529     check_in_var();
7530     if(check_in_type(otl_var_char,1)){
7531 
7532       int overflow;
7533       otl_strcpy
7534         (OTL_RCAST(unsigned char*,this->vl[cur_in]->val()),
7535          OTL_RCAST(unsigned char*,OTL_CCAST(char*,s.c_str())),
7536          overflow,
7537          this->vl[cur_in]->get_elem_size(),
7538          OTL_SCAST(int,s.length())
7539         );
7540       if(overflow){
7541         char temp_var_info[256];
7542         otl_var_info_var
7543           (this->vl[cur_in]->get_name(),
7544            this->vl[cur_in]->get_ftype(),
7545            otl_var_char,
7546            temp_var_info,
7547            sizeof(temp_var_info));
7548         if(this->adb)this->adb->increment_throw_count();
7549         if(this->adb&&this->adb->get_throw_count()>1)return *this;
7550         if(otl_uncaught_exception()) return *this;
7551         throw OTL_TMPL_EXCEPTION
7552           (otl_error_msg_4,
7553            otl_error_code_4,
7554            this->stm_label?this->stm_label:
7555            this->stm_text,
7556       temp_var_info);
7557       }
7558 
7559       this->vl[cur_in]->set_not_null(0);
7560 
7561     }
7562     get_in_next();
7563     return *this;
7564   }
7565 
7566 #endif
7567 
7568   OTL_TMPL_SELECT_STREAM& operator<<(const unsigned char* s)
7569  {
7570   check_in_var();
7571   if(check_in_type(otl_var_char,1)){
7572 
7573    int overflow;
7574    otl_strcpy4
7575     (OTL_RCAST(unsigned char*,this->vl[cur_in]->val()),
7576      OTL_CCAST(unsigned char*,s),
7577      overflow,
7578      this->vl[cur_in]->get_elem_size()
7579     );
7580    if(overflow){
7581     char temp_var_info[256];
7582     otl_var_info_var
7583       (this->vl[cur_in]->get_name(),
7584        this->vl[cur_in]->get_ftype(),
7585        otl_var_char,
7586        temp_var_info,
7587        sizeof(temp_var_info));
7588     if(this->adb)this->adb->increment_throw_count();
7589     if(this->adb&&this->adb->get_throw_count()>1)return *this;
7590     if(otl_uncaught_exception()) return *this;
7591     throw OTL_TMPL_EXCEPTION
7592      (otl_error_msg_4,
7593       otl_error_code_4,
7594       this->stm_label?this->stm_label:
7595       this->stm_text,
7596       temp_var_info);
7597    }
7598 
7599    this->vl[cur_in]->set_not_null(0);
7600 
7601   }
7602   get_in_next();
7603   return *this;
7604  }
7605 
7606 #define OTL_D2(T,T_type)                        \
7607   OTL_TMPL_SELECT_STREAM& operator<<(const T n) \
7608   {                                             \
7609     check_in_var();                             \
7610     if(check_in_type(T_type,sizeof(T))){        \
7611       *OTL_RCAST(T*,this->vl[cur_in]->val())=n; \
7612     }                                           \
7613     this->vl[cur_in]->set_not_null(0);          \
7614     get_in_next();                              \
7615     return *this;                               \
7616   }
7617 
7618 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
7619   OTL_D2(int,otl_var_int)
7620   OTL_D2(unsigned,otl_var_unsigned_int)
7621 #if defined(OTL_BIGINT)
7622   OTL_D2(OTL_BIGINT,otl_var_bigint)
7623 #endif
7624   OTL_D2(long,otl_var_long_int)
7625   OTL_D2(short,otl_var_short)
7626   OTL_D2(float,otl_var_float)
7627   OTL_D2(double,otl_var_double)
7628 #else
7629   template<OTL_TYPE_NAME T,const int T_type> OTL_D2(T,T_type)
7630 #endif
7631 
7632   OTL_TMPL_SELECT_STREAM& operator<<(const TTimestampStruct& t)
7633  {
7634   check_in_var();
7635   if(check_in_type(otl_var_timestamp,sizeof(TTimestampStruct))){
7636    TTimestampStruct* tm=
7637     OTL_RCAST(TTimestampStruct*,this->vl[cur_in]->val());
7638    int rc=this->vl[cur_in]->get_var_struct().write_dt
7639      (tm,&t,sizeof(TTimestampStruct));
7640    if(rc==0){
7641      if(this->adb)this->adb->increment_throw_count();
7642      if(this->adb&&this->adb->get_throw_count()>1)return *this;
7643      if(otl_uncaught_exception()) return *this;
7644      throw OTL_TMPL_EXCEPTION
7645        (this->adb->get_connect_struct(),
7646         this->stm_label?this->stm_label:
7647         this->stm_text);
7648    }
7649   }
7650   this->vl[cur_in]->set_not_null(0);
7651   get_in_next();
7652   return *this;
7653  }
7654 
7655 private:
7656 
7657  otl_tmpl_select_stream
7658  (const otl_tmpl_select_stream&):
7659    OTL_TMPL_SELECT_CURSOR(),
7660    sl_desc(0),
7661    sl(0),
7662    sl_len(0),
7663    null_fetched(0),
7664    cur_col(0),
7665    cur_in(0),
7666    executed(0),
7667    eof_status(0),
7668    var_info(),
7669    override(0),
7670    delay_next(0),
7671    lob_stream_mode(false),
7672    _rfc(0)
7673  {
7674  }
7675 
7676  otl_tmpl_select_stream& operator=(const otl_tmpl_select_stream&)
7677  {
7678    return *this;
7679  }
7680 
7681 };
7682 
7683 template <OTL_TYPE_NAME TExceptionStruct,
7684           OTL_TYPE_NAME TConnectStruct,
7685           OTL_TYPE_NAME TCursorStruct,
7686           OTL_TYPE_NAME TVariableStruct,
7687           OTL_TYPE_NAME TTimestampStruct>
7688 class otl_tmpl_out_stream: public OTL_TMPL_CURSOR{
7689 
7690 protected:
7691 
7692   int auto_commit_flag;
7693   int dirty;
7694   int cur_x;
7695   int cur_y;
7696   otl_stream_buffer_size_type array_size;
7697   int in_exception_flag;
7698   int in_destruct_flag;
7699   int should_delete_flag;
7700   char var_info[256];
7701   bool flush_flag;
7702   bool flush_flag2;
7703   bool lob_stream_mode;
7704   void* master_stream_ptr_;
7705 
7706 public:
7707 
7708   int get_dirty_buf_len() const
7709   {
7710     if(cur_y==0)
7711       return 0;
7712     else
7713       return cur_y+1;
7714   }
7715 
7716   void set_flush_flag(const bool aflush_flag)
7717   {
7718     flush_flag=aflush_flag;
7719   }
7720 
7721   void set_flush_flag2(const bool aflush_flag2)
7722   {
7723     flush_flag2=aflush_flag2;
7724   }
7725 
7726  void cleanup(void)
7727  {int i;
7728   if(should_delete_flag){
7729    for(i=0;i<this->vl_len;++i)
7730     delete this->vl[i];
7731   }
7732   delete[] this->vl;
7733  }
7734 
7735  otl_tmpl_out_stream
7736  (otl_stream_buffer_size_type arr_size,
7737   const char* sqlstm,
7738   OTL_TMPL_CONNECT& db,
7739   void* master_stream_ptr,
7740   const bool alob_stream_mode=false,
7741   const char* sqlstm_label=0):
7742    OTL_TMPL_CURSOR(db),
7743    auto_commit_flag(0),
7744    dirty(0),
7745    cur_x(0),
7746    cur_y(0),
7747    array_size(0),
7748    in_exception_flag(0),
7749    in_destruct_flag(0),
7750    should_delete_flag(0),
7751    var_info(),
7752    flush_flag(0),
7753    flush_flag2(0),
7754    lob_stream_mode(0),
7755    master_stream_ptr_(master_stream_ptr)
7756  {
7757    int i;
7758    if(sqlstm_label!=0){
7759      if(this->stm_label!=0){
7760        delete[] this->stm_label;
7761        this->stm_label=0;
7762      }
7763      size_t len=strlen(sqlstm_label)+1;
7764      this->stm_label=new char[strlen(sqlstm_label)+1];
7765      OTL_STRCPY_S(this->stm_label,len,sqlstm_label);
7766    }
7767    dirty=0;
7768    auto_commit_flag=1;
7769    flush_flag=true;
7770    flush_flag2=true;
7771    lob_stream_mode=alob_stream_mode;
7772    this->cursor_struct.last_param_data_token=0;
7773    this->cursor_struct.last_sql_param_data_status=0;
7774    this->cursor_struct.sql_param_data_count=0;
7775    cur_x=-1;
7776    cur_y=0;
7777    should_delete_flag=1;
7778    in_exception_flag=0;
7779    in_destruct_flag=0;
7780    this->stm_text=0;
7781    array_size=arr_size;
7782    {
7783      int len=strlen(sqlstm)+1;
7784      this->stm_text=new char[len];
7785      OTL_STRCPY_S(this->stm_text,len,sqlstm);
7786      otl_tmpl_ext_hv_decl
7787        <TVariableStruct,TTimestampStruct,TExceptionStruct,
7788        TConnectStruct,TCursorStruct> hvd(this->stm_text,arr_size);
7789      hvd.alloc_host_var_list(this->vl,this->vl_len,db);
7790    }
7791    try{
7792      this->parse();
7793      for(i=0;i<this->vl_len;++i){
7794        if(this->vl[i]->get_var_struct().otl_adapter==otl_odbc_adapter){
7795          this->vl[i]->get_var_struct().lob_stream_mode=lob_stream_mode;
7796          this->vl[i]->get_var_struct().vparam_type=this->vl[i]->get_param_type();
7797          if(this->vl[i]->get_ftype()==otl_var_varchar_long||
7798             this->vl[i]->get_ftype()==otl_var_raw_long){
7799            this->vl[i]->set_not_null(0);
7800          }
7801        }
7802        bind(*(this->vl[i]));
7803      }
7804    }catch(OTL_CONST_EXCEPTION OTL_TMPL_EXCEPTION&){
7805      cleanup();
7806      if(this->adb)this->adb->increment_throw_count();
7807      throw;
7808    }
7809  }
7810 
7811  otl_tmpl_out_stream
7812  (OTL_TMPL_CONNECT& pdb,
7813   void* master_stream_ptr,
7814   const bool alob_stream_mode=false,
7815   const char* sqlstm_label=0):
7816    OTL_TMPL_CURSOR(pdb),
7817    auto_commit_flag(0),
7818    dirty(0),
7819    cur_x(0),
7820    cur_y(0),
7821    array_size(0),
7822    in_exception_flag(0),
7823    in_destruct_flag(0),
7824    should_delete_flag(0),
7825    var_info(),
7826    flush_flag(0),
7827    flush_flag2(0),
7828    lob_stream_mode(0),
7829    master_stream_ptr_(master_stream_ptr)
7830  {
7831    if(sqlstm_label!=0){
7832      if(this->stm_label!=0){
7833        delete[] this->stm_label;
7834        this->stm_label=0;
7835      }
7836      size_t len=strlen(sqlstm_label)+1;
7837      this->stm_label=new char[len];
7838      OTL_STRCPY_S(this->stm_label,len,sqlstm_label);
7839    }
7840    should_delete_flag=1;
7841    in_exception_flag=0;
7842    in_destruct_flag=0;
7843    dirty=0;
7844    auto_commit_flag=1;
7845    flush_flag=true;
7846    flush_flag2=true;
7847    lob_stream_mode=alob_stream_mode;
7848    this->cursor_struct.reset_last_param_data_token();
7849    this->cursor_struct.reset_last_sql_param_data_status();
7850    this->cursor_struct.reset_sql_param_data_count();
7851    cur_x=-1;
7852    cur_y=0;
7853    this->stm_text=0;
7854  }
7855 
7856  virtual ~otl_tmpl_out_stream()
7857  {in_destruct_flag=1;
7858   this->in_destructor=1;
7859   if(dirty&&!in_exception_flag&&
7860      flush_flag&&flush_flag2)
7861    flush();
7862   cleanup();
7863   in_destruct_flag=0;
7864  }
7865 
7866   void reset_to_last_valid_row()
7867   {
7868     if(cur_y>0){
7869       --cur_y;
7870       this->in_exception_flag=0;
7871       cur_x=this->vl_len-1;
7872     }
7873   }
7874 
7875  virtual void flush(const int rowoff=0,const bool force_flush=false)
7876  {int i,rc;
7877 
7878  this->_rpc=0;
7879 
7880   if(!dirty)return;
7881   if(!flush_flag2)return;
7882 
7883   if(force_flush){
7884     if(rowoff>cur_y){
7885       clean();
7886       return;
7887     }
7888     int temp_rc;
7889     OTL_TRACE_STREAM_EXECUTION2
7890     this->exec(OTL_SCAST(otl_stream_buffer_size_type,(cur_y+1)),
7891                rowoff,
7892                otl_sql_exec_from_cursor_class);
7893     for(i=0;i<this->vl_len;++i){
7894       temp_rc=this->vl[i]->get_var_struct().put_blob();
7895       if(temp_rc==0){
7896         if(this->adb)this->adb->increment_throw_count();
7897         if(this->adb&&this->adb->get_throw_count()>1)return;
7898         if(otl_uncaught_exception()) return;
7899         throw OTL_TMPL_EXCEPTION
7900           (this->adb->get_connect_struct(),
7901            this->stm_label?this->stm_label:
7902            this->stm_text);
7903       }
7904     }
7905     if(auto_commit_flag)
7906       this->adb->commit();
7907     clean();
7908     return;
7909   }
7910 
7911 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
7912   if(otl_uncaught_exception()){
7913    clean();
7914    return;
7915   }
7916 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
7917    if(otl_uncaught_exception()){
7918      clean();
7919      return;
7920   }
7921 #endif
7922 
7923    if(this->retcode==0||this->adb->get_retcode()==0){
7924     clean();
7925     return;
7926   }
7927   if(cur_x!=this->vl_len-1){
7928    in_exception_flag=1;
7929    if(this->adb)this->adb->increment_throw_count();
7930    if(this->adb&&this->adb->get_throw_count()>1)return;
7931 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
7932    if(
7933 otl_uncaught_exception()){
7934     clean();
7935     return;
7936    }
7937 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
7938    if(otl_uncaught_exception()){
7939      clean();
7940      return;
7941    }
7942 #endif
7943    throw OTL_TMPL_EXCEPTION
7944     (otl_error_msg_3,
7945      otl_error_code_3,
7946      this->stm_label?this->stm_label:
7947      this->stm_text,
7948      0);
7949   }
7950   if(in_destruct_flag){
7951     OTL_TRACE_STREAM_EXECUTION2
7952     this->retcode=this->cursor_struct.exec
7953       (cur_y+1,
7954        rowoff,
7955        otl_sql_exec_from_cursor_class);
7956     for(i=0;i<this->vl_len;++i){
7957       rc=this->vl[i]->get_var_struct().put_blob();
7958       if(rc==0){
7959         if(this->adb)this->adb->increment_throw_count();
7960         if(this->adb&&this->adb->get_throw_count()>1)return;
7961         if(otl_uncaught_exception()) return;
7962         throw OTL_TMPL_EXCEPTION
7963           (this->adb->get_connect_struct(),
7964            this->stm_label?this->stm_label:
7965            this->stm_text);
7966       }
7967     }
7968     if(!this->retcode){
7969     clean();
7970     in_exception_flag=1;
7971     if(this->adb)this->adb->increment_throw_count();
7972     if(this->adb&&this->adb->get_throw_count()>1)return;
7973     if(otl_uncaught_exception()) return;
7974     throw OTL_TMPL_EXCEPTION
7975       (this->cursor_struct,
7976        this->stm_label?this->stm_label:
7977        this->stm_text);
7978    }
7979    if(auto_commit_flag){
7980      this->adb->set_retcode(this->adb->get_connect_struct().commit());
7981      if(!this->adb->get_retcode()){
7982      clean();
7983      if(this->adb)this->adb->increment_throw_count();
7984      if(this->adb&&this->adb->get_throw_count()>1)return;
7985      if(otl_uncaught_exception()) return;
7986      throw OTL_TMPL_EXCEPTION
7987        (this->adb->get_connect_struct(),
7988         this->stm_label?this->stm_label:
7989         this->stm_text);
7990     }
7991    }
7992   }else{
7993     int temp_rc;
7994     OTL_TRACE_STREAM_EXECUTION2
7995     this->exec(OTL_SCAST(otl_stream_buffer_size_type,(cur_y+1)),
7996                rowoff,
7997                otl_sql_exec_from_cursor_class);
7998     for(i=0;i<this->vl_len;++i){
7999       temp_rc=this->vl[i]->get_var_struct().put_blob();
8000       if(temp_rc==0){
8001         if(this->adb)this->adb->increment_throw_count();
8002         if(this->adb&&this->adb->get_throw_count()>1)return;
8003         if(otl_uncaught_exception()) return;
8004         throw OTL_TMPL_EXCEPTION
8005           (this->adb->get_connect_struct(),
8006            this->stm_label?this->stm_label:
8007            this->stm_text);
8008       }
8009     }
8010    if(auto_commit_flag)
8011     this->adb->commit();
8012    if(rowoff>0)
8013      clean();
8014    else
8015      clean(0);
8016   }
8017 
8018  }
8019 
8020  virtual void clean(const int clean_up_error_flag=0)
8021  {
8022    if(clean_up_error_flag){
8023      this->retcode=1;
8024      this->in_exception_flag=0;
8025    }
8026    if(!dirty)return;
8027    cur_x=-1;
8028    cur_y=0;
8029    dirty=0;
8030  }
8031 
8032  void set_commit(int auto_commit=0)
8033  {
8034    auto_commit_flag=auto_commit;
8035  }
8036 
8037  void get_next(void)
8038  {
8039   if(cur_x<this->vl_len-1)
8040    ++cur_x;
8041   else{
8042    if(cur_y<array_size-1){
8043     ++cur_y;
8044     cur_x=0;
8045    }else{
8046     flush();
8047     cur_x=0;
8048    }
8049   }
8050   dirty=1;
8051  }
8052 
8053   int check_type_throw(int type_code)
8054   {
8055    in_exception_flag=1;
8056    otl_var_info_var
8057      (this->vl[cur_x]->get_name(),
8058       this->vl[cur_x]->get_ftype(),
8059       type_code,
8060       var_info,
8061       sizeof(var_info));
8062    if(this->adb)this->adb->increment_throw_count();
8063    if(this->adb&&this->adb->get_throw_count()>1)return 0;
8064    if(otl_uncaught_exception()) return 0;
8065    throw OTL_TMPL_EXCEPTION
8066      (otl_error_msg_0,
8067       otl_error_code_0,
8068       this->stm_label?this->stm_label:
8069       this->stm_text,
8070       var_info);
8071   }
8072 
8073  int check_type(int type_code, int tsize)
8074  {
8075    switch(this->vl[cur_x]->get_ftype()){
8076    case otl_var_char:
8077      if(type_code==otl_var_char)return 1;
8078    case otl_var_db2time:
8079    case otl_var_tz_timestamp:
8080    case otl_var_ltz_timestamp:
8081    case otl_var_db2date:
8082      if(type_code==otl_var_timestamp)return 1;
8083    case otl_var_refcur:
8084      if(type_code==otl_var_refcur)return 1;
8085    default:
8086      if(this->vl[cur_x]->get_ftype()==type_code &&
8087         this->vl[cur_x]->get_elem_size()==tsize)
8088        return 1;
8089    }
8090    return check_type_throw(type_code);
8091  }
8092 
8093  void check_buf(void)
8094  {
8095   if(cur_x==this->vl_len-1 && cur_y==array_size-1)
8096    flush();
8097  }
8098 
8099  OTL_TMPL_OUT_STREAM& operator<<(const char c)
8100  {
8101   if(this->vl_len>0){
8102    get_next();
8103    if(check_type(otl_var_char,1)){
8104     char* tmp=OTL_RCAST(char*,this->vl[cur_x]->val(cur_y));
8105     tmp[0]=c;
8106     tmp[1]=0;
8107     this->vl[cur_x]->set_not_null(cur_y);
8108    }
8109    check_buf();
8110   }
8111   return *this;
8112  }
8113 
8114  OTL_TMPL_OUT_STREAM& operator<<(const unsigned char c)
8115  {
8116   if(this->vl_len>0){
8117    get_next();
8118    if(check_type(otl_var_char,1)){
8119     unsigned char* tmp=OTL_RCAST(unsigned char*,this->vl[cur_x]->val(cur_y));
8120     tmp[0]=c;
8121     tmp[1]=0;
8122     this->vl[cur_x]->set_not_null(cur_y);
8123    }
8124    check_buf();
8125   }
8126   return *this;
8127  }
8128 
8129 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
8130  OTL_TMPL_OUT_STREAM& operator<<(const OTL_STRING_CONTAINER& s)
8131  {
8132    if(this->vl_len>0){
8133      get_next();
8134 
8135      switch(this->vl[cur_x]->get_ftype()){
8136      case otl_var_char:
8137        {
8138          int overflow;
8139          otl_strcpy
8140            (OTL_RCAST(unsigned char*,this->vl[cur_x]->val(cur_y)),
8141             OTL_RCAST(unsigned char*,OTL_CCAST(char*,s.c_str())),
8142             overflow,
8143             this->vl[cur_x]->get_elem_size(),
8144             OTL_SCAST(int,s.length()));
8145          if(overflow){
8146            otl_var_info_var
8147              (this->vl[cur_x]->get_name(),
8148               this->vl[cur_x]->get_ftype(),
8149               otl_var_char,
8150               var_info,
8151               sizeof(var_info));
8152            in_exception_flag=1;
8153            if(this->adb)this->adb->increment_throw_count();
8154            if(this->adb&&this->adb->get_throw_count()>1)return *this;
8155            if(otl_uncaught_exception()) return *this;
8156            throw OTL_TMPL_EXCEPTION
8157              (otl_error_msg_4,
8158               otl_error_code_4,
8159               this->stm_label?this->stm_label:
8160               this->stm_text,
8161               var_info);
8162          }
8163          this->vl[cur_x]->set_not_null(cur_y);
8164        }
8165        break;
8166 #if defined(OTL_USER_DEFINED_STRING_CLASS_ON) || \
8167      defined(OTL_STL) || defined(OTL_ACE)
8168      case otl_var_varchar_long:
8169      case otl_var_raw_long:
8170        {
8171          unsigned char* c=OTL_RCAST(unsigned char*,
8172                                     this->vl[cur_x]->val(cur_y));
8173          int len=OTL_SCAST(int,s.length());
8174          this->vl[cur_x]->set_not_null(cur_y);
8175          if(len>this->vl[cur_x]->actual_elem_size()){
8176            otl_var_info_var
8177              (this->vl[cur_x]->get_name(),
8178               this->vl[cur_x]->get_ftype(),
8179               otl_var_char,
8180               var_info,
8181               sizeof(var_info));
8182            if(this->adb)this->adb->increment_throw_count();
8183            if(this->adb&&this->adb->get_throw_count()>1)return *this;
8184            if(otl_uncaught_exception()) return *this;
8185            throw OTL_TMPL_EXCEPTION
8186              (otl_error_msg_5,
8187               otl_error_code_5,
8188               this->stm_label?this->stm_label:
8189               this->stm_text,
8190               var_info);
8191          }
8192 
8193          otl_memcpy(c,
8194                     OTL_RCAST(unsigned char*,
8195                               OTL_CCAST(char*,s.c_str())),
8196                     len,
8197                     this->vl[cur_x]->get_ftype());
8198          this->vl[cur_x]->set_len(len,cur_y);
8199        }
8200        break;
8201      case otl_var_blob:
8202      case otl_var_clob:
8203        {
8204          int len=OTL_SCAST(int,s.length());
8205          if(len>this->vl[cur_x]->actual_elem_size()){
8206            otl_var_info_var
8207              (this->vl[cur_x]->get_name(),
8208               this->vl[cur_x]->get_ftype(),
8209               otl_var_char,
8210               var_info,
8211               sizeof(var_info));
8212            if(this->adb)this->adb->increment_throw_count();
8213            if(this->adb&&this->adb->get_throw_count()>1)return *this;
8214            if(otl_uncaught_exception()) return *this;
8215            throw OTL_TMPL_EXCEPTION
8216              (otl_error_msg_5,
8217               otl_error_code_5,
8218               this->stm_label?this->stm_label:
8219               this->stm_text,
8220               var_info);
8221          }
8222          this->vl[cur_x]->set_not_null(cur_y);
8223          this->vl[cur_x]->get_var_struct().save_blob
8224            (OTL_RCAST(unsigned char*,OTL_CCAST(char*,s.c_str())),len,0);
8225        }
8226        break;
8227 #endif
8228      default:
8229        check_type(otl_var_char,1);
8230      } // switch
8231      check_buf();
8232    }
8233    return *this;
8234  }
8235 #endif
8236 
8237 #if defined(OTL_UNICODE_STRING_TYPE)
8238   OTL_TMPL_OUT_STREAM& operator<<(const OTL_UNICODE_STRING_TYPE& s)
8239   {
8240     if(this->vl_len>0){
8241       get_next();
8242       switch(this->vl[cur_x]->get_ftype()){
8243       case otl_var_char:
8244         {
8245           int overflow;
8246           otl_strcpy4
8247             (OTL_RCAST(unsigned char*,this->vl[cur_x]->val(cur_y)),
8248              OTL_RCAST(unsigned char*,
8249                        OTL_CCAST(OTL_UNICODE_CHAR_TYPE*,s.c_str())),
8250              overflow,
8251              this->vl[cur_x]->get_elem_size(),
8252              OTL_SCAST(int,s.length())
8253              );
8254           if(overflow){
8255             otl_var_info_var
8256               (this->vl[cur_x]->get_name(),
8257                this->vl[cur_x]->get_ftype(),
8258                otl_var_char,
8259                var_info,
8260                sizeof(var_info));
8261             in_exception_flag=1;
8262             if(this->adb)this->adb->increment_throw_count();
8263             if(this->adb&&this->adb->get_throw_count()>1)return *this;
8264             throw OTL_TMPL_EXCEPTION
8265               (otl_error_msg_4,
8266                otl_error_code_4,
8267                this->stm_label?this->stm_label:
8268                this->stm_text,
8269                var_info);
8270           }
8271           this->vl[cur_x]->set_not_null(cur_y);
8272           break;
8273         }
8274       case otl_var_varchar_long:
8275         {
8276           unsigned char* c=OTL_RCAST(unsigned char*,
8277                                      this->vl[cur_x]->val(cur_y));
8278           int len=OTL_SCAST(int,s.length());
8279           this->vl[cur_x]->set_not_null(cur_y);
8280           if(len>this->vl[cur_x]->actual_elem_size()){
8281             otl_var_info_var
8282               (this->vl[cur_x]->get_name(),
8283                this->vl[cur_x]->get_ftype(),
8284                otl_var_char,
8285                var_info,
8286                sizeof(var_info));
8287             if(this->adb)this->adb->increment_throw_count();
8288             if(this->adb&&this->adb->get_throw_count()>1)return *this;
8289             if(otl_uncaught_exception()) return *this;
8290             throw OTL_TMPL_EXCEPTION
8291               (otl_error_msg_5,
8292                otl_error_code_5,
8293                this->stm_label?this->stm_label:
8294                this->stm_text,
8295                var_info);
8296           }
8297           otl_memcpy(c,
8298                      OTL_RCAST(unsigned char*,
8299                                OTL_CCAST(OTL_UNICODE_CHAR_TYPE*,s.c_str())),
8300                      len,
8301                      this->vl[cur_x]->get_ftype());
8302           this->vl[cur_x]->set_len(len,cur_y);
8303           break;
8304         }
8305       case otl_var_clob:
8306         {
8307           int len=OTL_SCAST(int,s.length());
8308           if(len>this->vl[cur_x]->actual_elem_size()){
8309             otl_var_info_var
8310               (this->vl[cur_x]->get_name(),
8311                this->vl[cur_x]->get_ftype(),
8312                otl_var_char,
8313                var_info,
8314                sizeof(var_info));
8315             if(this->adb)this->adb->increment_throw_count();
8316             if(this->adb&&this->adb->get_throw_count()>1)return *this;
8317             if(otl_uncaught_exception()) return *this;
8318             throw OTL_TMPL_EXCEPTION
8319               (otl_error_msg_5,
8320                otl_error_code_5,
8321                this->stm_label?this->stm_label:
8322                this->stm_text,
8323                var_info);
8324           }
8325           this->vl[cur_x]->set_not_null(cur_y);
8326           this->vl[cur_x]->get_var_struct().save_blob
8327             (OTL_RCAST(const unsigned char*,s.c_str()),
8328              len,
8329              0);
8330         }
8331         break;
8332       default:
8333         check_type(otl_var_char,1);
8334       }
8335       check_buf();
8336     }
8337     return *this;
8338   }
8339 #endif
8340 
8341   OTL_TMPL_OUT_STREAM& operator<<(const char* s)
8342   {
8343     if(this->vl_len>0){
8344       get_next();
8345       if(check_type(otl_var_char,1)){
8346 
8347         int overflow;
8348         otl_strcpy
8349           (OTL_RCAST(unsigned char*,this->vl[cur_x]->val(cur_y)),
8350            OTL_RCAST(unsigned char*,OTL_CCAST(char*,s)),
8351            overflow,
8352            this->vl[cur_x]->get_elem_size()
8353            );
8354         if(overflow){
8355           otl_var_info_var
8356             (this->vl[cur_x]->get_name(),
8357              this->vl[cur_x]->get_ftype(),
8358              otl_var_char,
8359              var_info,
8360              sizeof(var_info));
8361           in_exception_flag=1;
8362           if(this->adb)this->adb->increment_throw_count();
8363           if(this->adb&&this->adb->get_throw_count()>1)return *this;
8364           throw OTL_TMPL_EXCEPTION
8365             (otl_error_msg_4,
8366              otl_error_code_4,
8367              this->stm_label?this->stm_label:
8368              this->stm_text,
8369              var_info);
8370         }
8371         this->vl[cur_x]->set_not_null(cur_y);
8372       }
8373       check_buf();
8374     }
8375     return *this;
8376   }
8377 
8378  OTL_TMPL_OUT_STREAM& operator<<(const unsigned char* s)
8379  {
8380   if(this->vl_len>0){
8381    get_next();
8382    if(check_type(otl_var_char,1)){
8383 
8384     int overflow;
8385     otl_strcpy4
8386      (OTL_RCAST(unsigned char*,this->vl[cur_x]->val(cur_y)),
8387       OTL_CCAST(unsigned char*,s),
8388       overflow,
8389       this->vl[cur_x]->get_elem_size()
8390      );
8391     if(overflow){
8392      otl_var_info_var
8393        (this->vl[cur_x]->get_name(),
8394         this->vl[cur_x]->get_ftype(),
8395         otl_var_char,
8396         var_info,
8397         sizeof(var_info));
8398      in_exception_flag=1;
8399      if(this->adb)this->adb->increment_throw_count();
8400      if(this->adb&&this->adb->get_throw_count()>1)return *this;
8401      if(otl_uncaught_exception()) return *this;
8402      throw OTL_TMPL_EXCEPTION
8403       (otl_error_msg_4,
8404        otl_error_code_4,
8405        this->stm_label?this->stm_label:
8406        this->stm_text,
8407        var_info);
8408     }
8409     this->vl[cur_x]->set_not_null(cur_y);
8410    }
8411    check_buf();
8412   }
8413   return *this;
8414  }
8415 
8416 #define OTL_D3(T,T_type)                                \
8417  OTL_TMPL_OUT_STREAM& operator<<(const T n)             \
8418  {                                                      \
8419   if(this->vl_len>0){                                   \
8420    get_next();                                          \
8421    if(check_type(T_type,sizeof(T))){                    \
8422     *OTL_RCAST(T*,this->vl[cur_x]->val(cur_y))=n;       \
8423     this->vl[cur_x]->set_not_null(cur_y);               \
8424    }                                                    \
8425    check_buf();                                         \
8426   }                                                     \
8427   return *this;                                         \
8428  }
8429 
8430 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
8431   OTL_D3(int,otl_var_int)
8432 #if defined(OTL_BIGINT)
8433   OTL_D3(OTL_BIGINT,otl_var_bigint)
8434 #endif
8435   OTL_D3(unsigned,otl_var_unsigned_int)
8436   OTL_D3(long,otl_var_long_int)
8437   OTL_D3(short,otl_var_short)
8438   OTL_D3(float,otl_var_float)
8439   OTL_D3(double,otl_var_double)
8440 #else
8441     template<OTL_TYPE_NAME T,const int T_type> OTL_D3(T,T_type)
8442 #endif
8443 
8444 #if defined(OTL_PL_TAB)
8445  OTL_TMPL_OUT_STREAM& operator<<(otl_pl_tab_generic& tab)
8446  {
8447   if(this->vl_len>0){
8448    get_next();
8449    if(check_type(tab.get_vtype(),tab.get_elem_size())){
8450     int i,tmp_len;
8451     if(tab.len()<=this->vl[cur_x]->get_array_size())
8452      tmp_len=tab.len();
8453     else
8454       tmp_len=this->vl[cur_x]->get_array_size();
8455     this->vl[cur_x]->set_pl_tab_len(tmp_len);
8456     if(tab.get_vtype()==otl_var_char){
8457      int i2;
8458      for(i2=0;i2<tmp_len;++i2){
8459       int overflow;
8460       otl_strcpy4
8461        (OTL_RCAST(unsigned char*,this->vl[cur_x]->val(i2)),
8462         OTL_RCAST(unsigned char*,tab.val(i2)),
8463         overflow,
8464         this->vl[cur_x]->get_elem_size()
8465        );
8466       if(overflow){
8467        char tmp_var_info[256];
8468        otl_var_info_var
8469          (this->vl[cur_x]->get_name(),
8470           this->vl[cur_x]->get_ftype(),
8471           otl_var_char,
8472           tmp_var_info,
8473           sizeof(tmp_var_info));
8474        if(this->adb)this->adb->increment_throw_count();
8475        if(this->adb&&this->adb->get_throw_count()>1)return *this;
8476        if(otl_uncaught_exception()) return *this;
8477        throw OTL_TMPL_EXCEPTION
8478         (otl_error_msg_4,
8479          otl_error_code_4,
8480          this->stm_label?this->stm_label:
8481          this->stm_text,
8482          tmp_var_info);
8483       }
8484      }
8485     }else if(tab.get_vtype()==otl_var_timestamp){
8486       otl_datetime* ext_dt=OTL_RCAST(otl_datetime*,tab.get_p_v());
8487       otl_oracle_date* int_dt=OTL_RCAST(otl_oracle_date*,
8488                                         this->vl[cur_x]->val());
8489       int j;
8490       for(j=0;j<tmp_len;++j){
8491         convert_date(*int_dt,*ext_dt);
8492         ++int_dt;
8493         ++ext_dt;
8494       }
8495     }else
8496      memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8497             OTL_RCAST(char*,tab.val()),
8498             tab.get_elem_size()*tmp_len);
8499     for(i=0;i<tmp_len;++i){
8500      if(tab.is_null(i))
8501       this->vl[cur_x]->set_null(i);
8502      else
8503       this->vl[cur_x]->set_not_null(i);
8504     }
8505    }
8506    check_buf();
8507   }
8508   return *this;
8509  }
8510 #endif
8511 
8512 #if defined(OTL_PL_TAB) && defined(OTL_STL)
8513  OTL_TMPL_OUT_STREAM& operator<<(otl_pl_vec_generic& vec)
8514  {
8515   if(this->vl_len>0){
8516    get_next();
8517    if(check_type(vec.get_vtype(),vec.get_elem_size())){
8518     int i,tmp_len;
8519     if(vec.len()<=this->vl[cur_x]->get_array_size())
8520       tmp_len=vec.len();
8521     else
8522       tmp_len=this->vl[cur_x]->get_array_size();
8523     this->vl[cur_x]->set_pl_tab_len(tmp_len);
8524     switch(vec.get_vtype()){
8525     case otl_var_char:
8526      int i2;
8527      for(i2=0;i2<tmp_len;++i2){
8528       int overflow;
8529       otl_strcpy
8530        (OTL_RCAST(unsigned char*,this->vl[cur_x]->val(i2)),
8531         OTL_RCAST(unsigned char*,
8532                   OTL_CCAST(char*,(*OTL_RCAST(STD_NAMESPACE_PREFIX
8533                                               vector<OTL_STRING_CONTAINER>*,
8534                                               vec.get_p_v()))[i2].c_str())),
8535         overflow,
8536         this->vl[cur_x]->get_elem_size(),
8537         OTL_SCAST(int,(*OTL_RCAST(STD_NAMESPACE_PREFIX
8538                                   vector<OTL_STRING_CONTAINER>*,
8539                                   vec.get_p_v()))[i2].length())
8540        );
8541       if(overflow){
8542        char temp_var_info[256];
8543        otl_var_info_var
8544          (this->vl[cur_x]->get_name(),
8545           this->vl[cur_x]->get_ftype(),
8546           otl_var_char,
8547           temp_var_info,
8548           sizeof(temp_var_info));
8549        if(this->adb)this->adb->increment_throw_count();
8550        if(this->adb&&this->adb->get_throw_count()>1)return *this;
8551        if(otl_uncaught_exception()) return *this;
8552        throw OTL_TMPL_EXCEPTION
8553         (otl_error_msg_4,
8554          otl_error_code_4,
8555          this->stm_label?this->stm_label:
8556          this->stm_text,
8557          temp_var_info);
8558       }
8559      }
8560      break;
8561     case otl_var_timestamp:
8562      {
8563       otl_oracle_date* int_dt=OTL_RCAST(otl_oracle_date*,this->vl[cur_x]->val());
8564       int j;
8565       otl_datetime* ext_dt;
8566       for(j=0;j<tmp_len;++j){
8567        ext_dt=OTL_RCAST(otl_datetime*,
8568                         &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<otl_datetime>*,
8569                                      vec.get_p_v()))[j]);
8570        convert_date(*int_dt,*ext_dt);
8571        ++int_dt;
8572       }
8573      }
8574      break;
8575     case otl_var_int:
8576       if(tmp_len>0)
8577         memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8578                OTL_RCAST(char*,
8579                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<int>*,
8580                                       vec.get_p_v()))[0]),
8581                sizeof(int)*tmp_len);
8582       break;
8583     case otl_var_double:
8584       if(tmp_len>0)
8585         memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8586                OTL_RCAST(char*,
8587                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<double>*,
8588                                       vec.get_p_v()))[0]),
8589                sizeof(double)*tmp_len);
8590       break;
8591     case otl_var_float:
8592       if(tmp_len>0)
8593         memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8594                OTL_RCAST(char*,
8595                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<float>*,
8596                                       vec.get_p_v()))[0]),
8597                sizeof(float)*tmp_len);
8598       break;
8599     case otl_var_unsigned_int:
8600       if(tmp_len>0)
8601         memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8602                OTL_RCAST(char*,
8603                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<unsigned>*,
8604                                       vec.get_p_v()))[0]),
8605                sizeof(unsigned)*tmp_len);
8606       break;
8607     case otl_var_short:
8608       if(tmp_len>0)
8609         memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8610                OTL_RCAST(char*,
8611                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<short>*,
8612                                       vec.get_p_v()))[0]),
8613                  sizeof(short)*tmp_len);
8614       break;
8615     case otl_var_long_int:
8616       if(tmp_len>0)
8617         memcpy(OTL_RCAST(char*,this->vl[cur_x]->val()),
8618                OTL_RCAST(char*,
8619                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<long int>*,
8620                                       vec.get_p_v()))[0]),
8621                sizeof(long int)*tmp_len);
8622       break;
8623     }
8624     for(i=0;i<tmp_len;++i){
8625       if(vec.is_null(i))
8626         this->vl[cur_x]->set_null(i);
8627       else
8628         this->vl[cur_x]->set_not_null(i);
8629     }
8630    }
8631    check_buf();
8632   }
8633   return *this;
8634  }
8635 #endif
8636 
8637  OTL_TMPL_OUT_STREAM& operator<<(const otl_null& /* n */)
8638  {
8639   if(this->vl_len>0){
8640    get_next();
8641    this->vl[cur_x]->set_null(cur_y);
8642    check_buf();
8643   }
8644   return *this;
8645  }
8646 
8647  OTL_TMPL_OUT_STREAM& operator<<(const TTimestampStruct& t)
8648  {
8649   if(this->vl_len>0){
8650    get_next();
8651    if(check_type(otl_var_timestamp,sizeof(TTimestampStruct))){
8652     TTimestampStruct* tm=
8653      OTL_RCAST(TTimestampStruct*,this->vl[cur_x]->val(cur_y));
8654     this->vl[cur_x]->set_not_null(cur_y);
8655     int rc=this->vl[cur_x]->get_var_struct().write_dt
8656       (tm,&t,sizeof(TTimestampStruct));
8657     if(rc==0){
8658       if(this->adb)this->adb->increment_throw_count();
8659       if(this->adb&&this->adb->get_throw_count()>1)return *this;
8660       if(otl_uncaught_exception()) return *this;
8661       throw OTL_TMPL_EXCEPTION
8662         (this->adb->get_connect_struct(),
8663          this->stm_label?this->stm_label:
8664          this->stm_text);
8665     }
8666    }
8667    check_buf();
8668   }
8669   return *this;
8670  }
8671 
8672  OTL_TMPL_OUT_STREAM& operator<<(const otl_long_string& s)
8673  {
8674   if(this->vl_len>0){
8675    get_next();
8676 
8677    switch(this->vl[cur_x]->get_ftype()){
8678    case otl_var_varchar_long:
8679    case otl_var_raw_long:
8680    case otl_var_raw:
8681      {
8682        unsigned char* c=OTL_RCAST(unsigned char*,this->vl[cur_x]->val(cur_y));
8683        int len=OTL_CCAST(otl_long_string*,&s)->len();
8684        this->vl[cur_x]->set_not_null(cur_y);
8685        if(len>this->vl[cur_x]->actual_elem_size()){
8686          otl_var_info_var
8687            (this->vl[cur_x]->get_name(),
8688             this->vl[cur_x]->get_ftype(),
8689             otl_var_long_string,
8690             var_info,
8691             sizeof(var_info));
8692          if(this->adb)this->adb->increment_throw_count();
8693          if(this->adb&&this->adb->get_throw_count()>1)return *this;
8694          if(otl_uncaught_exception()) return *this;
8695          throw OTL_TMPL_EXCEPTION
8696            (otl_error_msg_5,
8697             otl_error_code_5,
8698             this->stm_label?this->stm_label:
8699             this->stm_text,
8700             var_info);
8701        }
8702        if((this->vl[cur_x]->get_var_struct().get_otl_adapter()==otl_ora7_adapter||
8703            this->vl[cur_x]->get_var_struct().get_otl_adapter()==otl_ora8_adapter) &&
8704           this->vl[cur_x]->get_ftype()==otl_var_raw){
8705          otl_memcpy
8706            (c+sizeof(unsigned short),
8707             s.v,
8708             len,
8709             this->vl[cur_x]->get_ftype());
8710          *OTL_RCAST(unsigned short*,
8711                     this->vl[cur_x]->val(cur_y))=OTL_SCAST(unsigned short,len);
8712          this->vl[cur_x]->set_len(len,cur_y);
8713        }else{
8714          otl_memcpy(c,s.v,len,this->vl[cur_x]->get_ftype());
8715          this->vl[cur_x]->set_len(len,cur_y);
8716        }
8717      }
8718      break;
8719    case otl_var_blob:
8720    case otl_var_clob:
8721      {
8722        int len=OTL_CCAST(otl_long_string*,&s)->len();
8723        if(len>this->vl[cur_x]->actual_elem_size()){
8724          otl_var_info_var
8725            (this->vl[cur_x]->get_name(),
8726             this->vl[cur_x]->get_ftype(),
8727             otl_var_long_string,
8728             var_info,
8729             sizeof(var_info));
8730          if(this->adb)this->adb->increment_throw_count();
8731          if(this->adb&&this->adb->get_throw_count()>1)return *this;
8732          if(otl_uncaught_exception()) return *this;
8733          throw OTL_TMPL_EXCEPTION
8734            (otl_error_msg_5,
8735             otl_error_code_5,
8736             this->stm_label?this->stm_label:
8737             this->stm_text,
8738             var_info);
8739        }
8740        this->vl[cur_x]->set_not_null(cur_y);
8741        this->vl[cur_x]->get_var_struct().save_blob
8742          (s.v,len,s.get_extern_buffer_flag());
8743      }
8744      break;
8745    }
8746    check_buf();
8747   }
8748   return *this;
8749  }
8750 
8751 #if defined(OTL_ORA8)||defined(OTL_ODBC)
8752 #define OTL_TMPL_CUR_DUMMY OTL_TMPL_CURSOR
8753 
8754  OTL_TMPL_OUT_STREAM& operator<<
8755   (otl_lob_stream_generic& s)
8756  {
8757   if(this->vl_len>0){
8758    get_next();
8759    if(((s.get_ora_lob() &&
8760         this->vl[cur_x]->get_ftype()==otl_var_blob)||
8761        this->vl[cur_x]->get_ftype()==otl_var_clob)||
8762       (this->vl[cur_x]->get_ftype()==otl_var_varchar_long||
8763        this->vl[cur_x]->get_ftype()==otl_var_raw_long)){
8764     s.init
8765      (this->vl[cur_x],
8766       this->adb,
8767       OTL_RCAST(OTL_TMPL_CUR_DUMMY*,this),
8768       0,
8769       otl_lob_stream_write_mode);
8770     if(!s.get_ora_lob())
8771      this->vl[cur_x]->set_not_null(cur_y);
8772    }
8773    check_buf();
8774   }else{
8775    char temp_var_info[256];
8776    otl_var_info_var
8777      (this->vl[cur_x]->get_name(),
8778       this->vl[cur_x]->get_ftype(),
8779       otl_var_long_string,
8780       temp_var_info,
8781      sizeof(temp_var_info));
8782    if(this->adb)this->adb->increment_throw_count();
8783    if(this->adb&&this->adb->get_throw_count()>1)return *this;
8784    if(otl_uncaught_exception()) return *this;
8785    throw OTL_TMPL_EXCEPTION
8786     (otl_error_msg_0,
8787      otl_error_code_0,
8788      this->stm_label?this->stm_label:
8789      this->stm_text,
8790      temp_var_info);
8791   }
8792   return *this;
8793  }
8794 #undef OTL_TMPL_CUR_DUMMY
8795 #endif
8796 
8797  otl_tmpl_out_stream():
8798    OTL_TMPL_CURSOR(),
8799    auto_commit_flag(0),
8800    dirty(0),
8801    cur_x(0),
8802    cur_y(0),
8803    array_size(0),
8804    in_exception_flag(0),
8805    in_destruct_flag(0),
8806    should_delete_flag(0),
8807    var_info(),
8808    flush_flag(0),
8809    flush_flag2(0),
8810    lob_stream_mode(0),
8811    master_stream_ptr_(0)
8812  {
8813  }
8814 
8815 private:
8816 
8817  otl_tmpl_out_stream
8818  (const otl_tmpl_out_stream&):
8819    OTL_TMPL_CURSOR(),
8820    auto_commit_flag(0),
8821    dirty(0),
8822    cur_x(0),
8823    cur_y(0),
8824    array_size(0),
8825    in_exception_flag(0),
8826    in_destruct_flag(0),
8827    should_delete_flag(0),
8828    var_info(),
8829    flush_flag(0),
8830    flush_flag2(0),
8831    lob_stream_mode(0),
8832    master_stream_ptr_(0)
8833  {
8834  }
8835 
8836  otl_tmpl_out_stream& operator=
8837  (const otl_tmpl_out_stream&)
8838  {
8839    return *this;
8840  }
8841 
8842 };
8843 
8844 template <OTL_TYPE_NAME TExceptionStruct,
8845           OTL_TYPE_NAME TConnectStruct,
8846           OTL_TYPE_NAME TCursorStruct,
8847           OTL_TYPE_NAME TVariableStruct,
8848           OTL_TYPE_NAME TTimestampStruct>
8849 class otl_tmpl_inout_stream: public OTL_TMPL_OUT_STREAM{
8850 
8851 protected:
8852 
8853   otl_tmpl_variable<TVariableStruct>** in_vl;
8854   int iv_len;
8855   int cur_in_x;
8856   int cur_in_y;
8857   int in_y_len;
8858   int null_fetched;
8859   otl_tmpl_variable<TVariableStruct>** avl;
8860   int avl_len;
8861   char var_info[256];
8862 
8863 public:
8864 
8865   int get_iv_len() const {return iv_len;}
8866   otl_tmpl_variable<TVariableStruct>** get_in_vl(){return in_vl;}
8867 
8868  void cleanup(void)
8869  {int i;
8870   for(i=0;i<avl_len;++i){
8871    delete avl[i];
8872   }
8873   delete[] avl;
8874   delete[] in_vl;
8875  }
8876 
8877  otl_tmpl_inout_stream
8878  (otl_stream_buffer_size_type arr_size,
8879   const char* sqlstm,
8880   OTL_TMPL_CONNECT& pdb,
8881   void* master_stream_ptr,
8882   const bool alob_stream_mode=false,
8883   const char* sqlstm_label=0)
8884    : OTL_TMPL_OUT_STREAM
8885      (pdb,
8886       master_stream_ptr,
8887       alob_stream_mode,
8888       sqlstm_label),
8889      in_vl(0),
8890      iv_len(0),
8891      cur_in_x(0),
8892      cur_in_y(0),
8893      in_y_len(0),
8894      null_fetched(0),
8895      avl(0),
8896      avl_len(0),
8897      var_info()
8898  {
8899   int i,j;
8900   this->dirty=0;
8901   this->auto_commit_flag=1;
8902   this->adb=&pdb;
8903   this->in_exception_flag=0;
8904   this->stm_text=0;
8905   this->array_size=arr_size;
8906   this->should_delete_flag=0;
8907 
8908   {
8909    size_t len=strlen(sqlstm)+1;
8910    this->stm_text=new char[len];
8911    OTL_STRCPY_S(this->stm_text,len,sqlstm);
8912    otl_tmpl_ext_hv_decl
8913     <TVariableStruct,TTimestampStruct,TExceptionStruct,
8914      TConnectStruct,TCursorStruct> hvd(this->stm_text,arr_size);
8915    if(hvd.has_plsql_tabs_or_refcur() && arr_size>1){
8916       if(this->adb)this->adb->increment_throw_count();
8917       if(this->adb&&this->adb->get_throw_count()>1)return;
8918       if(otl_uncaught_exception()) return;
8919       throw OTL_TMPL_EXCEPTION
8920        (otl_error_msg_33,
8921         otl_error_code_33,
8922         this->stm_label?this->stm_label:
8923         this->stm_text);
8924    }
8925    if(hvd.get_vst(otl_tmpl_ext_hv_decl
8926                   <TVariableStruct,TTimestampStruct,TExceptionStruct,
8927                   TConnectStruct,TCursorStruct>::def)==hvd.get_len()){
8928      this->should_delete_flag=1;
8929      hvd.alloc_host_var_list(this->vl,this->vl_len,pdb);
8930    }else{
8931      for(i=0;i<hvd.get_len();++i){
8932        if(hvd.get_inout(i)==
8933           otl_tmpl_ext_hv_decl
8934           <TVariableStruct,
8935           TTimestampStruct,
8936           TExceptionStruct,
8937           TConnectStruct,
8938           TCursorStruct>::in)
8939       ++this->vl_len;
8940        else if(hvd.get_inout(i)==
8941                otl_tmpl_ext_hv_decl
8942                <TVariableStruct,
8943                TTimestampStruct,
8944                TExceptionStruct,
8945                TConnectStruct,
8946                TCursorStruct>::out)
8947          ++iv_len;
8948        else if(hvd.get_inout(i)==
8949                otl_tmpl_ext_hv_decl
8950                <TVariableStruct,
8951                TTimestampStruct,
8952                TExceptionStruct,
8953                TConnectStruct,
8954                TCursorStruct>::io){
8955          ++this->vl_len;
8956          ++iv_len;
8957        }
8958      }
8959      if(this->vl_len>0){
8960        this->vl=new otl_tmpl_variable<TVariableStruct>*[this->vl_len];
8961      }
8962      if(iv_len>0){
8963        in_vl=new otl_tmpl_variable<TVariableStruct>*[iv_len];
8964      }
8965      if(hvd.get_len()>0){
8966        avl=new otl_tmpl_variable<TVariableStruct>*[hvd.get_len()];
8967      }
8968     iv_len=0;
8969     this->vl_len=0;
8970     avl_len=hvd.get_len();
8971     for(j=0;j<avl_len;++j){
8972 #if defined(OTL_STREAM_LEGACY_BUFFER_SIZE_TYPE)
8973      if(hvd.pl_tab_size[j]>32767){
8974       char tmp_var_info[256];
8975       otl_var_info_var
8976        (hvd[j],
8977         otl_var_none,
8978         otl_var_none,
8979         tmp_var_info,
8980         sizeof(tmp_var_info));
8981       if(this->adb)this->adb->increment_throw_count();
8982       if(this->adb&&this->adb->get_throw_count()>1)return;
8983       if(otl_uncaught_exception()) return;
8984       throw OTL_TMPL_EXCEPTION
8985        (otl_error_msg_6,
8986         otl_error_code_6,
8987         this->stm_label?this->stm_label:
8988         this->stm_text,
8989         tmp_var_info);
8990       }
8991 #endif
8992      otl_tmpl_variable<TVariableStruct>* v=hvd.alloc_var
8993       (hvd[j],
8994        hvd.get_inout(j),
8995        otl_tmpl_ext_hv_decl
8996         <TVariableStruct,TTimestampStruct,TExceptionStruct,
8997          TConnectStruct,TCursorStruct>::def,
8998        pdb,
8999        hvd.get_pl_tab_size(j));
9000      if(v==0){
9001        int k;
9002        for(k=0;k<j;++k){
9003          delete avl[k];
9004          avl[k]=0;
9005        }
9006        delete[] avl;
9007        avl=0;
9008        this->vl_len=0;
9009        throw OTL_TMPL_EXCEPTION
9010          (otl_error_msg_12,
9011           otl_error_code_12,
9012           hvd.stm_label()?hvd.stm_label():hvd.stm_text(),
9013           hvd[j]);
9014      }
9015      v->set_name_pos(j+1);
9016      avl[j]=v;
9017      if(hvd.get_inout(j)==
9018         otl_tmpl_ext_hv_decl
9019         <TVariableStruct,
9020         TTimestampStruct,
9021         TExceptionStruct,
9022         TConnectStruct,
9023         TCursorStruct>::in){
9024        ++this->vl_len;
9025        this->vl[this->vl_len-1]=v;
9026        v->set_param_type(otl_input_param);
9027      }else if(hvd.get_inout(j)==
9028               otl_tmpl_ext_hv_decl
9029               <TVariableStruct,
9030               TTimestampStruct,
9031               TExceptionStruct,
9032               TConnectStruct,
9033               TCursorStruct>::out){
9034        ++iv_len;
9035        in_vl[iv_len-1]=v;
9036        v->set_param_type(otl_output_param);
9037      }else if(hvd.get_inout(j)==
9038               otl_tmpl_ext_hv_decl
9039               <TVariableStruct,
9040               TTimestampStruct,
9041               TExceptionStruct,
9042               TConnectStruct,
9043               TCursorStruct>::io){
9044        ++this->vl_len;
9045        ++iv_len;
9046        this->vl[this->vl_len-1]=v;
9047        in_vl[iv_len-1]=v;
9048        v->set_param_type(otl_inout_param);
9049      }
9050     }
9051    }
9052   }
9053   try{
9054    this->parse();
9055    for(i=0;i<this->vl_len;++i){
9056      if(this->vl[i]->get_var_struct().get_otl_adapter()==otl_odbc_adapter){
9057        this->vl[i]->get_var_struct().set_lob_stream_mode(this->lob_stream_mode);
9058        this->vl[i]->get_var_struct().set_vparam_type(this->vl[i]->get_param_type());
9059        if(this->vl[i]->get_ftype()==otl_var_varchar_long||
9060           this->vl[i]->get_ftype()==otl_var_raw_long){
9061          this->vl[i]->set_not_null(0);
9062        }
9063     }
9064     this->bind(*(this->vl[i]));
9065    }
9066    for(j=0;j<iv_len;++j)
9067     this->bind(*in_vl[j]);
9068    rewind();
9069   }catch(OTL_CONST_EXCEPTION OTL_TMPL_EXCEPTION&){
9070    cleanup();
9071    if(this->adb)this->adb->increment_throw_count();
9072    throw;
9073   }
9074 
9075  }
9076 
9077  virtual ~otl_tmpl_inout_stream()
9078  {this->in_destructor=1;
9079   if(!this->in_exception_flag)
9080    flush();
9081   cleanup();
9082  }
9083 
9084  int eof(void)
9085  {
9086   if(iv_len==0)return 1;
9087   if(in_y_len==0)return 1;
9088   if(cur_in_y<=in_y_len-1)return 0;
9089   return 1;
9090  }
9091 
9092  void flush(const int rowoff=0, const bool force_flush=false)
9093  {
9094   if(this->vl_len==0)return;
9095   in_y_len=this->cur_y+1;
9096   cur_in_y=0;
9097   cur_in_x=0;
9098   if(!this->in_exception_flag)
9099    OTL_TMPL_OUT_STREAM::flush(rowoff,force_flush);
9100  }
9101 
9102   void clean(const int clean_up_error_flag=0)
9103  {
9104   if(this->vl_len!=0) {
9105     in_y_len=this->cur_y+1;
9106     cur_in_y=0;
9107     cur_in_x=0;
9108   }
9109   OTL_TMPL_OUT_STREAM::clean(clean_up_error_flag);
9110  }
9111 
9112  void rewind(void)
9113  {
9114   flush();
9115   cur_in_x=0;
9116   cur_in_y=0;
9117   this->cur_x=-1;
9118   this->cur_y=0;
9119   in_y_len=0;
9120   null_fetched=0;
9121   if(this->vl_len==0){
9122     this->exec(this->array_size,0,otl_sql_exec_from_cursor_class);
9123    in_y_len=this->array_size;
9124    cur_in_y=0;
9125    cur_in_x=0;
9126   }
9127  }
9128 
9129  int is_null(void)
9130  {
9131   return null_fetched;
9132  }
9133 
9134   void skip_to_end_of_row()
9135   {
9136     if(eof())return;
9137     if(iv_len==0)return;
9138     if(in_y_len==0)return;
9139     if(cur_in_y<in_y_len-1){
9140       ++cur_in_y;
9141       cur_in_x=0;
9142     }else{
9143       cur_in_y=0;
9144       cur_in_x=0;
9145       in_y_len=0;
9146     }
9147   }
9148 
9149  void get_in_next(void)
9150  {
9151   if(iv_len==0)return;
9152   if(in_y_len==0)return;
9153   if(cur_in_x<iv_len-1)
9154    ++cur_in_x;
9155   else{
9156    if(cur_in_y<in_y_len-1){
9157     ++cur_in_y;
9158     cur_in_x=0;
9159    }else{
9160     cur_in_y=0;
9161     cur_in_x=0;
9162     in_y_len=0;
9163    }
9164   }
9165  }
9166 
9167   int check_in_type_throw(int type_code)
9168   {
9169     this->in_exception_flag=1;
9170     otl_var_info_var
9171       (in_vl[cur_in_x]->get_name(),
9172        in_vl[cur_in_x]->get_ftype(),
9173        type_code,
9174        var_info,
9175        sizeof(var_info));
9176     if(this->adb)this->adb->increment_throw_count();
9177     if(this->adb&&this->adb->get_throw_count()>1)return 0;
9178     if(otl_uncaught_exception()) return 0;
9179     throw OTL_TMPL_EXCEPTION
9180       (otl_error_msg_0,
9181        otl_error_code_0,
9182        this->stm_label?this->stm_label:
9183        this->stm_text,
9184        var_info);
9185   }
9186 
9187   int check_in_type(int type_code,int tsize)
9188   {
9189     switch(in_vl[cur_in_x]->get_ftype()){
9190     case otl_var_refcur:
9191       if(type_code==otl_var_refcur)
9192         return 1;
9193     case otl_var_db2time:
9194     case otl_var_db2date:
9195       if(type_code==otl_var_timestamp)
9196         return 1;
9197     case otl_var_char:
9198       if(type_code==otl_var_char)
9199         return 1;
9200     default:
9201       if(in_vl[cur_in_x]->get_ftype()==type_code &&
9202          in_vl[cur_in_x]->get_elem_size()==tsize)
9203         return 1;
9204     }
9205     return check_in_type_throw(type_code);
9206  }
9207 
9208  int is_null_intern(void)
9209  {
9210   if(iv_len==0)return 0;
9211   if(in_y_len==0)return 0;
9212   if(in_y_len>0)
9213    return in_vl[cur_in_x]->is_null(cur_in_y);
9214   return 0;
9215  }
9216 
9217 
9218  OTL_TMPL_INOUT_STREAM& operator>>(char& c)
9219  {
9220   if(eof())return *this;
9221   if(check_in_type(otl_var_char,1)){
9222    c=*OTL_RCAST(char*,in_vl[cur_in_x]->val(cur_in_y));
9223    null_fetched=is_null_intern();
9224   }
9225   get_in_next();
9226   return *this;
9227  }
9228 
9229  OTL_TMPL_INOUT_STREAM& operator>>(unsigned char& c)
9230  {
9231   if(eof())return *this;
9232   if(check_in_type(otl_var_char,1)){
9233    c=*OTL_RCAST(unsigned char*,in_vl[cur_in_x]->val(cur_in_y));
9234    null_fetched=is_null_intern();
9235   }
9236   get_in_next();
9237   return *this;
9238  }
9239 
9240 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
9241  OTL_TMPL_INOUT_STREAM& operator>>(OTL_STRING_CONTAINER& s)
9242  {
9243   if(eof())return *this;
9244   switch(in_vl[cur_in_x]->get_ftype()){
9245   case otl_var_char:
9246     {
9247 #if defined(OTL_ACE)
9248       s.set(OTL_RCAST(char*,in_vl[cur_in_x]->val(cur_in_y)),1);
9249 #else
9250       s=OTL_RCAST(char*,in_vl[cur_in_x]->val(cur_in_y));
9251 #endif
9252       null_fetched=is_null_intern();
9253     }
9254     break;
9255 #if defined(USER_DEFINED_STRING_CLASS) || \
9256     defined(OTL_STL) || defined(OTL_ACE)
9257   case otl_var_varchar_long:
9258   case otl_var_raw_long:
9259     {
9260       unsigned char* c=
9261         OTL_RCAST(unsigned char*,in_vl[cur_in_x]->val(cur_in_y));
9262       int len=in_vl[cur_in_x]->get_len();
9263 #if (defined(USER_DEFINED_STRING_CLASS) || defined(OTL_STL)) && !defined(OTL_ACE)
9264       s.assign(OTL_RCAST(char*,c),len);
9265 #elif defined(OTL_ACE)
9266       s.set(OTL_RCAST(char*,c),len,1);
9267 #endif
9268       null_fetched=is_null_intern();
9269     }
9270     break;
9271   case otl_var_blob:
9272   case otl_var_clob:
9273     {
9274       int len=0;
9275       int max_long_sz=this->adb->get_max_long_size();
9276       otl_auto_array_ptr<unsigned char> loc_ptr(max_long_sz);
9277       unsigned char* temp_buf=loc_ptr.get_ptr();
9278       int rc=in_vl[cur_in_x]->get_var_struct().get_blob
9279         (cur_in_y,
9280          temp_buf,
9281          max_long_sz,
9282          len);
9283       if(rc==0){
9284         if(this->adb)this->adb->increment_throw_count();
9285         if(this->adb&&this->adb->get_throw_count()>1)return *this;
9286         if(otl_uncaught_exception()) return *this;
9287         throw OTL_TMPL_EXCEPTION
9288           (this->adb->get_connect_struct(),
9289            this->stm_label?this->stm_label:
9290            this->stm_text);
9291       }
9292 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_ACE)
9293       s.assign(OTL_RCAST(char*,temp_buf),len);
9294 #elif defined(OTL_ACE)
9295       s.set(OTL_RCAST(char*,temp_buf),len,1);
9296 #endif
9297 
9298       null_fetched=is_null_intern();
9299     }
9300     break;
9301 #endif
9302   default:
9303     check_in_type(otl_var_char,1);
9304   } // switch
9305   get_in_next();
9306   return *this;
9307  }
9308 #endif
9309 
9310  OTL_TMPL_INOUT_STREAM& operator>>(char* s)
9311  {
9312   if(eof())return *this;
9313   if(check_in_type(otl_var_char,1)){
9314    otl_strcpy(OTL_RCAST(unsigned char*,s),
9315               OTL_RCAST(const unsigned char*,in_vl[cur_in_x]->val(cur_in_y)));
9316    null_fetched=is_null_intern();
9317   }
9318   get_in_next();
9319   return *this;
9320  }
9321 
9322 #if defined(OTL_UNICODE_STRING_TYPE)
9323   OTL_TMPL_INOUT_STREAM& operator>>(OTL_UNICODE_STRING_TYPE& s)
9324   {
9325     if(eof())return *this;
9326     if(check_in_type(otl_var_char,1)){
9327 #if defined(OTL_ODBC) || defined(DB2_CLI)
9328       s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,in_vl[cur_in_x]->val(cur_in_y));
9329 #else
9330 #if defined(OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR)
9331       OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
9332         (OTL_UNICODE_CHAR_TYPE*,in_vl[cur_in_x]->val(cur_in_y));
9333       OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR(s,temp_s+1,*temp_s);
9334 #else
9335       OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
9336         (OTL_UNICODE_CHAR_TYPE*,in_vl[cur_in_x]->val(cur_in_y));
9337       s.assign(temp_s+1,*temp_s);
9338 #endif
9339 #endif
9340 
9341 
9342       null_fetched=is_null_intern();
9343     }
9344     get_in_next();
9345     return *this;
9346   }
9347 #endif
9348 
9349  OTL_TMPL_INOUT_STREAM& operator>>(unsigned char* s)
9350  {
9351   if(eof())return *this;
9352   if(check_in_type(otl_var_char,1)){
9353    otl_strcpy2(OTL_RCAST(unsigned char*,s),
9354                OTL_RCAST(unsigned char*,in_vl[cur_in_x]->val(cur_in_y)),
9355                in_vl[cur_in_x]->get_len(cur_in_y)
9356               );
9357    null_fetched=is_null_intern();
9358   }
9359   get_in_next();
9360   return *this;
9361  }
9362 
9363 #define OTL_D4(T,T_type)                                \
9364  OTL_TMPL_INOUT_STREAM& operator>>(T& n)                \
9365  {                                                      \
9366   if(eof())return *this;                                \
9367   if(check_in_type(T_type,sizeof(T))){                  \
9368    n=*OTL_RCAST(T*,in_vl[cur_in_x]->val(cur_in_y));     \
9369    null_fetched=is_null_intern();                       \
9370   }                                                     \
9371   get_in_next();                                        \
9372   return *this;                                         \
9373  }
9374 
9375 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
9376   OTL_D4(int,otl_var_int)
9377   OTL_D4(unsigned,otl_var_unsigned_int)
9378 #if defined(OTL_BIGINT)
9379   OTL_D4(OTL_BIGINT,otl_var_bigint)
9380 #endif
9381   OTL_D4(long,otl_var_long_int)
9382   OTL_D4(short,otl_var_short)
9383   OTL_D4(float,otl_var_float)
9384   OTL_D4(double,otl_var_double)
9385 #else
9386     template<OTL_TYPE_NAME T,const int T_type> OTL_D4(T,T_type)
9387 #endif
9388 
9389 #if defined(OTL_PL_TAB)
9390  OTL_TMPL_INOUT_STREAM& operator>>(otl_pl_tab_generic& tab)
9391  {
9392   if(eof())return *this;
9393   if(check_in_type(tab.get_vtype(),tab.get_elem_size())){
9394     int i,tmp_len;
9395     tmp_len=in_vl[cur_in_x]->get_pl_tab_len();
9396     if(tab.get_tab_size()<tmp_len)
9397       tmp_len=tab.get_tab_size();
9398     tab.set_len(tmp_len);
9399     if(tab.get_vtype()==otl_var_char){
9400      for(i=0;i<tmp_len;++i){
9401       int overflow;
9402       otl_strcpy3
9403        (OTL_RCAST(unsigned char*,tab.val(i)),
9404         OTL_RCAST(unsigned char*,in_vl[cur_in_x]->val(i)),
9405         in_vl[cur_in_x]->get_len(i),
9406         overflow,
9407         tab.get_elem_size()
9408        );
9409      }
9410     }else if(tab.get_vtype()==otl_var_timestamp){
9411       otl_datetime* ext_dt=OTL_RCAST(otl_datetime*,tab.get_p_v());
9412       otl_oracle_date* int_dt=
9413         OTL_RCAST(otl_oracle_date*,in_vl[cur_in_x]->val());
9414       int j;
9415       for(j=0;j<tmp_len;++j){
9416         convert_date(*ext_dt,*int_dt);
9417         ++int_dt;
9418         ++ext_dt;
9419       }
9420     }else
9421       memcpy(OTL_RCAST(char*,tab.val()),
9422              OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9423              tab.get_elem_size()*tmp_len);
9424     for(i=0;i<tmp_len;++i){
9425      if(in_vl[cur_in_x]->is_null(i))
9426       tab.set_null(i);
9427      else
9428       tab.set_non_null(i);
9429     }
9430    null_fetched=0;
9431   }
9432   get_in_next();
9433   return *this;
9434  }
9435 #endif
9436 
9437 #if defined(OTL_PL_TAB) && defined(OTL_STL)
9438  OTL_TMPL_INOUT_STREAM& operator>>(otl_pl_vec_generic& vec)
9439  {
9440   if(eof())return *this;
9441   if(check_in_type(vec.get_vtype(),vec.get_elem_size())){
9442     int i,tmp_len;
9443     tmp_len=in_vl[cur_in_x]->get_pl_tab_len();
9444     vec.set_len(tmp_len);
9445     if(tmp_len>0){
9446       switch(vec.get_vtype()){
9447       case otl_var_char:
9448         for(i=0;i<tmp_len;++i){
9449           (*OTL_RCAST(STD_NAMESPACE_PREFIX vector<OTL_STRING_CONTAINER>*,vec.get_p_v()))[i]=
9450             OTL_RCAST(char*,in_vl[cur_in_x]->val(i));
9451         }
9452         break;
9453       case otl_var_timestamp:
9454         {
9455           otl_datetime* ext_dt;
9456           otl_oracle_date* int_dt=
9457             OTL_RCAST(otl_oracle_date*,in_vl[cur_in_x]->val());
9458           int j;
9459           for(j=0;j<tmp_len;++j){
9460             ext_dt=OTL_RCAST
9461               (otl_datetime*,
9462                &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<otl_datetime>*,vec.get_p_v()))[j]);
9463             convert_date(*ext_dt,*int_dt);
9464             ++int_dt;
9465           }
9466         }
9467         break;
9468       case otl_var_int:
9469         memcpy(OTL_RCAST
9470                (char*,
9471                 &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<int>*,vec.get_p_v()))[0]),
9472                OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9473                sizeof(int)*tmp_len);
9474         break;
9475       case otl_var_double:
9476         memcpy(OTL_RCAST(char*,
9477                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<double>*,
9478                                       vec.get_p_v()))[0]),
9479                OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9480                sizeof(double)*tmp_len);
9481         break;
9482       case otl_var_float:
9483         memcpy(OTL_RCAST(char*,
9484                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<float>*,
9485                                       vec.get_p_v()))[0]),
9486                OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9487                sizeof(float)*tmp_len);
9488         break;
9489       case otl_var_unsigned_int:
9490         memcpy(OTL_RCAST(char*,
9491                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<unsigned>*,
9492                                       vec.get_p_v()))[0]),
9493                OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9494                sizeof(unsigned)*tmp_len);
9495         break;
9496       case otl_var_short:
9497         memcpy(OTL_RCAST(char*,
9498                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<short>*,
9499                                       vec.get_p_v()))[0]),
9500                OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9501                sizeof(short)*tmp_len);
9502         break;
9503       case otl_var_long_int:
9504         memcpy(OTL_RCAST(char*,
9505                          &(*OTL_RCAST(STD_NAMESPACE_PREFIX vector<long int>*,
9506                                       vec.get_p_v()))[0]),
9507                OTL_RCAST(char*,in_vl[cur_in_x]->val()),
9508                sizeof(long int)*tmp_len);
9509         break;
9510       }
9511 
9512     }
9513     for(i=0;i<tmp_len;++i){
9514      if(in_vl[cur_in_x]->is_null(i))
9515       vec.set_null(i);
9516      else
9517       vec.set_non_null(i);
9518     }
9519    null_fetched=0;
9520   }
9521   get_in_next();
9522   return *this;
9523  }
9524 #endif
9525 
9526 
9527  OTL_TMPL_INOUT_STREAM& operator>>(TTimestampStruct& t)
9528  {
9529   if(eof())return *this;
9530   if(check_in_type(otl_var_timestamp,sizeof(TTimestampStruct))){
9531    TTimestampStruct* tm=
9532     OTL_RCAST(TTimestampStruct*,in_vl[cur_in_x]->val(cur_in_y));
9533    int rc=in_vl[cur_in_x]->get_var_struct().read_dt
9534      (&t,tm,sizeof(TTimestampStruct));
9535    if(rc==0){
9536      if(this->adb)this->adb->increment_throw_count();
9537      if(this->adb&&this->adb->get_throw_count()>1)return *this;
9538      if(otl_uncaught_exception()) return *this;
9539      throw OTL_TMPL_EXCEPTION
9540        (this->adb->get_connect_struct(),
9541         this->stm_label?this->stm_label:
9542         this->stm_text);
9543    }
9544    null_fetched=is_null_intern();
9545   }
9546   get_in_next();
9547   return *this;
9548  }
9549 
9550  OTL_TMPL_INOUT_STREAM& operator>>(otl_long_string& s)
9551  {
9552   int len=0;
9553   if(eof())return *this;
9554   switch(in_vl[cur_in_x]->get_ftype()){
9555   case otl_var_raw:
9556   case otl_var_varchar_long:
9557   case otl_var_raw_long:
9558     {
9559       unsigned char* c=OTL_RCAST(unsigned char*,in_vl[cur_in_x]->val(cur_in_y));
9560       len=in_vl[cur_in_x]->get_len();
9561       if(len>s.get_buf_size())
9562         len=s.get_buf_size();
9563       otl_memcpy(s.v,c,len,in_vl[cur_in_x]->get_ftype());
9564       s.set_len(len);
9565       if(in_vl[cur_in_x]->get_ftype()==otl_var_varchar_long)
9566         s.null_terminate_string(len);
9567       null_fetched=is_null_intern();
9568     }
9569     break;
9570   case otl_var_clob:
9571   case otl_var_blob:
9572     {
9573       int rc=in_vl[cur_in_x]->get_var_struct().get_blob
9574         (cur_in_y,s.v,s.get_buf_size(),len);
9575       if(rc==0){
9576         if(this->adb)this->adb->increment_throw_count();
9577         if(this->adb&&this->adb->get_throw_count()>1)return *this;
9578         if(otl_uncaught_exception()) return *this;
9579         throw OTL_TMPL_EXCEPTION
9580           (this->adb->get_connect_struct(),
9581            this->stm_label?this->stm_label:
9582            this->stm_text);
9583       }
9584       if(len>s.get_buf_size())
9585         len=s.get_buf_size();
9586       s.set_len(len);
9587       if(in_vl[cur_in_x]->get_ftype()==otl_var_clob)
9588         s.null_terminate_string(len);
9589       null_fetched=is_null_intern();
9590     }
9591     break;
9592   default:
9593     {
9594       char temp_var_info[256];
9595       otl_var_info_var
9596         (in_vl[cur_in_x]->get_name(),
9597          in_vl[cur_in_x]->get_ftype(),
9598          otl_var_long_string,
9599          temp_var_info,
9600          sizeof(temp_var_info));
9601       if(this->adb)this->adb->increment_throw_count();
9602       if(this->adb&&this->adb->get_throw_count()>1)return *this;
9603       if(otl_uncaught_exception()) return *this;
9604       throw OTL_TMPL_EXCEPTION
9605         (otl_error_msg_0,
9606          otl_error_code_0,
9607          this->stm_label?this->stm_label:
9608          this->stm_text,
9609          temp_var_info);
9610     }
9611   }
9612   get_in_next();
9613   return *this;
9614  }
9615 
9616 #if defined(OTL_ORA8)||defined(OTL_ODBC)
9617  OTL_TMPL_INOUT_STREAM& operator>>
9618   (otl_lob_stream_generic& s)
9619  {
9620   if(eof())return *this;
9621   if((s.get_ora_lob() &&
9622       in_vl[cur_in_x]->get_ftype()==otl_var_clob)||
9623      in_vl[cur_in_x]->get_ftype()==otl_var_blob){
9624     null_fetched=is_null_intern();
9625     s.init
9626       (OTL_RCAST(void*,in_vl[cur_in_x]),
9627        OTL_RCAST(void*,this->adb),
9628        OTL_RCAST(void*,this),
9629        0,
9630        otl_lob_stream_read_mode,
9631        this->is_null());
9632   }else if(in_vl[cur_in_x]->get_ftype()==otl_var_varchar_long||
9633            in_vl[cur_in_x]->get_ftype()==otl_var_raw_long){
9634    s.init
9635     (OTL_RCAST(void*,in_vl[cur_in_x]),
9636      OTL_RCAST(void*,this->adb),
9637      OTL_RCAST(void*,this),
9638      0,
9639      otl_lob_stream_read_mode);
9640   }else{
9641    char tmp_var_info[256];
9642    otl_var_info_var
9643      (in_vl[cur_in_x]->get_name(),
9644       in_vl[cur_in_x]->get_ftype(),
9645      otl_var_long_string,
9646      tmp_var_info,
9647      sizeof(tmp_var_info));
9648    if(this->adb)this->adb->increment_throw_count();
9649    if(this->adb&&this->adb->get_throw_count()>1)return *this;
9650    if(otl_uncaught_exception()) return *this;
9651    throw OTL_TMPL_EXCEPTION
9652     (otl_error_msg_0,
9653      otl_error_code_0,
9654      this->stm_label?this->stm_label:
9655      this->stm_text,
9656      tmp_var_info);
9657   }
9658   get_in_next();
9659   return *this;
9660  }
9661 #endif
9662 
9663  otl_tmpl_inout_stream():
9664    OTL_TMPL_OUT_STREAM(),
9665    in_vl(0),
9666    iv_len(0),
9667    cur_in_x(0),
9668    cur_in_y(0),
9669    in_y_len(0),
9670    null_fetched(0),
9671    avl(0),
9672    avl_len(0),
9673    var_info()
9674  {
9675  }
9676 
9677 
9678 private:
9679 
9680  otl_tmpl_inout_stream
9681  (const otl_tmpl_inout_stream&):
9682    OTL_TMPL_OUT_STREAM(),
9683    in_vl(0),
9684    iv_len(0),
9685    cur_in_x(0),
9686    cur_in_y(0),
9687      in_y_len(0),
9688    null_fetched(0),
9689    avl(0),
9690    avl_len(0),
9691    var_info()
9692  {
9693  }
9694 
9695  otl_tmpl_inout_stream& operator=(const otl_tmpl_inout_stream&)
9696  {
9697    return *this;
9698  }
9699 
9700 };
9701 
9702 // ==================== OTL-Adapter for ODBC/CLI =========================
9703 
9704 #if defined(OTL_ODBC)
9705 
9706 #if !defined(OTL_DB2_CLI) && !defined(OTL_ODBC_zOS)
9707 
9708 // in case if it's ODBC for Windows (!OTL_ODBC_UNIX), and windows.h is
9709 // not included yet (_WINDOWS_ not defined yet), then include the file
9710 // explicitly
9711 #if !defined(OTL_ODBC_UNIX) && !defined(_WINDOWS_)
9712 #include <windows.h>
9713 #endif
9714 
9715 #if defined(OTL_ODBC_UNIX) && defined(OTL_INFORMIX_CLI)
9716 #include <infxsql.h>
9717 
9718 #define OTL_HENV SQLHANDLE
9719 #define OTL_HDBC SQLHANDLE
9720 #define OTL_SQLHANDLE SQLHANDLE
9721 #define OTL_SQLRETURN SQLRETURN
9722 #define OTL_SQLSMALLINT SQLSMALLINT
9723 #define OTL_SQLCHAR_PTR SQLCHAR*
9724 #define OTL_SQLINTEGER_PTR SQLINTEGER*
9725 #define OTL_SQLSMALLINT_PTR SQLSMALLINT*
9726 #define OTL_SQLINTEGER SQLINTEGER
9727 #define OTL_SQLHSTMT SQLHSTMT
9728 #define OTL_SQLUSMALLINT SQLUSMALLINT
9729 #define OTL_SQLPOINTER SQLPOINTER
9730 #define OTL_SQLCHAR SQLCHAR
9731 #define OTL_SQLUINTEGER SQLUINTEGER
9732 #define OTL_SQLLEN SQLINTEGER
9733 #define OTL_SQLLEN_PTR SQLINTEGER*
9734 #define OTL_SQLULEN SQLUINTEGER
9735 #define OTL_SQLULEN_PTR SQLUINTEGER*
9736 
9737 #else
9738 #include <sql.h>
9739 #include <sqlext.h>
9740 #endif
9741 
9742 #else
9743 #include <sqlcli1.h>
9744 #endif
9745 
9746 #if defined(OTL_ODBC) && !defined(OTL_DB2_CLI)
9747 #define OTL_SQL_XML (-152)
9748 #endif
9749 
9750 #if defined(OTL_ODBC) && defined(OTL_DB2_CLI)
9751 #if defined(SQL_XML)
9752 #define OTL_SQL_XML SQL_XML
9753 #else
9754 #define OTL_SQL_XML (-370)
9755 #endif
9756 #endif
9757 
9758 #if defined(OTL_ODBC)
9759 
9760 #if (ODBCVER >= 0x0300)
9761 #define OTL_SQL_TIMESTAMP_STRUCT SQL_TIMESTAMP_STRUCT
9762 #define OTL_SQL_TIME_STRUCT SQL_TIME_STRUCT
9763 #define OTL_SQL_DATE_STRUCT SQL_DATE_STRUCT
9764 #else
9765 #define OTL_SQL_TIMESTAMP_STRUCT TIMESTAMP_STRUCT
9766 #define OTL_SQL_TIME_STRUCT TIME_STRUCT
9767 #define OTL_SQL_DATE_STRUCT DATE_STRUCT
9768 #endif
9769 
9770 #if defined(OTL_DB2_CLI)
9771 
9772 #define OTL_HENV SQLHANDLE
9773 #define OTL_HDBC SQLHANDLE
9774 #define OTL_SQLHANDLE SQLHANDLE
9775 #define OTL_SQLRETURN SQLRETURN
9776 #define OTL_SQLSMALLINT SQLSMALLINT
9777 #define OTL_SQLCHAR_PTR SQLCHAR*
9778 #define OTL_SQLINTEGER_PTR SQLINTEGER*
9779 #define OTL_SQLSMALLINT_PTR SQLSMALLINT*
9780 #define OTL_SQLINTEGER SQLINTEGER
9781 #define OTL_SQLHSTMT SQLHSTMT
9782 #define OTL_SQLUSMALLINT SQLUSMALLINT
9783 #define OTL_SQLPOINTER SQLPOINTER
9784 #define OTL_SQLCHAR SQLCHAR
9785 #define OTL_SQLUINTEGER SQLUINTEGER
9786 
9787 #if defined(OTL_IODBC_BSD)
9788 
9789 #define OTL_SQLLEN SQLLEN
9790 #define OTL_SQLULEN SQLULEN
9791 #define OTL_SQLULEN_PTR SQLULEN*
9792 #define OTL_SQLLEN_PTR SQLLEN*
9793 
9794 #else // #if defined(OTL_IODBC_BSD)
9795 
9796 #define OTL_SQLLEN SQLINTEGER
9797 #define OTL_SQLLEN_PTR SQLINTEGER*
9798 #define OTL_SQLULEN SQLUINTEGER
9799 #define OTL_SQLULEN_PTR SQLUINTEGER*
9800 
9801 #endif // #if defined(OTL_IODBC_BSD)
9802 
9803 #else // #if defined(OTL_DB2_CLI)
9804 
9805 #if (ODBCVER >= 0x0300)
9806 
9807 #define OTL_HENV SQLHANDLE
9808 #define OTL_HDBC SQLHANDLE
9809 #define OTL_SQLHANDLE SQLHANDLE
9810 #define OTL_SQLRETURN SQLRETURN
9811 #define OTL_SQLSMALLINT SQLSMALLINT
9812 #define OTL_SQLCHAR_PTR SQLCHAR*
9813 #define OTL_SQLINTEGER_PTR SQLINTEGER*
9814 #define OTL_SQLSMALLINT_PTR SQLSMALLINT*
9815 #define OTL_SQLINTEGER SQLINTEGER
9816 #define OTL_SQLHSTMT SQLHSTMT
9817 #define OTL_SQLUSMALLINT SQLUSMALLINT
9818 #define OTL_SQLPOINTER SQLPOINTER
9819 #define OTL_SQLCHAR SQLCHAR
9820 #define OTL_SQLUINTEGER SQLUINTEGER
9821 
9822 #if defined(OTL_IODBC_BSD)
9823 
9824 #define OTL_SQLLEN SQLLEN
9825 #define OTL_SQLLEN_PTR SQLLEN*
9826 #define OTL_SQLULEN SQLULEN
9827 #define OTL_SQLULEN_PTR SQLULEN*
9828 
9829 #else // #if defined(OTL_IODBC_BSD)
9830 
9831 #if (defined(_MSC_VER)&&(_MSC_VER==1200)) // VC 6++
9832 #define OTL_SQLLEN SQLINTEGER
9833 #define OTL_SQLLEN_PTR SQLINTEGER*
9834 #define OTL_SQLULEN SQLUINTEGER
9835 #define OTL_SQLULEN_PTR SQLUINTEGER*
9836 #else
9837 
9838 #if !defined(OTL_SQLLEN)
9839 #define OTL_SQLLEN SQLLEN
9840 #define OTL_SQLLEN_PTR SQLLEN*
9841 #define OTL_SQLULEN SQLULEN
9842 #define OTL_SQLULEN_PTR SQLULEN*
9843 #endif
9844 
9845 #endif
9846 
9847 #endif // #if defined(OTL_IODBC_BSD)
9848 
9849 #else // #if (ODBCVER >= 0x0300)
9850 
9851 #define OTL_HENV HENV
9852 #define OTL_HDBC HDBC
9853 #define OTL_SQLHANDLE HSTMT
9854 #define OTL_SQLRETURN SQLRETURN
9855 #define OTL_SQLSMALLINT SQLSMALLINT
9856 #define OTL_SQLCHAR_PTR SQLCHAR*
9857 #define OTL_SQLINTEGER_PTR SQLINTEGER*
9858 #define OTL_SQLSMALLINT_PTR SQLSMALLINT*
9859 #define OTL_SQLINTEGER SQLINTEGER
9860 #define OTL_SQLHSTMT SQLHSTMT
9861 #define OTL_SQLUSMALLINT SQLUSMALLINT
9862 #define OTL_SQLPOINTER SQLPOINTER
9863 #define OTL_SQLCHAR SQLCHAR
9864 #define OTL_SQLUINTEGER SQLUINTEGER
9865 
9866 #if defined(OTL_IODBC_BSD)
9867 
9868 #define OTL_SQLLEN SQLLEN
9869 #define OTL_SQLLEN_PTR SQLLEN*
9870 #define OTL_SQLULEN SQLULEN
9871 #define OTL_SQLULEN_PTR SQLULEN*
9872 
9873 #else // #if defined(OTL_IODBC_BSD)
9874 
9875 #if (defined(_MSC_VER)&&(_MSC_VER==1200)) // VC 6++
9876 #define OTL_SQLLEN SQLINTEGER
9877 #define OTL_SQLLEN_PTR SQLINTEGER*
9878 #define OTL_SQLULEN SQLUINTEGER
9879 #define OTL_SQLULEN_PTR SQLUINTEGER*
9880 #else
9881 #define OTL_SQLLEN SQLLEN
9882 #define OTL_SQLLEN_PTR SQLLEN*
9883 #define OTL_SQLULEN SQLULEN
9884 #define OTL_SQLULEN_PTR SQLULEN*
9885 #endif
9886 
9887 #endif // #if defined(OTL_IODBC_BSD)
9888 
9889 #endif
9890 
9891 #endif
9892 
9893 #endif
9894 
9895 OTL_ODBC_NAMESPACE_BEGIN
9896 
9897 #if (defined(UNICODE) || defined(_UNICODE)) && defined(OTL_ODBC)
9898 
9899 inline void otl_convert_char_to_SQLWCHAR(SQLWCHAR* dst, const unsigned char* src)
9900 {
9901   while(*src)
9902     *dst++=OTL_SCAST(SQLWCHAR,*src++);
9903   *dst=0;
9904 }
9905 
9906 inline void otl_convert_SQLWCHAR_to_char(unsigned char* dst, const SQLWCHAR*src)
9907 {
9908   while(*src)
9909     *dst++=OTL_SCAST(unsigned char,*src++);
9910   *dst=0;
9911 }
9912 
9913 inline size_t otl_strlen(const SQLWCHAR* s)
9914 {
9915   size_t len=0;
9916   while(*s){
9917     ++s;
9918     ++len;
9919   }
9920   return len;
9921 }
9922 
9923 #endif
9924 
9925 typedef OTL_SQL_TIMESTAMP_STRUCT otl_time;
9926 const int otl_odbc_date_prec=23;
9927 #if defined(OTL_ODBC_MSSQL_2008)
9928 const int otl_odbc_date_scale=7;
9929 #elif defined(OTL_ODBC_MSSQL_2005)
9930 const int otl_odbc_date_scale=3;
9931 #else
9932 const int otl_odbc_date_scale=0;
9933 #endif
9934 
9935 const int OTL_MAX_MSG_ARR=512;
9936 
9937 class otl_exc{
9938 public:
9939 
9940 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
9941   SQLWCHAR msg[1000];
9942   SQLWCHAR sqlstate[1000];
9943 #else
9944   unsigned char msg[1000];
9945   unsigned char sqlstate[1000];
9946 #endif
9947   int code;
9948 
9949 #if defined(OTL_EXTENDED_EXCEPTION)
9950 
9951 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
9952   SQLWCHAR** msg_arr;
9953   SQLWCHAR** sqlstate_arr;
9954 #else
9955   char** msg_arr;
9956   char** sqlstate_arr;
9957 #endif
9958 
9959   int* code_arr;
9960   int arr_len;
9961 
9962 #endif
9963 
9964  enum{disabled=0,enabled=1};
9965 
9966   otl_exc():
9967     msg(),
9968     sqlstate(),
9969     code(0)
9970 #if defined(OTL_EXTENDED_EXCEPTION)
9971 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
9972     ,msg_arr(0),
9973     sqlstate_arr(0),
9974 #else
9975     ,msg_arr(0),
9976     sqlstate_arr(0),
9977 #endif
9978     code_arr(0),
9979     arr_len(0)
9980 #endif
9981  {
9982   sqlstate[0]=0;
9983   msg[0]=0;
9984  }
9985 
9986 #if defined(OTL_EXTENDED_EXCEPTION)
9987   otl_exc(const otl_exc& ex):
9988 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
9989     msg(),
9990     sqlstate(),
9991 #else
9992     msg(),
9993     sqlstate(),
9994 #endif
9995     code(0),
9996 #if defined(OTL_EXTENDED_EXCEPTION)
9997 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
9998     msg_arr(0),
9999     sqlstate_arr(0),
10000 #else
10001     msg_arr(0),
10002     sqlstate_arr(0),
10003 #endif
10004     code_arr(0),
10005     arr_len(0)
10006 #endif
10007   {
10008 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
10009     otl_strcpy(OTL_RCAST(unsigned char*,msg),
10010                OTL_RCAST(const unsigned char*,
10011                          OTL_CCAST(SQLWCHAR*,ex.msg)));
10012     otl_strcpy(OTL_RCAST(unsigned char*,
10013                          OTL_CCAST(SQLWCHAR*,sqlstate)),
10014                OTL_RCAST(const unsigned char*,
10015                          OTL_CCAST(SQLWCHAR*,ex.sqlstate)));
10016     code=ex.code;
10017     arr_len=0;
10018     msg_arr=0;
10019     sqlstate_arr=0;
10020     code_arr=0;
10021     if(ex.arr_len>0){
10022       sqlstate_arr=new SQLWCHAR*[ex.arr_len];
10023       msg_arr=new SQLWCHAR*[ex.arr_len];
10024       code_arr=new int[ex.arr_len];
10025       int i;
10026       size_t msg_len, sqlstate_len;
10027       for(i=0;i<ex.arr_len;++i){
10028         msg_len=otl_strlen(ex.msg_arr[i]);
10029         sqlstate_len=otl_strlen(ex.sqlstate_arr[i]);
10030         msg_arr[i]=new SQLWCHAR[msg_len+1];
10031         sqlstate_arr[i]=new SQLWCHAR[sqlstate_len+1];
10032         otl_strcpy(OTL_RCAST(unsigned char*,msg_arr[i]),
10033                    OTL_RCAST(const unsigned char*,
10034                              OTL_CCAST(SQLWCHAR*,ex.msg_arr[i])));
10035         otl_strcpy(OTL_RCAST(unsigned char*,sqlstate_arr[i]),
10036                    OTL_RCAST(const unsigned char*,
10037                              OTL_CCAST(SQLWCHAR*,ex.sqlstate_arr[i])));
10038         code_arr[i]=ex.code_arr[i];
10039       }
10040       arr_len=ex.arr_len;
10041     }
10042 #else
10043     OTL_STRCPY_S(OTL_RCAST(char*,msg),
10044                  sizeof(msg),
10045                  OTL_RCAST(const char*,ex.msg));
10046     OTL_STRCPY_S(OTL_RCAST(char*,sqlstate),
10047                  sizeof(sqlstate),
10048                  OTL_RCAST(const char*,ex.sqlstate));
10049     code=ex.code;
10050     arr_len=0;
10051     msg_arr=0;
10052     sqlstate_arr=0;
10053     code_arr=0;
10054     if(ex.arr_len>0){
10055       sqlstate_arr=new char*[ex.arr_len];
10056       msg_arr=new char*[ex.arr_len];
10057       code_arr=new int[ex.arr_len];
10058       int i;
10059       size_t msg_len, sqlstate_len;
10060       for(i=0;i<ex.arr_len;++i){
10061         msg_len=strlen(ex.msg_arr[i]);
10062         sqlstate_len=strlen(ex.sqlstate_arr[i]);
10063         msg_arr[i]=new char[msg_len+1];
10064         sqlstate_arr[i]=new char[sqlstate_len+1];
10065         OTL_STRCPY_S(msg_arr[i],msg_len+1,ex.msg_arr[i]);
10066         OTL_STRCPY_S(sqlstate_arr[i],sqlstate_len+1,ex.sqlstate_arr[i]);
10067         code_arr[i]=ex.code_arr[i];
10068       }
10069       arr_len=ex.arr_len;
10070     }
10071 #endif
10072   }
10073 #endif
10074 
10075  void init(const char* amsg, const int acode)
10076  {
10077 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
10078    otl_convert_char_to_SQLWCHAR(msg,OTL_RCAST(unsigned char*,OTL_CCAST(char*,amsg)));
10079 #else
10080   OTL_STRCPY_S(OTL_RCAST(char*,msg),sizeof(msg),amsg);
10081 #endif
10082    code=acode;
10083    sqlstate[0]=0;
10084 #if defined(OTL_EXTENDED_EXCEPTION)
10085    msg_arr=0;
10086    sqlstate_arr=0;
10087    code_arr=0;
10088    arr_len=0;
10089 #endif
10090  }
10091 
10092   virtual ~otl_exc()
10093   {
10094 #if defined(OTL_EXTENDED_EXCEPTION)
10095     int i;
10096     if(arr_len>0){
10097       for(i=0;i<arr_len;++i){
10098         delete[] msg_arr[i];
10099         delete[] sqlstate_arr[i];
10100       }
10101       delete[] msg_arr;
10102       delete[] sqlstate_arr;
10103       delete[] code_arr;
10104       arr_len=0;
10105       msg_arr=0;
10106       sqlstate_arr=0;
10107       code_arr=0;
10108     }
10109 #endif
10110   }
10111 
10112 private:
10113 
10114   otl_exc& operator=(const otl_exc&)
10115   {
10116     return *this;
10117   }
10118 
10119 };
10120 
10121 #if (ODBCVER >= 0x0300)
10122 #if defined(OTL_EXTENDED_EXCEPTION)
10123 inline void otl_fill_exception(
10124   otl_exc& exception_struct,
10125   OTL_SQLHANDLE handle,
10126   OTL_SQLSMALLINT htype
10127 )
10128 {
10129 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
10130   OTL_SQLRETURN rc;
10131   OTL_SQLSMALLINT msg_len=0;
10132   SQLWCHAR* tmp_msg_arr[OTL_MAX_MSG_ARR];
10133   SQLWCHAR* tmp_sqlstate_arr[OTL_MAX_MSG_ARR];
10134   int tmp_code_arr[OTL_MAX_MSG_ARR];
10135   int tmp_arr_len=0;
10136   OTL_SQLSMALLINT tmp_msg_len=0;
10137   OTL_SQLSMALLINT tmp_sqlstate_len=0;
10138   int tmp_code;
10139   SQLWCHAR tmp_msg[SQL_MAX_MESSAGE_LENGTH];
10140   SQLWCHAR tmp_sqlstate[1000];
10141 
10142   otl_strcpy(OTL_RCAST(unsigned char*,tmp_msg),
10143              OTL_RCAST(const unsigned char*,
10144                        OTL_CCAST(SQLWCHAR*,exception_struct.msg)));
10145   otl_strcpy(OTL_RCAST(unsigned char*,tmp_sqlstate),
10146              OTL_RCAST(const unsigned char*,
10147                        OTL_CCAST(SQLWCHAR*,exception_struct.sqlstate)));
10148   tmp_code=exception_struct.code;
10149 
10150   do{
10151     tmp_sqlstate_len=OTL_SCAST(OTL_SQLSMALLINT,otl_strlen(tmp_sqlstate));
10152     tmp_msg_len=OTL_SCAST(OTL_SQLSMALLINT,otl_strlen(tmp_msg));
10153     ++tmp_arr_len;
10154     tmp_msg_arr[tmp_arr_len-1]=new SQLWCHAR[tmp_msg_len+1];
10155     tmp_sqlstate_arr[tmp_arr_len-1]=new SQLWCHAR[tmp_sqlstate_len+1];
10156     otl_strcpy(OTL_RCAST(unsigned char*,tmp_msg_arr[tmp_arr_len-1]),
10157                OTL_RCAST(const unsigned char*,
10158                          OTL_CCAST(SQLWCHAR*,tmp_msg)));
10159     otl_strcpy(OTL_RCAST(unsigned char*,tmp_sqlstate_arr[tmp_arr_len-1]),
10160                OTL_RCAST(const unsigned char*,
10161                          OTL_CCAST(SQLWCHAR*,tmp_sqlstate)));
10162     tmp_code_arr[tmp_arr_len-1]=tmp_code;
10163     rc=SQLGetDiagRec
10164       (htype,
10165        handle,
10166        OTL_SCAST(OTL_SQLSMALLINT,tmp_arr_len+1),
10167        OTL_RCAST(SQLWCHAR*,tmp_sqlstate),
10168        OTL_RCAST(OTL_SQLINTEGER_PTR,&tmp_code),
10169        OTL_RCAST(SQLWCHAR*,tmp_msg),
10170        SQL_MAX_MESSAGE_LENGTH-1,
10171        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
10172     tmp_msg[msg_len]=0;
10173     if((rc==SQL_NO_DATA||rc==SQL_INVALID_HANDLE||
10174         rc==SQL_ERROR)&&tmp_arr_len==1){
10175       int i;
10176       for(i=0;i<tmp_arr_len;++i){
10177         delete[] tmp_msg_arr[i];
10178         delete[] tmp_sqlstate_arr[i];
10179       }
10180       return;
10181     }
10182   }while(rc!=SQL_NO_DATA&&rc!=SQL_INVALID_HANDLE&&
10183          rc!=SQL_ERROR&&tmp_arr_len<OTL_MAX_MSG_ARR);
10184 
10185   exception_struct.arr_len=tmp_arr_len;
10186   exception_struct.msg_arr=new SQLWCHAR*[tmp_arr_len];
10187   exception_struct.sqlstate_arr=new SQLWCHAR*[tmp_arr_len];
10188   exception_struct.code_arr=new int[tmp_arr_len];
10189   memcpy(exception_struct.msg_arr,tmp_msg_arr,tmp_arr_len*sizeof(SQLWCHAR*));
10190   memcpy(exception_struct.sqlstate_arr,
10191          tmp_sqlstate_arr,
10192          tmp_arr_len*sizeof(SQLWCHAR*));
10193   memcpy(exception_struct.code_arr,
10194          tmp_code_arr,
10195          tmp_arr_len*sizeof(int));
10196 #elif defined(UNICODE)||defined(_UNICODE)
10197   OTL_SQLRETURN rc;
10198   OTL_SQLSMALLINT msg_len=0;
10199   char* tmp_msg_arr[OTL_MAX_MSG_ARR];
10200   char* tmp_sqlstate_arr[OTL_MAX_MSG_ARR];
10201   int tmp_code_arr[OTL_MAX_MSG_ARR];
10202   int tmp_arr_len=0;
10203   OTL_SQLSMALLINT tmp_msg_len=0;
10204   OTL_SQLSMALLINT tmp_sqlstate_len=0;
10205   int tmp_code;
10206   SQLWCHAR tmp_msg[SQL_MAX_MESSAGE_LENGTH];
10207   SQLWCHAR tmp_sqlstate[1000];
10208 
10209   otl_convert_char_to_SQLWCHAR
10210     (tmp_msg,
10211      OTL_RCAST(const unsigned char*,exception_struct.msg));
10212   otl_convert_char_to_SQLWCHAR
10213     (tmp_sqlstate,
10214      OTL_RCAST(const unsigned char*,exception_struct.sqlstate));
10215   tmp_code=exception_struct.code;
10216 
10217   do{
10218     tmp_sqlstate_len=OTL_SCAST(OTL_SQLSMALLINT,otl_strlen(tmp_sqlstate));
10219     tmp_msg_len=OTL_SCAST(OTL_SQLSMALLINT,otl_strlen(tmp_msg));
10220     ++tmp_arr_len;
10221     tmp_msg_arr[tmp_arr_len-1]=new char[tmp_msg_len+1];
10222     tmp_sqlstate_arr[tmp_arr_len-1]=new char[tmp_sqlstate_len+1];
10223     otl_convert_SQLWCHAR_to_char
10224       (OTL_RCAST(unsigned char*,tmp_msg_arr[tmp_arr_len-1]),tmp_msg);
10225     otl_convert_SQLWCHAR_to_char
10226       (OTL_RCAST(unsigned char*,tmp_sqlstate_arr[tmp_arr_len-1]),tmp_sqlstate);
10227     tmp_code_arr[tmp_arr_len-1]=tmp_code;
10228     rc=SQLGetDiagRec
10229       (htype,
10230        handle,
10231        OTL_SCAST(OTL_SQLSMALLINT,tmp_arr_len+1),
10232        tmp_sqlstate,
10233        OTL_RCAST(OTL_SQLINTEGER_PTR,&tmp_code),
10234        tmp_msg,
10235        SQL_MAX_MESSAGE_LENGTH-1,
10236        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
10237     tmp_msg[msg_len]=0;
10238     if((rc==SQL_NO_DATA||rc==SQL_INVALID_HANDLE||
10239         rc==SQL_ERROR)&&tmp_arr_len==1){
10240       int i;
10241       for(i=0;i<tmp_arr_len;++i){
10242         delete[] tmp_msg_arr[i];
10243         delete[] tmp_sqlstate_arr[i];
10244       }
10245       return;
10246     }
10247   }while(rc!=SQL_NO_DATA&&rc!=SQL_INVALID_HANDLE&&
10248          rc!=SQL_ERROR&&tmp_arr_len<OTL_MAX_MSG_ARR);
10249 
10250   exception_struct.arr_len=tmp_arr_len;
10251   exception_struct.msg_arr=new char*[tmp_arr_len];
10252   exception_struct.sqlstate_arr=new char*[tmp_arr_len];
10253   exception_struct.code_arr=new int[tmp_arr_len];
10254   memcpy(exception_struct.msg_arr,tmp_msg_arr,tmp_arr_len*sizeof(char*));
10255   memcpy(exception_struct.sqlstate_arr,tmp_sqlstate_arr,tmp_arr_len*sizeof(char*));
10256   memcpy(exception_struct.code_arr,tmp_code_arr,tmp_arr_len*sizeof(int));
10257 
10258 #else
10259 
10260   OTL_SQLRETURN rc;
10261   OTL_SQLSMALLINT msg_len=0;
10262   char* tmp_msg_arr[OTL_MAX_MSG_ARR];
10263   char* tmp_sqlstate_arr[OTL_MAX_MSG_ARR];
10264   int tmp_code_arr[OTL_MAX_MSG_ARR];
10265   int tmp_arr_len=0;
10266   OTL_SQLSMALLINT tmp_msg_len=0;
10267   OTL_SQLSMALLINT tmp_sqlstate_len=0;
10268   int tmp_code;
10269   char tmp_msg[SQL_MAX_MESSAGE_LENGTH];
10270   char tmp_sqlstate[1000];
10271 
10272   OTL_STRCPY_S(tmp_msg,
10273                sizeof(tmp_msg),
10274                OTL_RCAST(char*,exception_struct.msg));
10275   OTL_STRCPY_S(tmp_sqlstate,
10276                sizeof(tmp_sqlstate),
10277                OTL_RCAST(char*,exception_struct.sqlstate));
10278   tmp_code=exception_struct.code;
10279 
10280   do{
10281     tmp_sqlstate_len=OTL_SCAST(OTL_SQLSMALLINT,strlen(tmp_sqlstate));
10282     tmp_msg_len=OTL_SCAST(OTL_SQLSMALLINT,strlen(tmp_msg));
10283     ++tmp_arr_len;
10284     tmp_msg_arr[tmp_arr_len-1]=new char[tmp_msg_len+1];
10285     tmp_sqlstate_arr[tmp_arr_len-1]=new char[tmp_sqlstate_len+1];
10286     OTL_STRCPY_S(tmp_msg_arr[tmp_arr_len-1],tmp_msg_len+1,tmp_msg);
10287     OTL_STRCPY_S(tmp_sqlstate_arr[tmp_arr_len-1],
10288                  tmp_sqlstate_len+1,
10289                  tmp_sqlstate);
10290     tmp_code_arr[tmp_arr_len-1]=tmp_code;
10291     void* temp_ptr=&tmp_code;
10292     rc=SQLGetDiagRec
10293       (htype,
10294        handle,
10295        OTL_SCAST(OTL_SQLSMALLINT,tmp_arr_len+1),
10296        OTL_RCAST(OTL_SQLCHAR_PTR,tmp_sqlstate),
10297        OTL_RCAST(OTL_SQLINTEGER_PTR,temp_ptr),
10298        OTL_RCAST(OTL_SQLCHAR_PTR,tmp_msg),
10299        SQL_MAX_MESSAGE_LENGTH-1,
10300        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
10301     tmp_msg[msg_len]=0;
10302     if((rc==SQL_NO_DATA||rc==SQL_INVALID_HANDLE||
10303         rc==SQL_ERROR)&&tmp_arr_len==1){
10304       int i;
10305       for(i=0;i<tmp_arr_len;++i){
10306         delete[] tmp_msg_arr[i];
10307         delete[] tmp_sqlstate_arr[i];
10308       }
10309       return;
10310     }
10311   }while(rc!=SQL_NO_DATA&&rc!=SQL_INVALID_HANDLE&&
10312          rc!=SQL_ERROR&&tmp_arr_len<OTL_MAX_MSG_ARR);
10313 
10314   exception_struct.arr_len=tmp_arr_len;
10315   exception_struct.msg_arr=new char*[tmp_arr_len];
10316   exception_struct.sqlstate_arr=new char*[tmp_arr_len];
10317   exception_struct.code_arr=new int[tmp_arr_len];
10318   memcpy(exception_struct.msg_arr,tmp_msg_arr,tmp_arr_len*sizeof(char*));
10319   memcpy(exception_struct.sqlstate_arr,tmp_sqlstate_arr,tmp_arr_len*sizeof(char*));
10320   memcpy(exception_struct.code_arr,tmp_code_arr,tmp_arr_len*sizeof(int));
10321 #endif
10322 }
10323 #endif
10324 #endif
10325 
10326 const int OTL_DEFAULT_ODBC_CONNECT=1;
10327 const int OTL_TIMESTEN_ODBC_CONNECT=2;
10328 const int OTL_MSSQL_2005_ODBC_CONNECT=3;
10329 const int OTL_POSTGRESQL_ODBC_CONNECT=4;
10330 const int OTL_ENTERPRISE_DB_ODBC_CONNECT=5;
10331 const int OTL_MYODBC35_ODBC_CONNECT=6;
10332 const int OTL_MSSQL_2008_ODBC_CONNECT=7;
10333 
10334 class otl_cur;
10335 class otl_connect;
10336 class otl_sel;
10337 
10338 class otl_conn{
10339 protected:
10340 
10341   friend class otl_connect;
10342   friend class otl_cur;
10343   friend class otl_sel;
10344 
10345   OTL_HENV henv;
10346   OTL_HDBC hdbc;
10347   int timeout;
10348   int cursor_type;
10349   int status;
10350   int long_max_size;
10351   bool extern_lda;
10352 
10353 #if defined(OTL_ODBC_zOS)
10354   bool logoff_commit;
10355 #endif
10356 
10357 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
10358   bool throws_on_sql_success_with_info;
10359 #endif
10360 
10361   int connection_type;
10362 
10363 public:
10364 
10365 
10366   void cleanup(void){}
10367 
10368   OTL_HENV& get_henv(){return henv;}
10369   OTL_HDBC& get_hdbc(){return hdbc;}
10370 
10371   int get_connection_type(void)
10372   {
10373     return connection_type;
10374   }
10375 
10376   static int initialize(const int /* threaded_mode */=0)
10377   {
10378     return 1;
10379   }
10380 
10381  otl_conn():
10382    henv(0),
10383    hdbc(0),
10384    timeout(0),
10385    cursor_type(0),
10386    status(SQL_SUCCESS),
10387    long_max_size(32760),
10388    extern_lda(false)
10389 #if defined(OTL_ODBC_zOS)
10390    ,logoff_commit(true)
10391 #endif
10392 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
10393    ,throws_on_sql_success_with_info(false)
10394 #endif
10395    ,connection_type(OTL_DEFAULT_ODBC_CONNECT)
10396  {
10397  }
10398 
10399 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
10400  int rlogon(const SQLWCHAR* username,
10401             const SQLWCHAR* passwd,
10402             const SQLWCHAR* tnsname,
10403             const int auto_commit)
10404   {
10405     if(extern_lda){
10406       extern_lda=false;
10407       henv=0;
10408       hdbc=0;
10409     }
10410     OTL_TRACE_RLOGON_ODBC_W
10411       (0x1,
10412        L"otl_connect",
10413        L"rlogon",
10414        OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,tnsname),
10415        OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,username),
10416        OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,passwd),
10417        auto_commit);
10418     if(henv==0||hdbc==0){
10419       status=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);
10420       if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10421       status=SQLSetEnvAttr
10422         (henv,
10423          SQL_ATTR_ODBC_VERSION,
10424          OTL_RCAST(void*,SQL_OV_ODBC3),
10425          SQL_NTS);
10426       if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10427       status=SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc);
10428       if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10429     }
10430     if(auto_commit){
10431       status=SQLSetConnectAttr
10432         (hdbc,
10433          SQL_ATTR_AUTOCOMMIT,
10434          OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_ON),
10435          SQL_IS_POINTER);
10436       if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10437     }else{
10438       status=SQLSetConnectAttr
10439         (hdbc,
10440          SQL_ATTR_AUTOCOMMIT,
10441          OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_OFF),
10442          SQL_IS_POINTER);
10443       if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10444     }
10445     if(timeout>0){
10446       status=SQLSetConnectAttr
10447         (hdbc,
10448          SQL_ATTR_LOGIN_TIMEOUT,
10449          OTL_RCAST(void*,OTL_SCAST(size_t,timeout)),
10450          0);
10451       if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10452     }
10453 
10454 #if defined(OTL_DB2_CLI)
10455     status=SQLSetConnectAttr
10456       (hdbc,
10457        SQL_ATTR_LONGDATA_COMPAT,
10458        OTL_RCAST(SQLPOINTER,SQL_LD_COMPAT_YES),
10459        SQL_IS_INTEGER);
10460     if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10461 #endif
10462 #if defined(OTL_ENABLE_MSSQL_MARS)
10463 #define OTL_SQL_COPT_SS_BASE 1200
10464 #define OTL_SQL_COPT_SS_MARS_ENABLED (OTL_SQL_COPT_SS_BASE+24)
10465 #define OTL_SQL_MARS_ENABLED_YES 1L
10466 #if !defined(OTL_DB2_CLI) && (ODBCVER >= 0x0300)
10467  SQLSetConnectAttr
10468    (hdbc,
10469     OTL_SQL_COPT_SS_MARS_ENABLED,
10470     OTL_RCAST(SQLPOINTER,OTL_SQL_MARS_ENABLED_YES),
10471     SQL_IS_UINTEGER);
10472 #endif
10473 #endif
10474     status=SQLConnect
10475       (hdbc,
10476        OTL_CCAST(SQLWCHAR*,tnsname),SQL_NTS,
10477        OTL_CCAST(SQLWCHAR*,username),SQL_NTS,
10478        OTL_CCAST(SQLWCHAR*,passwd),SQL_NTS);
10479     if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
10480       return 0;
10481     else
10482       return 1;
10483   }
10484 #endif
10485 
10486  int ext_logon(OTL_HENV ahenv,
10487                OTL_HDBC ahdbc,
10488                const int
10489 #ifndef OTL_ODBC_MYSQL
10490                auto_commit
10491 #endif
10492               )
10493  {
10494   if(!extern_lda){
10495 #if (ODBCVER >= 0x0300)
10496     if(hdbc!=0){
10497       status=SQLFreeHandle(SQL_HANDLE_DBC,hdbc);
10498     }
10499 #else
10500     if(hdbc!=0)
10501       status=SQLFreeConnect(hdbc);
10502 #endif
10503     hdbc=0;
10504 #if (ODBCVER >= 0x0300)
10505     if(henv!=0){
10506       status=SQLFreeHandle(SQL_HANDLE_ENV,henv);
10507     }
10508 #else
10509    if(henv!=0)
10510      status=SQLFreeEnv(henv);
10511 #endif
10512    henv=0;
10513   }
10514   extern_lda=true;
10515   henv=ahenv;
10516   hdbc=ahdbc;
10517 #ifndef OTL_ODBC_MYSQL
10518 #if (ODBCVER >= 0x0300)
10519   if(auto_commit)
10520    status=SQLSetConnectAttr
10521     (hdbc,
10522      SQL_ATTR_AUTOCOMMIT,
10523      OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_ON),
10524      SQL_IS_POINTER);
10525   else
10526    status=SQLSetConnectAttr
10527     (hdbc,
10528      SQL_ATTR_AUTOCOMMIT,
10529      OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_OFF),
10530      SQL_IS_POINTER);
10531 #else
10532   if(auto_commit)
10533    status=SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT,1);
10534   else
10535    status=SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT,0);
10536 #endif
10537   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10538 #endif
10539 
10540 #if defined(OTL_DB2_CLI)
10541   status=SQLSetConnectAttr
10542    (hdbc,
10543     SQL_ATTR_LONGDATA_COMPAT,
10544     OTL_RCAST(SQLPOINTER,SQL_LD_COMPAT_YES),
10545     SQL_IS_INTEGER);
10546   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10547 #endif
10548 
10549   return 1;
10550 
10551  }
10552 
10553  virtual ~otl_conn()
10554  {
10555   if(extern_lda){
10556    hdbc=0;
10557    henv=0;
10558    extern_lda=false;
10559   }else{
10560 #if (ODBCVER >= 0x0300)
10561     if(hdbc!=0){
10562       status=SQLFreeHandle(SQL_HANDLE_DBC,hdbc);
10563     }
10564 #else
10565     if(hdbc!=0)
10566       status=SQLFreeConnect(hdbc);
10567 #endif
10568    hdbc=0;
10569 #if (ODBCVER >= 0x0300)
10570    if(henv!=0){
10571      status=SQLFreeHandle(SQL_HANDLE_ENV,henv);
10572    }
10573 #else
10574    if(henv!=0)
10575      status=SQLFreeEnv(henv);
10576 #endif
10577    henv=0;
10578   }
10579  }
10580 
10581  void set_timeout(const int atimeout=0)
10582  {
10583   timeout=atimeout;
10584  }
10585 
10586  void set_cursor_type(const int acursor_type=0)
10587  {
10588   cursor_type=acursor_type;
10589  }
10590 
10591  int rlogon(const char* connect_str,
10592             const int
10593 #ifndef OTL_ODBC_MYSQL
10594             auto_commit
10595 #endif
10596            )
10597  {
10598   char username[256];
10599   char passwd[256];
10600   char tnsname[1024];
10601   char* tnsname_ptr=0;
10602   char* c=OTL_CCAST(char*,connect_str);
10603   char* username_ptr=username;
10604   char* passwd_ptr=passwd;
10605   char temp_connect_str[512];
10606 
10607   if(extern_lda){
10608    extern_lda=false;
10609    henv=0;
10610    hdbc=0;
10611   }
10612   memset(username,0,sizeof(username));
10613   memset(passwd,0,sizeof(passwd));
10614   memset(tnsname,0,sizeof(tnsname));
10615 
10616   char* c1=OTL_CCAST(char*,connect_str);
10617   int oracle_format=0;
10618   char prev_c=' ';
10619   while(*c1){
10620    if(*c1=='@' && prev_c!='\\'){
10621     oracle_format=1;
10622     break;
10623    }
10624    prev_c=*c1;
10625    ++c1;
10626   }
10627 
10628   if(oracle_format){
10629    while(*c && *c!='/' && (OTL_SCAST(unsigned,username_ptr-username)<
10630                            sizeof(username)-1)){
10631     *username_ptr=*c;
10632     ++c;
10633     ++username_ptr;
10634    }
10635    *username_ptr=0;
10636 
10637    if(*c=='/')++c;
10638    prev_c=' ';
10639    while(*c && !(*c=='@' && prev_c!='\\') &&
10640          (OTL_SCAST(unsigned,passwd_ptr-passwd)<sizeof(passwd)-1)){
10641      if(prev_c=='\\')--passwd_ptr;
10642     *passwd_ptr=*c;
10643     prev_c=*c;
10644     ++c;
10645     ++passwd_ptr;
10646    }
10647    *passwd_ptr=0;
10648 
10649    if(*c=='@'){
10650     ++c;
10651     tnsname_ptr=tnsname;
10652     while(*c && (OTL_SCAST(unsigned,tnsname_ptr-tnsname)<sizeof(tnsname)-1)){
10653      *tnsname_ptr=*c;
10654      ++c;
10655      ++tnsname_ptr;
10656     }
10657     *tnsname_ptr=0;
10658    }
10659   }else{
10660    c1=OTL_CCAST(char*,connect_str);
10661    char* c2=temp_connect_str;
10662    while(*c1 && (OTL_SCAST(unsigned,c2-temp_connect_str)
10663                  <sizeof(temp_connect_str)-1)){
10664     *c2=otl_to_upper(*c1);
10665     ++c1;
10666     ++c2;
10667    }
10668    *c2=0;
10669    c1=temp_connect_str;
10670    char entry_name[256];
10671    char entry_value[256];
10672    while(*c1 && (OTL_SCAST(unsigned,c1-temp_connect_str)<
10673                  sizeof(temp_connect_str)-1)){
10674     c2=entry_name;
10675     while(*c1 && *c1!='=' &&
10676           (OTL_SCAST(unsigned,c1-temp_connect_str)<
10677            sizeof(temp_connect_str)-1)){
10678      *c2=*c1;
10679      ++c1;
10680      ++c2;
10681     }
10682     *c2=0;
10683     if(*c1) ++c1;
10684     c2=entry_value;
10685     prev_c=' ';
10686     while(*c1&&*c1!=';' &&
10687           (OTL_SCAST(unsigned,c2-entry_value)<
10688            sizeof(entry_value)-1)){
10689       if(prev_c=='\\')
10690         --c2;
10691       *c2=*c1;
10692       prev_c=*c1;
10693       ++c1;
10694       ++c2;
10695     }
10696     *c2=0;
10697     if(*c1) ++c1;
10698     if(strcmp(entry_name,"DSN")==0)
10699       OTL_STRCPY_S(tnsname,sizeof(tnsname),entry_value);
10700     if(strcmp(entry_name,"UID")==0)
10701       OTL_STRCPY_S(username,sizeof(username),entry_value);
10702     if(strcmp(entry_name,"PWD")==0)
10703       OTL_STRCPY_S(passwd,sizeof(passwd),entry_value);
10704    }
10705   }
10706 #ifndef OTL_ODBC_MYSQL
10707   OTL_TRACE_RLOGON_ODBC
10708     (0x1,
10709      "otl_connect",
10710      "rlogon",
10711      tnsname,
10712      username,
10713      passwd,
10714      auto_commit)
10715 #else
10716   OTL_TRACE_RLOGON_ODBC
10717     (0x1,
10718      "otl_connect",
10719      "rlogon",
10720      tnsname,
10721      username,
10722      passwd,
10723      0)
10724 #endif
10725   if(henv==0||hdbc==0){
10726 #if (ODBCVER >= 0x0300)
10727    status=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);
10728 #else
10729    status=SQLAllocEnv(&henv);
10730 #endif
10731    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10732 
10733 #if (ODBCVER >= 0x0300)
10734    status=SQLSetEnvAttr
10735      (henv,
10736       SQL_ATTR_ODBC_VERSION,
10737       OTL_RCAST(void*,SQL_OV_ODBC3),
10738       SQL_NTS);
10739    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10740 #endif
10741 
10742 #if (ODBCVER >= 0x0300)
10743    status=SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc);
10744 #else
10745    status=SQLAllocConnect(henv, &hdbc);
10746 #endif
10747    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10748   }else
10749     status=SQL_SUCCESS;
10750 
10751 #ifndef OTL_ODBC_MYSQL
10752 #if (ODBCVER >= 0x0300)
10753   if(auto_commit)
10754    status=SQLSetConnectAttr
10755     (hdbc,
10756      SQL_ATTR_AUTOCOMMIT,
10757      OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_ON),
10758      SQL_IS_POINTER);
10759   else
10760    status=SQLSetConnectAttr
10761     (hdbc,
10762      SQL_ATTR_AUTOCOMMIT,
10763      OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_OFF),
10764      SQL_IS_POINTER);
10765 #else
10766   if(auto_commit)
10767    status=SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT,1);
10768   else
10769    status=SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT,0);
10770 #endif
10771   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10772 #endif
10773 #if (ODBCVER >= 0x0300)
10774   if(timeout>0)
10775    status=SQLSetConnectAttr
10776     (hdbc,
10777      SQL_ATTR_LOGIN_TIMEOUT,
10778      OTL_RCAST(void*,OTL_SCAST(size_t,timeout)),
10779      0);
10780 #else
10781   if (timeout>0)
10782     status=SQLSetConnectOption(hdbc,SQL_LOGIN_TIMEOUT,timeout);
10783 #endif
10784   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10785 
10786 
10787 #if defined(OTL_DB2_CLI)
10788   status=SQLSetConnectAttr
10789    (hdbc,
10790     SQL_ATTR_LONGDATA_COMPAT,
10791     OTL_RCAST(SQLPOINTER,SQL_LD_COMPAT_YES),
10792     SQL_IS_INTEGER);
10793   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
10794 #endif
10795 
10796 #if defined(OTL_ENABLE_MSSQL_MARS)
10797 #define OTL_SQL_COPT_SS_BASE 1200
10798 #define OTL_SQL_COPT_SS_MARS_ENABLED (OTL_SQL_COPT_SS_BASE+24)
10799 #define OTL_SQL_MARS_ENABLED_YES 1L
10800 #if !defined(OTL_DB2_CLI) && (ODBCVER >= 0x0300)
10801  SQLSetConnectAttr
10802    (hdbc,
10803     OTL_SQL_COPT_SS_MARS_ENABLED,
10804     OTL_RCAST(SQLPOINTER,OTL_SQL_MARS_ENABLED_YES),
10805     SQL_IS_UINTEGER);
10806 #endif
10807 #endif
10808 
10809   if(oracle_format){
10810 #if defined(OTL_ODBC_zOS)
10811     if(tnsname[0]==0 && username[0]==0 && passwd[0]==0){
10812       status=SQLConnect
10813         (hdbc,
10814          0L,SQL_NTS,
10815          0L,SQL_NTS,
10816          0L,SQL_NTS);
10817       logoff_commit = false;
10818     }else
10819       status=SQLConnect
10820         (hdbc,
10821          OTL_RCAST(unsigned char*,tnsname),SQL_NTS,
10822          OTL_RCAST(unsigned char*,username),SQL_NTS,
10823          OTL_RCAST(unsigned char*,passwd),SQL_NTS);
10824 #else
10825 
10826 #if defined(UNICODE) || defined(_UNICODE)
10827  {
10828    SQLWCHAR* temp_tnsname=new SQLWCHAR[strlen(tnsname)+1];
10829    SQLWCHAR* temp_username=new SQLWCHAR[strlen(username)+1];
10830    SQLWCHAR* temp_passwd=new SQLWCHAR[strlen(passwd)+1];
10831    otl_convert_char_to_SQLWCHAR(temp_tnsname,OTL_RCAST(unsigned char*,tnsname));
10832    otl_convert_char_to_SQLWCHAR(temp_username,OTL_RCAST(unsigned char*,username));
10833    otl_convert_char_to_SQLWCHAR(temp_passwd,OTL_RCAST(unsigned char*,passwd));
10834    status=SQLConnect
10835      (hdbc,
10836       temp_tnsname,SQL_NTS,
10837       temp_username,SQL_NTS,
10838       temp_passwd,SQL_NTS);
10839     delete[] temp_tnsname;
10840     delete[] temp_username;
10841     delete[] temp_passwd;
10842  }
10843 #else
10844     status=SQLConnect
10845       (hdbc,
10846        OTL_RCAST(unsigned char*,tnsname),SQL_NTS,
10847        OTL_RCAST(unsigned char*,username),SQL_NTS,
10848        OTL_RCAST(unsigned char*,passwd),SQL_NTS);
10849 #endif
10850 
10851 #endif
10852   }else{
10853    char* tc2=temp_connect_str;
10854    const char* tc1=connect_str;
10855    prev_c=' ';
10856    while(*tc1 && (OTL_SCAST(unsigned,tc2-temp_connect_str)<
10857                   sizeof(temp_connect_str)-1)){
10858      if(*tc1=='@' && prev_c=='\\')
10859        --tc2;
10860      *tc2=*tc1;
10861      prev_c=*tc1;
10862      ++tc1;
10863      ++tc2;
10864    }
10865    *tc2=0;
10866    SQLSMALLINT out_len=0;
10867 #if (defined(UNICODE)||defined(_UNICODE))
10868  {
10869    size_t len=strlen(temp_connect_str);
10870    SQLWCHAR* temp_connect_str2=new SQLWCHAR[len+1];
10871    SQLWCHAR out_str[2048];
10872    otl_convert_char_to_SQLWCHAR(temp_connect_str2,OTL_RCAST(unsigned char*,temp_connect_str));
10873    status=SQLDriverConnect
10874     (hdbc,
10875      0,
10876      temp_connect_str2,
10877      OTL_SCAST(short,len),
10878      out_str,
10879      sizeof(out_str)/sizeof(SQLWCHAR),
10880      &out_len,
10881      SQL_DRIVER_NOPROMPT);
10882     delete[] temp_connect_str2;
10883  }
10884 #else
10885    SQLCHAR out_str[2048];
10886    status=SQLDriverConnect
10887     (hdbc,
10888      0,
10889      OTL_RCAST(SQLCHAR*,OTL_CCAST(char*,temp_connect_str)),
10890      OTL_SCAST(short,strlen(temp_connect_str)),
10891      out_str,
10892      sizeof(out_str),
10893      &out_len,
10894      SQL_DRIVER_NOPROMPT);
10895 #endif
10896   }
10897 
10898   if(status == SQL_SUCCESS_WITH_INFO || status == SQL_SUCCESS)
10899     return 1;
10900   else
10901     return 0;
10902 
10903  }
10904 
10905   int set_transaction_isolation_level
10906   (const long int
10907 #ifndef OTL_ODBC_MYSQL
10908    level
10909 #endif
10910   )
10911   {
10912 #ifndef OTL_ODBC_MYSQL
10913 #if (ODBCVER >= 0x0300)
10914    status=SQLSetConnectAttr
10915     (hdbc,
10916      SQL_ATTR_TXN_ISOLATION,
10917      OTL_RCAST(SQLPOINTER,OTL_SCAST(size_t,level)),
10918      SQL_IS_POINTER);
10919 #else
10920    status=SQLSetConnectOption(hdbc,SQL_TXN_ISOLATION,level);
10921 #endif
10922    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
10923     return 0;
10924    else
10925     return 1;
10926 #else
10927    return 1;
10928 #endif
10929 
10930   }
10931 
10932  int auto_commit_on(void)
10933  {
10934 #if defined(OTL_ODBC_MYSQL)
10935   return 1;
10936 #else
10937 #if (ODBCVER >= 0x0300)
10938   status=SQLSetConnectAttr
10939    (hdbc,
10940     SQL_ATTR_AUTOCOMMIT,
10941     OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_ON),
10942     SQL_IS_POINTER);
10943 #else
10944   status=SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT,1);
10945 #endif
10946   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
10947    return 0;
10948   else
10949    return 1;
10950 #endif
10951  }
10952 
10953  int auto_commit_off(void)
10954  {
10955 #if defined(OTL_ODBC_MYSQL)
10956   return 1;
10957 #else
10958 #if (ODBCVER >= 0x0300)
10959   status=SQLSetConnectAttr
10960    (hdbc,
10961     SQL_ATTR_AUTOCOMMIT,
10962     OTL_RCAST(SQLPOINTER,SQL_AUTOCOMMIT_OFF),
10963     SQL_IS_POINTER);
10964 #else
10965  status=SQLSetConnectOption(hdbc,SQL_AUTOCOMMIT,0);
10966 #endif
10967   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
10968    return 0;
10969   else
10970    return 1;
10971 #endif
10972  }
10973 
10974 
10975  int logoff(void)
10976  {
10977   if(extern_lda){
10978    extern_lda=false;
10979    henv=0;
10980    hdbc=0;
10981    return 1;
10982   }else{
10983 #if defined(OTL_ODBC_zOS)
10984    if(logoff_commit)
10985      commit();
10986 #else
10987    commit();
10988 #endif
10989    status=SQLDisconnect(hdbc);
10990 #if defined(OTL_ODBC_LOGOFF_FREES_HANDLES)
10991 #if (ODBCVER >= 0x0300)
10992    if(hdbc!=0){
10993      SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
10994      hdbc=0;
10995    }
10996    if(henv!=0){
10997      SQLFreeHandle(SQL_HANDLE_ENV, henv);
10998      henv=0;
10999    }
11000    #else
11001    if(hdbc!=0){
11002      SQLFreeConnect(hdbc);
11003      hdbc=0;
11004    }
11005    if(henv!=0){
11006      SQLFreeEnv(henv);
11007      henv=0;
11008    }
11009 #endif
11010 #endif
11011    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
11012     return 0;
11013    else
11014     return 1;
11015 
11016   }
11017  }
11018 
11019  void error(otl_exc& exception_struct)
11020  {OTL_SQLRETURN rc;
11021   OTL_SQLSMALLINT msg_len=0;
11022 
11023 #if (ODBCVER >= 0x0300)
11024 
11025 #if (defined(UNICODE)||defined(_UNICODE))
11026 
11027 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
11028 
11029    rc=SQLGetDiagRec
11030 #if defined(OTL_ODBC_zOS)
11031      (hdbc==0?SQL_HANDLE_ENV:SQL_HANDLE_DBC,
11032       hdbc==0?henv:hdbc,
11033 #else
11034       (SQL_HANDLE_DBC,
11035        hdbc,
11036 #endif
11037        1,
11038        &exception_struct.sqlstate[0],
11039        OTL_RCAST(OTL_SQLINTEGER_PTR,&exception_struct.code),
11040        &exception_struct.msg[0],
11041        SQL_MAX_MESSAGE_LENGTH-1,
11042        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
11043    exception_struct.msg[msg_len]=0;
11044 
11045 #else
11046 
11047  {
11048    SQLWCHAR temp_msg[SQL_MAX_MESSAGE_LENGTH];
11049    SQLWCHAR temp_sqlstate[1000];
11050 
11051    rc=SQLGetDiagRec
11052 #if defined(OTL_ODBC_zOS)
11053      (hdbc==0?SQL_HANDLE_ENV:SQL_HANDLE_DBC,
11054       hdbc==0?henv:hdbc,
11055 #else
11056       (SQL_HANDLE_DBC,
11057        hdbc,
11058 #endif
11059        1,
11060        temp_sqlstate,
11061        OTL_RCAST(OTL_SQLINTEGER_PTR,&exception_struct.code),
11062        temp_msg,
11063        SQL_MAX_MESSAGE_LENGTH-1,
11064        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
11065    temp_msg[msg_len]=0;
11066    otl_convert_SQLWCHAR_to_char
11067       (OTL_RCAST(unsigned char*,&exception_struct.sqlstate[0]),
11068        temp_sqlstate);
11069    otl_convert_SQLWCHAR_to_char
11070       (OTL_RCAST(unsigned char*,&exception_struct.msg[0]),
11071        temp_msg);
11072   }
11073 
11074 #endif
11075 
11076 #else
11077    void* temp_ptr=&exception_struct.code;
11078    rc=SQLGetDiagRec
11079 #if defined(OTL_ODBC_zOS)
11080      (hdbc==0?SQL_HANDLE_ENV:SQL_HANDLE_DBC,
11081       hdbc==0?henv:hdbc,
11082 #else
11083       (SQL_HANDLE_DBC,
11084        hdbc,
11085 #endif
11086        1,
11087        OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.sqlstate[0]),
11088        OTL_RCAST(OTL_SQLINTEGER_PTR,temp_ptr),
11089        OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.msg[0]),
11090        SQL_MAX_MESSAGE_LENGTH-1,
11091        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
11092 #endif
11093 
11094 #else
11095  rc=SQLError(henv,
11096              hdbc,
11097              0, // hstmt
11098              OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.sqlstate[0]),
11099              OTL_RCAST(OTL_SQLINTEGER_PTR,&exception_struct.code),
11100              OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.msg[0]),
11101              SQL_MAX_MESSAGE_LENGTH-1,
11102              OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
11103 #endif
11104   exception_struct.msg[msg_len]=0;
11105 
11106   if(rc==SQL_INVALID_HANDLE||rc==SQL_ERROR)
11107     exception_struct.msg[0]=0;
11108 #if (ODBCVER >= 0x0300)
11109 #if defined(OTL_EXTENDED_EXCEPTION)
11110   else if(rc!=SQL_NO_DATA)
11111 #if defined(OTL_ODBC_zOS)
11112     {
11113       if(hdbc)
11114         otl_fill_exception(exception_struct,hdbc,SQL_HANDLE_DBC);
11115       else
11116         otl_fill_exception(exception_struct,henv,SQL_HANDLE_ENV);
11117     }
11118 #else
11119     otl_fill_exception(exception_struct,hdbc,SQL_HANDLE_DBC);
11120 #endif
11121 #endif
11122 #endif
11123 
11124  }
11125 
11126  int commit(void)
11127  {
11128 #ifndef OTL_ODBC_MYSQL
11129 #if (ODBCVER >= 0x0300)
11130   status=SQLEndTran(SQL_HANDLE_DBC,hdbc,SQL_COMMIT);
11131 #else
11132  status=SQLTransact(henv,hdbc,SQL_COMMIT);
11133 #endif
11134   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
11135    return 0;
11136   else
11137   return 1;
11138 #else
11139   return 1;
11140 #endif
11141  }
11142 
11143  int rollback(void)
11144  {
11145 #ifndef OTL_ODBC_MYSQL
11146 #if (ODBCVER >= 0x0300)
11147   status=SQLEndTran(SQL_HANDLE_DBC,hdbc,SQL_ROLLBACK);
11148 #else
11149  status=SQLTransact(henv,hdbc,SQL_ROLLBACK);
11150 #endif
11151   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
11152    return 0;
11153   else
11154   return 1;
11155 #else
11156   return 1;
11157 #endif
11158  }
11159 
11160 private:
11161 
11162  otl_conn(const otl_conn&):
11163    henv(0),
11164    hdbc(0),
11165    timeout(0),
11166    cursor_type(0),
11167    status(SQL_SUCCESS),
11168    long_max_size(32760),
11169    extern_lda(false)
11170 #if defined(OTL_ODBC_zOS)
11171    ,logoff_commit(true)
11172 #endif
11173 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
11174    ,throws_on_sql_success_with_info(false)
11175 #endif
11176    ,connection_type(OTL_DEFAULT_ODBC_CONNECT)
11177  {
11178  }
11179 
11180  otl_conn& operator=(const otl_conn&)
11181  {
11182    return *this;
11183  }
11184 
11185 
11186 };
11187 
11188 class otl_var;
11189 class otl_cur;
11190 class otl_sel;
11191 
11192 class otl_cur0{
11193 protected:
11194 
11195   friend class otl_sel;
11196   friend class otl_var;
11197   OTL_SQLHSTMT cda;
11198   int last_param_data_token;
11199   int last_sql_param_data_status;
11200   int sql_param_data_count;
11201 
11202 public:
11203 
11204  otl_cur0():
11205    cda(0),
11206    last_param_data_token(0),
11207    last_sql_param_data_status(0),
11208    sql_param_data_count(0)
11209  {
11210  }
11211 
11212  virtual ~otl_cur0(){}
11213 
11214   OTL_SQLHSTMT get_cda(){return cda;}
11215 
11216 private:
11217 
11218  otl_cur0(const otl_cur0&):
11219    cda(0),
11220    last_param_data_token(0),
11221    last_sql_param_data_status(0),
11222    sql_param_data_count(0)
11223  {
11224  }
11225 
11226  otl_cur0& operator=(const otl_cur0&)
11227  {
11228    return *this;
11229  }
11230 
11231 
11232 };
11233 
11234 class otl_cur;
11235 
11236 class otl_var{
11237 private:
11238 
11239   friend class otl_cur;
11240   unsigned char* p_v;
11241   OTL_SQLLEN_PTR p_len;
11242   int ftype;
11243   int act_elem_size;
11244   bool lob_stream_mode;
11245   int lob_stream_flag;
11246   int vparam_type;
11247   int lob_len;
11248   int lob_pos;
11249   int lob_ftype;
11250   int otl_adapter;
11251   bool charz_flag;
11252 
11253 public:
11254 
11255   int get_otl_adapter() const {return otl_adapter;}
11256 
11257   void set_lob_stream_mode(const bool alob_stream_mode)
11258   {
11259     lob_stream_mode=alob_stream_mode;
11260   }
11261 
11262   void set_vparam_type(const int avparam_type)
11263   {
11264     vparam_type=avparam_type;
11265   }
11266 
11267   void set_charz_flag(const bool acharz_flag)
11268   {
11269     charz_flag=acharz_flag;
11270   }
11271 
11272 
11273   otl_var():
11274     p_v(0),
11275     p_len(0),
11276     ftype(0),
11277     act_elem_size(0),
11278     lob_stream_mode(false),
11279     lob_stream_flag(0),
11280     vparam_type(-1),
11281     lob_len(0),
11282     lob_pos(0),
11283     lob_ftype(0),
11284     otl_adapter(otl_odbc_adapter),
11285     charz_flag(false)
11286  {
11287  }
11288 
11289  virtual ~otl_var()
11290  {
11291   delete[] p_v;
11292   delete[] p_len;
11293  }
11294 
11295   int write_dt(void* trg, const void* src, const int sz)
11296   {
11297     memcpy(trg,src,sz);
11298     return 1;
11299   }
11300 
11301   int read_dt(void* trg, const void* src, const int sz)
11302   {
11303     memcpy(trg,src,sz);
11304     return 1;
11305   }
11306 
11307  void set_lob_stream_flag(const int flg=1)
11308  {
11309   lob_stream_flag=flg;
11310  }
11311 
11312  int get_pl_tab_len(void)
11313  {
11314   return 0;
11315  }
11316 
11317  int get_max_pl_tab_len(void)
11318  {
11319   return 0;
11320  }
11321 
11322   void set_pl_tab_len(const int /* pl_tab_len */)
11323   {
11324   }
11325 
11326  int write_blob
11327  (const otl_long_string& s,
11328   const int /* alob_len */,
11329   int& aoffset,
11330   otl_cur0& cur)
11331  {
11332   SQLRETURN rc=0;
11333   SQLINTEGER temp_len=0;
11334   SQLPOINTER pToken=0;
11335   int param_number=0;
11336 
11337   if(!lob_stream_flag&&!lob_stream_mode)return 1;
11338   if(aoffset==1){
11339    if(cur.sql_param_data_count==0){
11340     rc=SQLParamData(cur.cda, &pToken);
11341     param_number=OTL_SCAST(int,OTL_RCAST(size_t,pToken));
11342     ++cur.sql_param_data_count;
11343     cur.last_sql_param_data_status=rc;
11344     cur.last_param_data_token=param_number;
11345     if(rc!=SQL_SUCCESS&&rc!=SQL_SUCCESS_WITH_INFO&&
11346        rc!=SQL_NEED_DATA)
11347      return 0;
11348    }
11349   }
11350   if(ftype==otl_var_raw_long)
11351     temp_len=s.len();
11352   else
11353     temp_len=s.len()*sizeof(OTL_CHAR);
11354   rc=SQLPutData(cur.cda,s.v,temp_len);
11355   if(rc!=SQL_SUCCESS&&rc!=SQL_SUCCESS_WITH_INFO)
11356     return 0;
11357    else{
11358      aoffset+=s.len();
11359     return 1;
11360    }
11361  }
11362 
11363  int clob_blob(otl_cur0& cur)
11364  {
11365   SQLRETURN rc=0;
11366   SQLPOINTER pToken=0;
11367   int param_number=0;
11368 
11369   if(!(cur.last_param_data_token==0&&cur.sql_param_data_count>0)){
11370     rc=SQLParamData(cur.cda, &pToken);
11371     param_number=OTL_SCAST(int,OTL_RCAST(size_t,pToken));
11372     ++cur.sql_param_data_count;
11373     cur.last_sql_param_data_status=rc;
11374     cur.last_param_data_token=param_number;
11375     if(rc!=SQL_SUCCESS&&rc!=SQL_SUCCESS_WITH_INFO&&
11376 #if (ODBCVER >= 0x0300)
11377        rc!=SQL_NO_DATA &&
11378 #endif
11379        rc!=SQL_NEED_DATA)
11380       return 0;
11381   }
11382   return 1;
11383  }
11384 
11385  int read_blob
11386  (otl_cur0& cur,
11387   otl_long_string& s,
11388   const int andx,
11389   int& aoffset,
11390   int& eof_flag)
11391  {
11392   SQLRETURN rc=0;
11393   OTL_SQLLEN retLen=0;
11394   int chunkLen=0;
11395   if(!lob_stream_flag&&!lob_stream_mode)return 1;
11396   int buf_size=s.get_buf_size()*sizeof(OTL_CHAR);
11397   if(ftype==otl_var_raw_long)
11398     buf_size=s.get_buf_size();
11399   rc=SQLGetData
11400    (cur.cda,
11401     OTL_SCAST(SQLSMALLINT,lob_pos),
11402     OTL_SCAST(SQLSMALLINT,lob_ftype),
11403     s.v,
11404     buf_size,
11405     &retLen);
11406   if(rc==SQL_SUCCESS_WITH_INFO||rc==SQL_SUCCESS){
11407    if(retLen==SQL_NULL_DATA){
11408     chunkLen=0;
11409     p_len[andx]=SQL_NULL_DATA;
11410    }else if(retLen>buf_size||retLen==SQL_NO_TOTAL)
11411      chunkLen=s.get_buf_size();
11412    else{
11413      if(ftype==otl_var_raw_long)
11414        chunkLen=OTL_SCAST(int,retLen);
11415      else
11416        chunkLen=OTL_SCAST(int,retLen)/sizeof(OTL_CHAR);
11417    }
11418 #if defined(OTL_UNICODE)
11419    if(lob_ftype==SQL_C_WCHAR)
11420     s.set_len(chunkLen-1);
11421 #else
11422    if(lob_ftype==SQL_C_CHAR)
11423     s.set_len(chunkLen-1);
11424 #endif
11425    else
11426     s.set_len(chunkLen);
11427    if(lob_len==0&&aoffset==1&&
11428       retLen!=SQL_NULL_DATA&&
11429       retLen!=SQL_NO_TOTAL)
11430     lob_len=OTL_SCAST(int,retLen);
11431    aoffset+=chunkLen;
11432    if(chunkLen<s.get_buf_size()||rc==SQL_SUCCESS){
11433     s.set_len(chunkLen);
11434     eof_flag=1;
11435    }else
11436     eof_flag=0;
11437    return 1;
11438   }
11439 #if (ODBCVER >= 0x0300)
11440   else if(rc==SQL_NO_DATA)
11441 #else
11442   else if(rc==SQL_NO_DATA_FOUND)
11443 #endif
11444    return 1;
11445   else
11446    return 0;
11447  }
11448 
11449 
11450   int get_blob_len(const int /* ndx */,int& alen)
11451   {
11452     alen=lob_len;
11453     return 1;
11454   }
11455 
11456  int put_blob(void)
11457  {
11458   return 1;
11459  }
11460 
11461  int get_blob
11462  (const int /* ndx */,
11463   unsigned char* /* abuf */,
11464   const int /* buf_size */,
11465   int& /* len */)
11466  {
11467   return 1;
11468  }
11469 
11470  int save_blob
11471  (const unsigned char* /* abuf  */,
11472   const int /* len */,
11473   const int /* extern_buffer_flag */)
11474  {
11475   return 1;
11476  }
11477 
11478  int actual_elem_size(void)
11479  {
11480   return act_elem_size;
11481  }
11482 
11483  void init
11484  (const bool,
11485   const int aftype,
11486   int& aelem_size,
11487   const otl_stream_buffer_size_type aarray_size,
11488   const void* /* connect_struct */=0,
11489   const int /*apl_tab_size*/=0)
11490  {int i;
11491   size_t byte_size=0;
11492   ftype=aftype;
11493   act_elem_size=aelem_size;
11494   byte_size=aelem_size*OTL_SCAST(size_t,aarray_size);
11495 #if defined(OTL_UNICODE)
11496   if(aftype==otl_var_char||aftype==otl_var_varchar_long){
11497     byte_size*=sizeof(OTL_CHAR);
11498     p_v=new unsigned char[byte_size];
11499   }
11500   else
11501   p_v=new unsigned char[byte_size];
11502 #else
11503   p_v=new unsigned char[byte_size];
11504 #endif
11505   p_len=new OTL_SQLLEN[aarray_size];
11506   memset(p_v,0,byte_size);
11507   for(i=0;i<aarray_size;++i){
11508    if(ftype==otl_var_char)
11509     p_len[i]=OTL_SCAST(OTL_SQLLEN,SQL_NTS);
11510    else if(ftype==otl_var_varchar_long||ftype==otl_var_raw_long)
11511     p_len[i]=0;
11512    else
11513     p_len[i]=OTL_SCAST(OTL_SQLLEN,aelem_size);
11514   }
11515  }
11516 
11517  void set_null(int ndx)
11518  {
11519   p_len[ndx]=SQL_NULL_DATA;
11520  }
11521 
11522  void set_not_null(int ndx, int pelem_size)
11523  {
11524    set_len(pelem_size,ndx);
11525  }
11526 
11527  void set_len(int len, int ndx)
11528  {
11529    switch(ftype){
11530    case otl_var_char:
11531      p_len[ndx]=SQL_NTS;
11532      break;
11533    case otl_var_varchar_long:
11534      if(lob_stream_mode &&
11535         (vparam_type==otl_input_param||
11536          vparam_type==otl_inout_param))
11537        p_len[ndx]=SQL_DATA_AT_EXEC;
11538      else
11539 #if defined(OTL_UNICODE)
11540        p_len[ndx]=OTL_SCAST(OTL_SQLLEN,len*sizeof(OTL_CHAR));
11541 #else
11542        p_len[ndx]=OTL_SCAST(OTL_SQLLEN,len);
11543 #endif
11544      break;
11545    case otl_var_raw_long:
11546      if(lob_stream_mode &&
11547         (vparam_type==otl_input_param||
11548          vparam_type==otl_inout_param))
11549        p_len[ndx]=SQL_DATA_AT_EXEC;
11550      else
11551        p_len[ndx]=OTL_SCAST(OTL_SQLLEN,len);
11552      break;
11553    default:
11554      p_len[ndx]=OTL_SCAST(OTL_SQLLEN,len);
11555      break;
11556    }
11557  }
11558 
11559  int get_len(int ndx)
11560  {
11561   if(p_len[ndx]==SQL_NULL_DATA)
11562    return 0;
11563   else
11564 #if defined(OTL_UNICODE)
11565     if(ftype==otl_var_varchar_long || ftype==otl_var_char)
11566       return OTL_SCAST(int,p_len[ndx])/sizeof(OTL_CHAR);
11567     else
11568       return OTL_SCAST(int,p_len[ndx]);
11569 #else
11570    return OTL_SCAST(int,p_len[ndx]);
11571 #endif
11572  }
11573 
11574  int is_null(int ndx)
11575  {
11576    return p_len[ndx]==SQL_NULL_DATA;
11577  }
11578 
11579  void* val(int ndx,int pelem_size)
11580  {
11581 #if defined(OTL_UNICODE)
11582    switch(ftype){
11583    case otl_var_char:
11584    case otl_var_varchar_long:
11585      return OTL_RCAST(void*,
11586                       &p_v[(OTL_SCAST(size_t,ndx))*pelem_size*sizeof(OTL_CHAR)]);
11587    default:
11588      return OTL_RCAST(void*,&p_v[(OTL_SCAST(size_t,ndx))*pelem_size]);
11589    }
11590 #else
11591    return OTL_RCAST(void*,&p_v[(OTL_SCAST(size_t,ndx))*pelem_size]);
11592 #endif
11593  }
11594 
11595 #define OTL_SQL_UNICODE_CHAR                        (-95)
11596 #define OTL_SQL_UNICODE_VARCHAR                     (-96)
11597 #define OTL_SQL_UNICODE_LONGVARCHAR                 (-97)
11598 
11599 #define OTL_SQL_SS_TIME2 (-154)
11600 #define OTL_SQL_SS_TIMESTAMPOFFSET (-155)
11601 
11602  static int int2ext(int int_type)
11603  {
11604    switch(int_type){
11605 #if defined(OTL_UNICODE)
11606    case SQL_VARCHAR: return SQL_C_WCHAR;
11607    case SQL_WVARCHAR: return SQL_C_WCHAR;
11608    case SQL_CHAR: return SQL_C_WCHAR;
11609    case SQL_WCHAR: return SQL_C_WCHAR;
11610    case SQL_LONGVARCHAR: return SQL_WLONGVARCHAR;
11611    case SQL_WLONGVARCHAR: return SQL_WLONGVARCHAR;
11612    case OTL_SQL_UNICODE_VARCHAR: return SQL_C_WCHAR;
11613    case OTL_SQL_UNICODE_CHAR: return SQL_C_WCHAR;
11614    case OTL_SQL_UNICODE_LONGVARCHAR: return SQL_WLONGVARCHAR;
11615 #else
11616    case SQL_CHAR: return SQL_C_CHAR;
11617    case SQL_VARCHAR: return SQL_C_CHAR;
11618 #if defined(SQL_WCHAR)
11619    case SQL_WCHAR: return SQL_C_CHAR;
11620 #else
11621    case -8: return SQL_C_CHAR;
11622 #endif
11623 #if defined(SQL_WVARCHAR)
11624    case SQL_WVARCHAR: return SQL_C_CHAR;
11625 #else
11626    case -9: return SQL_C_CHAR;
11627 #endif
11628    case SQL_LONGVARCHAR: return SQL_LONGVARCHAR;
11629 #if defined(SQL_WLONGVARCHAR)
11630    case SQL_WLONGVARCHAR: return SQL_LONGVARCHAR;
11631 #else
11632    case -10: return SQL_LONGVARCHAR;
11633 #endif
11634    case OTL_SQL_UNICODE_VARCHAR: return SQL_C_CHAR;
11635    case OTL_SQL_UNICODE_CHAR: return SQL_C_CHAR;
11636    case OTL_SQL_UNICODE_LONGVARCHAR: return SQL_LONGVARCHAR;
11637 #endif
11638 #if (ODBCVER >= 0x0300)
11639    case SQL_TYPE_DATE: return SQL_C_TIMESTAMP;
11640    case SQL_TYPE_TIMESTAMP: return SQL_C_TIMESTAMP;
11641    case SQL_TYPE_TIME: return SQL_C_TIMESTAMP;
11642    case OTL_SQL_SS_TIME2: return SQL_C_TIMESTAMP;
11643 #if defined(OTL_UNICODE)
11644    case OTL_SQL_SS_TIMESTAMPOFFSET: return SQL_C_WCHAR;
11645 #else
11646    case OTL_SQL_SS_TIMESTAMPOFFSET: return SQL_C_CHAR;
11647 #endif
11648 #else
11649    case SQL_DATE: return SQL_C_TIMESTAMP;
11650    case SQL_TIMESTAMP: return SQL_C_TIMESTAMP;
11651    case SQL_TIME: return SQL_C_TIMESTAMP;
11652 #endif
11653 #if defined(OTL_BIGINT)
11654    case SQL_BIGINT: return SQL_C_SBIGINT;
11655 #else
11656    case SQL_BIGINT: return SQL_C_DOUBLE;
11657 #endif
11658    case SQL_DECIMAL: return SQL_C_DOUBLE;
11659    case SQL_DOUBLE: return SQL_C_DOUBLE;
11660    case SQL_FLOAT: return SQL_C_DOUBLE;
11661    case SQL_INTEGER: return SQL_C_SLONG;
11662    case SQL_NUMERIC: return SQL_C_DOUBLE;
11663    case SQL_REAL: return SQL_C_DOUBLE;
11664    case SQL_SMALLINT: return SQL_C_SSHORT;
11665    case SQL_BIT: return SQL_C_SSHORT;
11666    case SQL_TINYINT: return SQL_C_SSHORT;
11667    case SQL_LONGVARBINARY: return SQL_LONGVARBINARY;
11668 #if defined(OTL_MAP_SQL_VARBINARY_TO_RAW_LONG)
11669    case SQL_VARBINARY: return SQL_LONGVARBINARY;
11670 #else
11671    case SQL_VARBINARY: return SQL_C_BINARY;
11672 #endif
11673 #if (ODBCVER >= 0x0350)
11674 #if defined(OTL_MAP_SQL_GUID_TO_CHAR)
11675 #if defined(OTL_UNICODE)
11676    case SQL_GUID: return SQL_C_WCHAR;
11677 #else
11678    case SQL_GUID: return SQL_C_CHAR;
11679 #endif
11680 #else
11681    case SQL_GUID: return SQL_C_BINARY;
11682 #endif
11683 #endif
11684 #if defined(OTL_MAP_SQL_BINARY_TO_CHAR)
11685 #if defined(OTL_UNICODE)
11686    case SQL_BINARY: // MS SQL TIMESTAMP, BINARY
11687      return SQL_C_WCHAR;
11688 #else
11689    case SQL_BINARY: // MS SQL TIMESTAMP, BINARY
11690      return SQL_C_CHAR;
11691 #endif
11692 #else
11693    case SQL_BINARY:
11694      return SQL_C_BINARY;
11695 #endif
11696 #if (ODBCVER >= 0x0350)
11697    case OTL_SQL_XML:
11698 #if defined(OTL_UNICODE)
11699      return SQL_C_WCHAR;
11700 #else
11701      return SQL_C_CHAR;
11702 #endif
11703 #endif
11704    default: return otl_unsupported_type;
11705    }
11706  }
11707 
11708  static int datatype_size(int ftype,int maxsz,int int_type,int max_long_size)
11709  {
11710   switch(ftype){
11711 #if defined(OTL_UNICODE)
11712   case SQL_C_WCHAR:
11713 #endif
11714   case SQL_C_CHAR:
11715    switch(int_type){
11716    case SQL_BINARY: // MS SQL TIMESTAMP
11717      return 17;
11718 #if defined(OTL_UNICODE)
11719    case SQL_WLONGVARCHAR:
11720 #endif
11721    case SQL_LONGVARCHAR:
11722      return max_long_size*sizeof(OTL_CHAR);
11723    case SQL_LONGVARBINARY:
11724     return max_long_size;
11725    case SQL_DATE:
11726     return 40;
11727 #if (ODBCVER >= 0x0300)
11728    case SQL_TYPE_TIMESTAMP:
11729 #else
11730    case SQL_TIMESTAMP:
11731 #endif
11732     return 40;
11733 #if (ODBCVER >= 0x0300)
11734    case SQL_TYPE_TIME:
11735 #else
11736    case SQL_TIME:
11737 #endif
11738     return 40;
11739 #if (ODBCVER >= 0x0350)
11740 #if defined(OTL_MAP_SQL_GUID_TO_SQL_VARBINARY)
11741    case SQL_GUID:
11742     return 16;
11743 #else
11744    case SQL_GUID:
11745     return 40;
11746 #endif
11747 #endif
11748    default:
11749      return (maxsz+1);
11750    }
11751 #if defined(OTL_BIGINT)
11752   case SQL_C_SBIGINT:
11753    return sizeof(OTL_BIGINT);
11754 #endif
11755   case SQL_C_DOUBLE:
11756    return sizeof(double);
11757   case SQL_C_SLONG:
11758    return sizeof(int);
11759   case SQL_C_SSHORT:
11760    return sizeof(short int);
11761   case SQL_C_TIMESTAMP:
11762    return sizeof(OTL_SQL_TIMESTAMP_STRUCT);
11763   case SQL_C_TIME:
11764    return sizeof(OTL_SQL_TIME_STRUCT);
11765   case SQL_C_DATE:
11766    return sizeof(OTL_SQL_DATE_STRUCT);
11767 #if defined(OTL_UNICODE)
11768   case SQL_WLONGVARCHAR:
11769     return max_long_size;
11770 #endif
11771   case SQL_LONGVARCHAR:
11772    return max_long_size;
11773   case SQL_LONGVARBINARY:
11774    return max_long_size;
11775   case SQL_C_BINARY:
11776    return maxsz;
11777   default:
11778    return 0;
11779   }
11780  }
11781 
11782  static void map_ftype
11783  (otl_column_desc& desc,
11784   const int max_long_size,
11785   int& ftype,
11786   int& elem_size,
11787   otl_select_struct_override& override,
11788   const int column_ndx,
11789   const int
11790 #if !defined(OTL_ODBC_TIMESTEN) && defined(OTL_ODBC_MULTI_MODE)
11791   connection_type
11792 #endif
11793   )
11794  {
11795   int ndx=override.find(column_ndx);
11796   if(ndx==-1){
11797 #if defined(OTL_ODBC_MSSQL_2005) && !defined(OTL_ODBC_MULTI_MODE)
11798    if(desc.prec==0 && desc.dbtype==SQL_VARBINARY)
11799      ftype=SQL_LONGVARBINARY;
11800    else
11801 #elif defined(OTL_ODBC_MULTI_MODE)
11802      if((connection_type==OTL_MSSQL_2005_ODBC_CONNECT ||
11803          connection_type==OTL_MSSQL_2008_ODBC_CONNECT)&&
11804       desc.prec==0 && desc.dbtype==SQL_VARBINARY)
11805      ftype=SQL_LONGVARBINARY;
11806    else
11807 #endif
11808      ftype=int2ext(desc.dbtype);
11809    if(desc.dbsize==0){
11810 #if !defined(OTL_UNICODE)
11811      if(ftype==SQL_C_CHAR)
11812        ftype=SQL_LONGVARCHAR;
11813 #else
11814      if(ftype==SQL_C_CHAR)
11815        ftype=SQL_LONGVARCHAR;
11816      else if(ftype==SQL_C_WCHAR)
11817        ftype=SQL_WLONGVARCHAR;
11818 #endif
11819      elem_size=max_long_size*sizeof(OTL_CHAR);
11820    }else{
11821      elem_size=datatype_size
11822        (ftype,
11823         OTL_SCAST(int,desc.dbsize),
11824         desc.dbtype,
11825         max_long_size);
11826    }
11827    switch(ftype){
11828 #if defined(OTL_UNICODE)
11829    case SQL_C_WCHAR:
11830     ftype=otl_var_char;
11831     break;
11832    case SQL_WLONGVARCHAR:
11833     ftype=otl_var_varchar_long;
11834     break;
11835 #else
11836    case SQL_C_CHAR:
11837     ftype=otl_var_char;
11838     break;
11839    case SQL_LONGVARCHAR:
11840     ftype=otl_var_varchar_long;
11841     break;
11842 #endif
11843    case SQL_C_DOUBLE:
11844      if(override.get_all_mask() & otl_all_num2str){
11845      ftype=otl_var_char;
11846      elem_size=otl_num_str_size;
11847     }else
11848      ftype=otl_var_double;
11849     break;
11850 #if defined(OTL_BIGINT)
11851    case SQL_C_SBIGINT:
11852      if(override.get_all_mask() & otl_all_num2str){
11853      ftype=otl_var_char;
11854      elem_size=otl_num_str_size;
11855     }else
11856      ftype=otl_var_bigint;
11857     break;
11858 #endif
11859    case SQL_C_SLONG:
11860      if(override.get_all_mask() & otl_all_num2str){
11861      ftype=otl_var_char;
11862      elem_size=otl_num_str_size;
11863     }else
11864      ftype=otl_var_int;
11865     break;
11866    case SQL_C_SSHORT:
11867      if(override.get_all_mask() & otl_all_num2str){
11868      ftype=otl_var_char;
11869      elem_size=otl_num_str_size;
11870     }else
11871      ftype=otl_var_short;
11872     break;
11873    case SQL_LONGVARBINARY:
11874     ftype=otl_var_raw_long;
11875     break;
11876    case SQL_C_DATE:
11877    case SQL_C_TIME:
11878    case SQL_C_TIMESTAMP:
11879      if(override.get_all_mask() & otl_all_date2str){
11880      ftype=otl_var_char;
11881      elem_size=otl_date_str_size;
11882     }else
11883      ftype=otl_var_timestamp;
11884     break;
11885    case SQL_C_BINARY:
11886     ftype=otl_var_raw;
11887     break;
11888    default:
11889     ftype=0;
11890     break;
11891    }
11892   }else{
11893     ftype=override.get_col_type(ndx);
11894    switch(ftype){
11895    case otl_var_char:
11896      elem_size=override.get_col_size(ndx)*sizeof(OTL_CHAR);
11897     break;
11898    case otl_var_raw:
11899      elem_size=override.get_col_size(ndx);
11900     break;
11901    case otl_var_double:
11902     elem_size=sizeof(double);
11903     break;
11904    case otl_var_float:
11905     elem_size=sizeof(float);
11906     break;
11907    case otl_var_int:
11908     elem_size=sizeof(int);
11909     break;
11910 #if defined(OTL_BIGINT)
11911    case otl_var_bigint:
11912     elem_size=sizeof(OTL_BIGINT);
11913     break;
11914 #endif
11915    case otl_var_unsigned_int:
11916     elem_size=sizeof(unsigned);
11917     break;
11918    case otl_var_short:
11919     elem_size=sizeof(short);
11920     break;
11921    case otl_var_long_int:
11922     elem_size=sizeof(double);
11923     break;
11924    default:
11925      elem_size=override.get_col_size(ndx);
11926     break;
11927    }
11928   }
11929   desc.otl_var_dbtype=ftype;
11930  }
11931 
11932 private:
11933 
11934   otl_var(const otl_var&):
11935     p_v(0),
11936     p_len(0),
11937     ftype(0),
11938     act_elem_size(0),
11939     lob_stream_mode(false),
11940     lob_stream_flag(0),
11941     vparam_type(-1),
11942     lob_len(0),
11943     lob_pos(0),
11944     lob_ftype(0),
11945     otl_adapter(otl_odbc_adapter),
11946     charz_flag(false)
11947  {
11948  }
11949 
11950  otl_var& operator=(const otl_var&)
11951  {
11952    return *this;
11953  }
11954 
11955 };
11956 
11957 #if defined(OTL_ODBC_zOS)||defined(OTL_ODBC_TIMESTEN)|| \
11958   (defined(SQL_TXN_READ_COMMITTED) && \
11959    !defined(SQL_TRANSACTION_READ_COMMITTED))
11960 const long otl_tran_read_uncommitted=SQL_TXN_READ_UNCOMMITTED;
11961 const long otl_tran_read_committed=SQL_TXN_READ_COMMITTED;
11962 const long otl_tran_repeatable_read=SQL_TXN_REPEATABLE_READ;
11963 const long otl_tran_serializable=SQL_TXN_SERIALIZABLE;
11964 #else
11965 const long otl_tran_read_uncommitted=SQL_TRANSACTION_READ_UNCOMMITTED;
11966 const long otl_tran_read_committed=SQL_TRANSACTION_READ_COMMITTED;
11967 const long otl_tran_repeatable_read=SQL_TRANSACTION_REPEATABLE_READ;
11968 const long otl_tran_serializable=SQL_TRANSACTION_SERIALIZABLE;
11969 #endif
11970 
11971 class otl_sel;
11972 
11973 class otl_cur: public otl_cur0{
11974 private:
11975 
11976   friend class otl_sel;
11977   int status;
11978   otl_conn* adb;
11979   int direct_exec_flag;
11980   long _rpc;
11981   bool canceled;
11982   int last_iters;
11983 
11984 public:
11985 
11986   void set_canceled(const bool acanceled)
11987   {
11988     canceled=acanceled;
11989   }
11990 
11991   void reset_last_param_data_token()
11992   {
11993     last_param_data_token=0;
11994   }
11995 
11996   void reset_last_sql_param_data_status()
11997   {
11998     last_sql_param_data_status=0;
11999   }
12000 
12001   void reset_sql_param_data_count()
12002   {
12003     sql_param_data_count=0;
12004   }
12005 
12006 
12007   otl_cur():
12008     otl_cur0(),
12009     status(0),
12010     adb(0),
12011     direct_exec_flag(0),
12012     _rpc(0),
12013     canceled(false),
12014     last_iters(0)
12015  {
12016   cda=0;
12017   last_param_data_token=0;
12018   last_sql_param_data_status=0;
12019   sql_param_data_count=0;
12020  }
12021 
12022  virtual ~otl_cur(){}
12023 
12024   int cancel(void)
12025   {
12026     status=SQLCancel(cda);
12027     canceled=true;
12028     if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
12029       return 0;
12030     else
12031       return 1;
12032   }
12033 
12034   int open(otl_conn& /* connect */,otl_var* /* var */)
12035   {
12036     return 1;
12037   }
12038 
12039  void set_direct_exec(const int flag)
12040  {
12041   direct_exec_flag=flag;
12042  }
12043 
12044   void set_parse_only(const int /*flag*/){}
12045 
12046  int open(otl_conn& connect)
12047  {
12048    last_iters=0;
12049   direct_exec_flag=0;
12050   adb=&connect;
12051 #if (ODBCVER >= 0x0300)
12052   status=SQLAllocHandle(SQL_HANDLE_STMT,connect.hdbc,&cda);
12053 #else
12054  status=SQLAllocStmt(connect.hdbc,&cda);
12055 #endif
12056   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
12057   if(connect.timeout>0){
12058 #if (ODBCVER >= 0x0300)
12059    status=SQLSetStmtAttr
12060     (cda,
12061      SQL_ATTR_QUERY_TIMEOUT,
12062      OTL_RCAST(void*,OTL_SCAST(size_t,connect.timeout)),
12063      SQL_NTS);
12064 #else
12065   status=SQLSetStmtOption(cda,SQL_QUERY_TIMEOUT,connect.timeout);
12066 #endif
12067    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
12068     return 0;
12069   }
12070   if(connect.cursor_type!=0){ // other than default
12071 #if (ODBCVER >= 0x0300)
12072    status=SQLSetStmtAttr
12073     (cda,
12074      SQL_ATTR_CURSOR_TYPE,
12075      OTL_RCAST(void*,OTL_SCAST(size_t,connect.cursor_type)),
12076      SQL_NTS);
12077 #else
12078   status=SQLSetStmtOption(cda,SQL_CURSOR_TYPE,connect.cursor_type);
12079 #endif
12080    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
12081     return 0;
12082   }
12083   return 1;
12084  }
12085 
12086  int close(void)
12087  {
12088    last_iters=0;
12089 #if (ODBCVER >= 0x0300)
12090   status=SQLFreeHandle(SQL_HANDLE_STMT,cda);
12091 #else
12092   status=SQLFreeStmt(cda,SQL_DROP);
12093 #endif
12094   adb=0;
12095   cda=0;
12096   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
12097    return 0;
12098   else
12099    return 1;
12100  }
12101 
12102 SQLRETURN sql_row_count(OTL_SQLLEN* total_rpc)
12103 {
12104 #if defined(OTL_ODBC_ALTERNATE_RPC)
12105   OTL_SQLLEN rpc=0;
12106   SQLRETURN rc;
12107   do{
12108     rc=SQLRowCount(cda,&rpc);
12109     if(rc!=SQL_SUCCESS)
12110       return rc;
12111     *total_rpc+=rpc;
12112     rc=SQLMoreResults(cda);
12113   }while(rc==SQL_SUCCESS);
12114   return SQL_SUCCESS;
12115 #else
12116   return SQLRowCount(cda,total_rpc);
12117 #endif
12118 }
12119 
12120 
12121  int parse(char* stm_text)
12122  {
12123 #if !defined(OTL_ODBC_TIMESTEN)
12124    short in_str=0;
12125 #endif
12126    bool do_not_call_sql_row_count=false;
12127 #if defined(OTL_ODBC_SQL_STATEMENT_WITH_DIAG_REC_OUTPUT)
12128    if(OTL_ODBC_SQL_STATEMENT_WITH_DIAG_REC_OUTPUT (stm_text)){
12129      do_not_call_sql_row_count=true;
12130      direct_exec_flag=1;
12131    }
12132 #endif
12133   char *c=stm_text;
12134   if(*c=='$'){
12135     ++c;
12136     _rpc=0;
12137     direct_exec_flag=1;
12138     const int ctl_arr_size=6;
12139     struct{
12140       OTL_SQLCHAR_PTR name_ptr;
12141       OTL_SQLSMALLINT name_len;
12142       OTL_SQLCHAR name[512];
12143     } ctl_arr[ctl_arr_size];
12144 #if (defined(UNICODE)||defined(_UNICODE))
12145     struct{
12146       SQLWCHAR name_ptr;
12147       OTL_SQLSMALLINT name_len;
12148       SQLWCHAR name[512];
12149     } ctl_arr_W[ctl_arr_size];
12150 #endif
12151     int i=0;
12152     for(i=0;i<ctl_arr_size;++i){
12153       ctl_arr[i].name_ptr=0;
12154       ctl_arr[i].name_len=0;
12155       ctl_arr[i].name[0]=0;
12156 #if (defined(UNICODE)||defined(_UNICODE))
12157       ctl_arr_W[i].name_ptr=0;
12158       ctl_arr_W[i].name_len=0;
12159       ctl_arr_W[i].name[0]=0;
12160 #endif
12161     }
12162     char func_name[256];
12163     int par_num=0;
12164     char par_val[512];
12165     size_t par_val_len=0;
12166     size_t fn_len=0;
12167     bool func_found=false;
12168     while(*c && *c!=' ' && fn_len<sizeof(func_name)){
12169       ++fn_len;
12170       func_name[fn_len-1]=*c;
12171       ++c;
12172     }
12173     if(fn_len<sizeof(func_name)-1){
12174       ++fn_len;
12175       func_name[fn_len-1]=0;
12176     }else
12177       func_name[sizeof(func_name)-1]=0;
12178     while(*c==' ')++c;
12179     while(*c){
12180       if(*c=='$'){
12181         ++c;
12182         par_num=OTL_SCAST(int,*c-'0')-1;
12183         ++c;
12184         while(*c && *c==' ')++c;
12185         if(*c==':' && ((c>stm_text && *(c-1)!='\\' )|| c==stm_text)){
12186           ++c;
12187           while(*c && *c==' ')++c;
12188           if(*c=='\''){
12189             par_val_len=0;
12190             ++c;
12191             while(*c && *c!='\'' && par_val_len<sizeof(par_val)){
12192               ++par_val_len;
12193               par_val[par_val_len-1]=*c;
12194               ++c;
12195             }
12196             if(par_val_len<sizeof(par_val)-1){
12197               ++par_val_len;
12198               par_val[par_val_len-1]=0;
12199             }else
12200               par_val[sizeof(par_val)-1]=0;
12201             if(par_num>=0 && par_num<ctl_arr_size){
12202               ctl_arr[par_num].name_ptr=ctl_arr[par_num].name;
12203               ctl_arr[par_num].name_len=SQL_NTS;
12204               OTL_STRCPY_S(OTL_RCAST(char*,ctl_arr[par_num].name),
12205                            sizeof(ctl_arr[par_num].name),
12206                            OTL_RCAST(const char*,par_val));
12207             }
12208           }
12209           ++c;
12210           while(*c && *c==' ')++c;
12211         }
12212       }else
12213         ++c;
12214     }
12215     status=SQL_SUCCESS;
12216     if(strcmp(func_name,"SQLTables")==0){
12217 #if (defined(UNICODE)||defined(_UNICODE))
12218       otl_convert_char_to_SQLWCHAR
12219         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12220       otl_convert_char_to_SQLWCHAR
12221         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12222       otl_convert_char_to_SQLWCHAR
12223         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12224       otl_convert_char_to_SQLWCHAR
12225         (ctl_arr_W[3].name,OTL_RCAST(unsigned char*,ctl_arr[3].name));
12226 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12227       status=SQLTables
12228         (cda,
12229          ctl_arr_W[0].name,SQL_NTS,
12230          ctl_arr_W[1].name,SQL_NTS,
12231          ctl_arr_W[2].name,SQL_NTS,
12232          ctl_arr_W[3].name,SQL_NTS);
12233 #else
12234       status=SQLTablesA
12235         (cda,
12236          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12237          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12238          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12239          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12240 #endif
12241 
12242 #else
12243       status=SQLTables
12244         (cda,
12245          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12246          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12247          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12248          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12249 #endif
12250       func_found=true;
12251     }else if(strcmp(func_name,"SQLGetTypeInfo")==0){
12252       status=SQLGetTypeInfo
12253         (cda,
12254          SQL_ALL_TYPES);
12255       func_found=true;
12256     }else if(strcmp(func_name,"SQLColumns")==0){
12257 #if (defined(UNICODE)||defined(_UNICODE))
12258       otl_convert_char_to_SQLWCHAR
12259         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12260       otl_convert_char_to_SQLWCHAR
12261         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12262       otl_convert_char_to_SQLWCHAR
12263         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12264       otl_convert_char_to_SQLWCHAR
12265         (ctl_arr_W[3].name,OTL_RCAST(unsigned char*,ctl_arr[3].name));
12266 
12267 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12268       status=SQLColumns
12269         (cda,
12270          ctl_arr_W[0].name,SQL_NTS,
12271          ctl_arr_W[1].name,SQL_NTS,
12272          ctl_arr_W[2].name,SQL_NTS,
12273          ctl_arr_W[3].name,SQL_NTS);
12274 #else
12275       status=SQLColumnsA
12276         (cda,
12277          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12278          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12279          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12280          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12281 #endif
12282 
12283 #else
12284       status=SQLColumns
12285         (cda,
12286          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12287          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12288          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12289          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12290 #endif
12291       func_found=true;
12292     }else if(strcmp(func_name,"SQLProcedures")==0){
12293 #if (defined(UNICODE)||defined(_UNICODE))
12294       otl_convert_char_to_SQLWCHAR
12295         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12296       otl_convert_char_to_SQLWCHAR
12297         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12298       otl_convert_char_to_SQLWCHAR
12299         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12300 
12301 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12302       status=SQLProcedures
12303         (cda,
12304          ctl_arr_W[0].name,SQL_NTS,
12305          ctl_arr_W[1].name,SQL_NTS,
12306          ctl_arr_W[2].name,SQL_NTS);
12307 #else
12308       status=SQLProceduresA
12309         (cda,
12310          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12311          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12312          ctl_arr[2].name_ptr,ctl_arr[2].name_len);
12313 #endif
12314 
12315 #else
12316       status=SQLProcedures
12317         (cda,
12318          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12319          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12320          ctl_arr[2].name_ptr,ctl_arr[2].name_len);
12321 #endif
12322       func_found=true;
12323     }else if(strcmp(func_name,"SQLColumnPrivileges")==0){
12324 #if (defined(UNICODE)||defined(_UNICODE))
12325       otl_convert_char_to_SQLWCHAR
12326         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12327       otl_convert_char_to_SQLWCHAR
12328         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12329       otl_convert_char_to_SQLWCHAR
12330         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12331       otl_convert_char_to_SQLWCHAR
12332         (ctl_arr_W[3].name,OTL_RCAST(unsigned char*,ctl_arr[3].name));
12333 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12334      status=SQLColumnPrivileges
12335        (cda,
12336         ctl_arr_W[0].name,SQL_NTS,
12337         ctl_arr_W[1].name,SQL_NTS,
12338         ctl_arr_W[2].name,SQL_NTS,
12339         ctl_arr_W[3].name,SQL_NTS);
12340 #else
12341      status=SQLColumnPrivilegesA
12342        (cda,
12343         ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12344         ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12345         ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12346         ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12347 #endif
12348 
12349 #else
12350       status=SQLColumnPrivileges
12351         (cda,
12352          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12353          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12354          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12355          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12356 #endif
12357       func_found=true;
12358     }else if(strcmp(func_name,"SQLTablePrivileges")==0){
12359 #if (defined(UNICODE)||defined(_UNICODE))
12360       otl_convert_char_to_SQLWCHAR
12361         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12362       otl_convert_char_to_SQLWCHAR
12363         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12364       otl_convert_char_to_SQLWCHAR
12365         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12366 
12367 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12368       status=SQLTablePrivileges
12369         (cda,
12370          ctl_arr_W[0].name,SQL_NTS,
12371          ctl_arr_W[1].name,SQL_NTS,
12372          ctl_arr_W[2].name,SQL_NTS);
12373 #else
12374       status=SQLTablePrivilegesA
12375         (cda,
12376          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12377          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12378          ctl_arr[2].name_ptr,ctl_arr[2].name_len);
12379 #endif
12380 
12381 #else
12382       status=SQLTablePrivileges
12383         (cda,
12384          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12385          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12386          ctl_arr[2].name_ptr,ctl_arr[2].name_len);
12387 #endif
12388       func_found=true;
12389     }else if(strcmp(func_name,"SQLPrimaryKeys")==0){
12390 #if (defined(UNICODE)||defined(_UNICODE))
12391       otl_convert_char_to_SQLWCHAR
12392         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12393       otl_convert_char_to_SQLWCHAR
12394         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12395       otl_convert_char_to_SQLWCHAR
12396         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12397 
12398 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12399       status=SQLPrimaryKeys
12400         (cda,
12401          ctl_arr_W[0].name,SQL_NTS,
12402          ctl_arr_W[1].name,SQL_NTS,
12403          ctl_arr_W[2].name,SQL_NTS);
12404 #else
12405       status=SQLPrimaryKeysA
12406         (cda,
12407          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12408          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12409          ctl_arr[2].name_ptr,ctl_arr[2].name_len);
12410 #endif
12411 
12412 #else
12413       status=SQLPrimaryKeys
12414         (cda,
12415          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12416          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12417          ctl_arr[2].name_ptr,ctl_arr[2].name_len);
12418 #endif
12419       func_found=true;
12420     }else if(strcmp(func_name,"SQLProcedureColumns")==0){
12421 #if (defined(UNICODE)||defined(_UNICODE))
12422       otl_convert_char_to_SQLWCHAR
12423         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12424       otl_convert_char_to_SQLWCHAR
12425         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12426       otl_convert_char_to_SQLWCHAR
12427         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12428       otl_convert_char_to_SQLWCHAR
12429         (ctl_arr_W[3].name,OTL_RCAST(unsigned char*,ctl_arr[3].name));
12430 
12431 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12432       status=SQLProcedureColumns
12433         (cda,
12434          ctl_arr_W[0].name,SQL_NTS,
12435          ctl_arr_W[1].name,SQL_NTS,
12436          ctl_arr_W[2].name,SQL_NTS,
12437          ctl_arr_W[3].name,SQL_NTS);
12438 #else
12439       status=SQLProcedureColumnsA
12440         (cda,
12441          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12442          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12443          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12444          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12445 #endif
12446 
12447 #else
12448       status=SQLProcedureColumns
12449         (cda,
12450          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12451          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12452          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12453          ctl_arr[3].name_ptr,ctl_arr[3].name_len);
12454 #endif
12455       func_found=true;
12456     }else if(strcmp(func_name,"SQLForeignKeys")==0){
12457 #if (defined(UNICODE)||defined(_UNICODE))
12458       otl_convert_char_to_SQLWCHAR
12459         (ctl_arr_W[0].name,OTL_RCAST(unsigned char*,ctl_arr[0].name));
12460       otl_convert_char_to_SQLWCHAR
12461         (ctl_arr_W[1].name,OTL_RCAST(unsigned char*,ctl_arr[1].name));
12462       otl_convert_char_to_SQLWCHAR
12463         (ctl_arr_W[2].name,OTL_RCAST(unsigned char*,ctl_arr[2].name));
12464       otl_convert_char_to_SQLWCHAR
12465         (ctl_arr_W[3].name,OTL_RCAST(unsigned char*,ctl_arr[3].name));
12466       otl_convert_char_to_SQLWCHAR
12467         (ctl_arr_W[4].name,OTL_RCAST(unsigned char*,ctl_arr[4].name));
12468       otl_convert_char_to_SQLWCHAR
12469         (ctl_arr_W[5].name,OTL_RCAST(unsigned char*,ctl_arr[5].name));
12470 
12471 #if !defined(OTL_UNICODE_USE_ANSI_ODBC_FUNCS_FOR_DATA_DICT)
12472       status=SQLForeignKeys
12473         (cda,
12474          ctl_arr_W[0].name,SQL_NTS,
12475          ctl_arr_W[1].name,SQL_NTS,
12476          ctl_arr_W[2].name,SQL_NTS,
12477          ctl_arr_W[3].name,SQL_NTS,
12478          ctl_arr_W[4].name,SQL_NTS,
12479          ctl_arr_W[5].name,SQL_NTS);
12480 #else
12481       status=SQLForeignKeysA
12482         (cda,
12483          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12484          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12485          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12486          ctl_arr[3].name_ptr,ctl_arr[3].name_len,
12487          ctl_arr[4].name_ptr,ctl_arr[4].name_len,
12488          ctl_arr[5].name_ptr,ctl_arr[5].name_len);
12489 #endif
12490 
12491 #else
12492       status=SQLForeignKeys
12493         (cda,
12494          ctl_arr[0].name_ptr,ctl_arr[0].name_len,
12495          ctl_arr[1].name_ptr,ctl_arr[1].name_len,
12496          ctl_arr[2].name_ptr,ctl_arr[2].name_len,
12497          ctl_arr[3].name_ptr,ctl_arr[3].name_len,
12498          ctl_arr[4].name_ptr,ctl_arr[4].name_len,
12499          ctl_arr[5].name_ptr,ctl_arr[5].name_len);
12500 #endif
12501       func_found=true;
12502     }
12503     if(!func_found)return 2;
12504     if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
12505       return 0;
12506     else
12507       return 1;
12508   }
12509 
12510   if(direct_exec_flag){
12511    _rpc=0;
12512 #if (defined(UNICODE)||defined(_UNICODE))
12513  {
12514    SQLWCHAR* temp_stm_text=new SQLWCHAR[strlen(stm_text)+1];
12515    otl_convert_char_to_SQLWCHAR(temp_stm_text,OTL_RCAST(unsigned char*,stm_text));
12516    status=SQLExecDirect
12517     (cda,
12518      temp_stm_text,
12519      SQL_NTS);
12520    delete[] temp_stm_text;
12521  }
12522 #else
12523    status=SQLExecDirect
12524     (cda,
12525      OTL_RCAST(OTL_SQLCHAR_PTR,stm_text),
12526      SQL_NTS);
12527 #endif
12528 
12529 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
12530    if(adb && adb->throws_on_sql_success_with_info &&
12531       status==SQL_SUCCESS_WITH_INFO)
12532      return 0;
12533 #endif
12534 
12535    if(status!=SQL_SUCCESS&&
12536       status!=SQL_SUCCESS_WITH_INFO&&
12537 #if (ODBCVER >= 0x0300)
12538       status!=SQL_NO_DATA
12539 #else
12540       status!=SQL_NO_DATA_FOUND
12541 #endif
12542      )
12543     return 0;
12544    else{
12545      _rpc=0;
12546      if(!do_not_call_sql_row_count){
12547        OTL_SQLLEN tmp_rpc=0;
12548        SQLRETURN diag_status=sql_row_count(&tmp_rpc);
12549        if(diag_status==SQL_SUCCESS||
12550           diag_status==SQL_SUCCESS_WITH_INFO)
12551          _rpc=OTL_SCAST(long,tmp_rpc);
12552      }
12553     return 1;
12554    }
12555   }
12556 
12557 #if !defined(OTL_ODBC_TIMESTEN)
12558   // Converting : notation into ODBC's native notation ?
12559   while(*c){
12560    if(*c=='\''){
12561     if(!in_str)
12562      in_str=1;
12563     else{
12564      if(c[1]=='\'')
12565       ++c;
12566      else
12567       in_str=0;
12568     }
12569    }
12570    if(*c==':' && !in_str &&
12571       ((c>stm_text && *(c-1)!='\\' )|| c==stm_text)){
12572     *c='?';
12573     ++c;
12574     while(isdigit(*c)||isalpha(*c)||*c=='_'){
12575      *c=' ';
12576      ++c;
12577     }
12578    }else if(*c==':' && !in_str &&
12579             ((c>stm_text && *(c-1)=='\\' )|| c==stm_text)){
12580      char* c_1=c-1;
12581      char* c_=c;
12582      while(*c_){
12583        *c_1=*c_;
12584        ++c_1;
12585        ++c_;
12586      }
12587      if(c_1>c-1)
12588        *c_1=0;
12589      --c;
12590    }
12591    ++c;
12592   }
12593 #endif
12594 
12595 #if defined(OTL_DB2_CLI)
12596 
12597   OTL_SQLINTEGER temp_isolation_level=0;
12598   status=SQLGetStmtAttr
12599    (cda,
12600     SQL_ATTR_TXN_ISOLATION,
12601     OTL_RCAST(SQLPOINTER,&temp_isolation_level),
12602     SQL_IS_POINTER,
12603     0);
12604   if(OTL_SCAST(long,temp_isolation_level)==otl_tran_read_committed||
12605      OTL_SCAST(long,temp_isolation_level)==otl_tran_read_uncommitted){
12606     status=SQLSetStmtAttr
12607       (cda,
12608        SQL_ATTR_CLOSE_BEHAVIOR,
12609        OTL_RCAST(void*,SQL_CC_RELEASE),
12610        SQL_NTS);
12611     if(status!=SQL_SUCCESS&&
12612        status!=SQL_SUCCESS_WITH_INFO)
12613       return 0;
12614   }
12615 #endif
12616 
12617 #if (defined(UNICODE)||defined(_UNICODE))
12618  {
12619    SQLWCHAR* temp_stm_text=new SQLWCHAR[strlen(stm_text)+1];
12620    otl_convert_char_to_SQLWCHAR(temp_stm_text,OTL_RCAST(unsigned char*,stm_text));
12621    status=SQLPrepare
12622      (cda,
12623       temp_stm_text,
12624       SQL_NTS);
12625    delete[] temp_stm_text;
12626  }
12627 #else
12628  status=SQLPrepare
12629   (cda,
12630    OTL_RCAST(OTL_SQLCHAR_PTR,stm_text),
12631    SQL_NTS);
12632 #endif
12633 
12634  if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
12635   return 0;
12636  else
12637   return 1;
12638  }
12639 
12640  int exec(const int iters,
12641           const int /*rowoff*/,
12642 #if defined(OTL_ODBC_ALTERNATE_RPC)
12643           const int otl_sql_exec_from_class)
12644 #else
12645           const int /*otl_sql_exec_from_class*/)
12646 #endif
12647  {
12648 #if (ODBCVER >= 0x0300)
12649 #else
12650   OTL_SQLUINTEGER irows;
12651 #endif
12652   if(direct_exec_flag){
12653    return 1;
12654   }else{
12655 #if !defined(OTL_ODBC_MYSQL) && !defined(OTL_ODBC_XTG_IBASE6)
12656 #if (ODBCVER >= 0x0300)
12657    if(last_iters>1||iters>1||_rpc>1){
12658      last_iters=iters;
12659      size_t temp_iters=OTL_SCAST(size_t,iters);
12660      status=SQLSetStmtAttr
12661        (cda,
12662         SQL_ATTR_PARAMSET_SIZE,
12663         OTL_RCAST(void*,temp_iters),
12664         SQL_NTS);
12665      if(status!=SQL_SUCCESS&&
12666         status!=SQL_SUCCESS_WITH_INFO)
12667        return 0;
12668    }
12669 #else
12670    if(last_iters>1||iters>1||_rpc>1){
12671      last_iters=iters;
12672      status=SQLParamOptions
12673        (cda,
12674         OTL_SCAST(OTL_SQLUINTEGER,iters),
12675         &irows);
12676      if(status!=SQL_SUCCESS&&
12677         status!=SQL_SUCCESS_WITH_INFO)
12678        return 0;
12679    }
12680 #endif
12681 #endif
12682    _rpc=0;
12683 
12684    last_param_data_token=0;
12685    last_sql_param_data_status=0;
12686    sql_param_data_count=0;
12687 
12688    status=SQLExecute(cda);
12689    if(canceled)return 0;
12690 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
12691    if(adb && adb->throws_on_sql_success_with_info &&
12692       status==SQL_SUCCESS_WITH_INFO)
12693      return 0;
12694 #endif
12695    if(status!=SQL_SUCCESS&&
12696       status!=SQL_SUCCESS_WITH_INFO&&
12697 #if (ODBCVER >= 0x0300)
12698       status!=SQL_NO_DATA&&
12699 #else
12700       status!=SQL_NO_DATA_FOUND&&
12701 #endif
12702       status!=SQL_NEED_DATA)return 0;
12703    if(status==SQL_NEED_DATA){
12704     _rpc=iters;
12705     return 1;
12706    }
12707    OTL_SQLLEN tmp_rpc=0;
12708    SQLRETURN diag_status=0;
12709 #if defined(OTL_ODBC_ALTERNATE_RPC)
12710    if(otl_sql_exec_from_class==otl_sql_exec_from_cursor_class){
12711      diag_status=sql_row_count(&tmp_rpc);
12712      if(diag_status==SQL_SUCCESS||diag_status==SQL_SUCCESS_WITH_INFO)
12713        _rpc=OTL_SCAST(long,tmp_rpc);
12714      return 1;
12715    }else{
12716      _rpc=0;
12717      return 1;
12718    }
12719 #else
12720    diag_status=sql_row_count(&tmp_rpc);
12721    if(diag_status==SQL_SUCCESS||diag_status==SQL_SUCCESS_WITH_INFO)
12722      _rpc=OTL_SCAST(long,tmp_rpc);
12723    return 1;
12724 #endif
12725   }
12726  }
12727 
12728  long get_rpc()
12729  {
12730   return _rpc;
12731  }
12732 
12733  int tmpl_ftype2odbc_ftype(const int ftype)
12734  {
12735   switch(ftype){
12736 #if defined(OTL_UNICODE)
12737   case otl_var_char:
12738    return SQL_C_WCHAR;
12739   case otl_var_varchar_long:
12740    return SQL_WLONGVARCHAR;
12741 #else
12742   case otl_var_char:
12743    return SQL_C_CHAR;
12744   case otl_var_varchar_long:
12745    return SQL_LONGVARCHAR;
12746 #endif
12747   case otl_var_double:
12748    return SQL_C_DOUBLE;
12749 #if defined(OTL_BIGINT)
12750   case otl_var_bigint:
12751    return SQL_C_SBIGINT;
12752 #endif
12753   case otl_var_float:
12754    return SQL_C_FLOAT;
12755   case otl_var_int:
12756     return SQL_C_SLONG;
12757   case otl_var_long_int:
12758 #if defined(OTL_MAP_LONG_TO_SQL_C_SBIGINT) && \
12759     ((ODBCVER >= 0x0300) || defined(OTL_ODBC_TIMESTEN))
12760   {
12761     static bool long_is_8_bytes=sizeof(long)==8;
12762     if(long_is_8_bytes)
12763       return SQL_C_SBIGINT;
12764     else
12765       return SQL_C_SLONG;
12766   }
12767 #else
12768   return SQL_C_SLONG;
12769 #endif
12770   case otl_var_unsigned_int:
12771    return SQL_C_ULONG;
12772   case otl_var_short:
12773    return SQL_C_SSHORT;
12774   case otl_var_timestamp:
12775   case otl_var_db2time:
12776   case otl_var_db2date:
12777    return SQL_C_TIMESTAMP;
12778   case otl_var_raw_long:
12779    return SQL_LONGVARBINARY;
12780   case otl_var_raw:
12781    return SQL_C_BINARY;
12782   default:
12783    return 0;
12784   }
12785  }
12786 
12787  int otl_map_ext2int(int ftype)
12788  {
12789   switch(ftype){
12790 #if defined(OTL_UNICODE)
12791   case SQL_WLONGVARCHAR: return SQL_WLONGVARCHAR;
12792   case SQL_C_WCHAR: return SQL_WVARCHAR;
12793 #else
12794   case SQL_LONGVARCHAR: return SQL_LONGVARCHAR;
12795   case SQL_C_CHAR: return SQL_VARCHAR;
12796 #endif
12797   case SQL_LONGVARBINARY: return SQL_LONGVARBINARY;
12798   case SQL_C_DATE: return SQL_DATE;
12799 #if (ODBCVER >= 0x0300)
12800   case SQL_C_TIME: return SQL_TYPE_TIME;
12801   case SQL_C_TIMESTAMP: return SQL_TYPE_TIMESTAMP;
12802 #else
12803   case SQL_C_TIME: return SQL_TIME;
12804   case SQL_C_TIMESTAMP: return SQL_TIMESTAMP;
12805 #endif
12806   case SQL_C_DOUBLE: return SQL_DOUBLE;
12807 #if defined(OTL_BIGINT)
12808   case SQL_C_SBIGINT: return SQL_BIGINT;
12809 #endif
12810   case SQL_C_FLOAT: return SQL_FLOAT;
12811   case SQL_C_SLONG: return SQL_INTEGER;
12812   case SQL_C_SSHORT: return SQL_SMALLINT;
12813   case SQL_C_ULONG: return SQL_DOUBLE;
12814   case SQL_C_BINARY: return SQL_VARBINARY;
12815   default: return -1;
12816   }
12817  }
12818 
12819  int bind
12820  (const char* /* name */,
12821   otl_var& v,
12822   const int aelem_size,
12823   const int aftype,
12824   const int aparam_type,
12825   const int name_pos,
12826   const int
12827 #if !defined(OTL_ODBC_TIMESTEN) && defined(OTL_ODBC_MULTI_MODE)
12828   connection_type
12829 #endif
12830   ,
12831   const int /* apl_tab_size */)
12832  {OTL_SQLSMALLINT ftype=OTL_SCAST(OTL_SQLSMALLINT,tmpl_ftype2odbc_ftype(aftype));
12833   OTL_SQLSMALLINT ftype_save=ftype;
12834   int param_type;
12835   int parm_pos=name_pos;
12836   v.vparam_type=aparam_type;
12837   switch(aparam_type){
12838   case otl_input_param:
12839    param_type=SQL_PARAM_INPUT;
12840    break;
12841   case otl_output_param:
12842    param_type=SQL_PARAM_OUTPUT;
12843    break;
12844   case otl_inout_param:
12845    param_type=SQL_PARAM_INPUT_OUTPUT;
12846    break;
12847   default:
12848    param_type=SQL_PARAM_INPUT;
12849    break;
12850   }
12851 #if defined(OTL_UNICODE)
12852   if(ftype==SQL_WLONGVARCHAR){
12853    ftype=SQL_C_WCHAR;
12854 #else
12855   if(ftype==SQL_LONGVARCHAR){
12856    ftype=SQL_C_CHAR;
12857 #endif
12858   }else if(ftype==SQL_LONGVARBINARY){
12859    ftype=SQL_C_BINARY;
12860   }
12861   int sqltype=otl_map_ext2int(ftype_save);
12862   int mapped_sqltype=sqltype;
12863 
12864   if(aftype==otl_var_db2date)
12865 #if (ODBCVER >= 0x0300)
12866    mapped_sqltype=SQL_TYPE_DATE;
12867 #else
12868    mapped_sqltype=SQL_DATE;
12869 #endif
12870   else if(aftype==otl_var_db2time)
12871 #if (ODBCVER >= 0x0300)
12872    mapped_sqltype=SQL_TYPE_TIME;
12873 #else
12874    mapped_sqltype=SQL_TIME;
12875 #endif
12876   if(v.lob_stream_mode&&
12877      (ftype_save==SQL_LONGVARBINARY||
12878 #if defined(OTL_UNICODE)
12879       ftype_save==SQL_WLONGVARCHAR)){
12880 #else
12881       ftype_save==SQL_LONGVARCHAR)){
12882 #endif
12883    // in case of "stream mode" the variable
12884    // gets bound in a special way
12885 #if defined(OTL_ODBC_MSSQL_2005) && !defined(OTL_ODBC_MULTI_MODE)
12886     switch(ftype_save){
12887     case SQL_LONGVARBINARY:
12888       mapped_sqltype=SQL_VARBINARY;
12889       break;
12890 #if defined(OTL_UNICODE)
12891     case SQL_WLONGVARCHAR:
12892       mapped_sqltype=SQL_WVARCHAR;
12893       break;
12894 #else
12895     case SQL_LONGVARCHAR:
12896       mapped_sqltype=SQL_VARCHAR;
12897       break;
12898 #endif
12899     }
12900 #elif defined(OTL_ODBC_MULTI_MODE)
12901     if(connection_type==OTL_MSSQL_2005_ODBC_CONNECT||
12902        connection_type==OTL_MSSQL_2008_ODBC_CONNECT){
12903       switch(ftype_save){
12904       case SQL_LONGVARBINARY:
12905         mapped_sqltype=SQL_VARBINARY;
12906         break;
12907 #if defined(OTL_UNICODE)
12908       case SQL_WLONGVARCHAR:
12909         mapped_sqltype=SQL_WVARCHAR;
12910         break;
12911 #else
12912       case SQL_LONGVARCHAR:
12913         mapped_sqltype=SQL_VARCHAR;
12914         break;
12915 #endif
12916       }
12917     }
12918 #endif
12919    status=SQLBindParameter
12920     (cda,
12921      OTL_SCAST(OTL_SQLUSMALLINT,parm_pos),
12922      OTL_SCAST(OTL_SQLSMALLINT,param_type),
12923      ftype,
12924      OTL_SCAST(OTL_SQLSMALLINT,mapped_sqltype),
12925 #if (ODBCVER >= 0x0300)
12926 
12927 #if defined(OTL_ODBC_MSSQL_2005) && !defined(OTL_ODBC_MULTI_MODE)
12928      0,
12929 #elif defined(OTL_ODBC_MULTI_MODE)
12930      (connection_type==OTL_MSSQL_2005_ODBC_CONNECT||
12931       connection_type==OTL_MSSQL_2008_ODBC_CONNECT) ? 0 :
12932      (sqltype==SQL_TYPE_TIMESTAMP?otl_odbc_date_prec:aelem_size),
12933 #else
12934      sqltype==SQL_TYPE_TIMESTAMP?otl_odbc_date_prec:aelem_size,
12935 #endif
12936 #else
12937      sqltype==SQL_TIMESTAMP?otl_odbc_date_prec:aelem_size,
12938 #endif
12939 #if (ODBCVER >= 0x0300)
12940      sqltype==SQL_TYPE_TIMESTAMP ?
12941 #if defined(OTL_ODBC_MULTI_MODE)
12942      ((connection_type==OTL_MSSQL_2008_ODBC_CONNECT)? 7 :
12943       (connection_type==OTL_MSSQL_2005_ODBC_CONNECT)? 3 :
12944       otl_odbc_date_scale) : 0,
12945 #else
12946      otl_odbc_date_scale : 0,
12947 #endif
12948 #else
12949      sqltype==SQL_TIMESTAMP?otl_odbc_date_scale:0,
12950 #endif
12951      OTL_RCAST(OTL_SQLPOINTER,OTL_SCAST(size_t,parm_pos)),
12952      0,
12953      v.p_len);
12954   }else{
12955     int temp_column_size=0;
12956 #if (ODBCVER >= 0x0300)
12957     if(sqltype==SQL_TYPE_TIMESTAMP)
12958       temp_column_size=otl_odbc_date_prec;
12959 #if defined(OTL_UNICODE)
12960     else if(ftype==SQL_C_WCHAR)
12961       temp_column_size=(aelem_size-1)*sizeof(OTL_CHAR);
12962 #else
12963     else if(ftype==SQL_C_CHAR)
12964       temp_column_size=aelem_size-1;
12965 #endif
12966     else
12967       temp_column_size=aelem_size;
12968 #else
12969     if(sqltype==SQL_TIMESTAMP)
12970       temp_column_size=otl_odbc_date_prec;
12971     else if(ftype==SQL_C_CHAR)
12972       temp_column_size=aelem_size-1;
12973     else
12974       temp_column_size=aelem_size;
12975 #endif
12976     OTL_SQLINTEGER buflen=0;
12977 #if defined(OTL_UNICODE)
12978     if(ftype==SQL_C_WCHAR)
12979       buflen=aelem_size*sizeof(OTL_CHAR);
12980     else
12981 #endif
12982       buflen=aelem_size;
12983     status=SQLBindParameter
12984     (cda,
12985      OTL_SCAST(OTL_SQLUSMALLINT,parm_pos),
12986      OTL_SCAST(OTL_SQLSMALLINT,param_type),
12987      ftype,
12988      OTL_SCAST(OTL_SQLSMALLINT,mapped_sqltype),
12989      temp_column_size,
12990 #if (ODBCVER >= 0x0300)
12991      sqltype==SQL_TYPE_TIMESTAMP ?
12992 #if defined(OTL_ODBC_MULTI_MODE)
12993      ((connection_type==OTL_MSSQL_2008_ODBC_CONNECT)? 7 :
12994       (connection_type==OTL_MSSQL_2005_ODBC_CONNECT)? 3 :
12995       otl_odbc_date_scale) : 0,
12996 #else
12997      otl_odbc_date_scale : 0,
12998 #endif
12999 #else
13000      sqltype==SQL_TIMESTAMP?otl_odbc_date_scale:0,
13001 #endif
13002      OTL_RCAST(OTL_SQLPOINTER,v.p_v),
13003      buflen,
13004      v.p_len);
13005   }
13006   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
13007    return 0;
13008   else
13009    return 1;
13010  }
13011 
13012   int bind
13013   (const int column_num,
13014    otl_var& v,
13015    const int elem_size,
13016    const int aftype,
13017    const int param_type)
13018   {SWORD ftype=OTL_SCAST(SWORD,tmpl_ftype2odbc_ftype(aftype));
13019   v.vparam_type=param_type;
13020   SWORD ftype_save=ftype;
13021 #if defined(OTL_UNICODE)
13022   if(ftype==SQL_WLONGVARCHAR){
13023    ftype=SQL_C_WCHAR;
13024 #else
13025   if(ftype==SQL_LONGVARCHAR){
13026    ftype=SQL_C_CHAR;
13027 #endif
13028   }else if(ftype==SQL_LONGVARBINARY){
13029    ftype=SQL_C_BINARY;
13030   }
13031   if(v.lob_stream_mode&&
13032      (ftype_save==SQL_LONGVARBINARY||
13033 #if defined(OTL_UNICODE)
13034       ftype_save==SQL_WLONGVARCHAR)){
13035 #else
13036       ftype_save==SQL_LONGVARCHAR)){
13037 #endif
13038    // in case of "stream mode" the variable
13039    // remains unbound
13040    v.lob_ftype=ftype;
13041    v.lob_pos=column_num;
13042    return 1;
13043   }else{
13044     SQLINTEGER buflen=elem_size;
13045 #if defined(OTL_UNICODE)
13046     if(ftype==SQL_C_WCHAR||ftype==SQL_WLONGVARCHAR)
13047       buflen=elem_size*sizeof(OTL_CHAR);
13048 #endif
13049    status=SQLBindCol
13050     (cda,
13051      OTL_SCAST(unsigned short,column_num),
13052      ftype,
13053      OTL_RCAST(PTR,v.p_v),
13054      buflen,
13055      &v.p_len[0]);
13056    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)
13057     return 0;
13058    else
13059     return 1;
13060   }
13061 
13062  }
13063 
13064  int describe_column
13065  (otl_column_desc& col,
13066   const int column_num,
13067   int& eof_desc)
13068  {
13069   OTL_SQLCHAR name[256];
13070   OTL_SQLSMALLINT nlen;
13071   OTL_SQLSMALLINT dbtype;
13072   OTL_SQLLEN dbsize;
13073   OTL_SQLSMALLINT scale;
13074   OTL_SQLULEN prec;
13075   OTL_SQLSMALLINT nullok;
13076   OTL_SQLSMALLINT icols;
13077 
13078   eof_desc=0;
13079   status=SQLNumResultCols(cda,&icols);
13080   if(status!=SQL_SUCCESS&&
13081      status!=SQL_SUCCESS_WITH_INFO)
13082    return 0;
13083   if(column_num>icols){
13084    eof_desc=1;
13085    return 0;
13086   }
13087 #if (defined(UNICODE)||defined(_UNICODE))
13088  {
13089    SQLWCHAR temp_name[256];
13090    status=SQLDescribeCol
13091      (cda,
13092       OTL_SCAST(unsigned short,column_num),
13093       temp_name,
13094       sizeof(temp_name),
13095       &nlen,
13096       &dbtype,
13097       &prec,
13098       &scale,
13099       &nullok);
13100    otl_convert_SQLWCHAR_to_char(OTL_RCAST(unsigned char*,name),temp_name);
13101  }
13102 #else
13103   status=SQLDescribeCol
13104    (cda,
13105     OTL_SCAST(unsigned short,column_num),
13106     name,
13107     sizeof(name),
13108     &nlen,
13109     &dbtype,
13110     &prec,
13111     &scale,
13112     &nullok);
13113 #endif
13114   if(!(status == SQL_SUCCESS ||
13115        status == SQL_SUCCESS_WITH_INFO))
13116     return 0;
13117   dbsize=prec;
13118   col.set_name(OTL_RCAST(char*,name));
13119 
13120 #if defined(OTL_DB2_CLI) && defined(OTL_DB2_CLI_MAP_LONG_VARCHAR_TO_VARCHAR)
13121 #if defined(OTL_UNICODE)
13122 #error OTL_DB2_CLI_MAP_LONG_VARCHAR_TO_VARCHAR is not supported when \
13123 OTL_UNICODE is defined
13124 #else
13125   if(dbtype==SQL_LONGVARCHAR &&
13126      dbsize <= OTL_DB2_CLI_MAP_LONG_VARCHAR_TO_VARCHAR){
13127     dbtype=SQL_VARCHAR;
13128   }
13129 #endif
13130 #endif
13131 
13132   col.dbtype=dbtype;
13133   col.dbsize=dbsize;
13134   col.scale=scale;
13135   col.prec=prec;
13136   col.nullok=nullok;
13137   return 1;
13138  }
13139 
13140  void error(otl_exc& exception_struct)
13141  {OTL_SQLRETURN rc;
13142   OTL_SQLSMALLINT msg_len=0;
13143 #if (ODBCVER >= 0x0300)
13144 
13145 #if (defined(UNICODE)||defined(_UNICODE))
13146  {
13147 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
13148    rc=SQLGetDiagRec
13149      (SQL_HANDLE_STMT,
13150       cda,
13151       1,
13152       &exception_struct.sqlstate[0],
13153       OTL_RCAST(OTL_SQLINTEGER_PTR,&exception_struct.code),
13154       &exception_struct.msg[0],
13155       SQL_MAX_MESSAGE_LENGTH-1,
13156       OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
13157    exception_struct.msg[msg_len]=0;
13158 #else
13159    SQLWCHAR temp_sqlstate[1000];
13160    SQLWCHAR temp_msg[SQL_MAX_MESSAGE_LENGTH];
13161    rc=SQLGetDiagRec
13162      (SQL_HANDLE_STMT,
13163       cda,
13164       1,
13165       temp_sqlstate,
13166       OTL_RCAST(OTL_SQLINTEGER_PTR,&exception_struct.code),
13167       temp_msg,
13168       SQL_MAX_MESSAGE_LENGTH-1,
13169       OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
13170    temp_msg[msg_len]=0;
13171    otl_convert_SQLWCHAR_to_char
13172      (OTL_RCAST(unsigned char*,&exception_struct.sqlstate[0]),
13173       temp_sqlstate);
13174    otl_convert_SQLWCHAR_to_char
13175      (OTL_RCAST(unsigned char*,&exception_struct.msg[0]),
13176       temp_msg);
13177 #endif
13178  }
13179 #else
13180  void* temp_ptr=&exception_struct.code;
13181  rc=SQLGetDiagRec
13182    (SQL_HANDLE_STMT,
13183     cda,
13184     1,
13185     OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.sqlstate[0]),
13186     OTL_RCAST(OTL_SQLINTEGER_PTR,temp_ptr),
13187     OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.msg[0]),
13188     SQL_MAX_MESSAGE_LENGTH-1,
13189     OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
13190 #endif
13191 
13192 #else
13193  rc=SQLError(adb->henv,
13194              adb->hdbc,
13195              cda,
13196              OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.sqlstate[0]),
13197              OTL_RCAST(OTL_SQLINTEGER_PTR,&exception_struct.code),
13198              OTL_RCAST(OTL_SQLCHAR_PTR,&exception_struct.msg[0]),
13199              SQL_MAX_MESSAGE_LENGTH-1,
13200              OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
13201 #endif
13202 
13203   exception_struct.msg[msg_len]=0;
13204 
13205   if(rc==SQL_INVALID_HANDLE||rc==SQL_ERROR)
13206     exception_struct.msg[0]=0;
13207 #if (ODBCVER >= 0x0300)
13208 #if defined(OTL_EXTENDED_EXCEPTION)
13209   else if(rc!=SQL_NO_DATA)
13210     otl_fill_exception(exception_struct,cda,SQL_HANDLE_STMT);
13211 #endif
13212 #endif
13213  }
13214 private:
13215 
13216   otl_cur(const otl_cur&):
13217     otl_cur0(),
13218     status(0),
13219     adb(0),
13220     direct_exec_flag(0),
13221     _rpc(0),
13222     canceled(false),
13223     last_iters(0)
13224  {
13225  }
13226 
13227  otl_cur& operator=(const otl_cur&)
13228  {
13229    return *this;
13230  }
13231 
13232 };
13233 
13234 class otl_sel{
13235 private:
13236 
13237   int implicit_cursor;
13238   int status;
13239   int prefetch_array_size;
13240 
13241 #if defined(OTL_ODBC_UNIX)
13242 #if defined(SIZEOF_LONG)
13243 #if (SIZEOF_LONG==8)
13244 #if !defined(BUILD_REAL_64_BIT_MODE)
13245   OTL_SQLULEN crow;
13246 #else
13247   OTL_SQLUINTEGER crow;
13248 #endif
13249 #else // (SIZEOF_LONG==8)
13250   OTL_SQLULEN crow;
13251 #endif
13252 #else // defined(SIZEOF_LONG)
13253   OTL_SQLULEN crow;
13254 #endif
13255 #else // defined(OTL_ODBC_UNIX)
13256   OTL_SQLULEN crow;
13257 #endif
13258 
13259   int in_sequence;
13260 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON) || (ODBCVER<0x0300)
13261   OTL_SQLUSMALLINT* row_status;
13262   int row_status_arr_size;
13263 #endif
13264 
13265 public:
13266 
13267   int get_implicit_cursor() const {return implicit_cursor;
13268 }
13269  void set_arr_size
13270  (const int input_arr_size,
13271   int& out_array_size,
13272   int& out_prefetch_array_size)
13273  {
13274 #if defined(OTL_ODBC_TIMESTEN)
13275    out_array_size=1;
13276    out_prefetch_array_size=input_arr_size;
13277 #else
13278    out_array_size=input_arr_size;
13279    out_prefetch_array_size=0;
13280 #endif
13281  }
13282 
13283  int close_select(otl_cur& cur)
13284  {
13285   if(!in_sequence)return 1;
13286 #if defined(OTL_DB2_CLI)
13287   status=SQLCloseCursor(cur.cda);
13288 #else
13289   status=SQLFreeStmt(cur.cda,SQL_CLOSE);
13290 #endif
13291   in_sequence=0;
13292   if(status==SQL_ERROR)
13293    return 0;
13294   else
13295   return 1;
13296  }
13297 
13298  otl_sel():
13299    implicit_cursor(0),
13300    status(0),
13301    prefetch_array_size(0),
13302    crow(0),
13303    in_sequence(0)
13304 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON) || (ODBCVER<0x0300)
13305    ,row_status(0)
13306    ,row_status_arr_size(0)
13307 #endif
13308  {
13309  }
13310 
13311   virtual ~otl_sel()
13312   {
13313 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON) || (ODBCVER<0x0300)
13314     if(row_status!=0){
13315       delete[] row_status;
13316       row_status=0;
13317       row_status_arr_size=0;
13318     }
13319 #endif
13320   }
13321 
13322 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON) || (ODBCVER<0x0300)
13323   void alloc_row_status(const int array_size)
13324   {
13325     if(row_status==0){
13326       row_status=new OTL_SQLUSMALLINT[array_size];
13327       row_status_arr_size=array_size;
13328       memset(row_status,0,sizeof(OTL_SQLUSMALLINT)*array_size);
13329     }else if(row_status!=0 && array_size!=row_status_arr_size){
13330       delete[] row_status;
13331       row_status=new OTL_SQLUSMALLINT[array_size];
13332       row_status_arr_size=array_size;
13333       memset(row_status,0,sizeof(OTL_SQLUSMALLINT)*array_size);
13334     }
13335   }
13336 #endif
13337 
13338  void set_select_type(const int atype)
13339  {
13340   implicit_cursor=atype;
13341  }
13342 
13343   void init(const int /* array_size */)
13344   {
13345   }
13346 
13347   void set_prefetch_size(const int aprefetch_array_size)
13348   {
13349     prefetch_array_size=aprefetch_array_size;
13350   }
13351 
13352  int first
13353  (otl_cur& cur,
13354   int& cur_row,
13355   int& cur_size,
13356   int& row_count,
13357   int& eof_data,
13358   const int
13359 #if !defined(OTL_ODBC_XTG_IBASE6)
13360   array_size
13361 #endif
13362  )
13363  {
13364 #if defined(OTL_ODBC_XTG_IBASE6)
13365 
13366   cur_row=-1;
13367   eof_data=0;
13368   if(!implicit_cursor){
13369    status=SQLExecute(cur.cda);
13370    if(cur.canceled)return 0;
13371 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
13372    if(cur.adb && cur.adb->throws_on_sql_success_with_info &&
13373       status==SQL_SUCCESS_WITH_INFO)
13374      return 0;
13375 #endif
13376    if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
13377   }
13378   crow=0;
13379   status=SQLFetch(cur.cda);
13380   if(cur.canceled)return 0;
13381   if(status==SQL_SUCCESS||status==SQL_SUCCESS_WITH_INFO){
13382    crow=1;
13383    in_sequence=1;
13384   }
13385 
13386 #else
13387 
13388 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON)
13389   alloc_row_status(array_size);
13390 #endif
13391   cur_row=-1;
13392   eof_data=0;
13393 #if (ODBCVER >= 0x0300)
13394   status=SQLSetStmtAttr
13395    (cur.cda,
13396     SQL_ATTR_ROW_ARRAY_SIZE,
13397     OTL_RCAST(void*,OTL_SCAST(size_t,array_size)),
13398     SQL_NTS);
13399 #else
13400 #if defined(OTL_ODBC_TIMESTEN)
13401   status=SQLSetStmtOption(cur.cda,TT_PREFETCH_COUNT,prefetch_array_size);
13402 #else
13403  status=SQLSetStmtOption(cur.cda,SQL_ROWSET_SIZE,array_size);
13404 #endif
13405 #endif
13406   if(cur.canceled)return 0;
13407   if(status!=SQL_SUCCESS&&
13408      status!=SQL_SUCCESS_WITH_INFO)
13409    return 0;
13410 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON)
13411 #else
13412 #if (ODBCVER >= 0x0300)
13413 
13414   status=SQLSetStmtAttr(cur.cda,SQL_ATTR_ROWS_FETCHED_PTR,&crow,SQL_NTS);
13415   if(cur.canceled)return 0;
13416   if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
13417 
13418 #else
13419 #endif
13420 #endif
13421   if(!implicit_cursor){
13422     status=SQLExecute(cur.cda);
13423     if(cur.canceled)return 0;
13424 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
13425     if(cur.adb && cur.adb->throws_on_sql_success_with_info &&
13426       status==SQL_SUCCESS_WITH_INFO)
13427      return 0;
13428 #endif
13429     if(status!=SQL_SUCCESS&&status!=SQL_SUCCESS_WITH_INFO)return 0;
13430   }
13431 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON)
13432   if(array_size==1){
13433    crow=0;
13434    status=SQLFetch(cur.cda);
13435    if(cur.canceled)return 0;
13436    if(status==SQL_SUCCESS||status==SQL_SUCCESS_WITH_INFO){
13437     crow=1;
13438     in_sequence=1;
13439    }
13440   }else{
13441    status=SQLExtendedFetch
13442     (cur.cda,
13443      SQL_FETCH_NEXT,
13444      1,
13445      &crow,
13446      row_status);
13447   }
13448 #else
13449 #if (ODBCVER >= 0x0300)
13450   status=SQLFetchScroll(cur.cda,SQL_FETCH_NEXT,1);
13451 #else
13452   {
13453     alloc_row_status(array_size);
13454     status=SQLExtendedFetch
13455       (cur.cda,
13456        SQL_FETCH_NEXT,
13457        1,
13458        &crow,
13459        row_status);
13460   }
13461 #endif
13462 
13463 #endif
13464 
13465 #endif
13466 
13467   in_sequence=1;
13468   if(cur.canceled)return 0;
13469   if(status==SQL_ERROR||
13470      status==SQL_INVALID_HANDLE)
13471    return 0;
13472   if(status==SQL_NO_DATA_FOUND){
13473    eof_data=1;
13474    cur_row=-1;
13475    crow=0;
13476    row_count=0;
13477    cur_size=0;
13478 #if defined(OTL_DB2_CLI)
13479   status=SQLCloseCursor(cur.cda);
13480 #else
13481    status=SQLFreeStmt(cur.cda,SQL_CLOSE);
13482 #endif
13483    in_sequence=0;
13484    if(status==SQL_ERROR)return 0;
13485    return 1;
13486   }
13487   row_count=OTL_SCAST(int,crow);
13488   cur_size=row_count;
13489   if(cur_size!=0)cur_row=0;
13490   return 1;
13491  }
13492 
13493 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON)
13494  int next
13495  (otl_cur& cur,
13496   int& cur_row,
13497   int& cur_size,
13498   int& row_count,
13499   int& eof_data,
13500   const int array_size)
13501  {
13502    alloc_row_status(array_size);
13503 #else
13504  int next
13505  (otl_cur& cur,
13506   int& cur_row,
13507   int& cur_size,
13508   int& row_count,
13509   int& eof_data,
13510 #if (ODBCVER >= 0x0300)
13511   const int /* array_size */)
13512 #else
13513   const int array_size)
13514 #endif
13515  {
13516 #endif
13517   if(cur_row<cur_size-1){
13518    ++cur_row;
13519    return 1;
13520   }else{
13521    if(eof_data){
13522     cur_row=-1;
13523     cur_size=0;
13524     in_sequence=0;
13525 #if defined(OTL_DB2_CLI)
13526     status=SQLCloseCursor(cur.cda);
13527 #else
13528     status=SQLFreeStmt(cur.cda,SQL_CLOSE);
13529 #endif
13530     if(status==SQL_ERROR)return 0;
13531     return 1;
13532    }
13533 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON)
13534   if(array_size==1){
13535    crow=0;
13536    status=SQLFetch(cur.cda);
13537    if(cur.canceled)return 0;
13538    if(status==SQL_SUCCESS||status==SQL_SUCCESS_WITH_INFO){
13539     crow=1;
13540     in_sequence=1;
13541    }
13542   }else{
13543    status=SQLExtendedFetch
13544     (cur.cda,
13545      SQL_FETCH_NEXT,
13546      1,
13547      &crow,
13548      row_status);
13549  }
13550 #else
13551 #if (ODBCVER >= 0x0300)
13552   status=SQLFetchScroll(cur.cda,SQL_FETCH_NEXT,1);
13553 #else
13554   {
13555     alloc_row_status(array_size);
13556     status=SQLExtendedFetch
13557       (cur.cda,
13558        SQL_FETCH_NEXT,
13559        1,
13560        &crow,
13561        row_status);
13562   }
13563 #endif
13564 #endif
13565    in_sequence=1;
13566    if(cur.canceled)return 0;
13567    if(status==SQL_ERROR||
13568 //    status==SQL_SUCCESS_WITH_INFO||
13569       status==SQL_INVALID_HANDLE)
13570     return 0;
13571    if(status==SQL_NO_DATA_FOUND){
13572     eof_data=1;
13573     cur_row=-1;
13574     cur_size=0;
13575     in_sequence=0;
13576 #if defined(OTL_DB2_CLI)
13577     status=SQLCloseCursor(cur.cda);
13578 #else
13579     status=SQLFreeStmt(cur.cda,SQL_CLOSE);
13580 #endif
13581     if(status==SQL_ERROR)return 0;
13582     return 1;
13583    }
13584    cur_size=OTL_SCAST(int,crow);
13585    row_count+=OTL_SCAST(int,crow);
13586    if(cur_size!=0)cur_row=0;
13587    return 1;
13588   }
13589  }
13590 
13591 private:
13592 
13593  otl_sel(const otl_sel&):
13594    implicit_cursor(0),
13595    status(0),
13596    prefetch_array_size(0),
13597    crow(0),
13598    in_sequence(0)
13599 #if defined(OTL_ODBC_SQL_EXTENDED_FETCH_ON) || (ODBCVER<0x0300)
13600    ,row_status(0)
13601    ,row_status_arr_size(0)
13602 #endif
13603  {
13604  }
13605 
13606  otl_sel& operator=(const otl_sel&)
13607  {
13608    return *this;
13609  }
13610 
13611 };
13612 
13613 typedef otl_tmpl_connect
13614   <otl_exc,
13615    otl_conn,
13616    otl_cur> otl_odbc_connect;
13617 
13618 typedef otl_tmpl_cursor
13619   <otl_exc,
13620    otl_conn,
13621    otl_cur,
13622    otl_var> otl_cursor;
13623 
13624 typedef otl_tmpl_exception
13625   <otl_exc,
13626    otl_conn,
13627    otl_cur> otl_exception;
13628 
13629 typedef otl_tmpl_select_stream
13630  <otl_exc,
13631   otl_conn,
13632   otl_cur,
13633   otl_var,
13634   otl_sel,
13635   otl_time> otl_select_stream;
13636 
13637 typedef otl_tmpl_inout_stream
13638  <otl_exc,
13639   otl_conn,
13640   otl_cur,
13641   otl_var,
13642   otl_time> otl_inout_stream;
13643 
13644 class otl_stream;
13645 class otl_connect: public otl_odbc_connect{
13646 public:
13647 
13648   void set_connection_mode(const int connection_mode)
13649   {
13650     connect_struct.connection_type=connection_mode;
13651   }
13652 
13653   int get_connection_mode(void)
13654   {
13655     return connect_struct.connection_type;
13656   }
13657 
13658 protected:
13659 
13660   friend class otl_stream;
13661 
13662 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13663  otl_stream_pool sc;
13664 #endif
13665 
13666 public:
13667 
13668 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13669 
13670  void set_stream_pool_size(const int max_size=otl_max_default_pool_size)
13671  {
13672   sc.init(max_size);
13673  }
13674 
13675 #endif
13676 
13677   void commit(void)
13678   {
13679 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13680     if(!auto_commit_){
13681       (*this)<<"commit tran";
13682       otl_odbc_connect::commit();
13683       (*this)<<"begin tran";
13684     }
13685 #else
13686     otl_odbc_connect::commit();
13687 #endif
13688   }
13689 
13690   void rollback(void)
13691   {
13692 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13693     if(!auto_commit_){
13694       (*this)<<"rollback tran";
13695       otl_odbc_connect::rollback();
13696       (*this)<<"begin tran";
13697     }
13698 #else
13699     otl_odbc_connect::rollback();
13700 #endif
13701   }
13702 
13703   long direct_exec
13704   (const char* sqlstm,
13705    const int exception_enabled=1)
13706    OTL_THROWS_OTL_EXCEPTION
13707   {
13708     return otl_cursor::direct_exec(*this,sqlstm,exception_enabled);
13709   }
13710 
13711   void syntax_check(const char* sqlstm)
13712    OTL_THROWS_OTL_EXCEPTION
13713   {
13714     otl_cursor::syntax_check(*this,sqlstm);
13715   }
13716 
13717  otl_connect() OTL_NO_THROW :
13718     otl_odbc_connect(),
13719 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13720     sc(),
13721 #endif
13722     cmd_(0)
13723 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13724     ,auto_commit_(false)
13725 #endif
13726   {
13727   }
13728 
13729  otl_connect(const char* connect_str, const int aauto_commit=0)
13730    OTL_THROWS_OTL_EXCEPTION:
13731    otl_odbc_connect(connect_str, aauto_commit),
13732 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13733     sc(),
13734 #endif
13735     cmd_(0)
13736 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13737     ,auto_commit_(false)
13738 #endif
13739   {
13740 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13741     if(aauto_commit)
13742       auto_commit_=true;
13743     else
13744       auto_commit_=false;
13745 #endif
13746   }
13747 
13748  otl_connect(OTL_HENV ahenv,OTL_HDBC ahdbc,const int auto_commit=0)
13749    OTL_THROWS_OTL_EXCEPTION:
13750     otl_odbc_connect(),
13751 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13752     sc(),
13753 #endif
13754     cmd_(0)
13755 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13756     ,auto_commit_(false)
13757 #endif
13758   {
13759 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13760     if(auto_commit)
13761       auto_commit_=true;
13762     else
13763       auto_commit_=false;
13764 #endif
13765     rlogon(ahenv,ahdbc,auto_commit);
13766   }
13767 
13768   const char* getCmd(void) const
13769   {
13770     return cmd_;
13771   }
13772 
13773   otl_connect& operator<<(const char* cmd)
13774   {
13775     if(!connected){
13776       this->rlogon(cmd);
13777     }else{
13778       otl_cursor::direct_exec(*this,cmd);
13779     }
13780     return *this;
13781   }
13782 
13783   otl_connect& operator<<=(const char* cmd)
13784   {
13785     if(cmd_){
13786       delete[] cmd_;
13787       cmd_=0;
13788     }
13789     size_t cmd_len=strlen(cmd);
13790     cmd_=new char[cmd_len+1];
13791     OTL_STRCPY_S(cmd_,cmd_len+1,cmd);
13792     return *this;
13793   }
13794 
13795 #if defined(OTL_THROWS_ON_SQL_SUCCESS_WITH_INFO)
13796   void set_throw_on_sql_success_with_info(const bool throw_flag=false)
13797   {
13798     this->get_connect_struct().throws_on_sql_success_with_info=throw_flag;
13799   }
13800 #endif
13801 
13802   void rlogon(OTL_HENV ahenv,OTL_HDBC ahdbc,const int auto_commit=0)
13803     OTL_THROWS_OTL_EXCEPTION
13804   {
13805     if(this->connected){
13806      throw otl_exception(otl_error_msg_30,otl_error_code_30);
13807     }
13808     if(cmd_){
13809       delete[] cmd_;
13810       cmd_=0;
13811     }
13812 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13813     if(auto_commit)
13814       auto_commit_=true;
13815     else
13816       auto_commit_=false;
13817 #endif
13818     retcode=connect_struct.ext_logon(ahenv,ahdbc,auto_commit);
13819     if(retcode)
13820       connected=1;
13821    else{
13822      connected=0;
13823      increment_throw_count();
13824      if(get_throw_count()>1)return;
13825      if(otl_uncaught_exception()) return;
13826      throw otl_exception(connect_struct);
13827    }
13828 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13829     if(!auto_commit_){
13830       (*this)<<"begin tran";
13831     }
13832 #endif
13833   }
13834 
13835 #if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON)
13836   void rlogon(const OTL_UNICODE_CHAR_TYPE* username,
13837               const OTL_UNICODE_CHAR_TYPE* passwd,
13838               const OTL_UNICODE_CHAR_TYPE* dns,
13839               const int auto_commit=0)
13840     OTL_THROWS_OTL_EXCEPTION
13841   {
13842     if(this->connected){
13843      throw otl_exception(otl_error_msg_30,otl_error_code_30);
13844     }
13845 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13846     if(auto_commit)
13847       auto_commit_=true;
13848     else
13849       auto_commit_=false;
13850 #endif
13851     retcode=connect_struct.rlogon
13852       (OTL_RCAST(const SQLWCHAR*,username),
13853        OTL_RCAST(const SQLWCHAR*,passwd),
13854        OTL_RCAST(const SQLWCHAR*,dns),
13855        auto_commit);
13856     if(retcode)
13857       connected=1;
13858    else{
13859      connected=0;
13860      increment_throw_count();
13861      if(get_throw_count()>1)return;
13862      if(otl_uncaught_exception()) return;
13863      throw otl_exception(connect_struct);
13864    }
13865 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13866     if(!auto_commit_){
13867       (*this)<<"begin tran";
13868     }
13869 #endif
13870   }
13871 #endif
13872 
13873  virtual ~otl_connect()
13874 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
13875    OTL_THROWS_OTL_EXCEPTION
13876 #endif
13877   {
13878     if(cmd_){
13879       delete[] cmd_;
13880       cmd_=0;
13881     }
13882 #if defined(OTL_DESTRUCTORS_DO_NOT_THROW)
13883     try{
13884       logoff();
13885     }catch(OTL_CONST_EXCEPTION otl_exception&){
13886     }
13887 #endif
13888   }
13889 
13890  void rlogon(const char* connect_str, const int aauto_commit=0)
13891    OTL_THROWS_OTL_EXCEPTION
13892  {
13893     if(this->connected){
13894      throw otl_exception(otl_error_msg_30,otl_error_code_30);
13895     }
13896     if(cmd_){
13897       delete[] cmd_;
13898       cmd_=0;
13899    }
13900 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13901     if(aauto_commit)
13902       auto_commit_=true;
13903     else
13904       auto_commit_=false;
13905 #endif
13906     otl_odbc_connect::rlogon(connect_str,aauto_commit);
13907 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13908     if(!auto_commit_){
13909       (*this)<<"begin tran";
13910     }
13911 #endif
13912  }
13913 
13914  void logoff(void)
13915    OTL_THROWS_OTL_EXCEPTION
13916  {
13917 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
13918   if(connected)
13919     sc.init(sc.get_max_size());
13920 #endif
13921 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13922   if(!auto_commit_) rollback();
13923 #endif
13924   otl_odbc_connect::logoff();
13925  }
13926 
13927   void set_transaction_isolation_level(const long int level)
13928     OTL_THROWS_OTL_EXCEPTION
13929   {
13930     retcode=connect_struct.set_transaction_isolation_level(level);
13931     if(!retcode){
13932      increment_throw_count();
13933      if(get_throw_count()>1)return;
13934      if(otl_uncaught_exception()) return;
13935      throw otl_exception(connect_struct);
13936     }
13937   }
13938 
13939 private:
13940 
13941   char* cmd_;
13942 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13943   bool auto_commit_;
13944 #endif
13945 
13946  otl_connect(const otl_connect&) OTL_NO_THROW :
13947     otl_odbc_connect(),
13948 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13949     sc(),
13950 #endif
13951     cmd_(0)
13952 #if defined(OTL_FREETDS_ODBC_WORKAROUNDS)
13953     ,auto_commit_(false)
13954 #endif
13955   {
13956   }
13957 
13958  otl_connect& operator=(const otl_connect&)
13959  {
13960    return *this;
13961  }
13962 
13963 };
13964 
13965 const int otl_odbc_no_stream=0;
13966 const int otl_odbc_io_stream=1;
13967 const int otl_odbc_select_stream=2;
13968 
13969 class otl_stream_shell: public otl_stream_shell_generic{
13970 public:
13971 
13972   otl_select_stream* ss;
13973   otl_inout_stream* io;
13974   otl_connect* adb;
13975 
13976   int auto_commit_flag;
13977 
13978   otl_var_desc* iov;
13979   int iov_len;
13980   int next_iov_ndx;
13981 
13982   otl_var_desc* ov;
13983   int ov_len;
13984   int next_ov_ndx;
13985 
13986   bool flush_flag;
13987   int stream_type;
13988   bool lob_stream_flag;
13989 
13990  otl_select_struct_override override;
13991 
13992 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
13993  OTL_STRING_CONTAINER orig_sql_stm;
13994 #endif
13995 
13996   otl_stream_shell():
13997     otl_stream_shell_generic(),
13998     ss(0),
13999     io(0),
14000     adb(0),
14001     auto_commit_flag(0),
14002     iov(0),
14003     iov_len(0),
14004     next_iov_ndx(0),
14005     ov(0),
14006     ov_len(0),
14007     next_ov_ndx(0),
14008     flush_flag(false),
14009     stream_type(otl_odbc_no_stream),
14010     lob_stream_flag(0),
14011     override()
14012 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
14013     ,orig_sql_stm()
14014 #endif
14015  {
14016   should_delete=0;
14017  }
14018 
14019   otl_stream_shell(const int ashould_delete):
14020     otl_stream_shell_generic(),
14021     ss(0),
14022     io(0),
14023     adb(0),
14024     auto_commit_flag(0),
14025     iov(0),
14026     iov_len(0),
14027     next_iov_ndx(0),
14028     ov(0),
14029     ov_len(0),
14030     next_ov_ndx(0),
14031     flush_flag(true),
14032     stream_type(otl_odbc_no_stream),
14033     lob_stream_flag(false),
14034     override()
14035 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
14036     ,orig_sql_stm()
14037 #endif
14038  {
14039   should_delete=ashould_delete;
14040  }
14041 
14042  virtual ~otl_stream_shell()
14043  {
14044   if(should_delete){
14045    delete[] iov;
14046    delete[] ov;
14047 
14048    iov=0; iov_len=0;
14049    ov=0; ov_len=0;
14050    next_iov_ndx=0;
14051    next_ov_ndx=0;
14052    override.setLen(0);
14053    flush_flag=true;
14054 
14055    delete ss;
14056    delete io;
14057    ss=0; io=0;
14058    adb=0;
14059   }
14060  }
14061 
14062 private:
14063 
14064   otl_stream_shell(const otl_stream_shell&):
14065     otl_stream_shell_generic(),
14066     ss(0),
14067     io(0),
14068     adb(0),
14069     auto_commit_flag(0),
14070     iov(0),
14071     iov_len(0),
14072     next_iov_ndx(0),
14073     ov(0),
14074     ov_len(0),
14075     next_ov_ndx(0),
14076     flush_flag(false),
14077     stream_type(otl_odbc_no_stream),
14078     lob_stream_flag(0),
14079     override()
14080 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
14081     ,orig_sql_stm()
14082 #endif
14083  {
14084   should_delete=0;
14085  }
14086 
14087   otl_stream_shell& operator=(const otl_stream_shell&)
14088   {
14089     return *this;
14090   }
14091 
14092 };
14093 
14094 template <OTL_TYPE_NAME TExceptionStruct,
14095           OTL_TYPE_NAME TConnectStruct,
14096           OTL_TYPE_NAME TCursorStruct,
14097           OTL_TYPE_NAME TVariableStruct>
14098 class otl_tmpl_lob_stream: public otl_lob_stream_generic{
14099 public:
14100 
14101   typedef otl_tmpl_exception
14102   <TExceptionStruct,
14103    TConnectStruct,
14104    TCursorStruct> otl_exception;
14105 
14106   typedef otl_tmpl_variable<TVariableStruct>* p_bind_var;
14107   typedef otl_tmpl_connect
14108   <TExceptionStruct,
14109    TConnectStruct,
14110    TCursorStruct>* p_connect;
14111 
14112  typedef otl_tmpl_cursor
14113  <TExceptionStruct,
14114   TConnectStruct,
14115   TCursorStruct,
14116   TVariableStruct>* p_cursor;
14117 
14118 private:
14119 
14120   p_bind_var bind_var;
14121   p_connect connect;
14122   p_cursor cursor;
14123   otl_long_string* temp_buf;
14124   char* temp_char_buf;
14125   bool written_to_flag;
14126   bool closed_flag;
14127 
14128 public:
14129 
14130  void init
14131  (void* avar,void* aconnect,void* acursor,
14132   int andx,int amode,const int alob_is_null=0)
14133    OTL_THROWS_OTL_EXCEPTION
14134  {
14135    closed_flag=false;
14136    if(written_to_flag){
14137      retcode=bind_var->get_var_struct().clob_blob(cursor->get_cursor_struct());
14138       written_to_flag=false;
14139       if(!retcode){
14140         if(this->connect)this->connect->increment_throw_count();
14141         if(this->connect&&this->connect->get_throw_count()>1)return;
14142         if(otl_uncaught_exception()) return;
14143         throw OTL_TMPL_EXCEPTION
14144           (cursor->get_cursor_struct(),
14145            cursor->get_stm_label()?cursor->get_stm_label():
14146            cursor->get_stm_text());
14147       }
14148 
14149    }
14150   connect=OTL_RCAST(p_connect,aconnect);
14151   bind_var=OTL_RCAST(p_bind_var,avar);
14152   cursor=OTL_RCAST(p_cursor,acursor);
14153   mode=amode;
14154   retcode=0;
14155   lob_is_null=alob_is_null;
14156   ndx=andx;
14157   offset=0;
14158   lob_len=0;
14159   eof_flag=0;
14160   in_destructor=0;
14161   if(bind_var)
14162     bind_var->get_var_struct().set_lob_stream_flag();
14163  }
14164 
14165  void set_len(void) OTL_NO_THROW
14166  {
14167  }
14168 
14169  void set_len(const int /*new_len*/) OTL_NO_THROW
14170  {
14171  }
14172 
14173  otl_tmpl_lob_stream() OTL_NO_THROW:
14174    otl_lob_stream_generic(false),
14175    bind_var(0),
14176    connect(0),
14177    cursor(0),
14178    temp_buf(0),
14179    temp_char_buf(0),
14180    written_to_flag(false),
14181    closed_flag(false)
14182  {
14183   init(0,0,0,0,otl_lob_stream_zero_mode);
14184  }
14185 
14186  ~otl_tmpl_lob_stream()
14187 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
14188    OTL_THROWS_OTL_EXCEPTION
14189 #endif
14190  {
14191    in_destructor=1;
14192    if(temp_buf){
14193      delete temp_buf;
14194      temp_buf=0;
14195    }
14196    if(temp_char_buf){
14197      delete[] temp_char_buf;
14198      temp_char_buf=0;
14199    }
14200 #if defined(OTL_DESTRUCTORS_DO_NOT_THROW)
14201    try{
14202      if(!closed_flag)
14203        close();
14204    }catch(OTL_CONST_EXCEPTION otl_exception&){
14205    }
14206 #else
14207    if(!closed_flag)
14208    close();
14209 #endif
14210  }
14211 
14212 #if (defined(OTL_STL) || defined(OTL_ACE) || \
14213      defined(OTL_USER_DEFINED_STRING_CLASS_ON)) && !defined(OTL_UNICODE)
14214   otl_lob_stream_generic& operator<<(const OTL_STRING_CONTAINER& s)
14215     OTL_THROWS_OTL_EXCEPTION
14216   {
14217     otl_long_string temp_s(s.c_str(),
14218                            OTL_SCAST(int,s.length()),
14219                            OTL_SCAST(int,s.length()));
14220     (*this)<<temp_s;
14221     return *this;
14222   }
14223 
14224   void setStringBuffer(const int chunk_size)
14225   {
14226     delete[] temp_char_buf;
14227     temp_char_buf=0;
14228     delete temp_buf;
14229     temp_buf=0;
14230     temp_char_buf=new char[chunk_size+1];
14231     temp_buf=new otl_long_string(temp_char_buf,chunk_size);
14232   }
14233 
14234   otl_lob_stream_generic& operator>>(OTL_STRING_CONTAINER& s)
14235     OTL_THROWS_OTL_EXCEPTION
14236   {
14237     const int TEMP_BUF_SIZE=4096;
14238     if(!temp_char_buf)temp_char_buf=new char[TEMP_BUF_SIZE];
14239     if(!temp_buf)temp_buf=new otl_long_string(temp_char_buf,TEMP_BUF_SIZE-1);
14240     int iters=0;
14241     while(!this->eof()){
14242       ++iters;
14243       (*this)>>(*temp_buf);
14244       temp_char_buf[temp_buf->len()]=0;
14245       if(iters>1)
14246         s+=temp_char_buf;
14247       else
14248         s=temp_char_buf;
14249     }
14250     return *this;
14251   }
14252 
14253 #endif
14254 
14255  otl_lob_stream_generic& operator<<(const otl_long_string& s)
14256    OTL_THROWS_OTL_EXCEPTION
14257  {
14258   if(mode!=otl_lob_stream_write_mode){
14259    const char* stm=0;
14260    char var_info[256];
14261    var_info[0]=0;
14262    if(cursor!=0){
14263      if(cursor->get_stm_label())
14264        stm=cursor->get_stm_label();
14265      else
14266        stm=cursor->get_stm_text();
14267    }
14268    if(bind_var!=0){
14269     otl_var_info_var
14270       (bind_var->get_name(),
14271        bind_var->get_ftype(),
14272        otl_var_long_string,
14273        var_info,
14274        sizeof(var_info));
14275    }
14276    char* vinfo=0;
14277    if(var_info[0]!=0)
14278     vinfo=&var_info[0];
14279    if(this->connect)this->connect->increment_throw_count();
14280    if(this->connect&&this->connect->get_throw_count()>1)return *this;
14281    if(otl_uncaught_exception()) return *this;
14282    throw otl_tmpl_exception
14283     <TExceptionStruct,
14284      TConnectStruct,
14285      TCursorStruct>
14286      (otl_error_msg_9,
14287       otl_error_code_9,
14288       stm,
14289       vinfo);
14290   }
14291   if(offset==0)offset=1;
14292   retcode=bind_var->get_var_struct().write_blob
14293     (s,lob_len,offset,cursor->get_cursor_struct());
14294   written_to_flag=true;
14295   if(retcode)
14296    return *this;
14297   if(this->connect)this->connect->increment_throw_count();
14298   if(this->connect&&this->connect->get_throw_count()>1)return *this;
14299   if(otl_uncaught_exception()) return *this;
14300   throw OTL_TMPL_EXCEPTION
14301     (cursor->get_cursor_struct(),
14302      cursor->get_stm_label()?cursor->get_stm_label():
14303      cursor->get_stm_text());
14304  }
14305 
14306  otl_lob_stream_generic& operator>>(otl_long_string& s)
14307    OTL_THROWS_OTL_EXCEPTION
14308  {
14309   if(mode!=otl_lob_stream_read_mode){
14310    const char* stm=0;
14311    char var_info[256];
14312    var_info[0]=0;
14313    if(cursor!=0){
14314      if(cursor->get_stm_label())
14315        stm=cursor->get_stm_label();
14316      else
14317        stm=cursor->get_stm_text();
14318    }
14319    if(bind_var!=0){
14320     otl_var_info_var
14321       (bind_var->get_name(),
14322        bind_var->get_ftype(),
14323        otl_var_long_string,
14324        var_info,
14325        sizeof(var_info));
14326    }
14327    char* vinfo=0;
14328    if(var_info[0]!=0)
14329     vinfo=&var_info[0];
14330    if(this->connect)this->connect->increment_throw_count();
14331    if(this->connect&&this->connect->get_throw_count()>1)return *this;
14332    if(otl_uncaught_exception()) return *this;
14333    throw OTL_TMPL_EXCEPTION
14334     (otl_error_msg_10,
14335      otl_error_code_10,
14336      stm,
14337      vinfo);
14338   }
14339   if(offset==0)offset=1;
14340   retcode=bind_var->get_var_struct().read_blob
14341     (cursor->get_cursor_struct(),s,ndx,offset,eof_flag);
14342   if(retcode){
14343    if(eof())
14344     close();
14345    return *this;
14346   }
14347   if(this->connect)this->connect->increment_throw_count();
14348   if(this->connect&&this->connect->get_throw_count()>1)return *this;
14349   if(otl_uncaught_exception()) return *this;
14350   throw OTL_TMPL_EXCEPTION
14351     (cursor->get_cursor_struct(),
14352      cursor->get_stm_label()?cursor->get_stm_label():
14353      cursor->get_stm_text());
14354  }
14355 
14356  int eof(void) OTL_NO_THROW
14357  {
14358   if(mode!=otl_lob_stream_read_mode)return 1;
14359   if(lob_is_null)return 1;
14360   return eof_flag;
14361  }
14362 
14363  int len(void) OTL_THROWS_OTL_EXCEPTION
14364  {
14365   if(cursor==0||connect==0||bind_var==0||lob_is_null)return 0;
14366   int alen;
14367   retcode=bind_var->get_var_struct().get_blob_len(ndx,alen);
14368   if(retcode)return alen;
14369   if(this->connect)this->connect->increment_throw_count();
14370   if(this->connect&&this->connect->get_throw_count()>1)return 0;
14371   if(otl_uncaught_exception()) return 0;
14372   throw OTL_TMPL_EXCEPTION
14373     (connect->get_connect_struct(),
14374      cursor->get_stm_label()?cursor->get_stm_label():
14375      cursor->get_stm_text());
14376  }
14377 
14378  bool is_initialized(void) OTL_THROWS_OTL_EXCEPTION
14379  {
14380   if(cursor==0||connect==0||bind_var==0||lob_is_null)
14381     return false;
14382   else
14383     return true;
14384  }
14385 
14386  void close(void) OTL_THROWS_OTL_EXCEPTION
14387  {
14388   if(in_destructor){
14389    if(mode==otl_lob_stream_read_mode){
14390      bind_var->get_var_struct().set_lob_stream_flag(0);
14391     bind_var->set_not_null(0);
14392    } if(mode==otl_lob_stream_write_mode){
14393      retcode=bind_var->get_var_struct().clob_blob(cursor->get_cursor_struct());
14394      closed_flag=true;
14395      written_to_flag=false;
14396      if(!retcode){
14397        if(this->connect)this->connect->increment_throw_count();
14398        if(this->connect&&this->connect->get_throw_count()>1)return;
14399        if(otl_uncaught_exception()) return;
14400        throw OTL_TMPL_EXCEPTION
14401          (cursor->get_cursor_struct(),
14402           cursor->get_stm_label()?cursor->get_stm_label():
14403           cursor->get_stm_text());
14404      }
14405    }
14406    return;
14407   }
14408   if(mode==otl_lob_stream_zero_mode)return;
14409   if(mode==otl_lob_stream_read_mode){
14410     bind_var->get_var_struct().set_lob_stream_flag(0);
14411     bind_var->set_not_null(0);
14412     init(0,0,0,0,otl_lob_stream_zero_mode);
14413   }else{
14414     // write mode
14415     if(mode==otl_lob_stream_write_mode){
14416       retcode=bind_var->get_var_struct().clob_blob(cursor->get_cursor_struct());
14417       written_to_flag=false;
14418       closed_flag=true;
14419       if(!retcode){
14420         if(this->connect)this->connect->increment_throw_count();
14421         if(this->connect&&this->connect->get_throw_count()>1)return;
14422         if(otl_uncaught_exception()) return;
14423         throw OTL_TMPL_EXCEPTION
14424           (cursor->get_cursor_struct(),
14425            cursor->get_stm_label()?cursor->get_stm_label():
14426            cursor->get_stm_text());
14427       }
14428     }
14429     bind_var->get_var_struct().set_lob_stream_flag(0);
14430     bind_var->set_not_null(0);
14431   }
14432  }
14433 
14434 private:
14435 
14436  otl_tmpl_lob_stream(const otl_tmpl_lob_stream&) OTL_NO_THROW:
14437    otl_lob_stream_generic(false),
14438    bind_var(0),
14439    connect(0),
14440    cursor(0),
14441    temp_buf(0),
14442    temp_char_buf(0),
14443    written_to_flag(false),
14444    closed_flag(false)
14445  {
14446  }
14447 
14448  otl_tmpl_lob_stream& operator=(const otl_tmpl_lob_stream&)
14449  {
14450    return *this;
14451  }
14452 
14453 
14454 };
14455 
14456 typedef otl_tmpl_lob_stream
14457   <otl_exc,
14458    otl_conn,
14459    otl_cur,
14460    otl_var> otl_lob_stream;
14461 
14462 class otl_stream{
14463 private:
14464 
14465   otl_stream_shell* shell;
14466   otl_ptr<otl_stream_shell> shell_pt;
14467   int connected;
14468 
14469   otl_select_stream** ss;
14470   otl_inout_stream** io;
14471   otl_connect** adb;
14472 
14473   int* auto_commit_flag;
14474 
14475   otl_var_desc** iov;
14476   int* iov_len;
14477   int* next_iov_ndx;
14478 
14479   otl_var_desc** ov;
14480   int* ov_len;
14481   int* next_ov_ndx;
14482 
14483   otl_select_struct_override* override;
14484   int end_marker;
14485   int oper_int_called;
14486   int last_eof_rc;
14487   bool last_oper_was_read_op;
14488 
14489 public:
14490 
14491 #if defined(OTL_ODBC_SQL_STATEMENT_WITH_DIAG_REC_OUTPUT)
14492 
14493   OTL_SQLHSTMT get_stm_handle(){return (*io)->get_cursor_struct().get_cda();}
14494 
14495 #if defined(_UNICODE) || defined(UNICODE)
14496   typedef SQLWCHAR sqlchar_type;
14497 #else
14498   typedef SQLCHAR sqlchar_type;
14499 #endif
14500 
14501   bool get_next_diag_rec
14502   (short int& rec_ndx,
14503    sqlchar_type* sqlstate_buf,
14504    sqlchar_type* msg_buf,
14505    short int msg_buf_size,
14506    int& native_err)
14507   {
14508     OTL_SQLINTEGER rc;
14509     SQLSMALLINT msg_len;
14510     rc=SQLGetDiagRec
14511       (SQL_HANDLE_STMT,
14512        get_stm_handle(),
14513        OTL_SCAST(OTL_SQLSMALLINT,rec_ndx),
14514        OTL_RCAST(sqlchar_type*,sqlstate_buf),
14515        OTL_RCAST(OTL_SQLINTEGER_PTR,&native_err),
14516        OTL_RCAST(sqlchar_type*,msg_buf),
14517        msg_buf_size,
14518        OTL_RCAST(OTL_SQLSMALLINT_PTR,&msg_len));
14519     bool result=rc==SQL_NO_DATA||rc<0;
14520     msg_buf[msg_len]=0;
14521     ++rec_ndx;
14522     return result;
14523   }
14524 
14525 #endif
14526 
14527 protected:
14528 
14529   int buf_size_;
14530 
14531   void reset_end_marker(void)
14532   {
14533     last_eof_rc=0;
14534     end_marker=-1;
14535     oper_int_called=0;
14536   }
14537 
14538   void throw_end_of_row()
14539 #if defined(__GNUC__) && (__GNUC__>=4)
14540     __attribute__ ((noreturn))
14541 #endif
14542   {
14543       throw otl_exception
14544         (otl_error_msg_34,
14545          otl_error_code_34,
14546          this->get_stm_text());
14547   }
14548 
14549 public:
14550 
14551   int get_prefetched_row_count() const
14552   {
14553     if(*ss){
14554       (*adb)->reset_throw_count();
14555       return (*ss)->get_prefetched_row_count();
14556     }
14557     return 0;
14558   }
14559 
14560   bool get_lob_stream_flag() const
14561   {
14562     if(!shell)
14563       return false;
14564     else
14565       return shell->lob_stream_flag;
14566   }
14567 
14568   int get_adb_max_long_size() const
14569   {
14570     return this->shell->adb->get_max_long_size();
14571   }
14572 
14573   void check_end_of_row()
14574   {
14575     if(next_ov_ndx==0||(*next_ov_ndx)!=0)
14576       throw_end_of_row();
14577     if(next_iov_ndx==0||(*next_iov_ndx)!=0)
14578       throw_end_of_row();
14579   }
14580 
14581   otl_stream_shell* get_shell(){return shell;}
14582   int get_connected() const {return connected;}
14583 
14584   int get_dirty_buf_len() const
14585   {
14586     switch(shell->stream_type){
14587     case otl_odbc_no_stream:
14588       return 0;
14589     case otl_odbc_io_stream:
14590       return (*io)->get_dirty_buf_len();
14591     case otl_odbc_select_stream:
14592       return (*ss)->get_select_row_count();
14593     default:
14594       return 0;
14595     }
14596   }
14597 
14598   const char* get_stm_text(void)
14599   {
14600     const char* no_stm_text=OTL_NO_STM_TEXT;
14601     switch(shell->stream_type){
14602     case otl_odbc_no_stream:
14603       return no_stm_text;
14604     case otl_odbc_io_stream:
14605       return (*io)->get_stm_label()?(*io)->get_stm_label():(*io)->get_stm_text();
14606     case otl_odbc_select_stream:
14607       return (*ss)->get_stm_label()?(*ss)->get_stm_label():(*ss)->get_stm_text();
14608     default:
14609       return no_stm_text;
14610     }
14611   }
14612 
14613 
14614 
14615   void setBufSize(int buf_size)
14616   {
14617     buf_size_=buf_size;
14618   }
14619 
14620   int getBufSize(void) const
14621   {
14622     return buf_size_;
14623   }
14624 
14625  long get_rpc() OTL_THROWS_OTL_EXCEPTION
14626  {
14627   if((*io)){
14628    (*adb)->reset_throw_count();
14629    return (*io)->get_rpc();
14630   }else if((*ss)){
14631    (*adb)->reset_throw_count();
14632    return (*ss)->get_rfc();
14633   }else
14634    return 0;
14635  }
14636 
14637   void skip_to_end_of_row()
14638   {
14639     if(next_ov_ndx==0)
14640       return;
14641     if((*ov_len)==0)return;
14642     last_oper_was_read_op=true;
14643     switch(shell->stream_type){
14644     case otl_odbc_no_stream:
14645       break;
14646     case otl_odbc_io_stream:
14647       last_eof_rc=(*io)->eof();
14648       (*io)->skip_to_end_of_row();
14649       break;
14650     case otl_odbc_select_stream:
14651       last_eof_rc=(*ss)->eof();
14652       (*ss)->skip_to_end_of_row();
14653       break;
14654     }
14655     while ((*next_ov_ndx)<(*ov_len)-1)
14656       ++(*next_ov_ndx);
14657   }
14658 
14659 
14660   operator int(void) OTL_THROWS_OTL_EXCEPTION
14661   {
14662     if(shell && shell->lob_stream_flag){
14663       if(this->adb&&*this->adb)(*this->adb)->increment_throw_count();
14664       if(this->adb&&*this->adb&&(*this->adb)->get_throw_count()>1)return 0;
14665       const char* stm_label=0;
14666       const char* stm_text=0;
14667       if((*io)){
14668         stm_label=(*io)->get_stm_label();
14669         stm_text=(*io)->get_stm_text();
14670       }else if((*ss)){
14671         stm_label=(*ss)->get_stm_label();
14672         stm_text=(*ss)->get_stm_text();
14673       }
14674       throw otl_exception
14675         (otl_error_msg_24,
14676          otl_error_code_24,
14677          stm_label?stm_label:stm_text);
14678     }
14679     if(!last_oper_was_read_op){
14680       if(this->adb&&*this->adb)(*this->adb)->increment_throw_count();
14681       if(this->adb&&*this->adb&&(*this->adb)->get_throw_count()>1)return 0;
14682       const char* stm_label=0;
14683       const char* stm_text=0;
14684       if((*io)){
14685         stm_label=(*io)->get_stm_label();
14686         stm_text=(*io)->get_stm_text();
14687       }else if((*ss)){
14688         stm_label=(*ss)->get_stm_label();
14689         stm_text=(*ss)->get_stm_text();
14690       }
14691       throw otl_exception
14692         (otl_error_msg_18,
14693          otl_error_code_18,
14694          stm_label?stm_label:stm_text);
14695     }
14696     if(end_marker==1)return 0;
14697     int rc=0;
14698     int temp_eof=eof();
14699     if(temp_eof && end_marker==-1 && oper_int_called==0){
14700       end_marker=1;
14701       if(last_eof_rc==1)
14702         rc=0;
14703       else
14704         rc=1;
14705     }else if(!temp_eof && end_marker==-1)
14706       rc=1;
14707     else if(temp_eof && end_marker==-1){
14708       end_marker=0;
14709       rc=1;
14710     }else if(temp_eof && end_marker==0){
14711       end_marker=1;
14712       rc=0;
14713     }
14714     if(!oper_int_called)oper_int_called=1;
14715     return rc;
14716   }
14717 
14718   void cancel(void) OTL_THROWS_OTL_EXCEPTION
14719   {
14720     if((*ss)){
14721       (*adb)->reset_throw_count();
14722       int status=(*ss)->get_cursor_struct().cancel();
14723       if(status==0)
14724         throw otl_exception((*ss)->get_cursor_struct());
14725     }else if((*io)){
14726       (*adb)->reset_throw_count();
14727       int status=(*io)->get_cursor_struct().cancel();
14728       if(status==0)
14729         throw otl_exception((*io)->get_cursor_struct());
14730     }
14731   }
14732 
14733  void create_var_desc(void)
14734  {int i;
14735   delete[] (*iov);
14736   delete[] (*ov);
14737   (*iov)=0; (*iov_len)=0;
14738   (*ov)=0; (*ov_len)=0;
14739   if((*ss)){
14740     if((*ss)->get_vl_len()>0){
14741       (*iov)=new otl_var_desc[(*ss)->get_vl_len()];
14742       (*iov_len)=(*ss)->get_vl_len();
14743       for(i=0;i<(*ss)->get_vl_len();++i)
14744         (*ss)->get_vl()[i]->copy_var_desc((*iov)[i]);
14745     }
14746     if((*ss)->get_sl_len()>0){
14747       (*ov)=new otl_var_desc[(*ss)->get_sl_len()];
14748       (*ov_len)=(*ss)->get_sl_len();
14749       for(i=0;i<(*ss)->get_sl_len();++i){
14750         (*ss)->get_sl()[i].copy_var_desc((*ov)[i]);
14751         if((*ss)->get_sl_desc()!=0)
14752           (*ov)[i].copy_name((*ss)->get_sl_desc()[i].name);
14753       }
14754    }
14755   }else if((*io)){
14756     if((*io)->get_vl_len()>0){
14757       (*iov)=new otl_var_desc[(*io)->get_vl_len()];
14758       (*iov_len)=(*io)->get_vl_len();
14759       for(i=0;i<(*io)->get_vl_len();++i)
14760         (*io)->get_vl()[i]->copy_var_desc((*iov)[i]);
14761     }
14762     if((*io)->get_iv_len()>0){
14763       (*ov)=new otl_var_desc[(*io)->get_iv_len()];
14764       (*ov_len)=(*io)->get_iv_len();
14765       for(i=0;i<(*io)->get_iv_len();++i)
14766         (*io)->get_in_vl()[i]->copy_var_desc((*ov)[i]);
14767     }
14768   }
14769  }
14770 
14771  void set_column_type(const int column_ndx,
14772                       const int col_type,
14773                       const int col_size=0)
14774    OTL_NO_THROW
14775  {
14776    if(shell==0){
14777      init_stream();
14778      shell->flush_flag=true;
14779    }
14780   override->add_override(column_ndx,col_type,col_size);
14781  }
14782 
14783   void set_all_column_types(const unsigned mask=0)
14784     OTL_NO_THROW
14785   {
14786     if(shell==0){
14787       init_stream();
14788       shell->flush_flag=true;
14789     }
14790     override->set_all_column_types(mask);
14791   }
14792 
14793  void set_flush(const bool flush_flag=true)
14794    OTL_NO_THROW
14795  {
14796    if(shell==0)init_stream();
14797    shell->flush_flag=flush_flag;
14798  }
14799 
14800  void set_lob_stream_mode(const bool lob_stream_flag=false)
14801    OTL_NO_THROW
14802  {
14803   if(shell==0)return;
14804   shell->lob_stream_flag=lob_stream_flag;
14805  }
14806 
14807  void inc_next_ov(void)
14808  {
14809   if((*ov_len)==0)return;
14810   if((*next_ov_ndx)<(*ov_len)-1)
14811    ++(*next_ov_ndx);
14812   else
14813    (*next_ov_ndx)=0;
14814  }
14815 
14816  void inc_next_iov(void)
14817  {
14818   if((*iov_len)==0)return;
14819   if((*next_iov_ndx)<(*iov_len)-1)
14820    ++(*next_iov_ndx);
14821   else
14822    (*next_iov_ndx)=0;
14823  }
14824 
14825  otl_var_desc* describe_in_vars(int& desc_len)
14826    OTL_NO_THROW
14827  {
14828   desc_len=0;
14829   if(shell==0)return 0;
14830   if(shell->iov==0)return 0;
14831   desc_len=shell->iov_len;
14832   return shell->iov;
14833  }
14834 
14835  otl_var_desc* describe_out_vars(int& desc_len)
14836    OTL_NO_THROW
14837  {
14838   desc_len=0;
14839   if(shell==0)return 0;
14840   if(shell->ov==0)return 0;
14841   desc_len=shell->ov_len;
14842   return shell->ov;
14843  }
14844 
14845  otl_var_desc* describe_next_in_var(void)
14846    OTL_NO_THROW
14847  {
14848   if(shell==0)return 0;
14849   if(shell->iov==0)return 0;
14850   return &(shell->iov[shell->next_iov_ndx]);
14851  }
14852 
14853  otl_var_desc* describe_next_out_var(void)
14854    OTL_NO_THROW
14855  {
14856   if(shell==0)return 0;
14857   if(shell->ov==0)return 0;
14858   return &(shell->ov[shell->next_ov_ndx]);
14859  }
14860 
14861  void init_stream(void)
14862  {
14863    buf_size_=1;
14864    last_oper_was_read_op=false;
14865    shell=0;
14866    shell=new otl_stream_shell(0);
14867    shell_pt.assign(&shell);
14868    connected=0;
14869 
14870    ss=&(shell->ss);
14871    io=&(shell->io);
14872    adb=&(shell->adb);
14873    auto_commit_flag=&(shell->auto_commit_flag);
14874    iov=&(shell->iov);
14875    iov_len=&(shell->iov_len);
14876    next_iov_ndx=&(shell->next_iov_ndx);
14877    ov=&(shell->ov);
14878    ov_len=&(shell->ov_len);
14879    next_ov_ndx=&(shell->next_ov_ndx);
14880    override=&(shell->override);
14881 
14882    (*io)=0;
14883    (*ss)=0;
14884    (*adb)=0;
14885    (*ov)=0;
14886    (*ov_len)=0;
14887    (*next_iov_ndx)=0;
14888    (*next_ov_ndx)=0;
14889    (*auto_commit_flag)=1;
14890    (*iov)=0;
14891    (*iov_len)=0;
14892 
14893  }
14894 
14895  otl_stream
14896  (const otl_stream_buffer_size_type arr_size,
14897   const char* sqlstm,
14898   otl_connect& db,
14899   const int implicit_select=otl_explicit_select,
14900   const char* sqlstm_label=0)
14901    OTL_THROWS_OTL_EXCEPTION:
14902    shell(0),
14903    shell_pt(),
14904    connected(0),
14905    ss(0),
14906    io(0),
14907    adb(0),
14908    auto_commit_flag(0),
14909    iov(0),
14910    iov_len(0),
14911    next_iov_ndx(0),
14912    ov(0),
14913    ov_len(0),
14914    next_ov_ndx(0),
14915    override(0),
14916    end_marker(0),
14917    oper_int_called(0),
14918    last_eof_rc(0),
14919    last_oper_was_read_op(false),
14920    buf_size_(0)
14921  {
14922   init_stream();
14923 
14924   (*io)=0; (*ss)=0;
14925   (*iov)=0; (*iov_len)=0;
14926   (*ov)=0; (*ov_len)=0;
14927   (*auto_commit_flag)=1;
14928   (*next_iov_ndx)=0;
14929   (*next_ov_ndx)=0;
14930   (*adb)=&db;
14931   shell->flush_flag=true;
14932   open(arr_size,sqlstm,db,implicit_select,sqlstm_label);
14933  }
14934 
14935  otl_stream() OTL_NO_THROW:
14936    shell(0),
14937    shell_pt(),
14938    connected(0),
14939    ss(0),
14940    io(0),
14941    adb(0),
14942    auto_commit_flag(0),
14943    iov(0),
14944    iov_len(0),
14945    next_iov_ndx(0),
14946    ov(0),
14947    ov_len(0),
14948    next_ov_ndx(0),
14949    override(0),
14950    end_marker(0),
14951    oper_int_called(0),
14952    last_eof_rc(0),
14953    last_oper_was_read_op(false),
14954    buf_size_(0)
14955  {
14956   init_stream();
14957   shell->flush_flag=true;
14958  }
14959 
14960  virtual ~otl_stream()
14961 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
14962    OTL_THROWS_OTL_EXCEPTION
14963 #endif
14964  {
14965   if(!connected)return;
14966   try{
14967    if((*io)!=0&&shell->flush_flag==false)
14968      (*io)->set_flush_flag2(false);
14969    close();
14970    if(shell!=0){
14971     if((*io)!=0)
14972       (*io)->set_flush_flag2(true);
14973    }
14974   }catch(OTL_CONST_EXCEPTION otl_exception&){
14975    if(shell!=0){
14976     if((*io)!=0)
14977       (*io)->set_flush_flag2(true);
14978    }
14979 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
14980    clean(1);
14981    if(shell!=0)
14982      shell->set_should_delete(1);
14983    shell_pt.destroy();
14984 #else
14985    shell_pt.destroy();
14986 #endif
14987 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
14988    throw;
14989 #endif
14990   }
14991 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
14992   if((adb && (*adb) && (*adb)->get_throw_count()>0)
14993 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
14994      || otl_uncaught_exception()
14995 #endif
14996      ){
14997    //
14998   }
14999 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
15000    if(otl_uncaught_exception()){
15001      //
15002    }
15003 #else
15004    shell_pt.destroy();
15005 #endif
15006  }
15007 
15008  int eof(void) OTL_NO_THROW
15009  {
15010   if((*io)){
15011    (*adb)->reset_throw_count();
15012    return (*io)->eof();
15013   }else if((*ss)){
15014    (*adb)->reset_throw_count();
15015    return (*ss)->eof();
15016   }else
15017    return 1;
15018  }
15019 
15020   void reset_to_last_valid_row()
15021   {
15022     if((*io)){
15023       (*adb)->reset_throw_count();
15024       (*io)->reset_to_last_valid_row();
15025     }
15026   }
15027 
15028  void flush(void) OTL_THROWS_OTL_EXCEPTION
15029  {
15030   if((*io)){
15031    (*adb)->reset_throw_count();
15032    (*io)->flush();
15033   }
15034  }
15035 
15036  void clean(const int clean_up_error_flag=0)
15037    OTL_THROWS_OTL_EXCEPTION
15038  {
15039   if((*io)){
15040    (*adb)->reset_throw_count();
15041    (*io)->clean(clean_up_error_flag);
15042   }else if((*ss)){
15043     (*adb)->reset_throw_count();
15044     (*ss)->clean();
15045   }
15046  }
15047 
15048  void rewind(void) OTL_THROWS_OTL_EXCEPTION
15049  {
15050   if((*io)){
15051    (*adb)->reset_throw_count();
15052    (*io)->rewind();
15053   }else if((*ss)){
15054    (*adb)->reset_throw_count();
15055    (*ss)->rewind();
15056   }
15057  }
15058 
15059 
15060  int is_null(void) OTL_NO_THROW
15061  {
15062   if((*io))
15063    return (*io)->is_null();
15064   else if((*ss))
15065    return (*ss)->is_null();
15066   else
15067    return 0;
15068  }
15069 
15070  void set_commit(int auto_commit=0) OTL_NO_THROW
15071  {
15072   (*auto_commit_flag)=auto_commit;
15073   if((*io)){
15074    (*adb)->reset_throw_count();
15075    (*io)->set_commit(auto_commit);
15076   }
15077  }
15078 
15079  const char* assign_stream_type
15080  (const char* stm_text,
15081   const char* stm_label)
15082  {
15083    const char* temp_stm_text=0;
15084    temp_stm_text=stm_label?stm_label:stm_text;
15085    return temp_stm_text;
15086  }
15087 
15088  void open
15089  (const otl_stream_buffer_size_type arr_size,
15090   const char* sqlstm,
15091   otl_connect& db,
15092   const int implicit_select=otl_explicit_select,
15093   const char* sqlstm_label=0)
15094    OTL_THROWS_OTL_EXCEPTION
15095  {
15096    reset_end_marker();
15097    otl_stream_buffer_size_type temp_arr_size=arr_size;
15098    if(this->good()){
15099      const char* temp_stm_text=assign_stream_type(sqlstm,sqlstm_label);
15100      throw otl_exception
15101        (otl_error_msg_29,
15102         otl_error_code_29,
15103         temp_stm_text);
15104    }
15105   if(shell==0)
15106    init_stream();
15107   buf_size_=arr_size;
15108   OTL_TRACE_STREAM_OPEN
15109 
15110 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
15111   char temp_buf[128];
15112   otl_itoa(arr_size,temp_buf);
15113   OTL_STRING_CONTAINER sql_stm=
15114     OTL_STRING_CONTAINER(temp_buf)+
15115     OTL_STRING_CONTAINER("===>")+
15116     sqlstm;
15117   otl_stream_shell* temp_shell=OTL_RCAST(otl_stream_shell*,db.sc.find(sql_stm));
15118   if(temp_shell){
15119    if(shell!=0)shell_pt.destroy();
15120    shell=temp_shell;
15121    ss=&(shell->ss);
15122    io=&(shell->io);
15123    if((*io)!=0)(*io)->set_flush_flag2(true);
15124    adb=&(shell->adb);
15125    auto_commit_flag=&(shell->auto_commit_flag);
15126    iov=&(shell->iov);
15127    iov_len=&(shell->iov_len);
15128    next_iov_ndx=&(shell->next_iov_ndx);
15129    ov=&(shell->ov);
15130    ov_len=&(shell->ov_len);
15131    next_ov_ndx=&(shell->next_ov_ndx);
15132    override=&(shell->override);
15133    try{
15134      if((*iov_len)==0)this->rewind();
15135    }catch(OTL_CONST_EXCEPTION otl_exception&){
15136      if((*adb))
15137       (*adb)->sc.remove(shell,shell->orig_sql_stm);
15138      intern_cleanup();
15139      shell_pt.destroy();
15140      connected=0;
15141      throw;
15142    }
15143    connected=1;
15144    return;
15145   }
15146   shell->orig_sql_stm=sql_stm;
15147 #endif
15148 
15149   delete[] (*iov);
15150   delete[] (*ov);
15151 
15152   (*iov)=0; (*iov_len)=0;
15153   (*ov)=0; (*ov_len)=0;
15154   (*next_iov_ndx)=0;
15155   (*next_ov_ndx)=0;
15156 
15157   char tmp[7];
15158   char* c=OTL_CCAST(char*,sqlstm);
15159 
15160   override->set_lob_stream_mode(shell->lob_stream_flag);
15161   while(otl_isspace(*c)||(*c)=='(')++c;
15162   OTL_STRNCPY_S(tmp,sizeof(tmp),c,6);
15163   tmp[6]=0;
15164   c=tmp;
15165   while(*c){
15166    *c=OTL_SCAST(char,otl_to_upper(*c));
15167    ++c;
15168   }
15169   if(adb==0)adb=&(shell->adb);
15170   (*adb)=&db;
15171   (*adb)->reset_throw_count();
15172   try{
15173 #if (defined(OTL_ODBC_POSTGRESQL) && !defined(OTL_ODBC_ALTERNATE_RPC) || \
15174      defined(OTL_ODBC_SELECT_STM_EXECUTE_BEFORE_DESCRIBE)) && \
15175   !defined(OTL_ODBC_MULTI_MODE)
15176    if((strncmp(tmp,"SELECT",6)==0||
15177        strncmp(tmp,"WITH",4)==0)){
15178      override->set_master_stream_ptr(OTL_RCAST(void*,this));
15179      (*ss)=new otl_select_stream(override,
15180                                  temp_arr_size,
15181                                  sqlstm,
15182                                  db,otl_implicit_select,
15183                                  sqlstm_label);
15184      shell->stream_type=otl_odbc_select_stream;
15185    }
15186 #elif defined(OTL_ODBC_MULTI_MODE)
15187 #if defined(OTL_ODBC_ALTERNATE_RPC)
15188    bool alternate_rpc=true;
15189 #else
15190    bool alternate_rpc=false;
15191 #endif
15192    int connect_type=(*adb)->get_connect_struct().get_connection_type();
15193    if((connect_type==OTL_POSTGRESQL_ODBC_CONNECT&&!alternate_rpc ||
15194        connect_type==OTL_ENTERPRISE_DB_ODBC_CONNECT ||
15195        connect_type==OTL_MYODBC35_ODBC_CONNECT) &&
15196      (strncmp(tmp,"SELECT",6)==0||
15197       strncmp(tmp,"WITH",4)==0)){
15198      override->set_master_stream_ptr(OTL_RCAST(void*,this));
15199      (*ss)=new otl_select_stream(override,
15200                                  temp_arr_size,
15201                                  sqlstm,
15202                                  db,otl_implicit_select,
15203                                  sqlstm_label);
15204      shell->stream_type=otl_odbc_select_stream;
15205    }else if((strncmp(tmp,"SELECT",6)==0||
15206              strncmp(tmp,"WITH",4)==0)&&
15207             !implicit_select){
15208      (*ss)=new otl_select_stream(override,temp_arr_size,sqlstm,
15209                                  db,otl_explicit_select,
15210                                  sqlstm_label);
15211      shell->stream_type=otl_odbc_select_stream;
15212    }
15213 #else
15214    if((strncmp(tmp,"SELECT",6)==0||
15215        strncmp(tmp,"WITH",4)==0)&&
15216       !implicit_select){
15217 #if defined(OTL_ODBC_TIMESTEN)
15218    if(temp_arr_size>128||temp_arr_size<0){
15219      const char* temp_stm_text=assign_stream_type(sqlstm,sqlstm_label);
15220      throw otl_exception
15221        (otl_error_msg_31,
15222         otl_error_code_31,
15223         temp_stm_text);
15224    }
15225 #endif
15226      override->set_master_stream_ptr(OTL_RCAST(void*,this));
15227      (*ss)=new otl_select_stream(override,temp_arr_size,sqlstm,
15228                                  db,otl_explicit_select,
15229                                  sqlstm_label);
15230      shell->stream_type=otl_odbc_select_stream;
15231    }
15232 #endif
15233    else if(tmp[0]=='$'){
15234      override->set_master_stream_ptr(OTL_RCAST(void*,this));
15235      (*ss)=new otl_select_stream
15236        (override,temp_arr_size,
15237         sqlstm,db,
15238         1,sqlstm_label);
15239      shell->stream_type=otl_odbc_select_stream;
15240    }else{
15241      if(implicit_select){
15242 #if defined(OTL_ODBC_TIMESTEN)
15243    if(temp_arr_size>128||temp_arr_size<0){
15244      const char* temp_stm_text=assign_stream_type(sqlstm,sqlstm_label);
15245      throw otl_exception
15246        (otl_error_msg_31,
15247         otl_error_code_31,
15248         temp_stm_text);
15249    }
15250 #endif
15251    override->set_master_stream_ptr(OTL_RCAST(void*,this));
15252    (*ss)=new otl_select_stream(override,temp_arr_size,
15253                                sqlstm,db,
15254                                1,sqlstm_label);
15255    shell->stream_type=otl_odbc_select_stream;
15256      }else{
15257        (*io)=new otl_inout_stream
15258          (arr_size,sqlstm,db,
15259           OTL_RCAST(void*,this),
15260           shell->lob_stream_flag,
15261           sqlstm_label);
15262        (*io)->set_flush_flag(shell->flush_flag);
15263        shell->stream_type=otl_odbc_io_stream;
15264      }
15265    }
15266   }catch(OTL_CONST_EXCEPTION otl_exception&){
15267    shell_pt.destroy();
15268    throw;
15269   }
15270   if((*io))(*io)->set_commit((*auto_commit_flag));
15271   create_var_desc();
15272   connected=1;
15273  }
15274 
15275  void intern_cleanup(void)
15276  {
15277   delete[] (*iov);
15278   delete[] (*ov);
15279 
15280   (*iov)=0; (*iov_len)=0;
15281   (*ov)=0; (*ov_len)=0;
15282   (*next_iov_ndx)=0;
15283   (*next_ov_ndx)=0;
15284   override->setLen(0);
15285   override->set_lob_stream_mode(false);
15286 
15287   switch(shell->stream_type){
15288   case otl_odbc_no_stream:
15289     break;
15290   case otl_odbc_io_stream:
15291     try{
15292       (*io)->flush();
15293       (*io)->close();
15294     }catch(OTL_CONST_EXCEPTION otl_exception&){
15295       clean(1);
15296       (*io)->close();
15297       delete (*io);
15298       (*io)=0;
15299       shell->stream_type=otl_odbc_no_stream;
15300       throw;
15301     }
15302     delete (*io);
15303     (*io)=0;
15304     shell->stream_type=otl_odbc_no_stream;
15305     break;
15306   case otl_odbc_select_stream:
15307     try{
15308       (*ss)->close();
15309     }catch(OTL_CONST_EXCEPTION otl_exception&){
15310       delete (*ss);
15311       (*ss)=0;
15312       shell->stream_type=otl_odbc_no_stream;
15313       throw;
15314     }
15315     delete (*ss);
15316     (*ss)=0;
15317     shell->stream_type=otl_odbc_no_stream;
15318     break;
15319   }
15320   (*ss)=0; (*io)=0;
15321   if(adb!=0)(*adb)=0;
15322   adb=0;
15323  }
15324 
15325 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
15326  void close(const bool save_in_stream_pool=true)
15327    OTL_THROWS_OTL_EXCEPTION
15328 #else
15329  void close(void)
15330    OTL_THROWS_OTL_EXCEPTION
15331 #endif
15332  {
15333   if(shell==0)return;
15334 
15335   OTL_TRACE_FUNC(0x4,"otl_stream","close","")
15336 
15337 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
15338   if(save_in_stream_pool&&(*adb)&&
15339 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
15340      !(otl_uncaught_exception())&&
15341 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
15342      !(otl_uncaught_exception())&&
15343 #endif
15344      (*adb)->get_throw_count()==0){
15345    try{
15346     this->flush();
15347     this->clean(1);
15348    }catch(OTL_CONST_EXCEPTION otl_exception&){
15349     this->clean(1);
15350     throw;
15351    }
15352    if((*adb) && (*adb)->get_throw_count()>0){
15353     (*adb)->sc.remove(shell,shell->orig_sql_stm);
15354     intern_cleanup();
15355     shell_pt.destroy();
15356     connected=0;
15357     return;
15358    }
15359 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
15360    if(otl_uncaught_exception()){
15361     if((*adb))
15362      (*adb)->sc.remove(shell,shell->orig_sql_stm);
15363     intern_cleanup();
15364     shell_pt.destroy();
15365     connected=0;
15366     return;
15367    }
15368 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
15369    if(otl_uncaught_exception()){
15370     if((*adb))
15371      (*adb)->sc.remove(shell,shell->orig_sql_stm);
15372     intern_cleanup();
15373     shell_pt.destroy();
15374     connected=0;
15375     return;
15376    }
15377 #endif
15378    (*adb)->sc.add(shell,shell->orig_sql_stm.c_str());
15379    shell_pt.disconnect();
15380    connected=0;
15381   }else{
15382    if((*adb))
15383     (*adb)->sc.remove(shell,shell->orig_sql_stm);
15384    intern_cleanup();
15385    shell_pt.destroy();
15386    connected=0;
15387   }
15388 #else
15389   intern_cleanup();
15390   connected=0;
15391 #endif
15392  }
15393 
15394  otl_column_desc* describe_select(int& desc_len)
15395    OTL_NO_THROW
15396  {
15397   desc_len=0;
15398   if((*ss)){
15399    (*adb)->reset_throw_count();
15400    desc_len=(*ss)->get_sl_len();
15401    return (*ss)->get_sl_desc();
15402   }
15403   return 0;
15404  }
15405 
15406  int good(void) OTL_NO_THROW
15407  {
15408   if(!connected)return 0;
15409   if((*io)||(*ss)){
15410    (*adb)->reset_throw_count();
15411    return 1;
15412   }else
15413    return 0;
15414  }
15415 
15416  otl_stream& operator<<(otl_lob_stream& s)
15417    OTL_THROWS_OTL_EXCEPTION
15418  {
15419   last_oper_was_read_op=false;
15420    reset_end_marker();
15421   if((*io)){
15422     (*io)->operator<<(s);
15423    inc_next_iov();
15424   }
15425   return *this;
15426  }
15427 
15428   otl_stream& operator>>(otl_stream& (*pf) (otl_stream&))
15429   {
15430     (*pf)(*this);
15431     return *this;
15432   }
15433 
15434   otl_stream& operator<<(otl_stream& (*pf) (otl_stream&))
15435   {
15436     (*pf)(*this);
15437     return *this;
15438   }
15439 
15440  otl_stream& operator>>(otl_lob_stream& s)
15441    OTL_THROWS_OTL_EXCEPTION
15442  {
15443    last_oper_was_read_op=true;
15444    switch(shell->stream_type){
15445    case otl_odbc_no_stream:
15446      break;
15447    case otl_odbc_io_stream:
15448      last_eof_rc=(*io)->eof();
15449      (*io)->operator>>(s);
15450      break;
15451    case otl_odbc_select_stream:
15452      last_eof_rc=(*ss)->eof();
15453      (*ss)->operator>>(s);
15454      break;
15455    }
15456    inc_next_ov();
15457    return *this;
15458  }
15459 
15460  otl_stream& operator>>(otl_time& s)
15461    OTL_THROWS_OTL_EXCEPTION
15462  {
15463    last_oper_was_read_op=true;
15464    switch(shell->stream_type){
15465    case otl_odbc_no_stream:
15466      break;
15467    case otl_odbc_io_stream:
15468      last_eof_rc=(*io)->eof();
15469      (*io)->operator>>(s);
15470      break;
15471    case otl_odbc_select_stream:
15472      last_eof_rc=(*ss)->eof();
15473      (*ss)->operator>>(s);
15474      break;
15475    }
15476    return *this;
15477  }
15478 
15479  otl_stream& operator<<(const otl_time& n)
15480    OTL_THROWS_OTL_EXCEPTION
15481  {
15482    last_oper_was_read_op=false;
15483    reset_end_marker();
15484    switch(shell->stream_type){
15485    case otl_odbc_no_stream:
15486      break;
15487    case otl_odbc_io_stream:
15488      (*io)->operator<<(n);
15489      break;
15490    case otl_odbc_select_stream:
15491      (*ss)->operator<<(n);
15492      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
15493      break;
15494    }
15495    return *this;
15496  }
15497 
15498  otl_stream& operator>>(otl_datetime& s)
15499    OTL_THROWS_OTL_EXCEPTION
15500  {
15501    last_oper_was_read_op=true;
15502 #if defined(OTL_ODBC_STRING_TO_TIMESTAMP)
15503   if(describe_next_out_var()->ftype==otl_var_char){
15504 #if defined(OTL_UNICODE)
15505 #if defined(OTL_UNICODE_CHAR_TYPE)
15506     OTL_UNICODE_CHAR_TYPE tmp_str[100];
15507 #else
15508     OTL_CHAR tmp_str[100];
15509 #endif
15510 #else
15511     char tmp_str[100];
15512 #endif
15513     (*this)>>tmp_str;
15514 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
15515     if((*this).is_null())
15516       s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
15517     else
15518       OTL_ODBC_STRING_TO_TIMESTAMP(tmp_str,s);
15519 #else
15520     OTL_ODBC_STRING_TO_TIMESTAMP(tmp_str,s);
15521 #endif
15522 #if defined(OTL_ODBC_TIME_ZONE)
15523     OTL_TRACE_WRITE
15524       (OTL_TRACE_FORMAT_TZ_DATETIME(s),
15525        "operator >>",
15526        "otl_datetime&");
15527 #else
15528     OTL_TRACE_WRITE
15529       (OTL_TRACE_FORMAT_DATETIME(s),
15530        "operator >>",
15531        "otl_datetime&");
15532 #endif
15533     return *this;
15534   }else{
15535     otl_time tmp;
15536     (*this)>>tmp;
15537 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
15538     if((*this).is_null())
15539       s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
15540     else{
15541       s.year=tmp.year;
15542       s.month=tmp.month;
15543       s.day=tmp.day;
15544       s.hour=tmp.hour;
15545       s.minute=tmp.minute;
15546       s.second=tmp.second;
15547       s.fraction=otl_from_fraction(tmp.fraction,s.frac_precision);
15548     }
15549 #else
15550     s.year=tmp.year;
15551     s.month=tmp.month;
15552     s.day=tmp.day;
15553     s.hour=tmp.hour;
15554     s.minute=tmp.minute;
15555     s.second=tmp.second;
15556     s.fraction=otl_from_fraction(tmp.fraction,s.frac_precision);
15557 #endif
15558   }
15559 #else
15560    otl_time tmp;
15561    (*this)>>tmp;
15562 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
15563    if((*this).is_null())
15564      s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
15565    else{
15566      s.year=tmp.year;
15567      s.month=tmp.month;
15568      s.day=tmp.day;
15569      s.hour=tmp.hour;
15570      s.minute=tmp.minute;
15571      s.second=tmp.second;
15572      s.fraction=otl_from_fraction(tmp.fraction,s.frac_precision);
15573    }
15574 #else
15575   s.year=tmp.year;
15576   s.month=tmp.month;
15577   s.day=tmp.day;
15578   s.hour=tmp.hour;
15579   s.minute=tmp.minute;
15580   s.second=tmp.second;
15581   s.fraction=otl_from_fraction(tmp.fraction,s.frac_precision);
15582 #endif
15583 
15584 #endif
15585   OTL_TRACE_WRITE
15586     (OTL_TRACE_FORMAT_DATETIME(s),
15587      "operator >>",
15588      "otl_datetime&");
15589   inc_next_ov();
15590   return *this;
15591  }
15592 
15593  otl_stream& operator<<(const otl_datetime& s)
15594    OTL_THROWS_OTL_EXCEPTION
15595  {
15596    otl_time tmp;
15597    last_oper_was_read_op=false;
15598    reset_end_marker();
15599 #if defined(OTL_ODBC_TIMESTAMP_TO_STRING)
15600     if(describe_next_in_var()->ftype==otl_var_char){
15601 #if defined(OTL_UNICODE)
15602 #if defined(OTL_UNICODE_CHAR_TYPE)
15603      OTL_UNICODE_CHAR_TYPE tmp_str[100];
15604 #else
15605       OTL_CHAR tmp_str[100];
15606 #endif
15607 #else
15608       char tmp_str[100];
15609 #endif
15610      OTL_ODBC_TIMESTAMP_TO_STRING(s,tmp_str);
15611 #if defined(OTL_ODBC_TIME_ZONE)
15612      OTL_TRACE_READ
15613        (OTL_TRACE_FORMAT_TZ_DATETIME(s),
15614         "operator <<",
15615         "otl_datetime&");
15616 #else
15617      OTL_TRACE_READ
15618        (OTL_TRACE_FORMAT_DATETIME(s),
15619         "operator <<",
15620         "otl_datetime&");
15621 #endif
15622      (*this)<<tmp_str;
15623      return *this;
15624     }else{
15625       tmp.year=OTL_SCAST(SQLSMALLINT,s.year);
15626       tmp.month=OTL_SCAST(SQLSMALLINT,s.month);
15627       tmp.day=OTL_SCAST(SQLSMALLINT,s.day);
15628       tmp.hour=OTL_SCAST(SQLSMALLINT,s.hour);
15629       tmp.minute=OTL_SCAST(SQLSMALLINT,s.minute);
15630       tmp.second=OTL_SCAST(SQLSMALLINT,s.second);
15631       tmp.fraction=otl_to_fraction(s.fraction,s.frac_precision);
15632       (*this)<<tmp;
15633       OTL_TRACE_READ(OTL_TRACE_FORMAT_DATETIME(s),
15634                      "operator >>",
15635                      "otl_datetime&");
15636       inc_next_iov();
15637       return *this;
15638     }
15639 #else
15640     tmp.year=OTL_SCAST(SQLSMALLINT,s.year);
15641     tmp.month=OTL_SCAST(SQLSMALLINT,s.month);
15642     tmp.day=OTL_SCAST(SQLSMALLINT,s.day);
15643     tmp.hour=OTL_SCAST(SQLSMALLINT,s.hour);
15644     tmp.minute=OTL_SCAST(SQLSMALLINT,s.minute);
15645     tmp.second=OTL_SCAST(SQLSMALLINT,s.second);
15646     tmp.fraction=otl_to_fraction(s.fraction,s.frac_precision);
15647     (*this)<<tmp;
15648     OTL_TRACE_READ(OTL_TRACE_FORMAT_DATETIME(s),
15649                    "operator <<",
15650                    "otl_datetime&");
15651     inc_next_iov();
15652     return *this;
15653 #endif
15654  }
15655 
15656 #if !defined(OTL_UNICODE)
15657  otl_stream& operator>>(char& c)
15658    OTL_THROWS_OTL_EXCEPTION
15659  {
15660    last_oper_was_read_op=true;
15661    switch(shell->stream_type){
15662    case otl_odbc_no_stream:
15663      break;
15664    case otl_odbc_io_stream:
15665      last_eof_rc=(*io)->eof();
15666      (*io)->operator>>(c);
15667      break;
15668    case otl_odbc_select_stream:
15669      last_eof_rc=(*ss)->eof();
15670      (*ss)->operator>>(c);
15671      break;
15672    }
15673 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
15674    if((*this).is_null())
15675      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
15676 #endif
15677    OTL_TRACE_WRITE("'"<<c<<"'","operator >>","char&")
15678    inc_next_ov();
15679    return *this;
15680  }
15681 #endif
15682 
15683 #if !defined(OTL_UNICODE)
15684  otl_stream& operator>>(unsigned char& c)
15685    OTL_THROWS_OTL_EXCEPTION
15686  {
15687    last_oper_was_read_op=true;
15688    switch(shell->stream_type){
15689    case otl_odbc_no_stream:
15690      break;
15691    case otl_odbc_io_stream:
15692      last_eof_rc=(*io)->eof();
15693      (*io)->operator>>(c);
15694      break;
15695    case otl_odbc_select_stream:
15696      last_eof_rc=(*ss)->eof();
15697      (*ss)->operator>>(c);
15698      break;
15699    }
15700 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
15701    if((*this).is_null())
15702      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
15703 #endif
15704    OTL_TRACE_WRITE("'"<<c<<"'","operator >>","unsigned char&")
15705    inc_next_ov();
15706    return *this;
15707  }
15708 #endif
15709 
15710 #if !defined(OTL_UNICODE)
15711 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
15712  otl_stream& operator>>(OTL_STRING_CONTAINER& s)
15713    OTL_THROWS_OTL_EXCEPTION
15714  {
15715    last_oper_was_read_op=true;
15716    switch(shell->stream_type){
15717    case otl_odbc_no_stream:
15718      break;
15719    case otl_odbc_io_stream:
15720      last_eof_rc=(*io)->eof();
15721      (*io)->operator>>(s);
15722      break;
15723    case otl_odbc_select_stream:
15724      last_eof_rc=(*ss)->eof();
15725      (*ss)->operator>>(s);
15726      break;
15727    }
15728 
15729 #if defined(OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL)
15730    if((*this).is_null()){
15731      OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL(s);
15732    }
15733 #elif defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
15734    if((*this).is_null())
15735      s=OTL_DEFAULT_STRING_NULL_TO_VAL;
15736 #endif
15737 
15738    OTL_TRACE_WRITE(s,"operator >>","OTL_STRING_CONTAINER&")
15739    inc_next_ov();
15740    return *this;
15741  }
15742 #endif
15743 #endif
15744 
15745 #if !defined(OTL_UNICODE)
15746  otl_stream& operator>>(char* s)
15747    OTL_THROWS_OTL_EXCEPTION
15748  {
15749    last_oper_was_read_op=true;
15750    switch(shell->stream_type){
15751    case otl_odbc_no_stream:
15752      break;
15753    case otl_odbc_io_stream:
15754      last_eof_rc=(*io)->eof();
15755      (*io)->operator>>(s);
15756      break;
15757    case otl_odbc_select_stream:
15758      last_eof_rc=(*ss)->eof();
15759      (*ss)->operator>>(s);
15760      break;
15761    }
15762 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
15763    if((*this).is_null())
15764      otl_strcpy(OTL_RCAST(unsigned char*,s),
15765                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL));
15766 #endif
15767    OTL_TRACE_WRITE(s,"operator >>","char*")
15768    inc_next_ov();
15769    return *this;
15770  }
15771 #endif
15772 
15773 #if defined(OTL_UNICODE_STRING_TYPE)
15774  otl_stream& operator>>(OTL_UNICODE_STRING_TYPE& s)
15775    OTL_THROWS_OTL_EXCEPTION
15776  {
15777    last_oper_was_read_op=true;
15778    switch(shell->stream_type){
15779    case otl_odbc_no_stream:
15780      break;
15781    case otl_odbc_io_stream:
15782      last_eof_rc=(*io)->eof();
15783      (*io)->operator>>(s);
15784      break;
15785    case otl_odbc_select_stream:
15786      last_eof_rc=(*ss)->eof();
15787      (*ss)->operator>>(s);
15788      break;
15789    }
15790 
15791 #if defined(OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL)
15792    if((*this).is_null()){
15793      OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL(s);
15794    }
15795 #elif defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
15796    if((*this).is_null())
15797      s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,OTL_DEFAULT_STRING_NULL_TO_VAL);
15798 #endif
15799    OTL_TRACE_WRITE(s.c_str(),
15800                    "operator >>",
15801                    "OTL_UNICODE_STRING_TYPE&");
15802    inc_next_ov();
15803    return *this;
15804  }
15805 #endif
15806 
15807  otl_stream& operator>>(unsigned char* s)
15808    OTL_THROWS_OTL_EXCEPTION
15809  {
15810    last_oper_was_read_op=true;
15811    switch(shell->stream_type){
15812    case otl_odbc_no_stream:
15813      break;
15814    case otl_odbc_io_stream:
15815      last_eof_rc=(*io)->eof();
15816      (*io)->operator>>(s);
15817      break;
15818    case otl_odbc_select_stream:
15819      last_eof_rc=(*ss)->eof();
15820      (*ss)->operator>>(s);
15821      break;
15822    }
15823 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
15824    if((*this).is_null())
15825      otl_strcpy
15826        (OTL_RCAST(unsigned char*,s),
15827         OTL_RCAST(unsigned char*,
15828                   OTL_CCAST(char*,OTL_DEFAULT_STRING_NULL_TO_VAL)));
15829 #endif
15830 #if defined(OTL_UNICODE)
15831    OTL_TRACE_WRITE(OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,s),
15832                    "operator >>",
15833                    OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*")
15834 #else
15835    OTL_TRACE_WRITE(s,"operator >>","unsigned char*")
15836 #endif
15837    inc_next_ov();
15838    return *this;
15839  }
15840 
15841 #if defined(OTL_UNICODE)
15842 
15843  otl_stream& operator>>(OTL_UNICODE_CHAR_TYPE& c)
15844    OTL_THROWS_OTL_EXCEPTION
15845  {
15846    OTL_UNICODE_CHAR_TYPE s[1024];
15847    last_oper_was_read_op=true;
15848    switch(shell->stream_type){
15849    case otl_odbc_no_stream:
15850      break;
15851    case otl_odbc_io_stream:
15852      last_eof_rc=(*io)->eof();
15853      (*io)->operator>>(OTL_RCAST(unsigned char*,s));
15854      break;
15855    case otl_odbc_select_stream:
15856      last_eof_rc=(*ss)->eof();
15857      (*ss)->operator>>(OTL_RCAST(unsigned char*,s));
15858      break;
15859    }
15860    c=s[0];
15861 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
15862    if((*this).is_null())
15863      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
15864 #endif
15865    OTL_TRACE_WRITE(c,"operator >>",
15866                    OTL_UNICODE_CHAR_TYPE_TRACE_NAME "")
15867    inc_next_ov();
15868    return *this;
15869  }
15870 
15871  otl_stream& operator>>(OTL_UNICODE_CHAR_TYPE* s)
15872    OTL_THROWS_OTL_EXCEPTION
15873  {
15874    last_oper_was_read_op=true;
15875    switch(shell->stream_type){
15876    case otl_odbc_no_stream:
15877      break;
15878    case otl_odbc_io_stream:
15879      last_eof_rc=(*io)->eof();
15880      (*io)->operator>>(OTL_RCAST(unsigned char*,s));
15881      break;
15882    case otl_odbc_select_stream:
15883      last_eof_rc=(*ss)->eof();
15884      (*ss)->operator>>(OTL_RCAST(unsigned char*,s));
15885      break;
15886    }
15887 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
15888    if((*this).is_null())
15889      otl_strcpy(OTL_RCAST(unsigned char*,s),
15890                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL));
15891 #endif
15892    OTL_TRACE_WRITE(OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,s),
15893                    "operator >>",
15894                    OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*")
15895    inc_next_ov();
15896    return *this;
15897  }
15898 
15899 #endif
15900 
15901  otl_stream& operator>>(int& n)
15902    OTL_THROWS_OTL_EXCEPTION
15903  {
15904    last_oper_was_read_op=true;
15905    switch(shell->stream_type){
15906    case otl_odbc_no_stream:
15907      break;
15908    case otl_odbc_io_stream:
15909      last_eof_rc=(*io)->eof();
15910 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
15911      (*io)->operator>>(n);
15912 #else
15913      (*io)->operator>><int,otl_var_int>(n);
15914 #endif
15915      break;
15916    case otl_odbc_select_stream:
15917      last_eof_rc=(*ss)->eof();
15918 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
15919      (*ss)->operator>>(n);
15920 #else
15921      (*ss)->operator>><int,otl_var_int>(n);
15922 #endif
15923      break;
15924    }
15925 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
15926    if((*this).is_null())
15927      n=OTL_SCAST(int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
15928 #endif
15929    OTL_TRACE_WRITE(n,"operator >>","int&")
15930    inc_next_ov();
15931    return *this;
15932  }
15933 
15934  otl_stream& operator>>(unsigned& u)
15935    OTL_THROWS_OTL_EXCEPTION
15936  {
15937    last_oper_was_read_op=true;
15938    switch(shell->stream_type){
15939    case otl_odbc_no_stream:
15940      break;
15941    case otl_odbc_io_stream:
15942      last_eof_rc=(*io)->eof();
15943 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
15944      (*io)->operator>>(u);
15945 #else
15946      (*io)->operator>><unsigned,otl_var_unsigned_int>(u);
15947 #endif
15948      break;
15949    case otl_odbc_select_stream:
15950      last_eof_rc=(*ss)->eof();
15951 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
15952      (*ss)->operator>>(u);
15953 #else
15954      (*ss)->operator>><unsigned,otl_var_unsigned_int>(u);
15955 #endif
15956      break;
15957    }
15958 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
15959    if((*this).is_null())
15960      u=OTL_SCAST(unsigned int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
15961 #endif
15962    OTL_TRACE_WRITE(u,"operator >>","unsigned&")
15963    inc_next_ov();
15964    return *this;
15965  }
15966 
15967  otl_stream& operator>>(short& sh)
15968    OTL_THROWS_OTL_EXCEPTION
15969  {
15970    last_oper_was_read_op=true;
15971    switch(shell->stream_type){
15972    case otl_odbc_no_stream:
15973      break;
15974    case otl_odbc_io_stream:
15975      last_eof_rc=(*io)->eof();
15976 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
15977      (*io)->operator>>(sh);
15978 #else
15979      (*io)->operator>><short,otl_var_short>(sh);
15980 #endif
15981      break;
15982    case otl_odbc_select_stream:
15983      last_eof_rc=(*ss)->eof();
15984 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
15985      (*ss)->operator>>(sh);
15986 #else
15987      (*ss)->operator>><short,otl_var_short>(sh);
15988 #endif
15989      break;
15990    }
15991 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
15992    if((*this).is_null())
15993      sh=OTL_SCAST(short int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
15994 #endif
15995    OTL_TRACE_WRITE(sh,"operator >>","short int&")
15996    inc_next_ov();
15997    return *this;
15998  }
15999 
16000  otl_stream& operator>>(long int& l)
16001    OTL_THROWS_OTL_EXCEPTION
16002  {
16003    last_oper_was_read_op=true;
16004    switch(shell->stream_type){
16005    case otl_odbc_no_stream:
16006      break;
16007    case otl_odbc_io_stream:
16008      last_eof_rc=(*io)->eof();
16009 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16010      (*io)->operator>>(l);
16011 #else
16012      (*io)->operator>><long,otl_var_long_int>(l);
16013 #endif
16014      break;
16015    case otl_odbc_select_stream:
16016      last_eof_rc=(*ss)->eof();
16017 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16018      (*ss)->operator>>(l);
16019 #else
16020      (*ss)->operator>><long,otl_var_long_int>(l);
16021 #endif
16022      break;
16023    }
16024 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
16025    if((*this).is_null())
16026      l=OTL_SCAST(long int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
16027 #endif
16028    OTL_TRACE_WRITE(l,"operator >>","long int&")
16029    inc_next_ov();
16030    return *this;
16031  }
16032 
16033 #if defined(OTL_BIGINT)
16034  otl_stream& operator>>(OTL_BIGINT& l)
16035    OTL_THROWS_OTL_EXCEPTION
16036  {
16037    last_oper_was_read_op=true;
16038    switch(shell->stream_type){
16039    case otl_odbc_no_stream:
16040      break;
16041    case otl_odbc_io_stream:
16042      last_eof_rc=(*io)->eof();
16043 #if defined(OTL_STR_TO_BIGINT) && defined(OTL_BIGINT_TO_STR)
16044      {
16045        otl_var_desc* var_desc=describe_next_out_var();
16046        if(var_desc){
16047          if(var_desc->ftype==otl_var_char){
16048            char temp_val[otl_bigint_str_size];
16049 #if defined(OTL_UNICODE)
16050            OTL_CHAR unitemp_val[otl_bigint_str_size];
16051            (*ss)->operator>>(OTL_RCAST(unsigned char*,unitemp_val));
16052            OTL_CHAR* uc=unitemp_val;
16053            char* c=temp_val;
16054            while(*uc){
16055              *c=OTL_SCAST(char,*uc);
16056              ++c; ++uc;
16057            }
16058            *c=0;
16059 #else
16060            (*ss)->operator>>(temp_val);
16061 #endif
16062            OTL_STR_TO_BIGINT(temp_val,l);
16063          }else
16064 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16065            (*io)->operator>>(l);
16066 #else
16067            (*io)->operator>><OTL_BIGINT,otl_var_bigint>(l);
16068 #endif
16069        }
16070      }
16071 #else
16072 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16073      (*io)->operator>>(l);
16074 #else
16075      (*io)->operator>><OTL_BIGINT,otl_var_bigint>(l);
16076 #endif
16077 #endif
16078      break;
16079    case otl_odbc_select_stream:
16080      last_eof_rc=(*ss)->eof();
16081 #if defined(OTL_STR_TO_BIGINT) && defined(OTL_BIGINT_TO_STR)
16082      {
16083        otl_var_desc* var_desc=describe_next_out_var();
16084        if(var_desc){
16085          if(var_desc->ftype==otl_var_char){
16086            char temp_val[otl_bigint_str_size];
16087            (*ss)->operator>>(temp_val);
16088            OTL_STR_TO_BIGINT(temp_val,l);
16089          }else
16090 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16091            (*ss)->operator>>(l);
16092 #else
16093            (*ss)->operator>><OTL_BIGINT,otl_var_bigint>(l);
16094 #endif
16095        }
16096      }
16097 #else
16098 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16099      (*ss)->operator>>(l);
16100 #else
16101      (*ss)->operator>><OTL_BIGINT,otl_var_bigint>(l);
16102 #endif
16103 #endif
16104      break;
16105    }
16106 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
16107    if((*this).is_null())
16108      l=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
16109 #endif
16110 
16111 #if defined(_MSC_VER) && defined(OTL_TRACE_LEVEL)
16112    // VC ++
16113    {
16114      char temp_str[otl_bigint_str_size];
16115      _i64toa(l,temp_str,10);
16116      OTL_TRACE_WRITE(temp_str,"operator >>","BIGINT&")
16117    }
16118 #elif !defined(_MSC_VER) && defined(OTL_TRACE_LEVEL)
16119    OTL_TRACE_WRITE(l,"operator >>","BIGINT&")
16120 #endif
16121    inc_next_ov();
16122    return *this;
16123  }
16124 #endif
16125 
16126  otl_stream& operator>>(float& f)
16127    OTL_THROWS_OTL_EXCEPTION
16128  {
16129    last_oper_was_read_op=true;
16130    switch(shell->stream_type){
16131    case otl_odbc_no_stream:
16132      break;
16133    case otl_odbc_io_stream:
16134      last_eof_rc=(*io)->eof();
16135 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16136      (*io)->operator>>(f);
16137 #else
16138      (*io)->operator>><float,otl_var_float>(f);
16139 #endif
16140      break;
16141    case otl_odbc_select_stream:
16142      last_eof_rc=(*ss)->eof();
16143 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16144      (*ss)->operator>>(f);
16145 #else
16146      (*ss)->operator>><float,otl_var_float>(f);
16147 #endif
16148      break;
16149    }
16150 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
16151    if((*this).is_null())
16152      f=OTL_SCAST(float,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
16153 #endif
16154    OTL_TRACE_WRITE(f,"operator >>","float&")
16155    inc_next_ov();
16156    return *this;
16157  }
16158 
16159  otl_stream& operator>>(double& d)
16160    OTL_THROWS_OTL_EXCEPTION
16161  {
16162    last_oper_was_read_op=true;
16163    switch(shell->stream_type){
16164    case otl_odbc_no_stream:
16165      break;
16166    case otl_odbc_io_stream:
16167      last_eof_rc=(*io)->eof();
16168 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16169      (*io)->operator>>(d);
16170 #else
16171      (*io)->operator>><double,otl_var_double>(d);
16172 #endif
16173      break;
16174    case otl_odbc_select_stream:
16175      last_eof_rc=(*ss)->eof();
16176 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16177      (*ss)->operator>>(d);
16178 #else
16179      (*ss)->operator>><double,otl_var_double>(d);
16180 #endif
16181      break;
16182    }
16183 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
16184    if((*this).is_null())
16185      d=OTL_SCAST(double,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
16186 #endif
16187    OTL_TRACE_WRITE(d,"operator >>","double&")
16188    inc_next_ov();
16189    return *this;
16190  }
16191 
16192  otl_stream& operator>>(otl_long_string& s)
16193    OTL_THROWS_OTL_EXCEPTION
16194  {
16195    last_oper_was_read_op=true;
16196    switch(shell->stream_type){
16197    case otl_odbc_no_stream:
16198      break;
16199    case otl_odbc_io_stream:
16200      last_eof_rc=(*io)->eof();
16201      (*io)->operator>>(s);
16202      break;
16203    case otl_odbc_select_stream:
16204      last_eof_rc=(*ss)->eof();
16205      (*ss)->operator>>(s);
16206      break;
16207    }
16208    OTL_TRACE_WRITE(" string length: "<<s.len(),"operator >>","otl_long_string&")
16209    inc_next_ov();
16210    return *this;
16211  }
16212 
16213  otl_stream& operator<<(const char c)
16214    OTL_THROWS_OTL_EXCEPTION
16215  {
16216    last_oper_was_read_op=false;
16217    reset_end_marker();
16218    switch(shell->stream_type){
16219    case otl_odbc_no_stream:
16220      break;
16221    case otl_odbc_io_stream:
16222      (*io)->operator<<(c);
16223      break;
16224    case otl_odbc_select_stream:
16225      (*ss)->operator<<(c);
16226      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16227      break;
16228    }
16229    OTL_TRACE_READ("'"<<c<<"'","operator <<","char");
16230    inc_next_iov();
16231    return *this;
16232  }
16233 
16234  otl_stream& operator<<(const unsigned char c)
16235    OTL_THROWS_OTL_EXCEPTION
16236  {
16237    last_oper_was_read_op=false;
16238    reset_end_marker();
16239    OTL_TRACE_READ("'"<<c<<"'","operator <<","unsigned char");
16240    switch(shell->stream_type){
16241    case otl_odbc_no_stream:
16242      break;
16243    case otl_odbc_io_stream:
16244      (*io)->operator<<(c);
16245      break;
16246    case otl_odbc_select_stream:
16247      (*ss)->operator<<(c);
16248      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16249      break;
16250    }
16251    inc_next_iov();
16252    return *this;
16253  }
16254 
16255 #if defined(OTL_UNICODE)
16256 
16257  otl_stream& operator<<(const OTL_UNICODE_CHAR_TYPE* s)
16258    OTL_THROWS_OTL_EXCEPTION
16259  {
16260    last_oper_was_read_op=false;
16261    reset_end_marker();
16262    OTL_TRACE_READ
16263      ("\""<<OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
16264       "operator <<",
16265       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*");
16266    switch(shell->stream_type){
16267    case otl_odbc_no_stream:
16268      break;
16269    case otl_odbc_io_stream:
16270      (*io)->operator<<(OTL_RCAST(const unsigned char*,s));
16271      break;
16272    case otl_odbc_select_stream:
16273      (*ss)->operator<<(OTL_RCAST(const unsigned char*,s));
16274      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16275      break;
16276    }
16277    inc_next_iov();
16278    return *this;
16279  }
16280 
16281  otl_stream& operator<<(const OTL_UNICODE_CHAR_TYPE c)
16282    OTL_THROWS_OTL_EXCEPTION
16283  {
16284    OTL_UNICODE_CHAR_TYPE s[2];
16285    s[0]=c;
16286    s[1]=0;
16287    (*this)<<s;
16288    return *this;
16289  }
16290 
16291 #endif
16292 
16293 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
16294  otl_stream& operator<<(const OTL_STRING_CONTAINER& s)
16295    OTL_THROWS_OTL_EXCEPTION
16296  {
16297    last_oper_was_read_op=false;
16298    reset_end_marker();
16299    OTL_TRACE_READ("\""<<s<<"\"","operator <<","OTL_STRING_CONTAINER&");
16300    switch(shell->stream_type){
16301    case otl_odbc_no_stream:
16302      break;
16303    case otl_odbc_io_stream:
16304      (*io)->operator<<(s);
16305      break;
16306    case otl_odbc_select_stream:
16307      (*ss)->operator<<(s);
16308      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16309      break;
16310    }
16311    inc_next_iov();
16312    return *this;
16313  }
16314 #endif
16315 
16316 #if defined(OTL_UNICODE_STRING_TYPE)
16317  otl_stream& operator<<(const OTL_UNICODE_STRING_TYPE& s)
16318    OTL_THROWS_OTL_EXCEPTION
16319  {
16320    last_oper_was_read_op=false;
16321    reset_end_marker();
16322    OTL_TRACE_READ("\""<<s.c_str()<<"\"","operator <<","OTL_UNICODE_STRING_TYPE&");
16323    switch(shell->stream_type){
16324    case otl_odbc_no_stream:
16325      break;
16326    case otl_odbc_io_stream:
16327      (*io)->operator<<(s);
16328      break;
16329    case otl_odbc_select_stream:
16330      (*ss)->operator<<(s);
16331      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16332      break;
16333    }
16334    inc_next_iov();
16335    return *this;
16336  }
16337 #endif
16338 
16339 #if !defined(OTL_UNICODE)
16340  otl_stream& operator<<(const char* s)
16341    OTL_THROWS_OTL_EXCEPTION
16342  {
16343    last_oper_was_read_op=false;
16344    reset_end_marker();
16345    OTL_TRACE_READ("\""<<s<<"\"","operator <<","char*");
16346    switch(shell->stream_type){
16347    case otl_odbc_no_stream:
16348      break;
16349    case otl_odbc_io_stream:
16350      (*io)->operator<<(s);
16351      break;
16352    case otl_odbc_select_stream:
16353      (*ss)->operator<<(s);
16354      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16355      break;
16356    }
16357    inc_next_iov();
16358    return *this;
16359  }
16360 #endif
16361 
16362  otl_stream& operator<<(const unsigned char* s)
16363    OTL_THROWS_OTL_EXCEPTION
16364  {
16365    last_oper_was_read_op=false;
16366    reset_end_marker();
16367 #if defined(OTL_UNICODE)
16368    OTL_TRACE_READ
16369      ("\""<<OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
16370       "operator <<",
16371       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*");
16372 #else
16373    OTL_TRACE_READ("\""<<s<<"\"","operator <<","unsigned char*");
16374 #endif
16375    switch(shell->stream_type){
16376    case otl_odbc_no_stream:
16377      break;
16378    case otl_odbc_io_stream:
16379      (*io)->operator<<(s);
16380      break;
16381    case otl_odbc_select_stream:
16382      (*ss)->operator<<(s);
16383      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16384      break;
16385    }
16386    inc_next_iov();
16387    return *this;
16388  }
16389 
16390  otl_stream& operator<<(const int n)
16391    OTL_THROWS_OTL_EXCEPTION
16392  {
16393    last_oper_was_read_op=false;
16394    reset_end_marker();
16395    OTL_TRACE_READ(n,"operator <<","int");
16396    switch(shell->stream_type){
16397    case otl_odbc_no_stream:
16398      break;
16399    case otl_odbc_io_stream:
16400 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16401      (*io)->operator<<(n);
16402 #else
16403      (*io)->operator<<<int,otl_var_int>(n);
16404 #endif
16405      break;
16406    case otl_odbc_select_stream:
16407 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16408      (*ss)->operator<<(n);
16409 #else
16410      (*ss)->operator<<<int,otl_var_int>(n);
16411 #endif
16412      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16413      break;
16414    }
16415    inc_next_iov();
16416    return *this;
16417  }
16418 
16419 #if defined(OTL_BIGINT)
16420  otl_stream& operator<<(const OTL_BIGINT n)
16421    OTL_THROWS_OTL_EXCEPTION
16422  {
16423    last_oper_was_read_op=false;
16424    reset_end_marker();
16425 #if defined(_MSC_VER) && defined(OTL_TRACE_LEVEL)
16426    // VC ++
16427    {
16428      char temp_str[otl_bigint_str_size];
16429      _i64toa(n,temp_str,10);
16430      OTL_TRACE_READ(temp_str,"operator <<","BIGINT")
16431    }
16432 #elif !defined(_MSC_VER) && defined(OTL_TRACE_LEVEL)
16433    OTL_TRACE_READ(n,"operator <<","BIGINT");
16434 #endif
16435    switch(shell->stream_type){
16436    case otl_odbc_no_stream:
16437      break;
16438    case otl_odbc_io_stream:
16439 #if defined(OTL_STR_TO_BIGINT) && defined(OTL_BIGINT_TO_STR)
16440      {
16441        otl_var_desc* var_desc=describe_next_in_var();
16442        if(var_desc){
16443          if(var_desc->ftype==otl_var_char){
16444            char temp_val[otl_bigint_str_size];
16445            OTL_BIGINT_TO_STR(n,temp_val);
16446 #if defined(OTL_UNICODE)
16447            OTL_CHAR unitemp_val[otl_bigint_str_size];
16448            OTL_CHAR* uc=unitemp_val;
16449            char* c=temp_val;
16450            while(*c){
16451              *uc=OTL_SCAST(OTL_CHAR,*c);
16452              ++c; ++uc;
16453            }
16454            *uc=0;
16455            (*io)->operator<<(OTL_RCAST(const unsigned char*,unitemp_val));
16456 #else
16457            (*io)->operator<<(temp_val);
16458 #endif
16459          }else
16460 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16461            (*io)->operator<<(n);
16462 #else
16463            (*io)->operator<<<OTL_BIGINT,otl_var_bigint>(n);
16464 #endif
16465        }
16466      }
16467 #else
16468 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16469      (*io)->operator<<(n);
16470 #else
16471      (*io)->operator<<<OTL_BIGINT,otl_var_bigint>(n);
16472 #endif
16473 #endif
16474      break;
16475    case otl_odbc_select_stream:
16476 #if defined(OTL_STR_TO_BIGINT) && defined(OTL_BIGINT_TO_STR)
16477      {
16478        otl_var_desc* var_desc=describe_next_in_var();
16479        if(var_desc){
16480          if(var_desc->ftype==otl_var_char){
16481            char temp_val[otl_bigint_str_size];
16482            OTL_BIGINT_TO_STR(n,temp_val);
16483            (*ss)->operator<<(temp_val);
16484          }else
16485 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16486            (*ss)->operator<<(n);
16487 #else
16488            (*ss)->operator<<<OTL_BIGINT,otl_var_bigint>(n);
16489 #endif
16490        }
16491      }
16492 #else
16493 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16494      (*ss)->operator<<(n);
16495 #else
16496      (*ss)->operator<<<OTL_BIGINT,otl_var_bigint>(n);
16497 #endif
16498 #endif
16499      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16500      break;
16501    }
16502    inc_next_iov();
16503    return *this;
16504  }
16505 #endif
16506 
16507  otl_stream& operator<<(const unsigned u)
16508    OTL_THROWS_OTL_EXCEPTION
16509  {
16510    last_oper_was_read_op=false;
16511    reset_end_marker();
16512    OTL_TRACE_READ(u,"operator <<","unsigned int");
16513    switch(shell->stream_type){
16514    case otl_odbc_no_stream:
16515      break;
16516    case otl_odbc_io_stream:
16517 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16518      (*io)->operator<<(u);
16519 #else
16520      (*io)->operator<<<unsigned,otl_var_unsigned_int>(u);
16521 #endif
16522      break;
16523    case otl_odbc_select_stream:
16524 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16525      (*ss)->operator<<(u);
16526 #else
16527      (*ss)->operator<<<unsigned,otl_var_unsigned_int>(u);
16528 #endif
16529      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16530      break;
16531    }
16532    inc_next_iov();
16533    return *this;
16534  }
16535 
16536  otl_stream& operator<<(const short sh)
16537    OTL_THROWS_OTL_EXCEPTION
16538  {
16539    last_oper_was_read_op=false;
16540    reset_end_marker();
16541    OTL_TRACE_READ(sh,"operator <<","short int");
16542    switch(shell->stream_type){
16543    case otl_odbc_no_stream:
16544      break;
16545    case otl_odbc_io_stream:
16546 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16547      (*io)->operator<<(sh);
16548 #else
16549      (*io)->operator<<<short,otl_var_short>(sh);
16550 #endif
16551      break;
16552    case otl_odbc_select_stream:
16553 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16554      (*ss)->operator<<(sh);
16555 #else
16556      (*ss)->operator<<<short,otl_var_short>(sh);
16557 #endif
16558      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16559      break;
16560    }
16561    inc_next_iov();
16562    return *this;
16563  }
16564 
16565  otl_stream& operator<<(const long int l)
16566    OTL_THROWS_OTL_EXCEPTION
16567  {
16568    last_oper_was_read_op=false;
16569    reset_end_marker();
16570    OTL_TRACE_READ(l,"operator <<","long int");
16571    switch(shell->stream_type){
16572    case otl_odbc_no_stream:
16573      break;
16574    case otl_odbc_io_stream:
16575 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16576      (*io)->operator<<(l);
16577 #else
16578      (*io)->operator<<<long,otl_var_long_int>(l);
16579 #endif
16580      break;
16581    case otl_odbc_select_stream:
16582 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16583      (*ss)->operator<<(l);
16584 #else
16585      (*ss)->operator<<<long,otl_var_long_int>(l);
16586 #endif
16587      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16588      break;
16589    }
16590    inc_next_iov();
16591    return *this;
16592  }
16593 
16594  otl_stream& operator<<(const float f)
16595    OTL_THROWS_OTL_EXCEPTION
16596  {
16597    last_oper_was_read_op=false;
16598    reset_end_marker();
16599    OTL_TRACE_READ(f,"operator <<","float");
16600    switch(shell->stream_type){
16601    case otl_odbc_no_stream:
16602      break;
16603    case otl_odbc_io_stream:
16604 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16605      (*io)->operator<<(f);
16606 #else
16607      (*io)->operator<<<float,otl_var_float>(f);
16608 #endif
16609      break;
16610    case otl_odbc_select_stream:
16611 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16612      (*ss)->operator<<(f);
16613 #else
16614      (*ss)->operator<<<float,otl_var_float>(f);
16615 #endif
16616      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16617      break;
16618    }
16619    inc_next_iov();
16620    return *this;
16621  }
16622 
16623  otl_stream& operator<<(const double d)
16624    OTL_THROWS_OTL_EXCEPTION
16625  {
16626    last_oper_was_read_op=false;
16627    reset_end_marker();
16628    OTL_TRACE_READ(d,"operator <<","double");
16629    switch(shell->stream_type){
16630    case otl_odbc_no_stream:
16631      break;
16632    case otl_odbc_io_stream:
16633 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16634      (*io)->operator<<(d);
16635 #else
16636      (*io)->operator<<<double,otl_var_double>(d);
16637 #endif
16638      break;
16639    case otl_odbc_select_stream:
16640 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
16641      (*ss)->operator<<(d);
16642 #else
16643      (*ss)->operator<<<double,otl_var_double>(d);
16644 #endif
16645      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16646      break;
16647    }
16648    inc_next_iov();
16649    return *this;
16650  }
16651 
16652   otl_stream& operator<<(const otl_null& n)
16653     OTL_THROWS_OTL_EXCEPTION
16654  {
16655    last_oper_was_read_op=false;
16656    reset_end_marker();
16657    OTL_TRACE_READ("NULL","operator <<","otl_null&");
16658    switch(shell->stream_type){
16659    case otl_odbc_no_stream:
16660      break;
16661    case otl_odbc_io_stream:
16662      (*io)->operator<<(n);
16663      break;
16664    case otl_odbc_select_stream:
16665      (*ss)->operator<<(n);
16666      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16667      break;
16668    }
16669   inc_next_iov();
16670   return *this;
16671  }
16672 
16673  otl_stream& operator<<(const otl_long_string& d)
16674    OTL_THROWS_OTL_EXCEPTION
16675  {
16676    last_oper_was_read_op=false;
16677    reset_end_marker();
16678    OTL_TRACE_READ(" len= "<<d.len(),"operator <<","otl_long_string&");
16679    switch(shell->stream_type){
16680    case otl_odbc_no_stream:
16681      break;
16682    case otl_odbc_io_stream:
16683      (*io)->operator<<(d);
16684      break;
16685    case otl_odbc_select_stream:
16686      (*ss)->operator<<(d);
16687      if(!(*ov)&&(*ss)->get_sl()) create_var_desc();
16688      break;
16689    }
16690    inc_next_iov();
16691    return *this;
16692  }
16693 
16694 private:
16695 
16696   otl_stream& operator=(const otl_stream&)
16697   {
16698     return *this;
16699   }
16700 
16701   otl_stream(const otl_stream&):
16702    shell(0),
16703    shell_pt(),
16704    connected(0),
16705    ss(0),
16706    io(0),
16707    adb(0),
16708    auto_commit_flag(0),
16709    iov(0),
16710    iov_len(0),
16711    next_iov_ndx(0),
16712    ov(0),
16713    ov_len(0),
16714    next_ov_ndx(0),
16715    override(0),
16716    end_marker(0),
16717    oper_int_called(0),
16718    last_eof_rc(0),
16719    last_oper_was_read_op(false),
16720    buf_size_(0)
16721   {
16722   }
16723 
16724 #if !defined(OTL_STREAM_NO_PRIVATE_BOOL_OPERATORS)
16725   otl_stream& operator>>(bool&)
16726     OTL_NO_THROW
16727   {
16728    return *this;
16729   }
16730 
16731   otl_stream& operator<<(const bool)
16732     OTL_NO_THROW
16733   {
16734    return *this;
16735   }
16736 
16737 #endif
16738 
16739 #if !defined(OTL_STREAM_NO_PRIVATE_UNSIGNED_LONG_OPERATORS)
16740   otl_stream& operator>>(unsigned long int&)
16741     OTL_NO_THROW
16742   {
16743    return *this;
16744   }
16745 
16746   otl_stream& operator<<(const unsigned long int)
16747     OTL_NO_THROW
16748   {
16749    return *this;
16750   }
16751 #endif
16752 
16753 };
16754 
16755 inline otl_connect& operator>>(otl_connect& connect, otl_stream& s)
16756 {
16757   const char* cmd=connect.getCmd();
16758   const char* invalid_cmd="*** INVALID COMMAND ***";
16759   if(!cmd)
16760     cmd=invalid_cmd;
16761   s.open(s.getBufSize(),cmd,connect);
16762   return connect;
16763 }
16764 
16765 #if (defined(OTL_STL)||defined(OTL_VALUE_TEMPLATE_ON)) && defined(OTL_VALUE_TEMPLATE)
16766 template <OTL_TYPE_NAME TData>
16767 otl_stream& operator<<(otl_stream& s, const otl_value<TData>& var)
16768   OTL_THROWS_OTL_EXCEPTION
16769 {
16770  if(var.ind)
16771   s<<otl_null();
16772  else
16773   s<<var.v;
16774  return s;
16775 }
16776 
16777 template <OTL_TYPE_NAME TData>
16778 otl_stream& operator>>(otl_stream& s, otl_value<TData>& var)
16779   OTL_THROWS_OTL_EXCEPTION
16780 {
16781   s>>var.v;
16782   if(s.is_null())
16783     var.ind=true;
16784   else
16785     var.ind=false;
16786   return s;
16787 }
16788 
16789 #endif
16790 
16791 
16792 class otl_nocommit_stream: public otl_stream{
16793 public:
16794 
16795  otl_nocommit_stream() OTL_NO_THROW
16796    : otl_stream()
16797  {
16798   set_commit(0);
16799  }
16800 
16801  otl_nocommit_stream
16802  (const otl_stream_buffer_size_type arr_size,
16803   const char* sqlstm,
16804   otl_connect& db,
16805   const int implicit_select=otl_explicit_select)
16806    OTL_THROWS_OTL_EXCEPTION
16807   : otl_stream(arr_size,sqlstm,db,implicit_select)
16808  {
16809   set_commit(0);
16810  }
16811 
16812  void open
16813  (otl_stream_buffer_size_type arr_size,
16814   const char* sqlstm,
16815   otl_connect& db,
16816   const int implicit_select=otl_explicit_select)
16817    OTL_THROWS_OTL_EXCEPTION
16818  {
16819   otl_stream::open(arr_size,sqlstm,db,implicit_select);
16820   set_commit(0);
16821  }
16822 
16823 };
16824 
16825 inline otl_stream& endr(otl_stream& s)
16826 {
16827   s.check_end_of_row();
16828   return s;
16829 }
16830 
16831 OTL_ODBC_NAMESPACE_END
16832 #endif
16833 
16834 // ==================== OTL-Adapter for Oracle 7 =====================
16835 #if defined(OTL_ORA7)
16836 
16837 #if defined(OTL_UNICODE)
16838 #error OTL_ORA7 and OTL_UNICODE are incompatible
16839 #endif
16840 
16841 #if defined(OTL_ORA_TEXT_ON)
16842 #define text OTL_ORA_TEXT
16843 #endif
16844 
16845 extern "C"{
16846 #include <ociapr.h>
16847 }
16848 
16849 OTL_ORA7_NAMESPACE_BEGIN
16850 
16851  const int inVarChar2=1;
16852  const int inNumber=2;
16853  const int inLong=8;
16854  const int inRowId=11;
16855  const int inDate=12;
16856  const int inRaw=23;
16857  const int inLongRaw=24;
16858  const int inChar=96;
16859  const int inMslabel=106;
16860 
16861  const int  extVarChar2=inVarChar2;
16862  const int  extNumber=inNumber;
16863  const int  extInt=3;
16864  const int  extFloat=4;
16865  const int  extCChar=5;
16866  const int  extVarNum=6;
16867  const int  extLong=inLong;
16868  const int  extVarChar=9;
16869  const int  extRowId=inRowId;
16870  const int  extDate=inDate;
16871  const int  extVarRaw=15;
16872  const int  extRaw=extVarRaw;
16873  const int  extLongRaw=inLongRaw;
16874  const int  extUInt=68;
16875  const int  extLongVarChar=94;
16876  const int  extLongVarRaw=95;
16877  const int  extChar=inChar;
16878  const int  extCharZ=97;
16879  const int  extMslabel=inMslabel;
16880 
16881 typedef otl_oracle_date otl_time0;
16882 
16883 class otl_exc{
16884 public:
16885  unsigned char msg[1000];
16886  int code;
16887  char sqlstate[32];
16888 
16889 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
16890   int error_offset;
16891 #endif
16892 
16893 #if defined(OTL_EXTENDED_EXCEPTION)
16894  char** msg_arr;
16895  char** sqlstate_arr;
16896  int* code_arr;
16897  int arr_len;
16898 #endif
16899 
16900 
16901  enum{disabled=0,enabled=1};
16902 
16903   otl_exc():
16904     msg(),
16905     code(0),
16906     sqlstate()
16907 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
16908     ,error_offset(0)
16909 #endif
16910 #if defined(OTL_EXTENDED_EXCEPTION)
16911     ,msg_arr(0),
16912     sqlstate_arr(0),
16913     code_arr(0),
16914     arr_len(0)
16915 #endif
16916  {
16917   sqlstate[0]=0;
16918   msg[0]=0;
16919   code=0;
16920 #if defined(OTL_EXTENDED_EXCEPTION)
16921   msg_arr=0;
16922   sqlstate_arr=0;
16923   code_arr=0;
16924   arr_len=0;
16925 #endif
16926  }
16927 
16928   virtual ~otl_exc(){}
16929 
16930  void init(const char* amsg, const int acode)
16931  {
16932   OTL_STRCPY_S(OTL_RCAST(char*,msg),sizeof(msg),amsg);
16933   code=acode;
16934 #if defined(OTL_EXTENDED_EXCEPTION)
16935   msg_arr=0;
16936   sqlstate_arr=0;
16937   code_arr=0;
16938   arr_len=0;
16939 #endif
16940  }
16941 
16942 };
16943 
16944 class otl_cur;
16945 
16946 class otl_conn{
16947 private:
16948 
16949   friend class otl_cur;
16950   Lda_Def* lda;
16951   unsigned char hda[512];
16952   int extern_lda;
16953 
16954 public:
16955 
16956   int get_connection_type(void)
16957   {
16958     return 0;
16959   }
16960 
16961   void cleanup(void){}
16962 
16963  static int initialize(const int threaded_mode=0)
16964  {
16965   if(threaded_mode)
16966    return !opinit(1);
16967   else
16968    return 1;
16969  }
16970 
16971   otl_conn():
16972     lda(new Lda_Def),
16973     hda(),
16974     extern_lda(0)
16975  {
16976   memset(lda,0,sizeof(*lda));
16977   memset(hda,0,sizeof(hda));
16978  }
16979 
16980  virtual ~otl_conn()
16981  {
16982   delete lda;
16983  }
16984 
16985   void set_timeout(const int /*atimeout*/=0){}
16986   void set_cursor_type(const int /*acursor_type*/=0){}
16987 
16988  int ext_logon(Lda_Def* ext_lda,const int auto_commit)
16989  {int rc;
16990   if(!extern_lda)delete lda;
16991   lda=ext_lda;
16992   extern_lda=1;
16993   if(auto_commit){
16994    rc=ocon(lda);
16995    if(rc)
16996     return 0;
16997    else
16998     return 1;
16999   }
17000   return 1;
17001  }
17002 
17003  int rlogon(const char* connect_str,const int auto_commit)
17004  {
17005   if(!extern_lda)delete lda;
17006   OTL_TRACE_RLOGON_ORA7
17007     (0x1,
17008      "otl_connect",
17009      "rlogon",
17010      connect_str,
17011      auto_commit)
17012   lda=new Lda_Def;
17013   extern_lda=0;
17014   memset(lda,0,sizeof(*lda));
17015   memset(hda,0,sizeof(hda));
17016   int rc=olog(lda,
17017               hda,
17018               OTL_RCAST(unsigned char*,OTL_CCAST(char*,connect_str)),
17019               -1,
17020               0,
17021               -1,
17022               0,
17023               -1,
17024               0
17025              );
17026   if(rc)return 0;
17027   if(!auto_commit)return 1;
17028   rc=ocon(lda);
17029   if(rc)
17030    return 0;
17031   else
17032    return 1;
17033  }
17034 
17035  int logoff(void)
17036  {
17037   if(extern_lda){
17038    lda=0;
17039    extern_lda=0;
17040    return 1;
17041   }else{
17042    if(!lda)return 1;
17043    if(lda->rc==3113||lda->rc==1041||lda->rc==1033||lda->rc==1034){
17044     delete lda;
17045     lda=0;
17046     return 1;
17047    }
17048    int rc=ologof(lda);
17049    delete lda;
17050    lda=0;
17051    return !rc;
17052   }
17053  }
17054 
17055  void error(otl_exc& exception_struct)
17056  {
17057   if(!lda){
17058    exception_struct.code=3113;
17059    OTL_STRCPY_S(OTL_RCAST(char*,exception_struct.msg),
17060                 sizeof(exception_struct.msg),
17061                 "ORA-03113: end-of-file on communication channel"
17062                );
17063    return;
17064   }
17065   size_t len;
17066   exception_struct.code=lda->rc;
17067   oerhms
17068    (lda,
17069     lda->rc,
17070     exception_struct.msg,
17071     sizeof(exception_struct.msg)
17072     );
17073   len = strlen(OTL_RCAST(const char*,exception_struct.msg));
17074   exception_struct.msg[len]=0;
17075  }
17076 
17077  int commit(void)
17078  {
17079   return !ocom(lda);
17080  }
17081 
17082  int auto_commit_on(void)
17083  {
17084   return !ocon(lda);
17085  }
17086 
17087  int auto_commit_off(void)
17088  {
17089   return !ocof(lda);
17090  }
17091 
17092  int rollback(void)
17093  {
17094   return !orol(lda);
17095  }
17096 
17097 private:
17098 
17099   otl_conn(const otl_conn&):
17100     lda(0),
17101     hda(),
17102     extern_lda(0)
17103   {
17104   }
17105 
17106   otl_conn& operator=(const otl_conn&)
17107   {
17108     return *this;
17109   }
17110 
17111 };
17112 
17113 class otl_cur;
17114 
17115 class otl_var{
17116 private:
17117 
17118   friend class otl_cur;
17119   ub1* p_v;
17120   sb2* p_ind;
17121   ub2* p_rlen;
17122   ub2* p_rcode;
17123   int ftype;
17124   int act_elem_size;
17125   int array_size;
17126   ub4 max_tab_len;
17127   ub4 cur_tab_len;
17128   int pl_tab_flag;
17129   int vparam_type;
17130   int lob_len;
17131   int lob_pos;
17132   int lob_ftype;
17133   int otl_adapter;
17134   bool lob_stream_mode;
17135   bool charz_flag;
17136   sb2 null_ind;
17137 
17138 public:
17139 
17140   int get_otl_adapter() const {return otl_adapter;}
17141   void set_lob_stream_mode(const bool alob_stream_mode)
17142   {
17143     lob_stream_mode=alob_stream_mode;
17144   }
17145 
17146   void set_vparam_type(const int avparam_type)
17147   {
17148     vparam_type=avparam_type;
17149   }
17150 
17151   void set_charz_flag(const bool acharz_flag)
17152   {
17153     charz_flag=acharz_flag;
17154   }
17155 
17156   otl_var():
17157     p_v(0),
17158     p_ind(0),
17159     p_rlen(0),
17160     p_rcode(0),
17161     ftype(0),
17162     act_elem_size(0),
17163     array_size(0),
17164     max_tab_len(0),
17165     cur_tab_len(0),
17166     pl_tab_flag(0),
17167     vparam_type(-1),
17168     lob_len(0),
17169     lob_pos(0),
17170     lob_ftype(0),
17171     otl_adapter(otl_ora7_adapter),
17172     lob_stream_mode(false),
17173     charz_flag(false),
17174     null_ind(0)
17175  {
17176  }
17177 
17178  virtual ~otl_var()
17179  {
17180   delete[] p_v;
17181   delete[] p_ind;
17182   delete[] p_rlen;
17183   delete[] p_rcode;
17184  }
17185 
17186   int write_dt(void* trg, const void* src, const int sz)
17187   {
17188     memcpy(trg,src,sz);
17189     return 1;
17190   }
17191 
17192   int read_dt(void* trg, const void* src, const int sz)
17193   {
17194     memcpy(trg,src,sz);
17195     return 1;
17196   }
17197 
17198  int actual_elem_size(void)
17199  {
17200   return act_elem_size;
17201  }
17202 
17203  void init
17204  (const bool,
17205   const int aftype,
17206   int& aelem_size,
17207   const otl_stream_buffer_size_type aarray_size,
17208   const void* /*connect_struct*/=0,
17209   const int apl_tab_flag=0)
17210  {
17211    int i,elem_size;
17212    ftype=aftype;
17213    pl_tab_flag=apl_tab_flag;
17214    act_elem_size=aelem_size;
17215    if(aftype==otl_var_varchar_long||aftype==otl_var_raw_long){
17216      elem_size=aelem_size+sizeof(sb4);
17217      array_size=1;
17218    }else if(aftype==otl_var_raw){
17219      elem_size=aelem_size+sizeof(short int);
17220      array_size=aarray_size;
17221    }else{
17222      elem_size=aelem_size;
17223      array_size=aarray_size;
17224    }
17225 
17226    p_v=new ub1[elem_size*OTL_SCAST(unsigned,array_size)];
17227    p_ind=new sb2[array_size];
17228    p_rlen=new ub2[array_size];
17229    p_rcode=new ub2[array_size];
17230    memset(p_v,0,elem_size*OTL_SCAST(unsigned,array_size));
17231 
17232    if(aftype==otl_var_varchar_long||aftype==otl_var_raw_long){
17233      if(aelem_size>32760)
17234        p_ind[0]=0;
17235      else
17236        p_ind[0]=OTL_SCAST(short,aelem_size);
17237      p_rcode[0]=0;
17238    }else{
17239      for(i=0;i<array_size;++i){
17240        p_ind[i]=OTL_SCAST(short,aelem_size);
17241        p_rlen[i]=OTL_SCAST(short,elem_size);
17242        p_rcode[i]=0;
17243      }
17244    }
17245    max_tab_len=OTL_SCAST(ub4,array_size);
17246    cur_tab_len=OTL_SCAST(ub4,array_size);
17247    switch(ftype){
17248    case otl_var_varchar_long:
17249    case otl_var_raw_long:
17250      null_ind=0;
17251      break;
17252    case otl_var_raw:
17253      null_ind=OTL_SCAST(short,aelem_size);
17254      break;
17255    default:
17256      null_ind=OTL_SCAST(short,aelem_size);
17257      break;
17258    }
17259  }
17260 
17261  void set_pl_tab_len(const int apl_tab_len)
17262  {
17263   max_tab_len=OTL_SCAST(ub4,array_size);
17264   cur_tab_len=OTL_SCAST(ub4,apl_tab_len);
17265  }
17266 
17267  int get_pl_tab_len(void)
17268  {
17269   return OTL_SCAST(int,cur_tab_len);
17270  }
17271 
17272  int get_max_pl_tab_len(void)
17273  {
17274   return OTL_SCAST(int,max_tab_len);
17275  }
17276 
17277  int put_blob(void)
17278  {
17279   return 1;
17280  }
17281 
17282  int get_blob
17283  (const int /* ndx */,
17284   unsigned char* /* abuf */,
17285   const int /* buf_size */,
17286   int& /* len */)
17287  {
17288   return 1;
17289  }
17290 
17291  int save_blob
17292  (const unsigned char* /* abuf */,
17293   const int /* len */,
17294   const int /* extern_buffer_flag */)
17295  {
17296   return 1;
17297  }
17298 
17299  void set_null(int ndx)
17300  {
17301   p_ind[ndx]=-1;
17302  }
17303 
17304   void set_not_null(int ndx, int /*pelem_size*/)
17305  {
17306    p_ind[ndx]=null_ind;
17307  }
17308 
17309  void set_len(int len, int ndx)
17310  {
17311    switch(ftype){
17312    case otl_var_varchar_long:
17313    case otl_var_raw_long:
17314      *OTL_RCAST(sb4*,p_v)=len;
17315      break;
17316    default:
17317      p_rlen[ndx]=OTL_SCAST(short,len);
17318    }
17319  }
17320 
17321 
17322  int get_len(int ndx)
17323  {
17324   if(ftype==otl_var_varchar_long||ftype==otl_var_raw_long)
17325    return *OTL_RCAST(sb4*,p_v);
17326   else
17327    return p_rlen[ndx];
17328  }
17329 
17330  int is_null(int ndx)
17331  {
17332   return p_ind[ndx]==-1;
17333  }
17334 
17335  void* val(int ndx,int pelem_size)
17336  {
17337    switch(ftype){
17338    case otl_var_varchar_long:
17339    case otl_var_raw_long:
17340      return OTL_RCAST(void*,(p_v+sizeof(sb4)));
17341    case otl_var_raw:
17342      return OTL_RCAST(void*,&p_v[(OTL_SCAST(unsigned,ndx))*
17343                                  (pelem_size+sizeof(short int))]);
17344    default:
17345      return OTL_RCAST(void*,&p_v[(OTL_SCAST(unsigned,ndx))*pelem_size]);
17346    }
17347  }
17348 
17349  static int int2ext(int int_type)
17350  {
17351   switch(int_type){
17352   case inVarChar2: return extCChar;
17353   case inNumber:   return extFloat;
17354   case inLong:     return extLongVarChar;
17355   case inRowId:    return extCChar;
17356   case inDate:     return extDate;
17357   case inRaw:      return extRaw;
17358   case inLongRaw:  return extLongVarRaw;
17359   case inChar:     return extCChar;
17360   default:
17361    return otl_unsupported_type;
17362   }
17363  }
17364 
17365  static int datatype_size(int aftype,int maxsz,int int_type,int max_long_size)
17366  {
17367   switch(aftype){
17368   case extCChar:
17369    switch(int_type){
17370    case inRowId:
17371     return 30;
17372    case inDate:
17373     return otl_oracle_date_size;
17374    case inRaw:
17375      return max_long_size;
17376    default:
17377     return maxsz+1;
17378    }
17379   case extLongVarChar:
17380    return max_long_size;
17381   case extLongVarRaw:
17382    return max_long_size;
17383   case extFloat:
17384    return sizeof(double);
17385   case extDate:
17386    return otl_oracle_date_size;
17387   case extRaw:
17388     return maxsz;
17389   default:
17390    return 0;
17391   }
17392  }
17393 
17394  static void map_ftype
17395  (otl_column_desc& desc,
17396   const int max_long_size,
17397   int& aftype,
17398   int& elem_size,
17399   otl_select_struct_override& override,
17400   const int column_ndx,
17401   const int /*connection_type*/)
17402  {int ndx=override.find(column_ndx);
17403   if(ndx==-1){
17404    aftype=int2ext(desc.dbtype);
17405    elem_size=datatype_size
17406      (aftype,
17407       OTL_SCAST(int,desc.dbsize),
17408       desc.dbtype,
17409       max_long_size);
17410    switch(aftype){
17411    case extCChar:
17412     aftype=otl_var_char;
17413     break;
17414    case extRaw:
17415     aftype=otl_var_raw;
17416     break;
17417    case extFloat:
17418      if(override.get_all_mask() & otl_all_num2str){
17419      aftype=otl_var_char;
17420      elem_size=otl_num_str_size;
17421     }else
17422      aftype=otl_var_double;
17423     break;
17424    case extLongVarChar:
17425     aftype=otl_var_varchar_long;
17426     break;
17427    case extLongVarRaw:
17428     aftype=otl_var_raw_long;
17429     break;
17430    case extDate:
17431      if(override.get_all_mask() & otl_all_date2str){
17432      aftype=otl_var_char;
17433      elem_size=otl_date_str_size;
17434     }else
17435      aftype=otl_var_timestamp;
17436     break;
17437    }
17438   }else{
17439     aftype=override.get_col_type(ndx);
17440    switch(aftype){
17441    case otl_var_char:
17442      elem_size=override.get_col_size(ndx);
17443      break;
17444    case otl_var_raw:
17445      elem_size=override.get_col_size(ndx);
17446      break;
17447    case otl_var_double:
17448      elem_size=sizeof(double);
17449      break;
17450    case otl_var_float:
17451      elem_size=sizeof(float);
17452      break;
17453    case otl_var_int:
17454      elem_size=sizeof(int);
17455      break;
17456    case otl_var_unsigned_int:
17457      elem_size=sizeof(unsigned);
17458      break;
17459    case otl_var_short:
17460      elem_size=sizeof(short);
17461      break;
17462    case otl_var_long_int:
17463      elem_size=sizeof(long);
17464      break;
17465    default:
17466      elem_size=override.get_col_size(ndx);
17467      break;
17468    }
17469   }
17470   desc.otl_var_dbtype=aftype;
17471  }
17472 
17473 private:
17474 
17475   otl_var(const otl_var&):
17476     p_v(0),
17477     p_ind(0),
17478     p_rlen(0),
17479     p_rcode(0),
17480     ftype(0),
17481     act_elem_size(0),
17482     array_size(0),
17483     max_tab_len(0),
17484     cur_tab_len(0),
17485     pl_tab_flag(0),
17486     vparam_type(-1),
17487     lob_len(0),
17488     lob_pos(0),
17489     lob_ftype(0),
17490     otl_adapter(otl_ora7_adapter),
17491     lob_stream_mode(false),
17492     charz_flag(false),
17493     null_ind(0)
17494  {
17495  }
17496 
17497  otl_var& operator=(const otl_var&)
17498  {
17499    return *this;
17500  }
17501 
17502 };
17503 
17504 class otl_sel;
17505 class otl_ref_cursor;
17506 class otl_ref_select_stream;
17507 
17508 class otl_cur{
17509 private:
17510 
17511   friend class otl_sel;
17512   friend class otl_ref_cursor;
17513   friend class otl_ref_select_stream;
17514 
17515   Cda_Def cda;
17516 
17517   ub4* rpc; // reference to "rows processed count"
17518   ub2* ft; // reference to "OCI function code"
17519   ub2* rc; // reference to "V7 return code"
17520   ub2* peo; // reference to "parse error offset"
17521   int last_param_data_token;
17522   int last_sql_param_data_status;
17523   int sql_param_data_count;
17524   bool canceled;
17525 
17526 public:
17527 
17528   void set_canceled(const bool acanceled)
17529   {
17530     canceled=acanceled;
17531   }
17532 
17533   void reset_last_param_data_token()
17534   {
17535     last_param_data_token=0;
17536   }
17537 
17538   void reset_last_sql_param_data_status()
17539   {
17540     last_sql_param_data_status=0;
17541   }
17542 
17543   void reset_sql_param_data_count()
17544   {
17545     sql_param_data_count=0;
17546   }
17547 
17548  otl_cur& operator=(const otl_cur& cur)
17549  {
17550   *rpc=*cur.rpc;
17551   *ft=*cur.ft;
17552   *rc=*cur.rc;
17553   *peo=*cur.peo;
17554   memcpy(OTL_RCAST(void*,&cda),
17555          OTL_RCAST(void*,OTL_CCAST(cda_def *,&cur.cda)),
17556          sizeof(cda));
17557   return *this;
17558  }
17559 
17560  otl_cur():
17561    cda(),
17562    rpc(&cda.rpc),
17563    ft(&cda.ft),
17564    rc(&cda.rc),
17565    peo(&cda.peo),
17566    last_param_data_token(),
17567    last_sql_param_data_status(0),
17568    sql_param_data_count(0),
17569    canceled(false)
17570  {
17571   memset(&cda,0,sizeof(cda));
17572  }
17573 
17574  virtual ~otl_cur(){}
17575 
17576   int open(otl_conn& /* connect */,otl_var* /* var */)
17577   {
17578     return 1;
17579   }
17580 
17581  long get_rpc()
17582  {
17583   return *rpc;
17584  }
17585 
17586   void set_direct_exec(const int /* flag */){}
17587   void set_parse_only(const int /*flag*/){}
17588 
17589 
17590  int open(otl_conn& connect)
17591  {
17592   memset(&cda,0,sizeof(cda));
17593   return !oopen(&cda,connect.lda,0,-1,-1,0,-1);
17594  }
17595 
17596  int close(void)
17597  {
17598   if(cda.rc==3113||cda.rc==1041||cda.rc==1033||cda.rc==1034)
17599    return 1;
17600   return !oclose(&cda);
17601  }
17602 
17603  int parse(const char* stm_text)
17604  {
17605   return !oparse(&cda,OTL_RCAST(unsigned char*,OTL_CCAST(char*,stm_text)),-1,0,1);
17606  }
17607 
17608   int exec(const int iters,
17609            const int /*rowoff*/,
17610            const int /*otl_sql_exec_from_class*/)
17611  {
17612   int temp_rc=oexn(&cda,iters,0);
17613   return !temp_rc;
17614  }
17615 
17616  int fetch(const otl_stream_buffer_size_type iters,int& eof_data)
17617  {int temp_rc=ofen(&cda,iters);
17618   eof_data=0;
17619   if(cda.rc==1403){
17620    eof_data=1;
17621    return 1;
17622   }else if(temp_rc==0)
17623    return 1;
17624   else
17625    return 0;
17626  }
17627 
17628  int tmpl_ftype2ora_ftype(const int ftype)
17629  {
17630    switch(ftype){
17631    case otl_var_char:
17632      return extCChar;
17633    case otl_var_double:
17634      return extFloat;
17635    case otl_var_float:
17636      return extFloat;
17637    case otl_var_int:
17638      return extInt;
17639    case otl_var_long_int:
17640      return extInt;
17641    case otl_var_unsigned_int:
17642      return extUInt;
17643    case otl_var_short:
17644      return extInt;
17645    case otl_var_timestamp:
17646      return extDate;
17647    case otl_var_varchar_long:
17648      return extLongVarChar;
17649    case otl_var_raw_long:
17650      return extLongVarRaw;
17651    case otl_var_raw:
17652      return extRaw;
17653    default:
17654      return 0;
17655    }
17656  }
17657 
17658  int bind
17659  (const char* name,
17660   otl_var& v,
17661   const int elem_size,
17662   const int ftype,
17663   const int /* param_type */,
17664   const int /* name_pos */,
17665   const int /*connection_type*/,
17666   const int apl_tab_flag)
17667  {
17668   if(apl_tab_flag)
17669    return !obndra(&cda,
17670                   OTL_RCAST(unsigned char*,OTL_CCAST(char*,name)),
17671                   -1,
17672                   OTL_RCAST(ub1*,v.p_v),
17673                   ftype==otl_var_raw?elem_size+sizeof(short):elem_size,
17674                   v.charz_flag?extCharZ:tmpl_ftype2ora_ftype(ftype),
17675                   -1,
17676                   v.p_ind,
17677                   v.p_rlen,
17678                   v.p_rcode,
17679                   v.max_tab_len,
17680                   &v.cur_tab_len,
17681                   0,
17682                   -1,
17683                   -1);
17684   else
17685    return !obndrv
17686     (&cda,
17687      OTL_RCAST(unsigned char*,OTL_CCAST(char*,name)),
17688      -1,
17689      OTL_RCAST(ub1*,v.p_v),
17690      ftype==otl_var_raw?elem_size+sizeof(short):elem_size,
17691      tmpl_ftype2ora_ftype(ftype),
17692      -1,
17693      v.p_ind,
17694      0,
17695      -1,
17696      -1);
17697  }
17698 
17699  int bind
17700  (const int column_num,
17701   otl_var& v,
17702   const int elem_size,
17703   const int ftype,
17704   const int /* param_type */)
17705  {
17706   return !odefin
17707    (&cda,
17708     column_num,
17709     OTL_RCAST(ub1*,v.p_v),
17710     ftype==otl_var_raw?elem_size+sizeof(short):elem_size,
17711     tmpl_ftype2ora_ftype(ftype),
17712     -1,
17713     v.p_ind,
17714     0,
17715     -1,
17716     -1,
17717     v.p_rlen,
17718     v.p_rcode);
17719  }
17720 
17721  int describe_column
17722  (otl_column_desc& col,
17723   const int column_num,
17724   int& eof_desc)
17725  {
17726   sb1  name[241];
17727   sb4  nlen;
17728   sb4  dbsize;
17729   sb2  dbtype;
17730 
17731   sb2  scale;
17732   sb2  prec;
17733   sb4  dsize;
17734   sb2  nullok;
17735 
17736   nlen=sizeof(name)-1;
17737   int temp_rc=odescr
17738    (&cda,
17739     column_num,
17740     &dbsize,
17741     &dbtype,
17742     &name[0],
17743     &nlen,
17744     &dsize,
17745     &prec,
17746     &scale,
17747     &nullok);
17748   if(temp_rc==0)name[nlen]=0;
17749   eof_desc=0;
17750   if(cda.rc==1007){
17751    eof_desc=1;
17752    return 0;
17753   }
17754   if(temp_rc==0){
17755     col.set_name(OTL_RCAST(char*,name));
17756    col.dbtype=dbtype;
17757    col.dbsize=dbsize;
17758    col.scale=scale;
17759    col.prec=prec;
17760    col.nullok=nullok;
17761    return 1;
17762   }else
17763    return 0;
17764  }
17765 
17766  void error(otl_exc& exception_struct)
17767  {
17768   size_t len;
17769   exception_struct.code=cda.rc;
17770   oerhms
17771    (&cda,
17772     cda.rc,
17773     exception_struct.msg,
17774     sizeof(exception_struct.msg)
17775     );
17776   len=strlen(OTL_RCAST(const char*,exception_struct.msg));
17777   exception_struct.msg[len]=0;
17778 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
17779   ub2 error_offset=cda.peo;
17780   exception_struct.error_offset=OTL_SCAST(int,error_offset);
17781 #endif
17782  }
17783 
17784 private:
17785 
17786  otl_cur(const otl_cur&):
17787    cda(),
17788    rpc(&cda.rpc),
17789    ft(&cda.ft),
17790    rc(&cda.rc),
17791    peo(&cda.peo),
17792    last_param_data_token(),
17793    last_sql_param_data_status(0),
17794    sql_param_data_count(0),
17795    canceled(false)
17796  {
17797  }
17798 
17799 };
17800 
17801 class otl_sel{
17802 private:
17803 
17804  int implicit_cursor;
17805 
17806 public:
17807 
17808   int get_implicit_cursor() const {return implicit_cursor;}
17809 
17810  void set_arr_size
17811  (const int input_arr_size,
17812   int& out_array_size,
17813   int& out_prefetch_array_size)
17814  {
17815    out_array_size=input_arr_size;
17816    out_prefetch_array_size=0;
17817  }
17818 
17819   void set_prefetch_size(const int /*aprefetch_array_size*/)
17820   {
17821   }
17822 
17823   int close_select(otl_cur& /* cur */)
17824   {
17825     int rc=1;
17826     return rc;
17827   }
17828 
17829  otl_sel():
17830    implicit_cursor(0)
17831  {
17832  }
17833 
17834  virtual ~otl_sel(){}
17835 
17836   void set_select_type(const int /* atype */)
17837  {
17838   implicit_cursor=0;
17839  }
17840 
17841   void init(const int /* array_size */){}
17842 
17843  int first
17844  (otl_cur& cur,
17845   int& cur_row,
17846   int& cur_size,
17847   int& row_count,
17848   int& eof_data,
17849   const int array_size)
17850  {int rc;
17851   eof_data=0;
17852   cur_row=-1;
17853   rc=cur.exec(1,0,otl_sql_exec_from_select_cursor_class);
17854   if(rc==0)return 0;
17855   rc=cur.fetch(OTL_SCAST(otl_stream_buffer_size_type,array_size),eof_data);
17856   if(rc==0)return 0;
17857   row_count=*cur.rpc;
17858   cur_size=row_count;
17859   if(cur_size!=0)cur_row=0;
17860   return 1;
17861  }
17862 
17863  int next
17864  (otl_cur& cur,
17865   int& cur_row,
17866   int& cur_size,
17867   int& row_count,
17868   int& eof_data,
17869   const int array_size)
17870  {int rc;
17871   if(cur_row<cur_size-1){
17872    ++cur_row;
17873    return 1;
17874   }else{
17875    if(eof_data){
17876     cur_row=-1;
17877     cur_size=0;
17878     return 1;
17879    }
17880    rc=cur.fetch(OTL_SCAST(otl_stream_buffer_size_type,array_size),eof_data);
17881    if(rc==0)return 0;
17882    cur_size=*cur.rpc-row_count;
17883    row_count=*cur.rpc;
17884    if(cur_size!=0)cur_row=0;
17885    return 1;
17886   }
17887  }
17888 
17889 };
17890 
17891 typedef otl_tmpl_connect
17892   <otl_exc,
17893    otl_conn,
17894    otl_cur> otl_ora7_connect;
17895 
17896 typedef otl_tmpl_cursor
17897   <otl_exc,
17898    otl_conn,
17899    otl_cur,
17900    otl_var> otl_cursor;
17901 
17902 typedef otl_tmpl_exception
17903   <otl_exc,
17904    otl_conn,
17905    otl_cur> otl_exception;
17906 
17907 typedef otl_tmpl_inout_stream
17908  <otl_exc,
17909   otl_conn,
17910   otl_cur,
17911   otl_var,
17912   otl_time0> otl_inout_stream;
17913 
17914 typedef otl_tmpl_select_stream
17915  <otl_exc,
17916   otl_conn,
17917   otl_cur,
17918   otl_var,
17919   otl_sel,
17920   otl_time0> otl_select_stream;
17921 
17922 
17923 typedef otl_tmpl_ext_hv_decl
17924  <otl_var,
17925   otl_time0,
17926   otl_exc,
17927   otl_conn,
17928   otl_cur> otl_ext_hv_decl;
17929 
17930 class otl_stream_shell;
17931 
17932 class otl_connect: public otl_ora7_connect{
17933 public:
17934 
17935 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
17936  otl_stream_pool sc;
17937 
17938  void set_stream_pool_size(const int max_size=otl_max_default_pool_size)
17939  {
17940   sc.init(max_size);
17941  }
17942 
17943 #endif
17944 
17945   long direct_exec
17946   (const char* sqlstm,
17947    const int exception_enabled=1)
17948    OTL_THROWS_OTL_EXCEPTION
17949   {
17950     return otl_cursor::direct_exec(*this,sqlstm,exception_enabled);
17951   }
17952 
17953   void syntax_check(const char* sqlstm)
17954    OTL_THROWS_OTL_EXCEPTION
17955   {
17956     otl_cursor::syntax_check(*this,sqlstm);
17957   }
17958 
17959  otl_connect() OTL_NO_THROW :
17960    otl_ora7_connect(), cmd_(0)
17961   {
17962   }
17963 
17964  otl_connect(const char* connect_str, const int aauto_commit=0)
17965    OTL_THROWS_OTL_EXCEPTION
17966    : otl_ora7_connect(connect_str, aauto_commit), cmd_(0)
17967   {
17968   }
17969 
17970   virtual ~otl_connect()
17971 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
17972     OTL_THROWS_OTL_EXCEPTION
17973 #endif
17974   {
17975     if(cmd_){
17976       delete[] cmd_;
17977       cmd_=0;
17978     }
17979 #if defined(OTL_DESTRUCTORS_DO_NOT_THROW)
17980     try{
17981       logoff();
17982     }catch(OTL_CONST_EXCEPTION otl_exception&){
17983     }
17984 #endif
17985   }
17986 
17987   void rlogon(Lda_Def* alda)
17988    OTL_THROWS_OTL_EXCEPTION
17989   {
17990     if(this->connected){
17991      throw otl_exception(otl_error_msg_30,otl_error_code_30);
17992     }
17993     if(cmd_){
17994       delete[] cmd_;
17995       cmd_=0;
17996     }
17997     connected=0;
17998     long_max_size=32760;
17999     retcode=connect_struct.ext_logon(alda,0);
18000     if(retcode)
18001       connected=1;
18002     else{
18003       connected=0;
18004       increment_throw_count();
18005       if(get_throw_count()>1)return;
18006       if(otl_uncaught_exception()) return;
18007       throw otl_exception(connect_struct);
18008     }
18009   }
18010 
18011  void rlogon(const char* connect_str, const int aauto_commit=0)
18012    OTL_THROWS_OTL_EXCEPTION
18013  {
18014     if(this->connected){
18015      throw otl_exception(otl_error_msg_30,otl_error_code_30);
18016     }
18017     otl_ora7_connect::rlogon(connect_str,aauto_commit);
18018  }
18019 
18020  void logoff(void)
18021  {
18022 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
18023   if(connected)
18024     sc.init(sc.get_max_size());
18025 #endif
18026   otl_ora7_connect::logoff();
18027  }
18028 
18029   const char* getCmd(void) const
18030   {
18031     return cmd_;
18032   }
18033 
18034   otl_connect& operator<<(const char* cmd)
18035   {
18036     if(!connected){
18037       this->rlogon(cmd);
18038     }else{
18039       otl_cursor::direct_exec(*this,cmd);
18040     }
18041     return *this;
18042   }
18043 
18044   otl_connect& operator<<=(const char* cmd)
18045   {
18046     if(cmd_){
18047       delete[] cmd_;
18048       cmd_=0;
18049     }
18050     size_t cmd_len=strlen(cmd);
18051     cmd_=new char[cmd_len+1];
18052     OTL_STRCPY_S(cmd_,cmd_len+1,cmd);
18053     return *this;
18054   }
18055 
18056 private:
18057 
18058   char* cmd_;
18059 
18060   otl_connect& operator=(const otl_connect&)
18061   {
18062     return *this;
18063   }
18064 
18065   otl_connect(const otl_connect&)
18066     :otl_ora7_connect(),cmd_(0){}
18067 
18068 };
18069 
18070 
18071 // ============ OTL Reference Cursor Streams for Oracle 7 =================
18072 
18073 typedef otl_tmpl_variable<otl_var> otl_generic_variable;
18074 typedef otl_generic_variable* otl_p_generic_variable;
18075 
18076 class otl_ref_select_stream;
18077 
18078 class otl_ref_cursor: public
18079 otl_tmpl_cursor
18080   <otl_exc,
18081    otl_conn,
18082    otl_cur,
18083    otl_var>{
18084 private:
18085 
18086   friend class otl_ref_select_stream;
18087   int cur_row;
18088   int cur_size;
18089   int row_count;
18090   int array_size;
18091   otl_select_struct_override local_override;
18092 
18093 public:
18094 
18095  otl_ref_cursor
18096  (otl_connect& db,
18097   const char* cur_placeholder_name,
18098   void* master_stream_ptr,
18099   const otl_stream_buffer_size_type arr_size=1)
18100   :otl_tmpl_cursor
18101   <otl_exc,
18102    otl_conn,
18103    otl_cur,
18104    otl_var>(db),
18105    cur_row(-1),
18106    cur_size(0),
18107    row_count(0),
18108    array_size(arr_size),
18109    local_override(),
18110    sel_cur(),
18111    rvl_len(otl_var_list_size),
18112    rvl(new otl_p_generic_variable[rvl_len]),
18113    vl_cur_len(0),
18114    cur_placeholder(),
18115    master_stream_ptr_(master_stream_ptr)
18116  {
18117   local_override.reset();
18118   for(int i=0;i<rvl_len;++i)
18119     rvl[i]=0;
18120   OTL_STRCPY_S(cur_placeholder,sizeof(cur_placeholder),cur_placeholder_name);
18121  }
18122 
18123  otl_ref_cursor():
18124   otl_tmpl_cursor
18125   <otl_exc,
18126    otl_conn,
18127    otl_cur,
18128    otl_var>(),
18129    cur_row(-1),
18130    cur_size(0),
18131    row_count(0),
18132    array_size(0),
18133    local_override(),
18134    sel_cur(),
18135    rvl_len(0),
18136    rvl(0),
18137    vl_cur_len(0),
18138    cur_placeholder(),
18139    master_stream_ptr_(0)
18140  {
18141    local_override.reset();
18142  }
18143 
18144  virtual ~otl_ref_cursor()
18145  {
18146   this->in_destructor=1;
18147   delete[] rvl;
18148   rvl=0;
18149  }
18150 
18151  void open
18152  (otl_connect& db,
18153   const char* cur_placeholder_name,
18154   const otl_stream_buffer_size_type arr_size=1)
18155  {
18156   int i;
18157   local_override.reset();
18158   cur_row=-1;
18159   row_count=0;
18160   cur_size=0;
18161   array_size=arr_size;
18162   rvl_len=otl_var_list_size;
18163   vl_cur_len=0;
18164   rvl=new otl_p_generic_variable[rvl_len];
18165   for(i=0;i<rvl_len;++i)rvl[i]=0;
18166   OTL_STRCPY_S(cur_placeholder,sizeof(cur_placeholder),cur_placeholder_name);
18167   otl_tmpl_cursor
18168   <otl_exc,
18169    otl_conn,
18170    otl_cur,
18171    otl_var>::open(db);
18172  }
18173 
18174  void close(void)
18175  {
18176    local_override.reset();
18177    delete[] rvl;
18178    rvl=0;
18179    if(sel_cur.get_connected() && sel_cur.get_adb()==0)
18180      sel_cur.set_adb(adb);
18181    sel_cur.close();
18182    otl_tmpl_cursor
18183      <otl_exc,
18184      otl_conn,
18185      otl_cur,
18186      otl_var>::close();
18187  }
18188 
18189  int first(void)
18190  {int i,rc;
18191   rc=obndrv
18192    (&this->cursor_struct.cda,
18193     OTL_RCAST(unsigned char*,cur_placeholder),
18194     -1,
18195     OTL_RCAST(ub1*,&sel_cur.get_cursor_struct_ref().cda),
18196     sizeof(sel_cur.get_cursor_struct_ref().cda),
18197     102,-1,0,0,-1,-1);
18198   if(rc!=0){
18199    if(this->adb)this->adb->increment_throw_count();
18200    if(this->adb&&this->adb->get_throw_count()>1)return 0;
18201   if(otl_uncaught_exception()) return 0;
18202    throw otl_exception(cursor_struct,stm_label?stm_label:stm_text);
18203   }
18204   if(cur_row==-2)
18205    ; // Special case -- calling describe_select() between parse() and first()
18206   else{
18207 // Executing the PLSQL master block
18208     exec(1,0,otl_sql_exec_from_select_cursor_class);
18209    sel_cur.set_connected(1);
18210   }
18211   cur_row=-1;
18212   for(i=0;i<vl_cur_len;++i)
18213    sel_cur.bind(i+1,*rvl[i]);
18214   rc=sel_cur.get_cursor_struct_ref().fetch
18215    (OTL_SCAST(otl_stream_buffer_size_type,array_size),
18216     sel_cur.get_eof_data_ref());
18217   if(rc==0){
18218    if(this->adb)this->adb->increment_throw_count();
18219    if(this->adb&&this->adb->get_throw_count()>1)return 0;
18220   if(otl_uncaught_exception()) return 0;
18221   throw otl_exception(sel_cur.get_cursor_struct_ref(),stm_label?stm_label:stm_text);
18222   }
18223   row_count=sel_cur.get_cursor_struct_ref().cda.rpc;
18224   OTL_TRACE_FIRST_FETCH
18225   cur_size=row_count;
18226   if(cur_size!=0)cur_row=0;
18227   return cur_size!=0;
18228  }
18229 
18230  int next(void)
18231  {int rc;
18232   if(cur_row<0)return first();
18233   if(cur_row<cur_size-1)
18234    ++cur_row;
18235   else{
18236     if(sel_cur.eof()){
18237       cur_row=-1;
18238       return 0;
18239     }
18240     rc=sel_cur.get_cursor_struct_ref().fetch
18241       (OTL_SCAST(otl_stream_buffer_size_type,array_size),
18242        sel_cur.get_eof_data_ref());
18243     if(rc==0){
18244       if(this->adb)this->adb->increment_throw_count();
18245       if(this->adb&&this->adb->get_throw_count()>1)return 0;
18246       if(otl_uncaught_exception()) return 0;
18247       throw otl_exception(sel_cur.get_cursor_struct_ref(),
18248                           stm_label?stm_label:stm_text);
18249     }
18250     cur_size=sel_cur.get_cursor_struct_ref().cda.rpc-row_count;
18251     row_count=sel_cur.get_cursor_struct_ref().cda.rpc;
18252     OTL_TRACE_NEXT_FETCH2
18253     if(cur_size!=0)cur_row=0;
18254   }
18255   return cur_size!=0;
18256  }
18257 
18258  void bind
18259  (const int column_num,
18260   otl_generic_variable& v)
18261  {
18262   if(!connected)return;
18263   ++vl_cur_len;
18264   if(vl_cur_len==rvl_len){
18265     int temp_rvl_len=rvl_len*2;
18266     otl_p_generic_variable* temp_rvl=
18267       new otl_p_generic_variable[temp_rvl_len];
18268     int i;
18269     for(i=0;i<rvl_len;++i)
18270       temp_rvl[i]=rvl[i];
18271     for(i=rvl_len+1;i<temp_rvl_len;++i)
18272       temp_rvl[i]=0;
18273     delete[] rvl;
18274     rvl=temp_rvl;
18275     rvl_len=temp_rvl_len;
18276   }
18277   rvl[vl_cur_len-1]=&v;
18278   v.set_pos(column_num);
18279  }
18280 
18281  void bind(otl_generic_variable& v)
18282  {
18283    if(v.get_pos())
18284      bind(v.get_pos(),v);
18285    else if(v.get_name())
18286      otl_tmpl_cursor
18287        <otl_exc,
18288      otl_conn,
18289      otl_cur,
18290      otl_var>::bind(v);
18291  }
18292 
18293  void bind
18294  (const char* name,
18295   otl_generic_variable& v)
18296  {
18297   otl_tmpl_cursor
18298   <otl_exc,
18299    otl_conn,
18300    otl_cur,
18301    otl_var>::bind(name,v);
18302  }
18303 
18304  int describe_select
18305  (otl_column_desc* desc,
18306   int& desc_len)
18307  {int i,rc;
18308   rc=obndrv
18309    (&cursor_struct.cda,
18310     OTL_RCAST(unsigned char*,cur_placeholder),
18311     -1,
18312     OTL_RCAST(ub1*,&sel_cur.get_cursor_struct_ref().cda),
18313     sizeof(sel_cur.get_cursor_struct_ref().cda),
18314     102,-1,0,0,-1,-1);
18315   if(rc!=0){
18316    if(this->adb)this->adb->increment_throw_count();
18317    if(this->adb&&this->adb->get_throw_count()>1)return 0;
18318    if(otl_uncaught_exception()) return 0;
18319    throw otl_exception(cursor_struct,stm_label?stm_label:stm_text);
18320   }
18321 // Executing the PLSQL master block
18322   exec(1,0,otl_sql_exec_from_select_cursor_class);
18323   sel_cur.set_connected(1);
18324   cur_row=-2; // Special case -- describe_select() before first() or next()
18325   desc_len=0;
18326   for(i=1;sel_cur.describe_column(desc[i-1],i);++i)
18327    ++desc_len;
18328   return 1;
18329  }
18330 
18331 
18332 protected:
18333 
18334   otl_cursor sel_cur;
18335   int rvl_len;
18336   otl_p_generic_variable* rvl;
18337   int vl_cur_len;
18338   char cur_placeholder[64];
18339   void* master_stream_ptr_;
18340 
18341 private:
18342 
18343  otl_ref_cursor(const otl_ref_cursor&) :
18344   otl_tmpl_cursor
18345   <otl_exc,
18346    otl_conn,
18347    otl_cur,
18348    otl_var>(),
18349    cur_row(-1),
18350    cur_size(0),
18351    row_count(0),
18352    array_size(0),
18353    local_override(),
18354    sel_cur(),
18355    rvl_len(0),
18356    rvl(0),
18357    vl_cur_len(0),
18358   cur_placeholder(),
18359   master_stream_ptr_(0)
18360  {
18361  }
18362 
18363  otl_ref_cursor& operator=(const otl_ref_cursor&)
18364  {
18365    return *this;
18366  }
18367 
18368 };
18369 
18370 class otl_stream;
18371 
18372 class otl_ref_select_stream: public otl_ref_cursor{
18373 private:
18374 
18375   friend class otl_stream;
18376   otl_select_struct_override* override;
18377   long _rfc;
18378 
18379 public:
18380 
18381   int get_select_row_count() const
18382   {
18383     return this->cur_row==-1?0:this->cur_size-this->cur_row;
18384   }
18385 
18386  void cleanup(void)
18387  {int i;
18388   delete[] sl;
18389   for(i=0;i<vl_len;++i)
18390    delete vl[i];
18391   delete[] vl;
18392   delete[] sl_desc;
18393  }
18394 
18395  otl_ref_select_stream
18396  (otl_select_struct_override* aoverride,
18397   const otl_stream_buffer_size_type arr_size,
18398   const char* sqlstm,
18399   const char* acur_placeholder,
18400   otl_connect& db,
18401   const char* sqlstm_label=0)
18402   :otl_ref_cursor
18403    (db,
18404     acur_placeholder,
18405     aoverride->get_master_stream_ptr(),
18406     arr_size),
18407    override(0),
18408    _rfc(0),
18409    sl_desc(0),
18410    sl_len(0),
18411    sl(0),
18412    null_fetched(0),
18413    ret_code(0),
18414    cur_col(0),
18415    cur_in(0),
18416    executed(0),
18417    var_info()
18418  {
18419    if(sqlstm_label!=0){
18420      if(stm_label!=0){
18421        delete[] stm_label;
18422        stm_label=0;
18423      }
18424      size_t len=strlen(sqlstm_label)+1;
18425      stm_label=new char[len];
18426      OTL_STRCPY_S(stm_label,len,sqlstm_label);
18427    }
18428   _rfc=0;
18429   init();
18430   {
18431    size_t len=strlen(sqlstm)+1;
18432    stm_text=new char[len];
18433    OTL_STRCPY_S(stm_text,len,sqlstm);
18434    otl_select_struct_override* temp_local_override=&this->local_override;
18435    otl_ext_hv_decl hvd
18436      (this->stm_text,
18437       1,
18438       this->stm_label,
18439       &temp_local_override,
18440       adb
18441      );
18442    hvd.alloc_host_var_list(vl,vl_len,*adb);
18443   }
18444   override=aoverride;
18445   try{
18446    parse();
18447    if(vl_len==0){
18448     rewind();
18449     null_fetched=0;
18450    }
18451   }catch(OTL_CONST_EXCEPTION otl_exception&){
18452    cleanup();
18453    if(this->adb)this->adb->increment_throw_count();
18454    throw;
18455   }
18456 
18457  }
18458 
18459  virtual ~otl_ref_select_stream()
18460  {
18461   cleanup();
18462  }
18463 
18464  void rewind(void)
18465  {
18466    OTL_TRACE_STREAM_EXECUTION
18467   _rfc=0;
18468   get_select_list();
18469   ret_code=first();
18470   null_fetched=0;
18471   cur_col=-1;
18472   cur_in=0;
18473   executed=1;
18474  }
18475 
18476   void clean(void)
18477   {
18478     _rfc=0;
18479     null_fetched=0;
18480     cur_col=-1;
18481     cur_in=0;
18482     executed=0;
18483   }
18484 
18485  int is_null(void)
18486  {
18487   return null_fetched;
18488  }
18489 
18490  int eof(void)
18491  {
18492   return !ret_code;
18493  }
18494 
18495  void skip_to_end_of_row()
18496  {
18497    check_if_executed();
18498    if(eof())return;
18499    while(cur_col<sl_len-1){
18500      ++cur_col;
18501      null_fetched=sl[cur_col].is_null(this->cur_row);
18502    }
18503    ret_code=this->next();
18504    cur_col=0;
18505    if(!eof())
18506      cur_col=-1;
18507   ++_rfc;
18508  }
18509 
18510 
18511  otl_ref_select_stream& operator>>(otl_time0& t)
18512  {
18513   check_if_executed();
18514   if(eof())return *this;
18515   get_next();
18516   if(check_type(otl_var_timestamp)&&!eof()){
18517    otl_time0* tm=OTL_RCAST(otl_time0*,sl[cur_col].val(cur_row));
18518    memcpy(OTL_RCAST(void*,&t),tm,otl_oracle_date_size);
18519    look_ahead();
18520   }
18521   return *this;
18522  }
18523 
18524  otl_ref_select_stream& operator>>(char& c)
18525  {
18526   check_if_executed();
18527   if(eof())return *this;
18528   get_next();
18529   if(check_type(otl_var_char)&&!eof()){
18530    c=*OTL_RCAST(char*,sl[cur_col].val(cur_row));
18531    look_ahead();
18532   }
18533   return *this;
18534  }
18535 
18536  otl_ref_select_stream& operator>>(unsigned char& c)
18537  {
18538   check_if_executed();
18539   if(eof())return *this;
18540   get_next();
18541   if(check_type(otl_var_char)&&!eof()){
18542    c=*OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
18543    look_ahead();
18544   }
18545   return *this;
18546  }
18547 
18548 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
18549  otl_ref_select_stream& operator>>(OTL_STRING_CONTAINER& s)
18550  {
18551   check_if_executed();
18552   if(eof())return *this;
18553   get_next();
18554   switch(sl[cur_col].get_ftype()){
18555   case otl_var_char:
18556     if(!eof()){
18557 #if defined(OTL_ACE)
18558       s.set(OTL_RCAST(char*,sl[cur_col].val(cur_row)),1);
18559 #else
18560       s=OTL_RCAST(char*,sl[cur_col].val(cur_row));
18561 #endif
18562       look_ahead();
18563     }
18564     break;
18565 #if defined(USER_DEFINED_STRING_CLASS) || \
18566     defined(OTL_STL) || defined(OTL_ACE)
18567   case otl_var_varchar_long:
18568   case otl_var_raw_long:
18569     if(!eof()){
18570       unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
18571       int len=sl[cur_col].get_len(cur_row);
18572 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_ACE)
18573       s.assign(OTL_RCAST(char*,c),len);
18574 #elif defined(OTL_ACE)
18575       s.set(OTL_RCAST(char*,c),len,1);
18576 #endif
18577       look_ahead();
18578     }
18579     break;
18580 #endif
18581   default:
18582     check_type(otl_var_char);
18583   } // switch
18584   return *this;
18585  }
18586 #endif
18587 
18588  otl_ref_select_stream& operator>>(char* s)
18589  {
18590   check_if_executed();
18591   if(eof())return *this;
18592   get_next();
18593   if(check_type(otl_var_char)&&!eof()){
18594    otl_strcpy(OTL_RCAST(unsigned char*,s),
18595               OTL_RCAST(const unsigned char*,sl[cur_col].val(cur_row)));
18596    look_ahead();
18597   }
18598   return *this;
18599  }
18600 
18601  otl_ref_select_stream& operator>>(unsigned char* s)
18602  {
18603   check_if_executed();
18604   if(eof())return *this;
18605   get_next();
18606   if(check_type(otl_var_char)&&!eof()){
18607    otl_strcpy2(OTL_RCAST(unsigned char*,s),
18608                OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row)),
18609                sl[cur_col].get_len(cur_row)
18610              );
18611    look_ahead();
18612   }
18613   return *this;
18614  }
18615 
18616 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
18617 #define OTL_D5(T,T_type)                                \
18618   otl_ref_select_stream& operator>>(T& n)               \
18619   {                                                     \
18620     check_if_executed();                                \
18621     if(eof())return *this;                              \
18622     get_next();                                         \
18623     if(!eof()){                                         \
18624       int match_found=otl_numeric_convert_T<T,T_type>   \
18625         (sl[cur_col].get_ftype(),                       \
18626          sl[cur_col].val(cur_row),                      \
18627          n);                                            \
18628       if(!match_found)                                  \
18629         strict_check_throw(T_type);                     \
18630       look_ahead();                                     \
18631     }                                                   \
18632     return *this;                                       \
18633   }
18634 #else
18635 #define OTL_D5(T,T_type)                                        \
18636   otl_ref_select_stream& operator>>(T& n)                       \
18637   {                                                             \
18638     check_if_executed();                                        \
18639     if(eof())return *this;                                      \
18640     get_next();                                                 \
18641     if(!eof()){                                                 \
18642       int match_found=otl_numeric_convert_T                     \
18643         (sl[cur_col].get_ftype(),                               \
18644          sl[cur_col].val(cur_row),                              \
18645          n);                                                    \
18646       if(!match_found){                                         \
18647         if(check_type(otl_var_double,T_type))                   \
18648           n=OTL_PCONV(T,double,sl[cur_col].val(cur_row));       \
18649       }                                                         \
18650       look_ahead();                                             \
18651     }                                                           \
18652     return *this;                                               \
18653   }
18654 #endif
18655 
18656 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
18657   OTL_D5(int,otl_var_int)
18658   OTL_D5(unsigned,otl_var_unsigned_int)
18659   OTL_D5(long,otl_var_long_int)
18660   OTL_D5(short,otl_var_short)
18661   OTL_D5(float,otl_var_float)
18662   OTL_D5(double,otl_var_double)
18663 #else
18664     template<OTL_TYPE_NAME T,const int T_type> OTL_D5(T,T_type)
18665 #endif
18666 
18667  otl_ref_select_stream& operator>>(otl_long_string& s)
18668  {
18669   check_if_executed();
18670   if(eof())return *this;
18671   get_next();
18672   switch(sl[cur_col].get_ftype()){
18673   case otl_var_varchar_long:
18674   case otl_var_raw_long:
18675     {
18676       if(!eof()){
18677         unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
18678         int len=sl[cur_col].get_len(cur_row);
18679         if(len>s.get_buf_size())
18680           len=s.get_buf_size();
18681         otl_memcpy(s.v,c,len,sl[cur_col].get_ftype());
18682         if(sl[cur_col].get_ftype()==otl_var_varchar_long)
18683           s.null_terminate_string(len);
18684         s.set_len(len);
18685         look_ahead();
18686       }
18687     }
18688     break;
18689   case otl_var_raw:
18690     {
18691       if(!eof()){
18692         unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
18693         int len=OTL_SCAST(int,*OTL_RCAST(unsigned short*,c));
18694         if(len>s.get_buf_size())
18695           len=s.get_buf_size();
18696         otl_memcpy(s.v,c+sizeof(short int),len,sl[cur_col].get_ftype());
18697         s.set_len(len);
18698         look_ahead();
18699       }
18700     }
18701     break;
18702   }
18703   return *this;
18704  }
18705 
18706 
18707  otl_ref_select_stream& operator<<(const otl_time0& t)
18708  {
18709   check_in_var();
18710   if(check_in_type(otl_var_timestamp,otl_oracle_date_size)){
18711    otl_time0* tm=OTL_RCAST(otl_time0*,vl[cur_in]->val());
18712    memcpy(tm,OTL_RCAST(void*,OTL_CCAST(otl_time0*,&t)),otl_oracle_date_size);
18713   }
18714   this->vl[cur_in]->set_not_null(0);
18715   get_in_next();
18716   return *this;
18717  }
18718 
18719 
18720   otl_ref_select_stream& operator<<(const otl_null& /* n */)
18721  {
18722   check_in_var();
18723   this->vl[cur_in]->set_null(0);
18724   get_in_next();
18725   return *this;
18726  }
18727 
18728  otl_ref_select_stream& operator<<(const otl_long_string& s)
18729  {
18730    check_in_var();
18731    if(check_in_type(otl_var_raw,1)){
18732       unsigned char* c=OTL_RCAST(unsigned char*,vl[cur_in]->val());
18733       int len=OTL_CCAST(otl_long_string*,&s)->len();
18734       if(len>this->vl[cur_in]->actual_elem_size()){
18735         otl_var_info_var
18736           (this->vl[cur_in]->get_name(),
18737            this->vl[cur_in]->get_ftype(),
18738            otl_var_raw,
18739            var_info,
18740            sizeof(var_info));
18741         if(this->adb)this->adb->increment_throw_count();
18742         if(this->adb&&this->adb->get_throw_count()>1)return *this;
18743         if(otl_uncaught_exception()) return *this;
18744         throw otl_exception
18745           (otl_error_msg_5,
18746            otl_error_code_5,
18747            this->stm_label?this->stm_label:
18748            this->stm_text,
18749            var_info);
18750       }
18751       this->vl[cur_in]->set_not_null(0);
18752       otl_memcpy
18753         (c+sizeof(unsigned short),
18754          s.v,
18755          len,
18756          this->vl[cur_in]->get_ftype());
18757       *OTL_RCAST(unsigned short*,
18758                  this->vl[cur_in]->val(0))=OTL_SCAST(unsigned short,len);
18759       this->vl[cur_in]->set_len(len,0);
18760    }
18761    get_in_next();
18762    return *this;
18763  }
18764 
18765 
18766  otl_ref_select_stream& operator<<(const char c)
18767  {
18768   check_in_var();
18769   if(check_in_type(otl_var_char,1)){
18770    char* tmp=OTL_RCAST(char*,vl[cur_in]->val());
18771    tmp[0]=c;
18772    tmp[1]=0;
18773   }
18774   this->vl[cur_in]->set_not_null(0);
18775   get_in_next();
18776   return *this;
18777  }
18778 
18779  otl_ref_select_stream& operator<<(const unsigned char c)
18780  {
18781   check_in_var();
18782   if(check_in_type(otl_var_char,1)){
18783    unsigned char* tmp=OTL_RCAST(unsigned char*,vl[cur_in]->val());
18784    tmp[0]=c;
18785    tmp[1]=0;
18786   }
18787   this->vl[cur_in]->set_not_null(0);
18788   get_in_next();
18789   return *this;
18790  }
18791 
18792 
18793 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
18794  otl_ref_select_stream& operator<<(const OTL_STRING_CONTAINER& s)
18795  {
18796   check_in_var();
18797   if(check_in_type(otl_var_char,1)){
18798 
18799    int overflow;
18800    otl_strcpy
18801     (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
18802      OTL_RCAST(unsigned char*,OTL_CCAST(char*,s.c_str())),
18803      overflow,
18804      vl[cur_in]->get_elem_size(),
18805      OTL_SCAST(int,s.length())
18806     );
18807    if(overflow){
18808     char temp_var_info[256];
18809     otl_var_info_var
18810       (vl[cur_in]->get_name(),
18811        vl[cur_in]->get_ftype(),
18812       otl_var_char,
18813       temp_var_info,
18814       sizeof(temp_var_info));
18815     if(this->adb&&this->adb->get_throw_count()>1)return *this;
18816     if(this->adb)this->adb->increment_throw_count();
18817     if(otl_uncaught_exception()) return *this;
18818     throw otl_exception
18819      (otl_error_msg_4,
18820       otl_error_code_4,
18821       stm_label?stm_label:stm_text,
18822       temp_var_info);
18823    }
18824   }
18825   this->vl[cur_in]->set_not_null(0);
18826   get_in_next();
18827   return *this;
18828  }
18829 #endif
18830 
18831  otl_ref_select_stream& operator<<(const char* s)
18832  {
18833   check_in_var();
18834   if(check_in_type(otl_var_char,1)){
18835 
18836    int overflow;
18837    otl_strcpy
18838     (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
18839      OTL_RCAST(unsigned char*,OTL_CCAST(char*,s)),
18840      overflow,
18841      vl[cur_in]->get_elem_size()
18842     );
18843    if(overflow){
18844     char temp_var_info[256];
18845     otl_var_info_var
18846       (vl[cur_in]->get_name(),
18847        vl[cur_in]->get_ftype(),
18848        otl_var_char,
18849        temp_var_info,
18850        sizeof(temp_var_info));
18851     if(this->adb&&this->adb->get_throw_count()>1)return *this;
18852     if(this->adb)this->adb->increment_throw_count();
18853     if(otl_uncaught_exception()) return *this;
18854     throw otl_exception
18855      (otl_error_msg_4,
18856       otl_error_code_4,
18857       stm_label?stm_label:stm_text,
18858       temp_var_info);
18859    }
18860 
18861   }
18862   this->vl[cur_in]->set_not_null(0);
18863   get_in_next();
18864   return *this;
18865  }
18866 
18867  otl_ref_select_stream& operator<<(const unsigned char* s)
18868  {
18869   check_in_var();
18870   if(check_in_type(otl_var_char,1)){
18871 
18872    int overflow;
18873    otl_strcpy4
18874     (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
18875      OTL_CCAST(unsigned char*,s),
18876      overflow,
18877      vl[cur_in]->get_elem_size()
18878     );
18879    if(overflow){
18880     char temp_var_info[256];
18881     otl_var_info_var
18882       (vl[cur_in]->get_name(),
18883        vl[cur_in]->get_ftype(),
18884        otl_var_char,
18885        temp_var_info,
18886        sizeof(temp_var_info));
18887     if(this->adb)this->adb->increment_throw_count();
18888     if(this->adb&&this->adb->get_throw_count()>1)return *this;
18889     if(otl_uncaught_exception()) return *this;
18890     throw otl_exception
18891      (otl_error_msg_4,
18892       otl_error_code_4,
18893       stm_label?stm_label:stm_text,
18894       temp_var_info);
18895    }
18896 
18897   }
18898   this->vl[cur_in]->set_not_null(0);
18899   get_in_next();
18900   return *this;
18901  }
18902 
18903 #define OTL_D6(T,T_type)                        \
18904   otl_ref_select_stream& operator<<(const T n)  \
18905   {                                             \
18906     check_in_var();                             \
18907     if(check_in_type(T_type,sizeof(T))){        \
18908       *OTL_RCAST(T*,vl[cur_in]->val())=n;       \
18909     }                                           \
18910     this->vl[cur_in]->set_not_null(0);          \
18911     get_in_next();                              \
18912     return *this;                               \
18913   }
18914 
18915 
18916 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
18917   OTL_D6(int,otl_var_int)
18918   OTL_D6(unsigned,otl_var_unsigned_int)
18919   OTL_D6(long,otl_var_long_int)
18920   OTL_D6(short,otl_var_short)
18921   OTL_D6(float,otl_var_float)
18922   OTL_D6(double,otl_var_double)
18923 #else
18924   template<OTL_TYPE_NAME T,const int T_type> OTL_D6(T,T_type)
18925 #endif
18926 
18927 
18928  int select_list_len(void)
18929  {
18930   return sl_len;
18931  }
18932 
18933  int column_ftype(int ndx=0)
18934  {
18935    return sl[ndx].get_ftype();
18936  }
18937 
18938  int column_size(int ndx=0)
18939  {
18940    return sl[ndx].get_elem_size();
18941  }
18942 
18943 protected:
18944 
18945  otl_column_desc* sl_desc;
18946  int sl_len;
18947  otl_generic_variable* sl;
18948  int null_fetched;
18949  int ret_code;
18950  int cur_col;
18951  int cur_in;
18952  int executed;
18953  char var_info[256];
18954 
18955  void init(void)
18956  {
18957   sl=0;
18958   sl_len=0;
18959   null_fetched=0;
18960   ret_code=0;
18961   sl_desc=0;
18962   executed=0;
18963   cur_in=0;
18964   stm_text=0;
18965  }
18966 
18967  void get_next(void)
18968  {
18969   if(cur_col<sl_len-1){
18970    ++cur_col;
18971    null_fetched=sl[cur_col].is_null(cur_row);
18972   }else{
18973    ret_code=next();
18974    cur_col=0;
18975   }
18976  }
18977 
18978 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
18979   void strict_check_throw(int type_code)
18980   {
18981    otl_var_info_col
18982      (sl[cur_col].get_pos(),
18983       sl[cur_col].get_ftype(),
18984       type_code,
18985       var_info,
18986       sizeof(var_info));
18987    if(this->adb)this->adb->increment_throw_count();
18988    if(this->adb&&this->adb->get_throw_count()>1)return;
18989    if(otl_uncaught_exception()) return;
18990    throw otl_exception
18991      (otl_error_msg_0,
18992       otl_error_code_0,
18993       this->stm_label?
18994       this->stm_label:
18995       this->stm_text,
18996       var_info);
18997   }
18998 #endif
18999 
19000   int check_type_throw(int type_code,int actual_data_type)
19001   {
19002     int out_type_code;
19003     if(actual_data_type!=0)
19004       out_type_code=actual_data_type;
19005     else
19006       out_type_code=type_code;
19007     otl_var_info_col
19008       (sl[cur_col].get_pos(),
19009        sl[cur_col].get_ftype(),
19010        out_type_code,
19011        var_info,
19012        sizeof(var_info));
19013     if(this->adb)this->adb->increment_throw_count();
19014     if(this->adb&&this->adb->get_throw_count()>1)return 0;
19015     if(otl_uncaught_exception()) return 0;
19016     throw otl_exception
19017       (otl_error_msg_0,
19018        otl_error_code_0,
19019        stm_label?stm_label:stm_text,
19020        var_info);
19021   }
19022 
19023   int check_type(int type_code, int actual_data_type=0)
19024   {
19025     if(sl[cur_col].get_ftype()==type_code)
19026       return 1;
19027     else
19028       return check_type_throw(type_code,actual_data_type);
19029   }
19030 
19031  void look_ahead(void)
19032  {
19033   if(cur_col==sl_len-1){
19034    ret_code=next();
19035    cur_col=-1;
19036    ++_rfc;
19037   }
19038  }
19039 
19040  void get_select_list(void)
19041  {int i,j,rc;
19042 
19043   otl_auto_array_ptr<otl_column_desc> loc_ptr(otl_var_list_size);
19044   otl_column_desc* sl_desc_tmp=loc_ptr.get_ptr();
19045   int sld_tmp_len=0;
19046   int ftype,elem_size;
19047 
19048   rc=obndrv
19049    (&cursor_struct.cda,
19050     OTL_RCAST(unsigned char*,cur_placeholder),
19051     -1,
19052     OTL_RCAST(ub1*,&sel_cur.get_cursor_struct_ref().cda),
19053     sizeof(sel_cur.get_cursor_struct_ref().cda),
19054     102,-1,0,0,-1,-1);
19055   if(rc!=0){
19056    if(this->adb)this->adb->increment_throw_count();
19057    if(this->adb&&this->adb->get_throw_count()>1)return;
19058    if(otl_uncaught_exception()) return;
19059    throw otl_exception(cursor_struct,stm_label?stm_label:stm_text);
19060   }
19061   for(i=0;i<vl_len;++i)
19062     otl_tmpl_cursor
19063       <otl_exc,
19064      otl_conn,
19065      otl_cur,
19066      otl_var>::bind(*vl[i]);
19067  // Executing the PLSQL master block
19068   otl_tmpl_cursor
19069     <otl_exc,
19070      otl_conn,
19071      otl_cur,
19072      otl_var>::exec(1,0,otl_sql_exec_from_select_cursor_class);
19073   sel_cur.set_connected(1);
19074   cur_row=-2;
19075   sld_tmp_len=0;
19076   for(i=1;sel_cur.describe_column(sl_desc_tmp[i-1],i);++i){
19077     ++sld_tmp_len;
19078     if(sld_tmp_len==loc_ptr.get_arr_size()){
19079       loc_ptr.double_size();
19080       sl_desc_tmp=loc_ptr.get_ptr();
19081     }
19082   }
19083   sl_len=sld_tmp_len;
19084   if(sl){
19085    delete[] sl;
19086    sl=0;
19087   }
19088   sl=new otl_generic_variable[sl_len==0?1:sl_len];
19089   int max_long_size=this->adb->get_max_long_size();
19090   for(j=0;j<sl_len;++j){
19091    otl_generic_variable::map_ftype
19092     (sl_desc_tmp[j],
19093      max_long_size,
19094      ftype,
19095      elem_size,
19096      this->local_override.getLen()>0?this->local_override:*override,
19097      j+1,
19098      adb->get_connect_struct().get_connection_type());
19099    sl[j].copy_pos(j+1);
19100    sl[j].init(true,ftype,
19101               elem_size,
19102               OTL_SCAST(otl_stream_buffer_size_type,array_size),
19103               &adb->get_connect_struct()
19104              );
19105   }
19106   if(sl_desc){
19107    delete[] sl_desc;
19108    sl_desc=0;
19109   }
19110   sl_desc=new otl_column_desc[sl_len==0?1:sl_len];
19111   for(i=0;i<sl_len;++i)
19112     sl_desc[i]=sl_desc_tmp[i];
19113   for(i=0;i<sl_len;++i)sel_cur.bind(sl[i]);
19114  }
19115 
19116  void get_in_next(void)
19117  {
19118   if(cur_in==vl_len-1)
19119    rewind();
19120   else{
19121    ++cur_in;
19122    executed=0;
19123   }
19124  }
19125 
19126   int check_in_type_throw(int type_code)
19127   {
19128     otl_var_info_var
19129       (vl[cur_in]->get_name(),
19130        vl[cur_in]->get_ftype(),
19131        type_code,
19132        var_info,
19133        sizeof(var_info));
19134     if(this->adb)this->adb->increment_throw_count();
19135     if(this->adb&&this->adb->get_throw_count()>1)return 0;
19136     if(otl_uncaught_exception()) return 0;
19137 
19138     throw otl_exception
19139       (otl_error_msg_0,
19140        otl_error_code_0,
19141        stm_label?stm_label:stm_text,
19142        var_info);
19143   }
19144 
19145   int check_in_type(int type_code,int tsize)
19146   {
19147     switch(vl[cur_in]->get_ftype()){
19148     case otl_var_char:
19149       if(type_code==otl_var_char)
19150         return 1;
19151     case otl_var_raw:
19152       if(type_code==otl_var_raw)
19153         return 1;
19154     default:
19155       if(vl[cur_in]->get_ftype()==type_code &&
19156          vl[cur_in]->get_elem_size()==tsize)
19157         return 1;
19158     }
19159     return check_in_type_throw(type_code);
19160   }
19161 
19162   void check_in_var_throw(void)
19163   {
19164     if(this->adb)this->adb->increment_throw_count();
19165     if(this->adb&&this->adb->get_throw_count()>1)return;
19166     if(otl_uncaught_exception()) return;
19167     throw otl_exception
19168       (otl_error_msg_1,
19169        otl_error_code_1,
19170        stm_label?stm_label:stm_text,
19171        0);
19172   }
19173 
19174  void check_in_var(void)
19175  {
19176   if(vl_len==0)
19177     check_in_var();
19178  }
19179 
19180   void check_if_executed_throw(void)
19181   {
19182     if(this->adb)this->adb->increment_throw_count();
19183     if(this->adb&&this->adb->get_throw_count()>1)return;
19184     if(otl_uncaught_exception()) return;
19185     throw otl_exception
19186       (otl_error_msg_2,
19187        otl_error_code_2,
19188        stm_label?stm_label:stm_text,
19189        0);
19190   }
19191 
19192   void check_if_executed(void)
19193   {
19194     if(!executed)
19195       check_if_executed_throw();
19196   }
19197 
19198 private:
19199 
19200   otl_ref_select_stream(const otl_ref_select_stream&):
19201     otl_ref_cursor(),
19202     override(0),
19203     _rfc(0),
19204    sl_desc(0),
19205    sl_len(0),
19206    sl(0),
19207    null_fetched(0),
19208    ret_code(0),
19209    cur_col(0),
19210    cur_in(0),
19211    executed(0),
19212    var_info()
19213   {
19214   }
19215 
19216   otl_ref_select_stream& operator=(const otl_ref_select_stream&)
19217   {
19218     return *this;
19219   }
19220 
19221 };
19222 
19223 const int otl_ora7_no_stream=0;
19224 const int otl_ora7_io_stream=1;
19225 const int otl_ora7_select_stream=2;
19226 const int otl_ora7_refcur_select_stream=3;
19227 
19228 class otl_stream_shell: public otl_stream_shell_generic{
19229 public:
19230 
19231   otl_ref_select_stream* ref_ss;
19232   otl_select_stream* ss;
19233   otl_inout_stream* io;
19234   otl_connect* adb;
19235   bool lob_stream_flag;
19236 
19237   int auto_commit_flag;
19238 
19239   otl_var_desc* iov;
19240   int iov_len;
19241   int next_iov_ndx;
19242 
19243   otl_var_desc* ov;
19244   int ov_len;
19245   int next_ov_ndx;
19246 
19247   bool flush_flag;
19248   int stream_type;
19249 
19250   otl_select_struct_override override;
19251 
19252 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
19253   OTL_STRING_CONTAINER orig_sql_stm;
19254 #endif
19255 
19256 
19257   otl_stream_shell():
19258     otl_stream_shell_generic(),
19259     ref_ss(0),
19260     ss(0),
19261     io(0),
19262     adb(0),
19263     lob_stream_flag(false),
19264     auto_commit_flag(0),
19265     iov(0),
19266     iov_len(0),
19267     next_iov_ndx(0),
19268     ov(0),
19269     ov_len(0),
19270     next_ov_ndx(0),
19271     flush_flag(false),
19272     stream_type(otl_ora7_no_stream),
19273     override()
19274 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
19275     ,orig_sql_stm()
19276 #endif
19277  {
19278  }
19279 
19280  otl_stream_shell(const int ashould_delete):
19281     otl_stream_shell_generic(),
19282     ref_ss(0),
19283     ss(0),
19284     io(0),
19285     adb(0),
19286     lob_stream_flag(false),
19287     auto_commit_flag(0),
19288     iov(0),
19289     iov_len(0),
19290     next_iov_ndx(0),
19291     ov(0),
19292     ov_len(0),
19293     next_ov_ndx(0),
19294     flush_flag(true),
19295     stream_type(otl_ora7_no_stream),
19296     override()
19297 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
19298     ,orig_sql_stm()
19299 #endif
19300  {
19301    override.setLen(0);
19302   should_delete=ashould_delete;
19303  }
19304 
19305  virtual ~otl_stream_shell()
19306  {
19307   if(should_delete){
19308    delete[] iov;
19309    delete[] ov;
19310 
19311    iov=0; iov_len=0;
19312    ov=0; ov_len=0;
19313    next_iov_ndx=0;
19314    next_ov_ndx=0;
19315    override.setLen(0);
19316    flush_flag=true;
19317    stream_type=otl_ora7_no_stream;
19318 
19319    delete ss;
19320    delete io;
19321    delete ref_ss;
19322    ss=0; io=0; ref_ss=0;
19323    adb=0;
19324   }
19325  }
19326 
19327 private:
19328 
19329   otl_stream_shell(const otl_stream_shell&):
19330     otl_stream_shell_generic(),
19331     ref_ss(0),
19332     ss(0),
19333     io(0),
19334     adb(0),
19335     lob_stream_flag(false),
19336     auto_commit_flag(0),
19337     iov(0),
19338     iov_len(0),
19339     next_iov_ndx(0),
19340     ov(0),
19341     ov_len(0),
19342     next_ov_ndx(0),
19343     flush_flag(false),
19344     stream_type(otl_ora7_no_stream),
19345     override()
19346 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
19347     ,orig_sql_stm()
19348 #endif
19349  {
19350  }
19351 
19352   otl_stream_shell& operator=(const otl_stream_shell&)
19353   {
19354     return *this;
19355   }
19356 
19357 };
19358 
19359 class otl_stream{
19360 private:
19361 
19362   otl_stream_shell* shell;
19363   otl_ptr<otl_stream_shell> shell_pt;
19364   int connected;
19365 
19366   otl_ref_select_stream** ref_ss;
19367   otl_select_stream** ss;
19368   otl_inout_stream** io;
19369   otl_connect** adb;
19370 
19371   int* auto_commit_flag;
19372 
19373   otl_var_desc** iov;
19374   int* iov_len;
19375   int* next_iov_ndx;
19376 
19377   otl_var_desc** ov;
19378   int* ov_len;
19379   int* next_ov_ndx;
19380 
19381   otl_select_struct_override* override;
19382 
19383   int end_marker;
19384   int oper_int_called;
19385   int last_eof_rc;
19386   bool last_oper_was_read_op;
19387 
19388 protected:
19389 
19390   void reset_end_marker(void)
19391   {
19392     last_eof_rc=0;
19393     end_marker=-1;
19394     oper_int_called=0;
19395   }
19396 
19397   int buf_size_;
19398 
19399 
19400   void throw_end_of_row()
19401 #if defined(__GNUC__) && (__GNUC__>=4)
19402     __attribute__ ((noreturn))
19403 #endif
19404   {
19405     throw otl_exception
19406       (otl_error_msg_34,
19407        otl_error_code_34,
19408        this->get_stm_text());
19409   }
19410 
19411 public:
19412 
19413 
19414   void skip_to_end_of_row()
19415   {
19416     if(next_ov_ndx==0)
19417       return;
19418     if((*ov_len)==0)return;
19419     last_oper_was_read_op=true;
19420     switch(shell->stream_type){
19421     case otl_ora7_no_stream:
19422       break;
19423     case otl_ora7_io_stream:
19424       last_eof_rc=(*io)->eof();
19425       (*io)->skip_to_end_of_row();
19426       break;
19427     case otl_ora7_select_stream:
19428       last_eof_rc=(*ss)->eof();
19429       (*ss)->skip_to_end_of_row();
19430       break;
19431     case otl_ora7_refcur_select_stream:
19432       last_eof_rc=(*ref_ss)->eof();
19433       (*ref_ss)->skip_to_end_of_row();
19434       break;
19435     }
19436     while ((*next_ov_ndx)<(*ov_len)-1)
19437       ++(*next_ov_ndx);
19438   }
19439 
19440   void reset_to_last_valid_row()
19441   {
19442     if((*io)){
19443       (*adb)->reset_throw_count();
19444       (*io)->reset_to_last_valid_row();
19445     }
19446   }
19447 
19448   bool get_lob_stream_flag() const
19449   {
19450     if(!shell)
19451       return false;
19452     else
19453       return shell->lob_stream_flag;
19454   }
19455 
19456   int get_adb_max_long_size() const
19457   {
19458     return this->shell->adb->get_max_long_size();
19459   }
19460 
19461 
19462   void check_end_of_row()
19463   {
19464     if(next_ov_ndx==0||(*next_ov_ndx)!=0)
19465       throw_end_of_row();
19466     if(next_iov_ndx==0||(*next_iov_ndx)!=0)
19467       throw_end_of_row();
19468   }
19469 
19470   otl_stream_shell* get_shell(){return shell;}
19471   int get_connected() const {return connected;}
19472 
19473   int get_dirty_buf_len() const
19474   {
19475     switch(shell->stream_type){
19476     case otl_ora7_no_stream:
19477       return 0;
19478     case otl_ora7_io_stream:
19479       return (*io)->get_dirty_buf_len();
19480     case otl_ora7_select_stream:
19481       return (*ss)->get_select_row_count();
19482     case otl_ora7_refcur_select_stream:
19483       return (*ref_ss)->get_select_row_count();
19484     default:
19485       return 0;
19486    }
19487   }
19488 
19489   const char* get_stm_text(void)
19490   {
19491     const char* no_stm_text=OTL_NO_STM_TEXT;
19492     switch(shell->stream_type){
19493     case otl_ora7_no_stream:
19494       return no_stm_text;
19495     case otl_ora7_io_stream:
19496       return (*io)->get_stm_label()?(*io)->get_stm_label():(*io)->get_stm_text();
19497     case otl_ora7_select_stream:
19498       return (*ss)->get_stm_label()?(*ss)->get_stm_label():(*ss)->get_stm_text();
19499     case otl_ora7_refcur_select_stream:
19500       return (*ref_ss)->get_stm_label()?
19501              (*ref_ss)->get_stm_label():(*ref_ss)->get_stm_text();
19502     default:
19503       return no_stm_text;
19504     }
19505   }
19506 
19507   void setBufSize(int buf_size)
19508   {
19509     buf_size_=buf_size;
19510   }
19511 
19512   int getBufSize(void) const
19513   {
19514     return buf_size_;
19515   }
19516 
19517  long get_rpc() OTL_THROWS_OTL_EXCEPTION
19518  {
19519    switch(shell->stream_type){
19520    case otl_ora7_no_stream:
19521      return 0;
19522    case otl_ora7_io_stream:
19523      (*adb)->reset_throw_count();
19524      return (*io)->get_rpc();
19525    case otl_ora7_select_stream:
19526      (*adb)->reset_throw_count();
19527      return (*ss)->get_rfc();
19528    case otl_ora7_refcur_select_stream:
19529      (*adb)->reset_throw_count();
19530      return (*ref_ss)->_rfc;
19531    default:
19532      return 0;
19533    }
19534  }
19535 
19536   operator int(void) OTL_THROWS_OTL_EXCEPTION
19537   {
19538     if(!last_oper_was_read_op){
19539       if(this->adb&&*this->adb)(*this->adb)->increment_throw_count();
19540       if(this->adb&&*this->adb&&(*this->adb)->get_throw_count()>1)return 0;
19541       const char* stm_label=0;
19542       const char* stm_text=0;
19543       switch(shell->stream_type){
19544       case otl_ora7_no_stream:
19545         break;
19546       case otl_ora7_io_stream:
19547         stm_label=(*io)->get_stm_label();
19548         stm_text=(*io)->get_stm_text();
19549         break;
19550       case otl_ora7_select_stream:
19551         stm_label=(*ss)->get_stm_label();
19552         stm_text=(*ss)->get_stm_text();
19553         break;
19554       case otl_ora7_refcur_select_stream:
19555         stm_label=(*ref_ss)->get_stm_label();
19556         stm_text=(*ref_ss)->get_stm_text();
19557         break;
19558       }
19559       throw otl_exception
19560         (otl_error_msg_18,
19561          otl_error_code_18,
19562          stm_label?stm_label:stm_text);
19563     }
19564     if(end_marker==1)return 0;
19565     int rc=0;
19566     int temp_eof=eof();
19567     if(temp_eof && end_marker==-1 && oper_int_called==0){
19568       end_marker=1;
19569       if(last_eof_rc==1)
19570         rc=0;
19571       else
19572         rc=1;
19573     }else if(!temp_eof && end_marker==-1)
19574       rc=1;
19575     else if(temp_eof && end_marker==-1){
19576       end_marker=0;
19577       rc=1;
19578     }else if(temp_eof && end_marker==0){
19579       end_marker=1;
19580       rc=0;
19581     }
19582     if(!oper_int_called)oper_int_called=1;
19583     return rc;
19584   }
19585 
19586  void create_var_desc(void)
19587  {int i;
19588   delete[] (*iov);
19589   delete[] (*ov);
19590   (*iov)=0; (*iov_len)=0;
19591   (*ov)=0; (*ov_len)=0;
19592   switch(shell->stream_type){
19593   case otl_ora7_no_stream:
19594     break;
19595   case otl_ora7_io_stream:
19596     if((*io)->get_vl_len()>0){
19597       (*iov)=new otl_var_desc[(*io)->get_vl_len()];
19598       (*iov_len)=(*io)->get_vl_len();
19599       for(i=0;i<(*io)->get_vl_len();++i)
19600         (*io)->get_vl()[i]->copy_var_desc((*iov)[i]);
19601     }
19602     if((*io)->get_iv_len()>0){
19603       (*ov)=new otl_var_desc[(*io)->get_iv_len()];
19604       (*ov_len)=(*io)->get_iv_len();
19605       for(i=0;i<(*io)->get_iv_len();++i)
19606         (*io)->get_in_vl()[i]->copy_var_desc((*ov)[i]);
19607     }
19608     break;
19609   case otl_ora7_select_stream:
19610     if((*ss)->get_vl_len()>0){
19611       (*iov)=new otl_var_desc[(*ss)->get_vl_len()];
19612       (*iov_len)=(*ss)->get_vl_len();
19613       for(i=0;i<(*ss)->get_vl_len();++i)
19614         (*ss)->get_vl()[i]->copy_var_desc((*iov)[i]);
19615     }
19616     if((*ss)->get_sl_len()>0){
19617       (*ov)=new otl_var_desc[(*ss)->get_sl_len()];
19618       (*ov_len)=(*ss)->get_sl_len();
19619       for(i=0;i<(*ss)->get_sl_len();++i){
19620         (*ss)->get_sl()[i].copy_var_desc((*ov)[i]);
19621         (*ov)[i].copy_name((*ss)->get_sl_desc()[i].name);
19622       }
19623     }
19624     break;
19625   case otl_ora7_refcur_select_stream:
19626     if((*ref_ss)->vl_len>0){
19627       (*iov)=new otl_var_desc[(*ref_ss)->vl_len];
19628       (*iov_len)=(*ref_ss)->vl_len;
19629       for(i=0;i<(*ref_ss)->vl_len;++i)
19630         (*ref_ss)->vl[i]->copy_var_desc((*iov)[i]);
19631     }
19632     if((*ref_ss)->sl_len>0){
19633       (*ov)=new otl_var_desc[(*ref_ss)->sl_len];
19634       (*ov_len)=(*ref_ss)->sl_len;
19635       for(i=0;i<(*ref_ss)->sl_len;++i){
19636         (*ref_ss)->sl[i].copy_var_desc((*ov)[i]);
19637         (*ov)[i].copy_name((*ref_ss)->sl_desc[i].name);
19638       }
19639     }
19640     break;
19641   }
19642 
19643  }
19644 
19645  void set_column_type(const int column_ndx,
19646                       const int col_type,
19647                       const int col_size=0)
19648    OTL_NO_THROW
19649  {
19650    if(shell==0){
19651      init_stream();
19652      shell->flush_flag=true;
19653    }
19654    override->add_override(column_ndx,col_type,col_size);
19655  }
19656 
19657  void set_all_column_types(const unsigned mask=0)
19658    OTL_NO_THROW
19659  {
19660    if(shell==0){
19661      init_stream();
19662      shell->flush_flag=true;
19663    }
19664    override->set_all_column_types(mask);
19665  }
19666 
19667  void set_flush(const bool flush_flag=true)
19668    OTL_NO_THROW
19669  {
19670    if(shell==0)init_stream();
19671   if(shell==0)return;
19672   shell->flush_flag=flush_flag;
19673  }
19674 
19675 
19676  void inc_next_ov(void)
19677  {
19678   if((*ov_len)==0)return;
19679   if((*next_ov_ndx)<(*ov_len)-1)
19680    ++(*next_ov_ndx);
19681   else
19682    (*next_ov_ndx)=0;
19683  }
19684 
19685  void inc_next_iov(void)
19686  {
19687   if((*iov_len)==0)return;
19688   if((*next_iov_ndx)<(*iov_len)-1)
19689    ++(*next_iov_ndx);
19690   else
19691    (*next_iov_ndx)=0;
19692  }
19693 
19694  otl_var_desc* describe_in_vars(int& desc_len)
19695    OTL_NO_THROW
19696  {
19697   desc_len=0;
19698   if(shell==0)return 0;
19699   if(shell->iov==0)return 0;
19700   desc_len=shell->iov_len;
19701   return shell->iov;
19702  }
19703 
19704  otl_var_desc* describe_out_vars(int& desc_len)
19705    OTL_NO_THROW
19706  {
19707   desc_len=0;
19708   if(shell==0)return 0;
19709   if(shell->ov==0)return 0;
19710   desc_len=shell->ov_len;
19711   return shell->ov;
19712  }
19713 
19714  otl_var_desc* describe_next_in_var(void)
19715    OTL_NO_THROW
19716  {
19717   if(shell==0)return 0;
19718   if(shell->iov==0)return 0;
19719   return &(shell->iov[shell->next_iov_ndx]);
19720  }
19721 
19722   otl_var_desc* describe_next_out_var(void)
19723    OTL_NO_THROW
19724  {
19725   if(shell==0)return 0;
19726   if(shell->ov==0)return 0;
19727   return &(shell->ov[shell->next_ov_ndx]);
19728  }
19729 
19730  void init_stream(void)
19731  {
19732    buf_size_=1;
19733    last_oper_was_read_op=false;
19734    shell=0;
19735    shell=new otl_stream_shell(0);
19736    shell_pt.assign(&shell);
19737    connected=0;
19738 
19739    ref_ss=&(shell->ref_ss);
19740    ss=&(shell->ss);
19741    io=&(shell->io);
19742    adb=&(shell->adb);
19743    auto_commit_flag=&(shell->auto_commit_flag);
19744    iov=&(shell->iov);
19745    iov_len=&(shell->iov_len);
19746    next_iov_ndx=&(shell->next_iov_ndx);
19747    ov=&(shell->ov);
19748    ov_len=&(shell->ov_len);
19749    next_ov_ndx=&(shell->next_ov_ndx);
19750    override=&(shell->override);
19751 
19752    (*ref_ss)=0;
19753    (*io)=0;
19754    (*ss)=0;
19755    (*adb)=0;
19756    (*ov)=0;
19757    (*ov_len)=0;
19758    (*next_iov_ndx)=0;
19759    (*next_ov_ndx)=0;
19760    (*auto_commit_flag)=1;
19761    (*iov)=0;
19762    (*iov_len)=0;
19763 
19764  }
19765 
19766  otl_stream
19767  (const otl_stream_buffer_size_type arr_size,
19768   const char* sqlstm,
19769   otl_connect& db,
19770   const char* ref_cur_placeholder=0,
19771   const char* sqlstm_label=0)
19772  OTL_THROWS_OTL_EXCEPTION:
19773    shell(0),
19774    shell_pt(),
19775    connected(0),
19776    ref_ss(0),
19777    ss(0),
19778    io(0),
19779    adb(0),
19780    auto_commit_flag(0),
19781    iov(0),
19782    iov_len(0),
19783    next_iov_ndx(0),
19784    ov(0),
19785    ov_len(0),
19786    next_ov_ndx(0),
19787    override(0),
19788    end_marker(0),
19789    oper_int_called(0),
19790    last_eof_rc(0),
19791    last_oper_was_read_op(0),
19792    buf_size_(0)
19793  {
19794   init_stream();
19795 
19796   (*io)=0; (*ss)=0; (*ref_ss)=0;
19797   (*iov)=0; (*iov_len)=0;
19798   (*ov)=0; (*ov_len)=0;
19799   (*auto_commit_flag)=1;
19800   (*next_iov_ndx)=0;
19801   (*next_ov_ndx)=0;
19802   (*adb)=&db;
19803   shell->flush_flag=true;
19804   open(arr_size,sqlstm,db,ref_cur_placeholder,sqlstm_label);
19805  }
19806 
19807   otl_stream() OTL_NO_THROW:
19808    shell(0),
19809    shell_pt(),
19810    connected(0),
19811    ref_ss(0),
19812    ss(0),
19813    io(0),
19814    adb(0),
19815    auto_commit_flag(0),
19816    iov(0),
19817    iov_len(0),
19818    next_iov_ndx(0),
19819    ov(0),
19820    ov_len(0),
19821    next_ov_ndx(0),
19822    override(0),
19823    end_marker(0),
19824    oper_int_called(0),
19825    last_eof_rc(0),
19826    last_oper_was_read_op(0),
19827    buf_size_(0)
19828  {
19829   init_stream();
19830   shell->flush_flag=true;
19831  }
19832 
19833  virtual ~otl_stream()
19834 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
19835    OTL_THROWS_OTL_EXCEPTION
19836 #endif
19837  {
19838   if(!connected)return;
19839   try{
19840    if((*io)!=0&&shell->flush_flag==false)
19841      (*io)->set_flush_flag2(false);
19842    close();
19843    if(shell!=0){
19844     if((*io)!=0)
19845       (*io)->set_flush_flag2(true);
19846    }
19847   }catch(OTL_CONST_EXCEPTION otl_exception&){
19848    if(shell!=0){
19849     if((*io)!=0)
19850       (*io)->set_flush_flag2(true);
19851    }
19852 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
19853    clean(1);
19854    if(shell!=0)
19855      shell->set_should_delete(1);
19856    shell_pt.destroy();
19857 #else
19858    shell_pt.destroy();
19859 #endif
19860 
19861 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
19862    throw;
19863 #endif
19864 
19865   }
19866 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
19867   if(adb && (*adb) && (*adb)->get_throw_count()>0
19868 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
19869      || otl_uncaught_exception()
19870 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
19871      || otl_uncaught_exception()
19872 #endif
19873      ){
19874    //
19875   }
19876 #else
19877    shell_pt.destroy();
19878 #endif
19879  }
19880 
19881  int eof(void) OTL_NO_THROW
19882  {
19883    switch(shell->stream_type){
19884    case otl_ora7_no_stream:
19885      return 1;
19886    case otl_ora7_io_stream:
19887      (*adb)->reset_throw_count();
19888      return (*io)->eof();
19889    case otl_ora7_select_stream:
19890      (*adb)->reset_throw_count();
19891      return (*ss)->eof();
19892    case otl_ora7_refcur_select_stream:
19893      (*adb)->reset_throw_count();
19894      return (*ref_ss)->eof();
19895    default:
19896      return 0;
19897    }
19898  }
19899 
19900  void flush(void) OTL_THROWS_OTL_EXCEPTION
19901  {
19902   if((*io)){
19903    (*adb)->reset_throw_count();
19904    (*io)->flush();
19905   }
19906  }
19907 
19908  void clean(const int clean_up_error_flag=0)
19909    OTL_THROWS_OTL_EXCEPTION
19910  {
19911    switch(shell->stream_type){
19912    case otl_ora7_no_stream:
19913      break;
19914    case otl_ora7_io_stream:
19915      (*adb)->reset_throw_count();
19916      (*io)->clean(clean_up_error_flag);
19917      break;
19918    case otl_ora7_select_stream:
19919      (*adb)->reset_throw_count();
19920      (*ss)->clean();
19921      break;
19922    case otl_ora7_refcur_select_stream:
19923      (*adb)->reset_throw_count();
19924      (*ref_ss)->clean();
19925      break;
19926    }
19927  }
19928 
19929  void rewind(void)
19930    OTL_THROWS_OTL_EXCEPTION
19931  {
19932    switch(shell->stream_type){
19933    case otl_ora7_no_stream:
19934      break;
19935    case otl_ora7_io_stream:
19936      (*adb)->reset_throw_count();
19937      (*io)->rewind();
19938      break;
19939    case otl_ora7_select_stream:
19940      (*adb)->reset_throw_count();
19941      (*ss)->rewind();
19942      break;
19943    case otl_ora7_refcur_select_stream:
19944      (*adb)->reset_throw_count();
19945      (*ref_ss)->rewind();
19946      break;
19947    }
19948  }
19949 
19950  int is_null(void) OTL_NO_THROW
19951  {
19952    switch(shell->stream_type){
19953    case otl_ora7_no_stream:
19954      return 0;
19955    case otl_ora7_io_stream:
19956      return (*io)->is_null();
19957    case otl_ora7_select_stream:
19958      return (*ss)->is_null();
19959    case otl_ora7_refcur_select_stream:
19960      return (*ref_ss)->is_null();
19961    default:
19962      return 0;
19963    }
19964  }
19965 
19966  void set_commit(int auto_commit=0)
19967    OTL_NO_THROW
19968  {
19969   (*auto_commit_flag)=auto_commit;
19970   if((*io)){
19971    (*adb)->reset_throw_count();
19972    (*io)->set_commit(auto_commit);
19973   }
19974  }
19975 
19976  void intern_cleanup(void)
19977  {
19978   delete[] (*iov);
19979   delete[] (*ov);
19980 
19981   (*iov)=0; (*iov_len)=0;
19982   (*ov)=0; (*ov_len)=0;
19983   (*next_iov_ndx)=0;
19984   (*next_ov_ndx)=0;
19985   override->setLen(0);
19986 
19987   switch(shell->stream_type){
19988   case otl_ora7_no_stream:
19989     break;
19990   case otl_ora7_io_stream:
19991     try{
19992       (*io)->flush();
19993       (*io)->close();
19994     }catch(OTL_CONST_EXCEPTION otl_exception&){
19995       clean(1);
19996       (*io)->close();
19997       delete (*io);
19998       (*io)=0;
19999       shell->stream_type=otl_ora7_no_stream;
20000       throw;
20001     }
20002     delete (*io);
20003     (*io)=0;
20004     shell->stream_type=otl_ora7_no_stream;
20005     break;
20006   case otl_ora7_select_stream:
20007     try{
20008       (*ss)->close();
20009     }catch(OTL_CONST_EXCEPTION otl_exception&){
20010       delete (*ss);
20011       (*ss)=0;
20012       shell->stream_type=otl_ora7_no_stream;
20013       throw;
20014     }
20015     delete (*ss);
20016     (*ss)=0;
20017     shell->stream_type=otl_ora7_no_stream;
20018     break;
20019   case otl_ora7_refcur_select_stream:
20020     try{
20021       (*ref_ss)->close();
20022     }catch(OTL_CONST_EXCEPTION otl_exception&){
20023       delete (*ref_ss);
20024       (*ref_ss)=0;
20025       shell->stream_type=otl_ora7_no_stream;
20026       throw;
20027     }
20028     delete (*ref_ss);
20029     (*ref_ss)=0;
20030     shell->stream_type=otl_ora7_no_stream;
20031     break;
20032   }
20033   (*ss)=0; (*io)=0; (*ref_ss)=0;
20034   if(adb!=0)(*adb)=0;
20035   adb=0;
20036  }
20037 
20038  void open
20039  (const otl_stream_buffer_size_type arr_size,
20040   const char* sqlstm,
20041   otl_connect& db,
20042   const char* ref_cur_placeholder=0,
20043   const char* sqlstm_label=0)
20044    OTL_THROWS_OTL_EXCEPTION
20045  {
20046    reset_end_marker();
20047    if(this->good()){
20048      const char* temp_stm_text=0;
20049      switch(shell->stream_type){
20050      case otl_ora7_no_stream:
20051        temp_stm_text=OTL_NO_STM_TEXT;
20052        break;
20053      case otl_ora7_io_stream:
20054        temp_stm_text=(*io)->get_stm_label()?
20055                      (*io)->get_stm_label():(*io)->get_stm_text();
20056        break;
20057      case otl_ora7_select_stream:
20058        temp_stm_text=(*ss)->get_stm_label()?
20059                      (*ss)->get_stm_label():(*ss)->get_stm_text();
20060      case otl_ora7_refcur_select_stream:
20061        temp_stm_text=(*ref_ss)->get_stm_label()?
20062                      (*ref_ss)->get_stm_label():(*ref_ss)->get_stm_text();
20063        break;
20064      default:
20065        temp_stm_text=OTL_NO_STM_TEXT;
20066        break;
20067      }
20068      throw otl_exception
20069        (otl_error_msg_29,
20070         otl_error_code_29,
20071         temp_stm_text);
20072    }
20073   if(shell==0)
20074    init_stream();
20075   buf_size_=arr_size;
20076   OTL_TRACE_STREAM_OPEN2
20077 
20078 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
20079   char temp_buf[128];
20080   otl_itoa(arr_size,temp_buf);
20081   OTL_STRING_CONTAINER sql_stm=OTL_STRING_CONTAINER(temp_buf)+
20082     OTL_STRING_CONTAINER("===>")+sqlstm;
20083   otl_stream_shell* temp_shell=OTL_RCAST(otl_stream_shell*,
20084                                          db.sc.find(sql_stm));
20085   if(temp_shell){
20086    if(shell!=0)
20087     shell_pt.destroy();
20088    shell=temp_shell;
20089    ref_ss=&(shell->ref_ss);
20090    ss=&(shell->ss);
20091    io=&(shell->io);
20092    if((*io)!=0)(*io)->set_flush_flag2(true);
20093    adb=&(shell->adb);
20094    auto_commit_flag=&(shell->auto_commit_flag);
20095    iov=&(shell->iov);
20096    iov_len=&(shell->iov_len);
20097    next_iov_ndx=&(shell->next_iov_ndx);
20098    ov=&(shell->ov);
20099    ov_len=&(shell->ov_len);
20100    next_ov_ndx=&(shell->next_ov_ndx);
20101    override=&(shell->override);
20102    override->set_master_stream_ptr(OTL_RCAST(void*,this));
20103    try{
20104      if((*iov_len)==0)this->rewind();
20105    }catch(OTL_CONST_EXCEPTION otl_exception&){
20106      if((*adb))
20107       (*adb)->sc.remove(shell,shell->orig_sql_stm);
20108      intern_cleanup();
20109      shell_pt.destroy();
20110      connected=0;
20111      throw;
20112    }
20113 
20114    connected=1;
20115    return;
20116   }
20117   shell->orig_sql_stm=sql_stm;
20118 #endif
20119 
20120   delete[] (*iov);
20121   delete[] (*ov);
20122 
20123   (*iov)=0; (*iov_len)=0;
20124   (*ov)=0; (*ov_len)=0;
20125   (*next_iov_ndx)=0;
20126   (*next_ov_ndx)=0;
20127 
20128   char tmp[7];
20129   char* c=OTL_CCAST(char*,sqlstm);
20130 
20131   while(otl_isspace(*c)||(*c)=='(')++c;
20132   OTL_STRNCPY_S(tmp,sizeof(tmp),c,6);
20133   tmp[6]=0;
20134   c=tmp;
20135   while(*c){
20136    *c=OTL_SCAST(char,otl_to_upper(*c));
20137    ++c;
20138   }
20139   if(adb==0)adb=&(shell->adb);
20140   (*adb)=&db;
20141   (*adb)->reset_throw_count();
20142   try{
20143    if((strncmp(tmp,"SELECT",6)==0||
20144        strncmp(tmp,"WITH",4)==0)&&
20145       ref_cur_placeholder==0){
20146      override->set_master_stream_ptr(OTL_RCAST(void*,this));
20147      (*ss)=new otl_select_stream
20148        (override,
20149         arr_size,
20150         sqlstm,
20151         db,
20152         otl_explicit_select,
20153         sqlstm_label);
20154      shell->stream_type=otl_ora7_select_stream;
20155    }else if(ref_cur_placeholder!=0){
20156      override->set_master_stream_ptr(OTL_RCAST(void*,this));
20157      (*ref_ss)=new otl_ref_select_stream
20158        (override,arr_size,sqlstm,
20159         ref_cur_placeholder,db,
20160         sqlstm_label);
20161      shell->stream_type=otl_ora7_refcur_select_stream;
20162    }else{
20163      (*io)=new otl_inout_stream
20164        (arr_size,sqlstm,db,
20165         OTL_RCAST(void*,this),
20166         false,sqlstm_label);
20167      (*io)->set_flush_flag(shell->flush_flag);
20168      shell->stream_type=otl_ora7_io_stream;
20169    }
20170   }catch(OTL_CONST_EXCEPTION otl_exception&){
20171    shell_pt.destroy();
20172    throw;
20173   }
20174   if((*io))(*io)->set_commit((*auto_commit_flag));
20175   create_var_desc();
20176   connected=1;
20177  }
20178 
20179 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
20180  void close(const bool save_in_stream_pool=true)
20181    OTL_THROWS_OTL_EXCEPTION
20182 #else
20183  void close(void)
20184    OTL_THROWS_OTL_EXCEPTION
20185 #endif
20186  {
20187   if(shell==0)return;
20188   OTL_TRACE_FUNC(0x4,"otl_stream","close","")
20189 
20190 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
20191   if(save_in_stream_pool&&(*adb)&&
20192 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
20193      !(otl_uncaught_exception())&&
20194 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
20195      !(otl_uncaught_exception())&&
20196 #endif
20197      (*adb)->get_throw_count()==0){
20198    try{
20199     this->flush();
20200     this->clean(1);
20201    }catch(OTL_CONST_EXCEPTION otl_exception&){
20202     this->clean(1);
20203     throw;
20204    }
20205    if((*adb) && (*adb)->get_throw_count()>0){
20206     (*adb)->sc.remove(shell,shell->orig_sql_stm);
20207     intern_cleanup();
20208     shell_pt.destroy();
20209     connected=0;
20210     return;
20211    }
20212 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
20213    if(otl_uncaught_exception()){
20214     if((*adb))
20215      (*adb)->sc.remove(shell,shell->orig_sql_stm);
20216     intern_cleanup();
20217     shell_pt.destroy();
20218     connected=0;
20219     return;
20220    }
20221 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
20222    if(otl_uncaught_exception()){
20223      if((*adb))
20224        (*adb)->sc.remove(shell,shell->orig_sql_stm);
20225      intern_cleanup();
20226      shell_pt.destroy();
20227      connected=0;
20228      return;
20229    }
20230 #endif
20231    (*adb)->sc.add(shell,shell->orig_sql_stm.c_str());
20232    shell_pt.disconnect();
20233    connected=0;
20234   }else{
20235    if((*adb))
20236     (*adb)->sc.remove(shell,shell->orig_sql_stm);
20237    intern_cleanup();
20238    shell_pt.destroy();
20239    connected=0;
20240   }
20241 #else
20242   intern_cleanup();
20243   connected=0;
20244 #endif
20245  }
20246 
20247  otl_column_desc* describe_select(int& desc_len) OTL_NO_THROW
20248  {
20249    desc_len=0;
20250    switch(shell->stream_type){
20251    case otl_ora7_no_stream:
20252      return 0;
20253    case otl_ora7_io_stream:
20254      return 0;
20255    case otl_ora7_select_stream:
20256      (*adb)->reset_throw_count();
20257      desc_len=(*ss)->get_sl_len();
20258      return (*ss)->get_sl_desc();
20259    case otl_ora7_refcur_select_stream:
20260      (*adb)->reset_throw_count();
20261      desc_len=(*ref_ss)->sl_len;
20262      return (*ref_ss)->sl_desc;
20263    default:
20264      return 0;
20265    }
20266  }
20267 
20268  int good(void) OTL_NO_THROW
20269  {
20270    if(!connected)return 0;
20271    if((*io)||(*ss)||(*ref_ss)){
20272      (*adb)->reset_throw_count();
20273      return 1;
20274    }else
20275      return 0;
20276  }
20277 
20278   otl_stream& operator>>(otl_stream& (*pf) (otl_stream&))
20279   {
20280     (*pf)(*this);
20281     return *this;
20282   }
20283 
20284   otl_stream& operator<<(otl_stream& (*pf) (otl_stream&))
20285   {
20286     (*pf)(*this);
20287     return *this;
20288   }
20289 
20290  otl_stream& operator>>(otl_pl_tab_generic& tab)
20291    OTL_THROWS_OTL_EXCEPTION
20292  {
20293   last_oper_was_read_op=true;
20294   if((*io)){
20295     last_eof_rc=(*io)->eof();
20296    (*io)->operator>>(tab);
20297    OTL_TRACE_WRITE(", tab len="<<tab.len(),"operator >>","PL/SQL Tab&")
20298    inc_next_ov();
20299   }
20300   return *this;
20301  }
20302 
20303  otl_stream& operator<<(otl_pl_tab_generic& tab)
20304    OTL_THROWS_OTL_EXCEPTION
20305  {
20306   last_oper_was_read_op=false;
20307    reset_end_marker();
20308   if((*io)){
20309     OTL_TRACE_READ(", tab len="<<tab.len(),"operator <<","PL/SQL Tab&")
20310    (*io)->operator<<(tab);
20311    inc_next_iov();
20312   }
20313   return *this;
20314  }
20315 
20316 #if defined(OTL_PL_TAB) && defined(OTL_STL)
20317 
20318  otl_stream& operator>>(otl_pl_vec_generic& vec)
20319    OTL_THROWS_OTL_EXCEPTION
20320  {
20321   last_oper_was_read_op=true;
20322    if((*io)){
20323      last_eof_rc=(*io)->eof();
20324      (*io)->operator>>(vec);
20325      OTL_TRACE_WRITE(", tab len="<<vec.len(),"operator >>","PL/SQL Tab&")
20326      inc_next_ov();
20327    }
20328    return *this;
20329  }
20330 
20331  otl_stream& operator<<(otl_pl_vec_generic& vec)
20332    OTL_THROWS_OTL_EXCEPTION
20333  {
20334   last_oper_was_read_op=false;
20335    reset_end_marker();
20336   if((*io)){
20337    (*io)->operator<<(vec);
20338    OTL_TRACE_READ(", tab len="<<vec.len(),"operator <<","PL/SQL Tab&")
20339    inc_next_iov();
20340   }
20341   return *this;
20342  }
20343 
20344 #endif
20345 
20346  otl_stream& operator>>(otl_time0& s)
20347    OTL_THROWS_OTL_EXCEPTION
20348  {
20349    last_oper_was_read_op=true;
20350    switch(shell->stream_type){
20351    case otl_ora7_no_stream:
20352      break;
20353    case otl_ora7_io_stream:
20354      last_eof_rc=(*io)->eof();
20355      (*io)->operator>>(s);
20356      break;
20357    case otl_ora7_select_stream:
20358      last_eof_rc=(*ss)->eof();
20359      (*ss)->operator>>(s);
20360      break;
20361    case otl_ora7_refcur_select_stream:
20362      last_eof_rc=(*ref_ss)->eof();
20363      (*ref_ss)->operator>>(s);
20364      break;
20365    }
20366    return *this;
20367  }
20368 
20369  otl_stream& operator<<(const otl_time0& n)
20370    OTL_THROWS_OTL_EXCEPTION
20371  {
20372    last_oper_was_read_op=false;
20373    reset_end_marker();
20374    switch(shell->stream_type){
20375    case otl_ora7_no_stream:
20376      break;
20377    case otl_ora7_io_stream:
20378      (*io)->operator<<(n);
20379      break;
20380    case otl_ora7_select_stream:
20381      (*ss)->operator<<(n);
20382      break;
20383    case otl_ora7_refcur_select_stream:
20384      (*ref_ss)->operator<<(n);
20385      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
20386      break;
20387    }
20388    return *this;
20389  }
20390 
20391  otl_stream& operator>>(otl_datetime& s)
20392    OTL_THROWS_OTL_EXCEPTION
20393  {
20394   last_oper_was_read_op=true;
20395 #if defined(OTL_ORA7) && defined(OTL_ORA7_STRING_TO_TIMESTAMP)
20396   if(describe_next_out_var()->ftype==otl_var_char){
20397     char tmp_str[100];
20398     (*this)>>tmp_str;
20399 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
20400     if((*this).is_null())
20401       s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
20402     else
20403       OTL_ORA7_STRING_TO_TIMESTAMP(tmp_str,s);
20404 #else
20405     OTL_ORA7_STRING_TO_TIMESTAMP(tmp_str,s);
20406 #endif
20407     OTL_TRACE_WRITE
20408       (OTL_TRACE_FORMAT_DATETIME(s),
20409        "operator >>",
20410        "otl_datetime&");
20411     return *this;
20412   }else{
20413     otl_time0 tmp;
20414     (*this)>>tmp;
20415 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
20416     if((*this).is_null())
20417       s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
20418     else{
20419       s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
20420       s.month=tmp.month;
20421       s.day=tmp.day;
20422       s.hour=tmp.hour-1;
20423       s.minute=tmp.minute-1;
20424       s.second=tmp.second-1;
20425     }
20426 #else
20427     s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
20428     s.month=tmp.month;
20429     s.day=tmp.day;
20430     s.hour=tmp.hour-1;
20431     s.minute=tmp.minute-1;
20432     s.second=tmp.second-1;
20433 #endif
20434     OTL_TRACE_WRITE
20435       (OTL_TRACE_FORMAT_DATETIME(s),
20436        "operator >>",
20437        "otl_datetime&")
20438       inc_next_ov();
20439     return *this;
20440   }
20441 #else
20442   otl_time0 tmp;
20443   (*this)>>tmp;
20444 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
20445   if((*this).is_null())
20446    s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
20447   else{
20448    s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
20449    s.month=tmp.month;
20450    s.day=tmp.day;
20451    s.hour=tmp.hour-1;
20452    s.minute=tmp.minute-1;
20453    s.second=tmp.second-1;
20454   }
20455 #else
20456   s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
20457   s.month=tmp.month;
20458   s.day=tmp.day;
20459   s.hour=tmp.hour-1;
20460   s.minute=tmp.minute-1;
20461   s.second=tmp.second-1;
20462 #endif
20463   OTL_TRACE_WRITE
20464     (OTL_TRACE_FORMAT_DATETIME(s),
20465      "operator >>",
20466      "otl_datetime&")
20467   inc_next_ov();
20468   return *this;
20469 #endif
20470  }
20471 
20472  otl_stream& operator<<(const otl_datetime& s)
20473    OTL_THROWS_OTL_EXCEPTION
20474  {
20475    last_oper_was_read_op=false;
20476    reset_end_marker();
20477 #if defined(OTL_ORA7) && defined(OTL_ORA7_TIMESTAMP_TO_STRING)
20478     if(describe_next_in_var()->ftype==otl_var_char){
20479      char tmp_str[100];
20480      OTL_ORA7_TIMESTAMP_TO_STRING(s,tmp_str);
20481      OTL_TRACE_READ
20482        (OTL_TRACE_FORMAT_DATETIME(s),
20483         "operator <<",
20484         "otl_datetime&");
20485      (*this)<<tmp_str;
20486      return *this;
20487    }else{
20488      otl_time0 tmp;
20489      tmp.year=OTL_SCAST(unsigned char, ((s.year%100)+100));
20490      tmp.century=OTL_SCAST(unsigned char, ((s.year/100)+100));
20491      tmp.month=OTL_SCAST(unsigned char, s.month);
20492      tmp.day=OTL_SCAST(unsigned char, s.day);
20493      tmp.hour=OTL_SCAST(unsigned char, (s.hour+1));
20494      tmp.minute=OTL_SCAST(unsigned char, (s.minute+1));
20495      tmp.second=OTL_SCAST(unsigned char, (s.second+1));
20496      OTL_TRACE_READ
20497        (OTL_TRACE_FORMAT_DATETIME(s),
20498         "operator <<",
20499         "otl_datetime&");
20500      (*this)<<tmp;
20501      inc_next_iov();
20502      return *this;
20503    }
20504 #else
20505      otl_time0 tmp;
20506      tmp.year=OTL_SCAST(unsigned char, ((s.year%100)+100));
20507      tmp.century=OTL_SCAST(unsigned char, ((s.year/100)+100));
20508      tmp.month=OTL_SCAST(unsigned char, s.month);
20509      tmp.day=OTL_SCAST(unsigned char, s.day);
20510      tmp.hour=OTL_SCAST(unsigned char, (s.hour+1));
20511      tmp.minute=OTL_SCAST(unsigned char, (s.minute+1));
20512      tmp.second=OTL_SCAST(unsigned char, (s.second+1));
20513      OTL_TRACE_READ
20514        (OTL_TRACE_FORMAT_DATETIME(s),
20515         "operator <<",
20516         "otl_datetime&");
20517      (*this)<<tmp;
20518      inc_next_iov();
20519      return *this;
20520 #endif
20521  }
20522 
20523  otl_stream& operator>>(char& c)
20524    OTL_THROWS_OTL_EXCEPTION
20525  {
20526    last_oper_was_read_op=true;
20527    switch(shell->stream_type){
20528    case otl_ora7_no_stream:
20529      break;
20530    case otl_ora7_io_stream:
20531      last_eof_rc=(*io)->eof();
20532      (*io)->operator>>(c);
20533      break;
20534    case otl_ora7_select_stream:
20535      last_eof_rc=(*ss)->eof();
20536      (*ss)->operator>>(c);
20537      break;
20538    case otl_ora7_refcur_select_stream:
20539      last_eof_rc=(*ref_ss)->eof();
20540      (*ref_ss)->operator>>(c);
20541      break;
20542    }
20543 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
20544   if((*this).is_null())
20545    c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
20546 #endif
20547   OTL_TRACE_WRITE("'"<<c<<"'","operator >>","char&")
20548   inc_next_ov();
20549   return *this;
20550  }
20551 
20552  otl_stream& operator>>(unsigned char& c)
20553    OTL_THROWS_OTL_EXCEPTION
20554  {
20555    last_oper_was_read_op=true;
20556    switch(shell->stream_type){
20557    case otl_ora7_no_stream:
20558      break;
20559    case otl_ora7_io_stream:
20560      last_eof_rc=(*io)->eof();
20561      (*io)->operator>>(c);
20562      break;
20563    case otl_ora7_select_stream:
20564      last_eof_rc=(*ss)->eof();
20565      (*ss)->operator>>(c);
20566      break;
20567    case otl_ora7_refcur_select_stream:
20568      last_eof_rc=(*ref_ss)->eof();
20569      (*ref_ss)->operator>>(c);
20570      break;
20571    }
20572 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
20573   if((*this).is_null())
20574    c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
20575 #endif
20576   OTL_TRACE_WRITE("'"<<c<<"'","operator >>","unsigned char&")
20577   inc_next_ov();
20578   return *this;
20579  }
20580 
20581 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
20582  otl_stream& operator>>(OTL_STRING_CONTAINER& s)
20583    OTL_THROWS_OTL_EXCEPTION
20584  {
20585    last_oper_was_read_op=true;
20586    switch(shell->stream_type){
20587    case otl_ora7_no_stream:
20588      break;
20589    case otl_ora7_io_stream:
20590      last_eof_rc=(*io)->eof();
20591      (*io)->operator>>(s);
20592      break;
20593    case otl_ora7_select_stream:
20594      last_eof_rc=(*ss)->eof();
20595      (*ss)->operator>>(s);
20596      break;
20597    case otl_ora7_refcur_select_stream:
20598      last_eof_rc=(*ref_ss)->eof();
20599      (*ref_ss)->operator>>(s);
20600      break;
20601    }
20602 
20603 #if defined(OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL)
20604    if((*this).is_null()){
20605      OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL(s);
20606    }
20607 #elif defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
20608    if((*this).is_null())
20609      s=OTL_DEFAULT_STRING_NULL_TO_VAL;
20610 #endif
20611 
20612    OTL_TRACE_WRITE("\""<<s<<"\"","operator >>","OTL_STRING_CONTAINER&")
20613    inc_next_ov();
20614    return *this;
20615  }
20616 #endif
20617 
20618  otl_stream& operator>>(char* s)
20619    OTL_THROWS_OTL_EXCEPTION
20620  {
20621    last_oper_was_read_op=true;
20622    switch(shell->stream_type){
20623    case otl_ora7_no_stream:
20624      break;
20625    case otl_ora7_io_stream:
20626      last_eof_rc=(*io)->eof();
20627      (*io)->operator>>(s);
20628      break;
20629    case otl_ora7_select_stream:
20630      last_eof_rc=(*ss)->eof();
20631      (*ss)->operator>>(s);
20632      break;
20633    case otl_ora7_refcur_select_stream:
20634      last_eof_rc=(*ref_ss)->eof();
20635      (*ref_ss)->operator>>(s);
20636      break;
20637    }
20638 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
20639    if((*this).is_null())
20640      otl_strcpy(OTL_RCAST(unsigned char*,s),
20641                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL)
20642                );
20643 #endif
20644    OTL_TRACE_WRITE("\""<<s<<"\"","operator >>","char*")
20645    inc_next_ov();
20646    return *this;
20647  }
20648 
20649  otl_stream& operator>>(unsigned char* s)
20650    OTL_THROWS_OTL_EXCEPTION
20651  {
20652    last_oper_was_read_op=true;
20653    switch(shell->stream_type){
20654    case otl_ora7_no_stream:
20655      break;
20656    case otl_ora7_io_stream:
20657      last_eof_rc=(*io)->eof();
20658      (*io)->operator>>(s);
20659      break;
20660    case otl_ora7_select_stream:
20661      last_eof_rc=(*ss)->eof();
20662      (*ss)->operator>>(s);
20663      break;
20664    case otl_ora7_refcur_select_stream:
20665      last_eof_rc=(*ref_ss)->eof();
20666      (*ref_ss)->operator>>(s);
20667      break;
20668    }
20669 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
20670    if((*this).is_null())
20671      otl_strcpy(OTL_RCAST(unsigned char*,s),
20672                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL)
20673                );
20674 #endif
20675 
20676 #if defined(OTL_UNICODE)
20677    OTL_TRACE_WRITE
20678      ("\""<<OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
20679       "operator >>",
20680       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*")
20681 #else
20682    OTL_TRACE_WRITE("\""<<s<<"\"","operator >>","unsigned char*")
20683 #endif
20684    inc_next_ov();
20685    return *this;
20686  }
20687 
20688  otl_stream& operator>>(int& n)
20689    OTL_THROWS_OTL_EXCEPTION
20690  {
20691    last_oper_was_read_op=true;
20692    switch(shell->stream_type){
20693    case otl_ora7_no_stream:
20694      break;
20695    case otl_ora7_io_stream:
20696      last_eof_rc=(*io)->eof();
20697 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20698      (*io)->operator>>(n);
20699 #else
20700      (*io)->operator>><int,otl_var_int>(n);
20701 #endif
20702      break;
20703    case otl_ora7_select_stream:
20704      last_eof_rc=(*ss)->eof();
20705 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20706      (*ss)->operator>>(n);
20707 #else
20708      (*ss)->operator>><int,otl_var_int>(n);
20709 #endif
20710      break;
20711    case otl_ora7_refcur_select_stream:
20712      last_eof_rc=(*ref_ss)->eof();
20713 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20714      (*ref_ss)->operator>>(n);
20715 #else
20716      (*ref_ss)->operator>><int,otl_var_int>(n);
20717 #endif
20718      break;
20719    }
20720 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
20721    if((*this).is_null())
20722      n=OTL_SCAST(int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
20723 #endif
20724    OTL_TRACE_WRITE(n,"operator >>","int&")
20725    inc_next_ov();
20726    return *this;
20727  }
20728 
20729  otl_stream& operator>>(unsigned& u)
20730    OTL_THROWS_OTL_EXCEPTION
20731  {
20732    last_oper_was_read_op=true;
20733    switch(shell->stream_type){
20734    case otl_ora7_no_stream:
20735      break;
20736    case otl_ora7_io_stream:
20737      last_eof_rc=(*io)->eof();
20738 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20739      (*io)->operator>>(u);
20740 #else
20741      (*io)->operator>><unsigned,otl_var_unsigned_int>(u);
20742 #endif
20743      break;
20744    case otl_ora7_select_stream:
20745      last_eof_rc=(*ss)->eof();
20746 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20747      (*ss)->operator>>(u);
20748 #else
20749      (*ss)->operator>><unsigned,otl_var_unsigned_int>(u);
20750 #endif
20751      break;
20752    case otl_ora7_refcur_select_stream:
20753      last_eof_rc=(*ref_ss)->eof();
20754 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20755      (*ref_ss)->operator>>(u);
20756 #else
20757      (*ref_ss)->operator>><unsigned,otl_var_unsigned_int>(u);
20758 #endif
20759      break;
20760    }
20761 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
20762    if((*this).is_null())
20763      u=OTL_SCAST(unsigned int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
20764 #endif
20765    OTL_TRACE_WRITE(u,"operator >>","unsigned&")
20766    inc_next_ov();
20767    return *this;
20768  }
20769 
20770  otl_stream& operator>>(short& sh)
20771    OTL_THROWS_OTL_EXCEPTION
20772  {
20773    last_oper_was_read_op=true;
20774    switch(shell->stream_type){
20775    case otl_ora7_no_stream:
20776      break;
20777    case otl_ora7_io_stream:
20778      last_eof_rc=(*io)->eof();
20779 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20780      (*io)->operator>>(sh);
20781 #else
20782      (*io)->operator>><short,otl_var_short>(sh);
20783 #endif
20784      break;
20785    case otl_ora7_select_stream:
20786      last_eof_rc=(*ss)->eof();
20787 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20788      (*ss)->operator>>(sh);
20789 #else
20790      (*ss)->operator>><short,otl_var_short>(sh);
20791 #endif
20792      break;
20793    case otl_ora7_refcur_select_stream:
20794      last_eof_rc=(*ref_ss)->eof();
20795 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20796      (*ref_ss)->operator>>(sh);
20797 #else
20798      (*ref_ss)->operator>><short,otl_var_short>(sh);
20799 #endif
20800      break;
20801    }
20802 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
20803    if((*this).is_null())
20804      sh=OTL_SCAST(short int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
20805 #endif
20806    OTL_TRACE_WRITE(sh,"operator >>","short int&")
20807   inc_next_ov();
20808   return *this;
20809  }
20810 
20811  otl_stream& operator>>(long int& l)
20812    OTL_THROWS_OTL_EXCEPTION
20813  {
20814    last_oper_was_read_op=true;
20815    switch(shell->stream_type){
20816    case otl_ora7_no_stream:
20817      break;
20818    case otl_ora7_io_stream:
20819      last_eof_rc=(*io)->eof();
20820 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20821      (*io)->operator>>(l);
20822 #else
20823      (*io)->operator>><long,otl_var_long_int>(l);
20824 #endif
20825      break;
20826    case otl_ora7_select_stream:
20827      last_eof_rc=(*ss)->eof();
20828 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20829      (*ss)->operator>>(l);
20830 #else
20831      (*ss)->operator>><long,otl_var_long_int>(l);
20832 #endif
20833      break;
20834    case otl_ora7_refcur_select_stream:
20835      last_eof_rc=(*ref_ss)->eof();
20836 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20837      (*ref_ss)->operator>>(l);
20838 #else
20839      (*ref_ss)->operator>><long,otl_var_long_int>(l);
20840 #endif
20841      break;
20842    }
20843 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
20844    if((*this).is_null())
20845    l=OTL_SCAST(long int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
20846 #endif
20847    OTL_TRACE_WRITE(l,"operator >>","long int&")
20848    inc_next_ov();
20849    return *this;
20850  }
20851 
20852  otl_stream& operator>>(float& f)
20853    OTL_THROWS_OTL_EXCEPTION
20854  {
20855    last_oper_was_read_op=true;
20856    switch(shell->stream_type){
20857    case otl_ora7_no_stream:
20858      break;
20859    case otl_ora7_io_stream:
20860      last_eof_rc=(*io)->eof();
20861 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20862      (*io)->operator>>(f);
20863 #else
20864      (*io)->operator>><float,otl_var_float>(f);
20865 #endif
20866      break;
20867    case otl_ora7_select_stream:
20868      last_eof_rc=(*ss)->eof();
20869 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20870      (*ss)->operator>>(f);
20871 #else
20872      (*ss)->operator>><float,otl_var_float>(f);
20873 #endif
20874      break;
20875    case otl_ora7_refcur_select_stream:
20876      last_eof_rc=(*ref_ss)->eof();
20877 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20878      (*ref_ss)->operator>>(f);
20879 #else
20880      (*ref_ss)->operator>><float,otl_var_float>(f);
20881 #endif
20882      break;
20883    }
20884 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
20885    if((*this).is_null())
20886      f=OTL_SCAST(float,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
20887 #endif
20888    OTL_TRACE_WRITE(f,"operator >>","float&")
20889    inc_next_ov();
20890    return *this;
20891  }
20892 
20893  otl_stream& operator>>(double& d)
20894    OTL_THROWS_OTL_EXCEPTION
20895  {
20896    last_oper_was_read_op=true;
20897    switch(shell->stream_type){
20898    case otl_ora7_no_stream:
20899      break;
20900    case otl_ora7_io_stream:
20901      last_eof_rc=(*io)->eof();
20902 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20903      (*io)->operator>>(d);
20904 #else
20905      (*io)->operator>><double,otl_var_double>(d);
20906 #endif
20907      break;
20908    case otl_ora7_select_stream:
20909      last_eof_rc=(*ss)->eof();
20910 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20911      (*ss)->operator>>(d);
20912 #else
20913      (*ss)->operator>><double,otl_var_double>(d);
20914 #endif
20915      break;
20916    case otl_ora7_refcur_select_stream:
20917      last_eof_rc=(*ref_ss)->eof();
20918 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
20919      (*ref_ss)->operator>>(d);
20920 #else
20921      (*ref_ss)->operator>><double,otl_var_double>(d);
20922 #endif
20923      break;
20924    }
20925 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
20926   if((*this).is_null())
20927     d=OTL_SCAST(double,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
20928 #endif
20929   OTL_TRACE_WRITE(d,"operator >>","double&")
20930   inc_next_ov();
20931   return *this;
20932  }
20933 
20934  otl_stream& operator>>(otl_long_string& s)
20935    OTL_THROWS_OTL_EXCEPTION
20936  {
20937    last_oper_was_read_op=true;
20938    switch(shell->stream_type){
20939    case otl_ora7_no_stream:
20940      break;
20941    case otl_ora7_io_stream:
20942      last_eof_rc=(*io)->eof();
20943      (*io)->operator>>(s);
20944      break;
20945    case otl_ora7_select_stream:
20946      last_eof_rc=(*ss)->eof();
20947      (*ss)->operator>>(s);
20948      break;
20949    case otl_ora7_refcur_select_stream:
20950      last_eof_rc=(*ref_ss)->eof();
20951      (*ref_ss)->operator>>(s);
20952      break;
20953    }
20954    OTL_TRACE_WRITE(" len="<<s.len(),"operator >>","otl_long_string&")
20955    inc_next_ov();
20956    return *this;
20957  }
20958 
20959  otl_stream& operator<<(const char c)
20960    OTL_THROWS_OTL_EXCEPTION
20961  {
20962    last_oper_was_read_op=false;
20963    reset_end_marker();
20964    OTL_TRACE_READ("'"<<c<<"'","operator <<","char")
20965    switch(shell->stream_type){
20966    case otl_ora7_no_stream:
20967      break;
20968    case otl_ora7_io_stream:
20969     (*io)->operator<<(c);
20970      break;
20971    case otl_ora7_select_stream:
20972      (*ss)->operator<<(c);
20973      break;
20974    case otl_ora7_refcur_select_stream:
20975      (*ref_ss)->operator<<(c);
20976      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
20977      break;
20978    }
20979   inc_next_iov();
20980   return *this;
20981  }
20982 
20983  otl_stream& operator<<(const unsigned char c)
20984    OTL_THROWS_OTL_EXCEPTION
20985  {
20986    last_oper_was_read_op=false;
20987    reset_end_marker();
20988    OTL_TRACE_READ("'"<<c<<"'","operator <<","unsigned char")
20989    switch(shell->stream_type){
20990    case otl_ora7_no_stream:
20991      break;
20992    case otl_ora7_io_stream:
20993      (*io)->operator<<(c);
20994      break;
20995    case otl_ora7_select_stream:
20996      (*ss)->operator<<(c);
20997      break;
20998    case otl_ora7_refcur_select_stream:
20999      (*ref_ss)->operator<<(c);
21000      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21001      break;
21002    }
21003   inc_next_iov();
21004   return *this;
21005  }
21006 
21007 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
21008  otl_stream& operator<<(const OTL_STRING_CONTAINER& s)
21009    OTL_THROWS_OTL_EXCEPTION
21010  {
21011    last_oper_was_read_op=false;
21012    reset_end_marker();
21013    OTL_TRACE_READ("\""<<s<<"\"","operator <<","OTL_STRING_CONTAINER&")
21014    switch(shell->stream_type){
21015    case otl_ora7_no_stream:
21016      break;
21017    case otl_ora7_io_stream:
21018      (*io)->operator<<(s);
21019      break;
21020    case otl_ora7_select_stream:
21021      (*ss)->operator<<(s);
21022      break;
21023    case otl_ora7_refcur_select_stream:
21024      (*ref_ss)->operator<<(s);
21025      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21026      break;
21027    }
21028   inc_next_iov();
21029   return *this;
21030  }
21031 #endif
21032 
21033 
21034  otl_stream& operator<<(const char* s)
21035    OTL_THROWS_OTL_EXCEPTION
21036  {
21037    last_oper_was_read_op=false;
21038    reset_end_marker();
21039    OTL_TRACE_READ("\""<<s<<"\"","operator <<","char*")
21040    switch(shell->stream_type){
21041    case otl_ora7_no_stream:
21042      break;
21043    case otl_ora7_io_stream:
21044      (*io)->operator<<(s);
21045      break;
21046    case otl_ora7_select_stream:
21047      (*ss)->operator<<(s);
21048      break;
21049    case otl_ora7_refcur_select_stream:
21050      (*ref_ss)->operator<<(s);
21051      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21052      break;
21053    }
21054   inc_next_iov();
21055   return *this;
21056  }
21057 
21058  otl_stream& operator<<(const unsigned char* s)
21059    OTL_THROWS_OTL_EXCEPTION
21060  {
21061    last_oper_was_read_op=false;
21062    reset_end_marker();
21063 #if defined(OTL_UNICODE)
21064    OTL_TRACE_READ
21065      ("\""<<OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
21066       "operator <<",
21067       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*")
21068 #else
21069    OTL_TRACE_READ("\""<<s<<"\"","operator <<","unsigned char*")
21070 #endif
21071    switch(shell->stream_type){
21072    case otl_ora7_no_stream:
21073      break;
21074    case otl_ora7_io_stream:
21075      (*io)->operator<<(s);
21076      break;
21077    case otl_ora7_select_stream:
21078      (*ss)->operator<<(s);
21079      break;
21080    case otl_ora7_refcur_select_stream:
21081      (*ref_ss)->operator<<(s);
21082      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21083      break;
21084    }
21085    inc_next_iov();
21086    return *this;
21087  }
21088 
21089  otl_stream& operator<<(const int n)
21090    OTL_THROWS_OTL_EXCEPTION
21091  {
21092    last_oper_was_read_op=false;
21093    reset_end_marker();
21094    OTL_TRACE_READ(n,"operator <<","int")
21095    switch(shell->stream_type){
21096    case otl_ora7_no_stream:
21097      break;
21098    case otl_ora7_io_stream:
21099 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21100      (*io)->operator<<(n);
21101 #else
21102      (*io)->operator<<<int,otl_var_int>(n);
21103 #endif
21104      break;
21105    case otl_ora7_select_stream:
21106 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21107      (*ss)->operator<<(n);
21108 #else
21109      (*ss)->operator<<<int,otl_var_int>(n);
21110 #endif
21111      break;
21112    case otl_ora7_refcur_select_stream:
21113 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21114      (*ref_ss)->operator<<(n);
21115 #else
21116      (*ref_ss)->operator<<<int,otl_var_int>(n);
21117 #endif
21118      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21119      break;
21120    }
21121    inc_next_iov();
21122    return *this;
21123  }
21124 
21125  otl_stream& operator<<(const unsigned u)
21126    OTL_THROWS_OTL_EXCEPTION
21127  {
21128    last_oper_was_read_op=false;
21129    reset_end_marker();
21130    OTL_TRACE_READ(u,"operator <<","unsigned")
21131    switch(shell->stream_type){
21132    case otl_ora7_no_stream:
21133      break;
21134    case otl_ora7_io_stream:
21135 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21136      (*io)->operator<<(u);
21137 #else
21138      (*io)->operator<<<unsigned,otl_var_unsigned_int>(u);
21139 #endif
21140      break;
21141    case otl_ora7_select_stream:
21142 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21143      (*ss)->operator<<(u);
21144 #else
21145      (*ss)->operator<<<unsigned,otl_var_unsigned_int>(u);
21146 #endif
21147      break;
21148    case otl_ora7_refcur_select_stream:
21149 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21150      (*ref_ss)->operator<<(u);
21151 #else
21152      (*ref_ss)->operator<<<unsigned,otl_var_unsigned_int>(u);
21153 #endif
21154      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21155      break;
21156    }
21157    inc_next_iov();
21158    return *this;
21159  }
21160 
21161  otl_stream& operator<<(const short sh)
21162    OTL_THROWS_OTL_EXCEPTION
21163  {
21164    last_oper_was_read_op=false;
21165    reset_end_marker();
21166    OTL_TRACE_READ(sh,"operator <<","short int")
21167    switch(shell->stream_type){
21168    case otl_ora7_no_stream:
21169      break;
21170    case otl_ora7_io_stream:
21171 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21172      (*io)->operator<<(sh);
21173 #else
21174      (*io)->operator<<<short,otl_var_short>(sh);
21175 #endif
21176      break;
21177    case otl_ora7_select_stream:
21178 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21179      (*ss)->operator<<(sh);
21180 #else
21181      (*ss)->operator<<<short,otl_var_short>(sh);
21182 #endif
21183      break;
21184    case otl_ora7_refcur_select_stream:
21185 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21186      (*ref_ss)->operator<<(sh);
21187 #else
21188      (*ref_ss)->operator<<<short,otl_var_short>(sh);
21189 #endif
21190      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21191      break;
21192    }
21193    inc_next_iov();
21194    return *this;
21195  }
21196 
21197  otl_stream& operator<<(const long int l)
21198    OTL_THROWS_OTL_EXCEPTION
21199  {
21200    last_oper_was_read_op=false;
21201    reset_end_marker();
21202    OTL_TRACE_READ(l,"operator <<","long int")
21203    switch(shell->stream_type){
21204    case otl_ora7_no_stream:
21205      break;
21206    case otl_ora7_io_stream:
21207 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21208      (*io)->operator<<(l);
21209 #else
21210      (*io)->operator<<<long,otl_var_long_int>(l);
21211 #endif
21212      break;
21213    case otl_ora7_select_stream:
21214 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21215      (*ss)->operator<<(l);
21216 #else
21217      (*ss)->operator<<<long,otl_var_long_int>(l);
21218 #endif
21219      break;
21220    case otl_ora7_refcur_select_stream:
21221 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21222      (*ref_ss)->operator<<(l);
21223 #else
21224      (*ref_ss)->operator<<<long,otl_var_long_int>(l);
21225 #endif
21226      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21227      break;
21228    }
21229    inc_next_iov();
21230    return *this;
21231  }
21232 
21233  otl_stream& operator<<(const float f)
21234    OTL_THROWS_OTL_EXCEPTION
21235  {
21236    last_oper_was_read_op=false;
21237    reset_end_marker();
21238    OTL_TRACE_READ(f,"operator <<","float")
21239    switch(shell->stream_type){
21240    case otl_ora7_no_stream:
21241      break;
21242    case otl_ora7_io_stream:
21243 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21244      (*io)->operator<<(f);
21245 #else
21246      (*io)->operator<<<float,otl_var_float>(f);
21247 #endif
21248      break;
21249    case otl_ora7_select_stream:
21250 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21251      (*ss)->operator<<(f);
21252 #else
21253      (*ss)->operator<<<float,otl_var_float>(f);
21254 #endif
21255      break;
21256    case otl_ora7_refcur_select_stream:
21257 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21258      (*ref_ss)->operator<<(f);
21259 #else
21260      (*ref_ss)->operator<<<float,otl_var_float>(f);
21261 #endif
21262      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21263      break;
21264    }
21265    inc_next_iov();
21266    return *this;
21267  }
21268 
21269  otl_stream& operator<<(const double d)
21270    OTL_THROWS_OTL_EXCEPTION
21271  {
21272    last_oper_was_read_op=false;
21273    reset_end_marker();
21274    OTL_TRACE_READ(d,"operator <<","double")
21275    switch(shell->stream_type){
21276    case otl_ora7_no_stream:
21277      break;
21278    case otl_ora7_io_stream:
21279 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21280      (*io)->operator<<(d);
21281 #else
21282      (*io)->operator<<<double,otl_var_double>(d);
21283 #endif
21284      break;
21285    case otl_ora7_select_stream:
21286 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21287      (*ss)->operator<<(d);
21288 #else
21289      (*ss)->operator<<<double,otl_var_double>(d);
21290 #endif
21291      break;
21292    case otl_ora7_refcur_select_stream:
21293 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
21294      (*ref_ss)->operator<<(d);
21295 #else
21296      (*ref_ss)->operator<<<double,otl_var_double>(d);
21297 #endif
21298      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21299      break;
21300    }
21301    inc_next_iov();
21302    return *this;
21303  }
21304 
21305   otl_stream& operator<<(const otl_null& n)
21306     OTL_THROWS_OTL_EXCEPTION
21307  {
21308    last_oper_was_read_op=false;
21309    reset_end_marker();
21310    OTL_TRACE_READ("NULL","operator <<","otl_null&")
21311    switch(shell->stream_type){
21312    case otl_ora7_no_stream:
21313      break;
21314    case otl_ora7_io_stream:
21315      (*io)->operator<<(n);
21316      break;
21317    case otl_ora7_select_stream:
21318      (*ss)->operator<<(n);
21319      break;
21320    case otl_ora7_refcur_select_stream:
21321      (*ref_ss)->operator<<(n);
21322      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21323      break;
21324    }
21325    inc_next_iov();
21326    return *this;
21327  }
21328 
21329  otl_stream& operator<<(const otl_long_string& d)
21330    OTL_THROWS_OTL_EXCEPTION
21331  {
21332    last_oper_was_read_op=false;
21333    reset_end_marker();
21334    OTL_TRACE_READ(" len="<<d.len(),"operator <<","otl_long_string&")
21335    switch(shell->stream_type){
21336    case otl_ora7_no_stream:
21337      break;
21338    case otl_ora7_io_stream:
21339      (*io)->operator<<(d);
21340      break;
21341    case otl_ora7_select_stream:
21342      (*ss)->operator<<(d);
21343      break;
21344    case otl_ora7_refcur_select_stream:
21345      (*ref_ss)->operator<<(d);
21346      if(!(*ov)&&(*ref_ss)->sl) create_var_desc();
21347      break;
21348    }
21349    inc_next_iov();
21350    return *this;
21351  }
21352 
21353 private:
21354 
21355   otl_stream& operator=(const otl_stream&)
21356   {
21357     return *this;
21358   }
21359 
21360   otl_stream(const otl_stream&):
21361    shell(0),
21362    shell_pt(),
21363    connected(0),
21364    ref_ss(0),
21365    ss(0),
21366    io(0),
21367    adb(0),
21368    auto_commit_flag(0),
21369    iov(0),
21370    iov_len(0),
21371    next_iov_ndx(0),
21372    ov(0),
21373    ov_len(0),
21374    next_ov_ndx(0),
21375    override(0),
21376    end_marker(0),
21377    oper_int_called(0),
21378    last_eof_rc(0),
21379    last_oper_was_read_op(0),
21380    buf_size_(0)
21381   {
21382   }
21383 
21384 #if !defined(OTL_STREAM_NO_PRIVATE_BOOL_OPERATORS)
21385   otl_stream& operator>>(bool&)
21386     OTL_NO_THROW
21387   {
21388    return *this;
21389   }
21390 
21391   otl_stream& operator<<(const bool)
21392     OTL_NO_THROW
21393   {
21394    return *this;
21395   }
21396 
21397 #endif
21398 
21399 #if !defined(OTL_STREAM_NO_PRIVATE_UNSIGNED_LONG_OPERATORS)
21400   otl_stream& operator>>(unsigned long int&)
21401     OTL_NO_THROW
21402   {
21403    return *this;
21404   }
21405 
21406   otl_stream& operator<<(const unsigned long int)
21407     OTL_NO_THROW
21408   {
21409    return *this;
21410   }
21411 #endif
21412 
21413 };
21414 
21415 inline otl_connect& operator>>(otl_connect& connect, otl_stream& s)
21416 {
21417   const char* cmd=connect.getCmd();
21418   const char* invalid_cmd="*** INVALID COMMAND ***";
21419   if(!cmd)
21420     cmd=invalid_cmd;
21421   s.open(s.getBufSize(),cmd,connect);
21422   return connect;
21423 }
21424 
21425 #if (defined(OTL_STL)||defined(OTL_VALUE_TEMPLATE_ON)) && defined(OTL_VALUE_TEMPLATE)
21426 template <OTL_TYPE_NAME TData>
21427 otl_stream& operator<<(otl_stream& s, const otl_value<TData>& var)
21428   OTL_THROWS_OTL_EXCEPTION
21429 {
21430  if(var.ind)
21431   s<<otl_null();
21432  else
21433   s<<var.v;
21434  return s;
21435 }
21436 
21437 template <OTL_TYPE_NAME TData>
21438 otl_stream& operator>>(otl_stream& s, otl_value<TData>& var)
21439   OTL_THROWS_OTL_EXCEPTION
21440 {
21441   s>>var.v;
21442   if(s.is_null())
21443     var.ind=true;
21444   else
21445     var.ind=false;
21446   return s;
21447 }
21448 
21449 #endif
21450 
21451 typedef otl_tmpl_nocommit_stream
21452 <otl_stream,
21453  otl_connect,
21454  otl_exception> otl_nocommit_stream;
21455 
21456 #if defined(OTL_BIGINT) && defined(OTL_STR_TO_BIGINT) && \
21457     defined(OTL_BIGINT_TO_STR)
21458 inline otl_stream& operator>>(otl_stream& s, OTL_BIGINT& n)
21459   OTL_THROWS_OTL_EXCEPTION
21460 {
21461   char temp_val[otl_bigint_str_size];
21462 
21463   s>>temp_val;
21464   if(s.is_null()){
21465 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
21466    if(s.is_null())
21467      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
21468 #endif
21469     return s;
21470   }
21471   OTL_STR_TO_BIGINT(temp_val,n)
21472   return s;
21473 }
21474 
21475 inline otl_stream& operator<<(otl_stream& s, const OTL_BIGINT n)
21476   OTL_THROWS_OTL_EXCEPTION
21477 {
21478   char temp_val[otl_bigint_str_size];
21479   OTL_BIGINT_TO_STR(n,temp_val);
21480   s<<temp_val;
21481   return s;
21482 }
21483 #elif defined(OTL_BIGINT) && defined(OTL_ORA_MAP_BIGINT_TO_LONG)
21484 inline otl_stream& operator>>(otl_stream& s, OTL_BIGINT& n)
21485   OTL_THROWS_OTL_EXCEPTION
21486 {
21487   long temp_val;
21488 
21489   s>>temp_val;
21490   if(s.is_null()){
21491 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
21492    if(s.is_null())
21493      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
21494 #endif
21495     return s;
21496   }
21497   n=OTL_SCAST(OTL_BIGINT,temp_val);
21498   return s;
21499 }
21500 
21501 inline otl_stream& operator<<(otl_stream& s, const OTL_BIGINT n)
21502   OTL_THROWS_OTL_EXCEPTION
21503 {
21504   long temp_val=OTL_SCAST(long,n);
21505   s<<temp_val;
21506   return s;
21507 }
21508 
21509 #endif
21510 
21511 inline otl_stream& endr(otl_stream& s)
21512 {
21513   s.check_end_of_row();
21514   return s;
21515 }
21516 
21517 OTL_ORA7_NAMESPACE_END
21518 #endif
21519 
21520 // ==================== OTL-Adapter for Oracle 8 =====================
21521 #if defined(OTL_ORA8)
21522 #if defined(__STDC__)
21523 #define __STDC__DEFINED
21524 #else
21525 #define __STDC__ 1 // making OCI function prototypes show up in oci.h
21526 #endif
21527 #if defined(OTL_ORA_TEXT_ON)
21528 #define text OTL_ORA_TEXT
21529 #endif
21530 #include <oci.h>
21531 
21532 #if !defined(OTL_ORA_DOES_NOT_UNDEF_MIN_MAX)
21533 
21534 #if defined(min)
21535 #undef min
21536 #endif
21537 
21538 #if defined(max)
21539 #undef max
21540 #endif
21541 
21542 #endif
21543 
21544 #define OTL_UTF8_BYTES_PER_CHAR (4)
21545 
21546 #if defined(OTL_ORA8_PROC)
21547 extern "C" {
21548 #include <sql2oci.h>
21549 }
21550 #endif
21551 
21552 OTL_ORA8_NAMESPACE_BEGIN
21553 
21554 const int inVarChar2=1;
21555 const int inNumber=2;
21556 const int inLong=8;
21557 const int inRowId=104;
21558 const int inDate=12;
21559 const int inRaw=23;
21560 const int inLongRaw=24;
21561 const int inChar=96;
21562 #if defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)
21563 const int inBFloat=SQLT_IBFLOAT;
21564 const int inBDouble=SQLT_IBDOUBLE;
21565 #endif
21566 const int inMslabel=105;
21567 const int inUserDefinedType=108;
21568 const int inRef=111;
21569 const int inCLOB=112;
21570 const int inBLOB=113;
21571 
21572 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
21573 const int inTimestamp=SQLT_TIMESTAMP;
21574 const int inTimestamp_TZ=SQLT_TIMESTAMP_TZ;
21575 const int inTimestamp_LTZ=SQLT_TIMESTAMP_LTZ;
21576 const int inIntervalYM=SQLT_INTERVAL_YM;
21577 const int inIntervalDS=SQLT_INTERVAL_DS;
21578 #endif
21579 
21580 const int  extVarChar2=1;
21581 const int  extNumber=2;
21582 const int  extInt=3;
21583 const int  extFloat=4;
21584 #if defined(OTL_ORA_MAP_STRINGS_TO_CHARZ)
21585 const int  extCChar=97;
21586 #else
21587 const int  extCChar=5;
21588 #endif
21589 const int  extVarNum=6;
21590 const int  extLong=8;
21591 const int  extVarChar=9;
21592 const int  extRowId=11;
21593 const int  extDate=12;
21594 const int  extVarRaw=15;
21595 const int  extRaw=extVarRaw;
21596 const int  extLongRaw=24;
21597 const int  extUInt=68;
21598 const int  extLongVarChar=94;
21599 const int  extLongVarRaw=95;
21600 const int  extChar=96;
21601 const int  extCharZ=97;
21602 const int  extMslabel=105;
21603 const int  extCLOB=inCLOB;
21604 const int  extBLOB=inBLOB;
21605 
21606 #if (defined(OTL_ORA10G)||defined(OTL_ORA10G_R2))&&!defined(OTL_ORA_LEGACY_NUMERIC_TYPES)
21607 const int extBFloat=SQLT_BFLOAT;
21608 const int extBDouble=SQLT_BDOUBLE;
21609 #endif
21610 
21611 
21612 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
21613 const int extTimestamp=SQLT_TIMESTAMP;
21614 const int extTimestamp_TZ=SQLT_TIMESTAMP_TZ;
21615 const int extTimestamp_LTZ=SQLT_TIMESTAMP_LTZ;
21616 #endif
21617 
21618 
21619 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
21620 typedef otl_datetime otl_time0;
21621 #else
21622 typedef otl_oracle_date otl_time0;
21623 #endif
21624 
21625 
21626 class otl_exc{
21627 public:
21628   unsigned char msg[1000];
21629   int code;
21630   char sqlstate[32];
21631 
21632 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
21633   int error_offset;
21634 #endif
21635 
21636 #if defined(OTL_EXTENDED_EXCEPTION)
21637   char** msg_arr;
21638   char** sqlstate_arr;
21639   int* code_arr;
21640   int arr_len;
21641 #endif
21642 
21643   enum{disabled=0,enabled=1};
21644 
21645   otl_exc():
21646     msg(),
21647     code(0),
21648     sqlstate()
21649 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
21650     ,error_offset(-1)
21651 #endif
21652 #if defined(OTL_EXTENDED_EXCEPTION)
21653     ,msg_arr(0),
21654     sqlstate_arr(0),
21655     code_arr(0),
21656     arr_len(0)
21657 #endif
21658   {
21659     sqlstate[0]=0;
21660     msg[0]=0;
21661   }
21662 
21663   virtual ~otl_exc(){}
21664 
21665  void init(const char* amsg, const int acode)
21666  {
21667    OTL_STRCPY_S(OTL_RCAST(char*,msg),sizeof(msg),amsg);
21668    code=acode;
21669 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
21670    error_offset=-1;
21671 #endif
21672 #if defined(OTL_EXTENDED_EXCEPTION)
21673    msg_arr=0;
21674    sqlstate_arr=0;
21675    code_arr=0;
21676    arr_len=0;
21677 #endif
21678  }
21679 
21680 };
21681 
21682 class otl_cur;
21683 class otl_var;
21684 
21685 class otl_conn{
21686 private:
21687 
21688   friend class otl_cur;
21689   friend class otl_var;
21690 
21691   OCIEnv *envhp; // OCI environment handle
21692   OCIServer *srvhp; // OCI Server handle
21693   OCIError *errhp; // OCI Error handle
21694   OCISvcCtx *svchp; // OCI Service context handle
21695   OCISession *authp; // OCI Session handle
21696   int auto_commit;
21697   int extern_lda;
21698   int attached;
21699   int in_session;
21700   int char_set_;
21701   int session_begin_count;
21702   int session_mode_;
21703   int ext_cred;
21704   int last_status;
21705   char* xa_server_external_name;
21706   char* xa_server_internal_name;
21707 
21708 #if defined(OTL_ORA_OCI_ENV_CREATE)
21709   bool threaded_mode;
21710 #endif
21711 
21712 public:
21713 
21714 #if defined(OTL_ORA_OCI_ENV_CREATE)
21715   void set_threaded_mode(const bool athreaded_mode)
21716   {
21717     threaded_mode=athreaded_mode;
21718   }
21719 #endif
21720 
21721 
21722   void cleanup(void)
21723   {
21724     session_end();
21725     server_detach();
21726   }
21727 
21728   int get_session_begin_count() const
21729   {
21730     return session_begin_count;
21731   }
21732 
21733   int get_extern_lda() const
21734   {
21735     return extern_lda;
21736   }
21737 
21738   int get_last_status() const
21739   {
21740     return last_status;
21741   }
21742 
21743   int get_auto_commit() const
21744   {
21745     return auto_commit;
21746   }
21747 
21748   OCIEnv* get_envhp()
21749   {
21750     return envhp;
21751   }
21752 
21753   OCIError* get_errhp()
21754   {
21755     return errhp;
21756   }
21757 
21758   OCISvcCtx* get_svchp()
21759   {
21760     return svchp;
21761   }
21762 
21763   OCIServer* get_srvhp()
21764   {
21765     return srvhp;
21766   }
21767 
21768   OCISession* get_authp()
21769   {
21770     return authp;
21771   }
21772 
21773   int get_char_set() const
21774   {
21775     return char_set_;
21776   }
21777 
21778   int get_connection_type(void)
21779   {
21780     return 0;
21781   }
21782 
21783 #if !defined(OTL_ORA_OCI_ENV_CREATE)
21784   static int initialize(const int threaded_mode=0)
21785   {
21786     int status;
21787     int mode;
21788     if(threaded_mode)
21789       mode=OCI_THREADED;
21790     else
21791       mode=OCI_DEFAULT;
21792     status=OCIInitialize
21793       (OTL_SCAST(ub4,mode),
21794        OTL_RCAST(dvoid *,0),
21795        0,
21796        0,
21797        0);
21798     if(status!=OCI_SUCCESS)
21799       return 0;
21800     else
21801       return 1;
21802 #else
21803   static int initialize(const int /*threaded_mode*/)
21804   {
21805     return 1;
21806 #endif
21807   }
21808 
21809   otl_conn():
21810     envhp(0),
21811     srvhp(0),
21812     errhp(0),
21813     svchp(0),
21814     authp(0),
21815     auto_commit(0),
21816     extern_lda(0),
21817     attached(0),
21818     in_session(0),
21819     char_set_(SQLCS_IMPLICIT),
21820     session_begin_count(0),
21821     session_mode_(OCI_DEFAULT),
21822     ext_cred(0),
21823     last_status(OCI_SUCCESS),
21824     xa_server_external_name(0),
21825     xa_server_internal_name(0)
21826 #if defined(OTL_ORA_OCI_ENV_CREATE)
21827     ,threaded_mode(false)
21828 #endif
21829  {
21830  }
21831 
21832 #if defined(OTL_ORA_OCI_ENV_CREATE)
21833   void set_connect_mode(bool mode)
21834   {
21835     threaded_mode=mode;
21836   }
21837 #endif
21838 
21839  void set_char_set(const int char_set)
21840  {
21841   char_set_=char_set;
21842  }
21843 
21844   void set_xa_server_external_name(const char* name)
21845   {
21846    if(xa_server_external_name){
21847      delete[] xa_server_external_name;
21848      xa_server_external_name=0;
21849    }
21850    size_t len=strlen(name)+1;
21851    xa_server_external_name=new char[len];
21852    OTL_STRCPY_S(xa_server_external_name,len,name);
21853   }
21854 
21855   void set_xa_server_internal_name(const char* name)
21856   {
21857    if(xa_server_internal_name){
21858      delete[] xa_server_internal_name;
21859      xa_server_internal_name=0;
21860    }
21861    size_t len=strlen(name)+1;
21862    xa_server_internal_name=new char[len];
21863    OTL_STRCPY_S(xa_server_internal_name,len,name);
21864   }
21865 
21866   void delete_xa_strings(void )
21867   {
21868     if(xa_server_external_name){
21869       delete[] xa_server_external_name;
21870       xa_server_external_name=0;
21871     }
21872     if(xa_server_internal_name){
21873       delete[] xa_server_internal_name;
21874       xa_server_internal_name=0;
21875     }
21876   }
21877 
21878  virtual ~otl_conn()
21879  {
21880    delete_xa_strings();
21881  }
21882 
21883   void set_timeout(const int /*atimeout*/=0){}
21884   void set_cursor_type(const int /*acursor_type*/=0){}
21885 
21886  int cancel(void)
21887  {int status;
21888   status=OCIBreak(srvhp,errhp);
21889   if(status)
21890    return 0;
21891   else
21892    return 1;
21893  }
21894 
21895  int server_attach(const char* tnsname)
21896  {int& status=last_status;
21897 
21898   envhp=0;
21899   srvhp=0;
21900   errhp=0;
21901   svchp=0;
21902   authp=0;
21903   extern_lda=0;
21904   attached=0;
21905   in_session=0;
21906   session_begin_count=0;
21907 
21908 #if !defined(OTL_ORA_OCI_ENV_CREATE)
21909   status=OCIEnvInit
21910    (OTL_RCAST(OCIEnv**,&envhp),
21911     OCI_DEFAULT,
21912     0,
21913     0);
21914 #else
21915   status=OCIEnvCreate
21916     (OTL_RCAST(OCIEnv**,&envhp),
21917 #if defined(OTL_ORA_OCI_ENV_CREATE_MODE)
21918      OTL_ORA_OCI_ENV_CREATE_MODE,
21919 #else
21920      threaded_mode?OCI_THREADED:OCI_DEFAULT,
21921 #endif
21922      0,
21923      0,
21924      0,
21925      0,
21926      0,
21927      0);
21928 #endif
21929 
21930   if(status)return 0;
21931 
21932 #if defined(__GNUC__) && (__GNUC__>=4)
21933   void* temp_errhp=&errhp;
21934 #endif
21935   status=OCIHandleAlloc
21936    (OTL_RCAST(dvoid*,envhp),
21937 #if defined(__GNUC__) && (__GNUC__>=4)
21938     OTL_RCAST(dvoid**,temp_errhp),
21939 #else
21940     OTL_RCAST(dvoid**,&errhp),
21941 #endif
21942     OCI_HTYPE_ERROR,
21943     0,
21944     0);
21945   if(status)return 0;
21946 
21947 #if defined(__GNUC__) && (__GNUC__>=4)
21948   void* temp_srvhp=&srvhp;
21949 #endif
21950   status=OCIHandleAlloc
21951    (OTL_RCAST(dvoid*,envhp),
21952 #if defined(__GNUC__) && (__GNUC__>=4)
21953     OTL_RCAST(dvoid**,temp_srvhp),
21954 #else
21955     OTL_RCAST(dvoid**,&srvhp),
21956 #endif
21957     OCI_HTYPE_SERVER,
21958     0,
21959     0);
21960   if(status)return 0;
21961 
21962 #if defined(__GNUC__) && (__GNUC__>=4)
21963   void * temp_svchp=&svchp;
21964 #endif
21965   status=OCIHandleAlloc
21966    (OTL_RCAST(dvoid*,envhp),
21967 #if defined(__GNUC__) && (__GNUC__>=4)
21968     OTL_RCAST(dvoid**,temp_svchp),
21969 #else
21970     OTL_RCAST(dvoid**,&svchp),
21971 #endif
21972     OCI_HTYPE_SVCCTX,
21973     0,
21974     0);
21975   if(status)return 0;
21976 
21977   status=OCIServerAttach
21978    (srvhp,
21979     errhp,
21980     tnsname==0?OTL_RCAST(text*,OTL_CCAST(char*,"")):
21981                OTL_RCAST(text*,OTL_CCAST(char*,tnsname)),
21982     tnsname==0?0:OTL_SCAST(sb4,strlen(OTL_CCAST(char*,tnsname))),
21983     0);
21984   if(status)return 0;
21985   status=OCIAttrSet
21986    (OTL_RCAST(dvoid*,svchp),
21987     OCI_HTYPE_SVCCTX,
21988     OTL_RCAST(dvoid*,srvhp),
21989     0,
21990     OCI_ATTR_SERVER,
21991     OTL_RCAST(OCIError*,errhp));
21992   if(status)return 0;
21993 
21994   if(xa_server_external_name!=0 && xa_server_internal_name!=0){
21995     status=OCIAttrSet
21996       (OTL_RCAST(dvoid*,srvhp),
21997        OCI_HTYPE_SERVER,
21998        OTL_RCAST(dvoid*,xa_server_external_name),
21999        0,
22000        OCI_ATTR_EXTERNAL_NAME,
22001        errhp);
22002     if(status)return 0;
22003 
22004     status=OCIAttrSet
22005       (OTL_RCAST(dvoid*,srvhp),
22006        OCI_HTYPE_SERVER,
22007        OTL_RCAST(dvoid*,xa_server_internal_name),
22008        0,
22009        OCI_ATTR_INTERNAL_NAME,
22010        errhp);
22011     if(status)return 0;
22012   }
22013 
22014 #if defined(__GNUC__) && (__GNUC__>=4)
22015   void* temp_authp=&authp;
22016 #endif
22017   status=OCIHandleAlloc
22018    (OTL_RCAST(dvoid*,envhp),
22019 #if defined(__GNUC__) && (__GNUC__>=4)
22020     OTL_RCAST(dvoid **,temp_authp),
22021 #else
22022     OTL_RCAST(dvoid **,&authp),
22023 #endif
22024     OTL_SCAST(ub4,OCI_HTYPE_SESSION),
22025     0,
22026     0);
22027   if(status)return 0;
22028 
22029   attached=1;
22030   return 1;
22031 
22032  }
22033 
22034  int session_begin(const int aauto_commit)
22035   {int& status=last_status;
22036   int cred_type;
22037 
22038   if(!attached)return 0;
22039   if(session_begin_count==0)return 0;
22040 
22041   if(ext_cred)
22042    cred_type=OCI_CRED_EXT;
22043   else
22044    cred_type=OCI_CRED_RDBMS;
22045   status=OCISessionBegin
22046    (svchp,
22047     errhp,
22048     authp,
22049     cred_type,
22050     OTL_SCAST(ub4,session_mode_));
22051   if(status!=OCI_SUCCESS &&
22052      status!=OCI_SUCCESS_WITH_INFO)
22053     return 0;
22054 
22055   in_session=1;
22056   auto_commit=aauto_commit;
22057   ++session_begin_count;
22058   return 1;
22059 
22060  }
22061 
22062  int session_begin
22063    (const char* userid,
22064     const char* password,
22065     const int aauto_commit,
22066     const int session_mode=OCI_DEFAULT)
22067  {int& status=last_status;
22068   int cred_type;
22069 
22070   if(!attached)return 0;
22071 
22072   status=OCIAttrSet
22073    (OTL_RCAST(dvoid*,authp),
22074     OTL_SCAST(ub4,OCI_HTYPE_SESSION),
22075     OTL_RCAST(dvoid*,OTL_CCAST(char*,userid)),
22076     OTL_SCAST(ub4,strlen(OTL_CCAST(char*,userid))),
22077     OTL_SCAST(ub4,OCI_ATTR_USERNAME),
22078     errhp);
22079   if(status)return 0;
22080 
22081   status=OCIAttrSet
22082    (OTL_RCAST(dvoid*,authp),
22083     OTL_SCAST(ub4,OCI_HTYPE_SESSION),
22084     OTL_RCAST(dvoid*,OTL_CCAST(char*,password)),
22085     OTL_SCAST(ub4,strlen(OTL_CCAST(char*,password))),
22086     OTL_SCAST(ub4,OCI_ATTR_PASSWORD),
22087     errhp);
22088   if(status)return 0;
22089 
22090    cred_type=OCI_CRED_RDBMS;
22091 
22092   if(userid[0]==0&&password[0]==0){
22093    ext_cred=1;
22094    cred_type=OCI_CRED_EXT;
22095   }else{
22096    ext_cred=0;
22097    cred_type=OCI_CRED_RDBMS;
22098   }
22099 
22100   session_mode_=session_mode;
22101   status=OCISessionBegin
22102    (svchp,
22103     errhp,
22104     authp,
22105     cred_type,
22106     OTL_SCAST(ub4,session_mode_));
22107   if(status!=OCI_SUCCESS &&
22108      status!=OCI_SUCCESS_WITH_INFO)
22109     return 0;
22110 
22111   status=OCIAttrSet
22112    (OTL_RCAST(dvoid*,svchp),
22113     OTL_SCAST(ub4,OCI_HTYPE_SVCCTX),
22114     OTL_RCAST(dvoid *,authp),
22115     0,
22116     OTL_SCAST(ub4,OCI_ATTR_SESSION),
22117     errhp);
22118   if(status)return 0;
22119 
22120   in_session=1;
22121   auto_commit=aauto_commit;
22122   ++session_begin_count;
22123   return 1;
22124 
22125  }
22126 
22127 #if defined(OTL_ORA8I) || defined(OTL_ORA9I)
22128   int change_password
22129   (const char* user_name,
22130    const char* password,
22131    const char* new_password)
22132   {int& status=last_status;
22133 
22134     OCIAttrSet
22135       (OTL_RCAST(dvoid*,svchp),
22136        OTL_SCAST(ub4,OCI_HTYPE_SVCCTX),
22137        OTL_RCAST(dvoid *,authp),
22138        0,
22139        OTL_SCAST(ub4,OCI_ATTR_SESSION),
22140        errhp);
22141 
22142     status=OCIPasswordChange
22143       (svchp,
22144        errhp,
22145        OTL_RCAST(text*,OTL_CCAST(char*,user_name)),
22146        OTL_SCAST(ub4,strlen(user_name)),
22147        OTL_RCAST(text*,OTL_CCAST(char*,password)),
22148        OTL_SCAST(ub4,strlen(password)),
22149        OTL_RCAST(text*,OTL_CCAST(char*,new_password)),
22150        OTL_SCAST(ub4,strlen(new_password)),
22151        OCI_AUTH);
22152     if(status)
22153       return 0;
22154     else
22155       return 1;
22156 
22157   }
22158 #endif
22159 
22160  int server_detach(void)
22161  {int rc=0;
22162   if(attached){
22163    OCIServerDetach(srvhp,errhp,OTL_SCAST(ub4,OCI_DEFAULT));
22164    rc=1;
22165   }
22166   if(authp!=0)OCIHandleFree(OTL_RCAST(dvoid*,authp),
22167                             OTL_SCAST(ub4,OCI_HTYPE_SESSION));
22168   if(errhp!=0)OCIHandleFree(OTL_RCAST(dvoid*,errhp),
22169                             OTL_SCAST(ub4,OCI_HTYPE_ERROR));
22170   if(svchp!=0)OCIHandleFree(OTL_RCAST(dvoid*,svchp),
22171                             OTL_SCAST(ub4,OCI_HTYPE_SVCCTX));
22172   if(srvhp!=0)OCIHandleFree(OTL_RCAST(dvoid*,srvhp),
22173                             OTL_SCAST(ub4,OCI_HTYPE_SERVER));
22174   if(envhp!=0)OCIHandleFree(OTL_RCAST(dvoid*,envhp),
22175                             OTL_SCAST(ub4,OCI_HTYPE_ENV));
22176   auto_commit=0;
22177   attached=0;
22178   in_session=0;
22179   envhp=0;
22180   srvhp=0;
22181   errhp=0;
22182   svchp=0;
22183   authp=0;
22184   delete_xa_strings();
22185   return rc;
22186  }
22187 
22188  int session_end(void)
22189  {int& status=last_status;
22190   if(!in_session)return 0;
22191   status=OCISessionEnd(svchp,errhp,authp,0);
22192   if(status)return 0;
22193 
22194   in_session=0;
22195   auto_commit=0;
22196   return 1;
22197  }
22198 
22199  int auto_commit_on(void)
22200  {
22201   auto_commit=1;
22202   return 1;
22203  }
22204 
22205  int auto_commit_off(void)
22206  {
22207   auto_commit=0;
22208   return 1;
22209  }
22210 
22211  int rlogon(const char* connect_str,const int aauto_commit)
22212  {
22213    int status;
22214    char username[256];
22215    char passwd[256];
22216    char tnsname[1024];
22217    char* tnsname_ptr=0;
22218    char* username_ptr=username;
22219    char* c=OTL_CCAST(char*,connect_str);
22220    char* passwd_ptr=passwd;
22221    char prev_c=' ';
22222 
22223    auto_commit=aauto_commit;
22224 
22225    username[0]=0;
22226    passwd[0]=0;
22227    tnsname[0]=0;
22228 
22229    while(*c&&*c!='/'&&(OTL_SCAST(unsigned,username_ptr-username)<
22230                        sizeof(username)-1)){
22231     *username_ptr=*c;
22232     ++c;
22233     ++username_ptr;
22234    }
22235    *username_ptr=0;
22236    if(*c=='/')++c;
22237    prev_c=' ';
22238    while(*c && !(*c=='@' && prev_c!='\\') &&
22239          (OTL_SCAST(unsigned,passwd_ptr-passwd)<sizeof(passwd)-1)){
22240      if(prev_c=='\\')--passwd_ptr;
22241      *passwd_ptr=*c;
22242      prev_c=*c;
22243      ++c;
22244      ++passwd_ptr;
22245    }
22246    *passwd_ptr=0;
22247 
22248    if(*c=='@'){
22249      ++c;
22250      tnsname_ptr=tnsname;
22251      while(*c&&(OTL_SCAST(unsigned,tnsname_ptr-tnsname)<sizeof(tnsname)-1)){
22252        *tnsname_ptr=*c;
22253        ++c;
22254        ++tnsname_ptr;
22255      }
22256      *tnsname_ptr=0;
22257    }
22258 
22259    envhp=0;
22260    srvhp=0;
22261    errhp=0;
22262    svchp=0;
22263    authp=0;
22264    extern_lda=0;
22265    attached=0;
22266    in_session=0;
22267 
22268   OTL_TRACE_RLOGON_ORA8
22269     (0x1,
22270      "otl_connect",
22271      "rlogon",
22272      tnsname,
22273      username,
22274      passwd,
22275      auto_commit)
22276 
22277    status=server_attach(tnsname);
22278    if(!status)return 0;
22279 
22280    status=session_begin(username,passwd,aauto_commit);
22281    if(!status)return 0;
22282 
22283    return 1;
22284 
22285  }
22286 
22287  int ext_logon(OCIEnv *a_envhp,OCISvcCtx *a_svchp,const int aauto_commit=0)
22288  {int& status=last_status;
22289 
22290   envhp=a_envhp;
22291   svchp=a_svchp;
22292   errhp=0;
22293   srvhp=0;
22294   authp=0;
22295   extern_lda=1;
22296   auto_commit=aauto_commit;
22297 
22298 #if defined(__GNUC__) && (__GNUC__>=4)
22299   void* temp_errhp=&errhp;
22300 #endif
22301   status=OCIHandleAlloc
22302    (OTL_RCAST(dvoid*,envhp),
22303 #if defined(__GNUC__) && (__GNUC__>=4)
22304     OTL_RCAST(dvoid**,temp_errhp),
22305 #else
22306     OTL_RCAST(dvoid**,&errhp),
22307 #endif
22308     OCI_HTYPE_ERROR,
22309     0,
22310     0);
22311   if(status)return 0;
22312 
22313   return 1;
22314 
22315  }
22316 
22317  int logoff(void)
22318  {
22319   int rc;
22320   if(extern_lda){
22321    OCIHandleFree(OTL_RCAST(dvoid*,errhp), OTL_SCAST(ub4,OCI_HTYPE_ERROR));
22322    envhp=0;
22323    svchp=0;
22324    errhp=0;
22325    extern_lda=0;
22326   }else{
22327    rc=session_end();
22328    if(!rc)return 0;
22329    rc=server_detach();
22330    if(!rc)return 0;
22331   }
22332   auto_commit=0;
22333   return 1;
22334  }
22335 
22336  void error(otl_exc& exception_struct)
22337  {sb4 errcode;
22338   size_t len;
22339   OCIErrorGet
22340    (OTL_RCAST(dvoid*,errhp),
22341     OTL_SCAST(ub4,1),
22342     0,
22343     &errcode,
22344     OTL_RCAST(text*,exception_struct.msg),
22345     OTL_SCAST(ub4,sizeof(exception_struct.msg)),
22346     OCI_HTYPE_ERROR);
22347   exception_struct.code=errcode;
22348   len=strlen(OTL_RCAST(char*,exception_struct.msg));
22349   exception_struct.msg[len]=0;
22350  }
22351 
22352  int commit(void)
22353  {
22354    last_status=OCITransCommit(svchp,errhp,OTL_SCAST(ub4,OCI_DEFAULT));
22355    return !last_status;
22356  }
22357 
22358 #if defined(OTL_ORA10G_R2)
22359 
22360  int commit_nowait(void)
22361  {
22362 #if defined(OCI_TRANS_WRITENOWAIT)
22363    last_status=OCITransCommit
22364      (svchp,
22365       errhp,
22366       OTL_SCAST(ub4,OCI_TRANS_WRITENOWAIT));
22367 #else
22368    last_status=OCITransCommit
22369      (svchp,
22370       errhp,
22371       OTL_SCAST(ub4,0x00000008));
22372 #endif
22373    return !last_status;
22374  }
22375 
22376 #endif
22377 
22378  int rollback(void)
22379  {
22380    last_status=OCITransRollback(svchp,errhp,OTL_SCAST(ub4,OCI_DEFAULT));
22381    return !last_status;
22382  }
22383 
22384 private:
22385 
22386   otl_conn(const otl_conn&):
22387     envhp(0),
22388     srvhp(0),
22389     errhp(0),
22390     svchp(0),
22391     authp(0),
22392     auto_commit(0),
22393     extern_lda(0),
22394     attached(0),
22395     in_session(0),
22396     char_set_(SQLCS_IMPLICIT),
22397     session_begin_count(0),
22398     session_mode_(OCI_DEFAULT),
22399     ext_cred(0),
22400     last_status(OCI_SUCCESS),
22401     xa_server_external_name(0),
22402     xa_server_internal_name(0)
22403 #if defined(OTL_ORA_OCI_ENV_CREATE)
22404     ,threaded_mode(false)
22405 #endif
22406  {
22407  }
22408 
22409   otl_conn& operator=(const otl_conn&)
22410   {
22411     return *this;
22412   }
22413 
22414 };
22415 
22416 class otl_cur0{
22417 public:
22418   virtual ~otl_cur0(){}
22419 };
22420 
22421 class otl_cur;
22422 class otl_inout_stream;
22423 class otl_refcur_stream;
22424 class otl_ref_select_stream;
22425 
22426 class otl_var{
22427 private:
22428 
22429   friend class otl_cur;
22430   friend class otl_inout_stream;
22431   friend class otl_refcur_stream;
22432   friend class otl_ref_select_stream;
22433 
22434   ub1* p_v;
22435   sb2* p_ind;
22436   ub2* p_rlen;
22437   ub2* p_rcode;
22438   int ftype;
22439   int array_size;
22440   int elem_size;
22441   bool nls_flag;
22442   OCILobLocator** lob;
22443 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22444   OCIDateTime** timestamp;
22445 #endif
22446   OCIStmt* cda;
22447   otl_conn* connect;
22448   ub1* buf;
22449   int buf_len;
22450   int ext_buf_flag;
22451   int act_elem_size;
22452   ub4 max_tab_len;
22453   ub4 cur_tab_len;
22454   int pl_tab_flag;
22455   int lob_stream_flag;
22456   int vparam_type;
22457   int lob_len;
22458   int lob_pos;
22459   int lob_ftype;
22460   int otl_adapter;
22461   bool lob_stream_mode;
22462   sb4 unicode_var_len;
22463   ub2 csid;
22464   ub1 csfrm;
22465   ub4 read_blob_amt;
22466   ub4 total_read_blob_amt;
22467   bool charz_flag;
22468   bool select_stm_flag;
22469 
22470 public:
22471 
22472   int get_otl_adapter() const {return otl_adapter;}
22473   OCIStmt* get_cda(){return cda;}
22474   OCIStmt** get_cda_ptr(){return &cda;}
22475   void set_nls_flag(const bool anls_flag)
22476   {
22477     nls_flag=anls_flag;
22478   }
22479 
22480   void set_lob_stream_mode(const bool alob_stream_mode)
22481   {
22482     lob_stream_mode=alob_stream_mode;
22483   }
22484 
22485   void set_vparam_type(const int avparam_type)
22486   {
22487     vparam_type=avparam_type;
22488   }
22489 
22490   void set_charz_flag(const bool acharz_flag)
22491   {
22492     charz_flag=acharz_flag;
22493   }
22494 
22495   otl_var():
22496     p_v(0),
22497     p_ind(0),
22498     p_rlen(0),
22499     p_rcode(0),
22500     ftype(0),
22501     array_size(0),
22502     elem_size(0),
22503     nls_flag(false),
22504     lob(0),
22505 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22506     timestamp(0),
22507 #endif
22508     cda(0),
22509     connect(0),
22510     buf(0),
22511     buf_len(0),
22512     ext_buf_flag(0),
22513     act_elem_size(0),
22514     max_tab_len(0),
22515     cur_tab_len(0),
22516     pl_tab_flag(0),
22517     lob_stream_flag(0),
22518     vparam_type(-1),
22519     lob_len(0),
22520     lob_pos(0),
22521     lob_ftype(0),
22522     otl_adapter(otl_ora8_adapter),
22523     lob_stream_mode(false),
22524     unicode_var_len(0),
22525     csid(0),
22526     csfrm(SQLCS_IMPLICIT),
22527     read_blob_amt(0),
22528     total_read_blob_amt(0),
22529     charz_flag(false),
22530     select_stm_flag(false)
22531  {
22532  }
22533 
22534  virtual ~otl_var()
22535  {int i;
22536   if(ftype==otl_var_refcur&&cda!=0){
22537     OCIHandleFree(OTL_RCAST(dvoid*,cda),OCI_HTYPE_STMT);
22538     cda=0;
22539   }
22540   if(ftype==otl_var_blob||(ftype==otl_var_clob&&lob!=0)){
22541    for(i=0;i<array_size;++i)
22542     OCIDescriptorFree(OTL_RCAST(dvoid*,lob[i]),
22543                       OTL_SCAST(ub4,OCI_DTYPE_LOB));
22544   }
22545 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22546   if((ftype==otl_var_timestamp ||
22547       ftype==otl_var_tz_timestamp ||
22548       ((ftype==otl_var_ltz_timestamp)&&
22549        timestamp!=0))){
22550     ub4 dtype=0;
22551     switch(ftype){
22552     case otl_var_timestamp:
22553       dtype=OCI_DTYPE_TIMESTAMP;
22554       break;
22555     case otl_var_ltz_timestamp:
22556       dtype=OCI_DTYPE_TIMESTAMP_LTZ;
22557       break;
22558     case otl_var_tz_timestamp:
22559       dtype=OCI_DTYPE_TIMESTAMP_TZ;
22560       break;
22561     }
22562    for(i=0;i<array_size;++i)
22563     OCIDescriptorFree(OTL_RCAST(dvoid*,timestamp[i]),dtype);
22564   }
22565 #endif
22566   delete[] p_v;
22567   delete[] p_ind;
22568   delete[] p_rlen;
22569   delete[] p_rcode;
22570   if(!ext_buf_flag)
22571    delete[] buf;
22572  }
22573 
22574   int write_dt(void* trg,
22575                const void* src,
22576                const int
22577 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22578 #else
22579                sz
22580 #endif
22581               )
22582   {
22583 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22584     OCIDateTime* trg_ptr=OTL_RCAST(OCIDateTime*,trg);
22585     otl_datetime* src_ptr=OTL_RCAST(otl_datetime*,OTL_CCAST(void*,src));
22586     int rc=0;
22587     if(ftype!=otl_var_tz_timestamp){
22588       rc=OCIDateTimeConstruct
22589         (connect->envhp,
22590          connect->errhp,
22591          trg_ptr,
22592          OTL_SCAST(sb2,src_ptr->year),
22593          OTL_SCAST(ub1,src_ptr->month),
22594          OTL_SCAST(ub1,src_ptr->day),
22595          OTL_SCAST(ub1,src_ptr->hour),
22596          OTL_SCAST(ub1,src_ptr->minute),
22597          OTL_SCAST(ub1,src_ptr->second),
22598          OTL_SCAST
22599          (ub4,otl_to_fraction(src_ptr->fraction,
22600                               src_ptr->frac_precision)),
22601          0,
22602          0);
22603     }else{
22604       int tz_hour=src_ptr->tz_hour;
22605       int tz_minute=src_ptr->tz_minute;
22606       char tz_str[60];
22607       char* tzc=otl_itoa(tz_hour,tz_str);
22608       *tzc=':';
22609       ++tzc;
22610       tzc=otl_itoa(tz_minute,tzc);
22611       size_t tz_len=tzc-tz_str;
22612       rc=OCIDateTimeConstruct
22613         (connect->envhp,
22614          connect->errhp,
22615          trg_ptr,
22616          OTL_SCAST(sb2,src_ptr->year),
22617          OTL_SCAST(ub1,src_ptr->month),
22618          OTL_SCAST(ub1,src_ptr->day),
22619          OTL_SCAST(ub1,src_ptr->hour),
22620          OTL_SCAST(ub1,src_ptr->minute),
22621          OTL_SCAST(ub1,src_ptr->second),
22622          OTL_SCAST
22623          (ub4,otl_to_fraction(src_ptr->fraction,
22624                               src_ptr->frac_precision)),
22625          OTL_RCAST(text*,tz_str),
22626          tz_len);
22627     }
22628     if(rc!=0)return 0;
22629     return 1;
22630 #else
22631     memcpy(trg,src,sz);
22632     return 1;
22633 #endif
22634   }
22635 
22636   int read_dt(void* trg,
22637               const void* src,
22638               const int
22639 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22640 #else
22641               sz
22642 #endif
22643              )
22644   {
22645 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22646     OCIDateTime* src_ptr=OTL_RCAST(OCIDateTime*,OTL_CCAST(void*,src));
22647     otl_datetime* trg_ptr=OTL_RCAST(otl_datetime*,OTL_CCAST(void*,trg));
22648     sb2 year;
22649     ub1 month, day, hour, minute, sec;
22650     ub4 fsec;
22651     sb1 tz_hour;
22652     sb1 tz_minute;
22653     int rc=OCIDateTimeGetDate
22654       (connect->envhp,
22655        connect->errhp,
22656        src_ptr,
22657        &year,
22658        &month,
22659        &day);
22660     if(rc!=0)return 0;
22661     rc=OCIDateTimeGetTime
22662       (connect->envhp,
22663        connect->errhp,
22664        src_ptr,
22665        &hour,
22666        &minute,
22667        &sec,
22668        &fsec);
22669     if(rc!=0)return 0;
22670     trg_ptr->year=year;
22671     trg_ptr->month=month;
22672     trg_ptr->day=day;
22673     trg_ptr->hour=hour;
22674     trg_ptr->minute=minute;
22675     trg_ptr->second=sec;
22676     trg_ptr->fraction=otl_from_fraction(fsec,trg_ptr->frac_precision);
22677     trg_ptr->tz_hour=0;
22678     trg_ptr->tz_minute=0;
22679     if(ftype==otl_var_tz_timestamp ||
22680        ftype==otl_var_ltz_timestamp){
22681       rc=OCIDateTimeGetTimeZoneOffset
22682         (connect->envhp,
22683          connect->errhp,
22684          src_ptr,
22685          &tz_hour,
22686          &tz_minute);
22687       if(rc!=0)return 0;
22688       trg_ptr->tz_hour=tz_hour;
22689       trg_ptr->tz_minute=tz_minute;
22690     }
22691     return 1;
22692 #else
22693     memcpy(trg,src,sz);
22694     return 1;
22695 #endif
22696   }
22697 
22698 
22699  int actual_elem_size(void)
22700  {
22701   return act_elem_size;
22702  }
22703 
22704  void init
22705  (const bool aselect_stm_flag,
22706   const int aftype,
22707   int& aelem_size,
22708   const otl_stream_buffer_size_type aarray_size,
22709   const void* connect_struct=0,
22710   const int apl_tab_flag=0)
22711  {
22712   int i;
22713   ub4 lobEmpty=0;
22714   select_stm_flag=aselect_stm_flag;
22715   connect=OTL_RCAST(otl_conn*,OTL_CCAST(void*,connect_struct));
22716   ftype=aftype;
22717 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
22718   if(ftype==otl_var_nchar){
22719     ftype=otl_var_char;
22720     nls_flag=true;
22721   }else if(ftype==otl_var_nclob){
22722     ftype=otl_var_clob;
22723     nls_flag=true;
22724   }
22725 #endif
22726   pl_tab_flag=apl_tab_flag;
22727   act_elem_size=aelem_size;
22728 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22729   if((ftype==otl_var_timestamp ||
22730       ftype==otl_var_tz_timestamp ||
22731       ftype==otl_var_ltz_timestamp) &&
22732       apl_tab_flag)
22733     act_elem_size=sizeof(otl_oracle_date);
22734 #endif
22735   if(ftype==otl_var_refcur){
22736    array_size=aarray_size;
22737    elem_size=1;
22738 #if defined(__GNUC__) && (__GNUC__>=4)
22739    void* temp_cda=&cda;
22740 #endif
22741    OCIHandleAlloc
22742      (OTL_RCAST(dvoid*,connect->get_envhp()),
22743 #if defined(__GNUC__) && (__GNUC__>=4)
22744      OTL_RCAST(dvoid**,temp_cda),
22745 #else
22746      OTL_RCAST(dvoid**,&cda),
22747 #endif
22748      OCI_HTYPE_STMT,
22749      0,
22750      0);
22751 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22752   }else if((ftype==otl_var_timestamp ||
22753             ftype==otl_var_tz_timestamp ||
22754             ftype==otl_var_ltz_timestamp) &&
22755            !apl_tab_flag){
22756    array_size=aarray_size;
22757    elem_size=sizeof(OCIDateTime*);
22758    act_elem_size=elem_size;
22759    timestamp=new OCIDateTime*[array_size];
22760    p_v=OTL_RCAST(ub1*,timestamp);
22761    p_ind=new sb2[array_size];
22762    p_rlen=new ub2[array_size];
22763    p_rcode=new ub2[array_size];
22764    for(i=0;i<array_size;++i){
22765      p_ind[i]=OTL_SCAST(short,elem_size);
22766      p_rlen[i]=OTL_SCAST(short,elem_size);
22767      p_rcode[i]=0;
22768    }
22769    if(connect!=0){
22770      otl_datetime dt;
22771      ub4 dtype=0;
22772      switch(ftype){
22773      case otl_var_timestamp:
22774        dtype=OCI_DTYPE_TIMESTAMP;
22775        break;
22776      case otl_var_ltz_timestamp:
22777        dtype=OCI_DTYPE_TIMESTAMP_LTZ;
22778        break;
22779      case otl_var_tz_timestamp:
22780        dtype=OCI_DTYPE_TIMESTAMP_TZ;
22781        break;
22782      }
22783      for(i=0;i<array_size;++i){
22784        OCIDescriptorAlloc
22785          (OTL_RCAST(dvoid*,connect->envhp),
22786           OTL_RCAST(dvoid**,&timestamp[i]),
22787           dtype,
22788           0,
22789           0);
22790        write_dt(timestamp[i],&dt,1);
22791     }
22792    }else
22793     timestamp=0;
22794 #endif
22795   }else if(ftype==otl_var_blob||ftype==otl_var_clob){
22796    array_size=aarray_size;
22797    elem_size=aelem_size;
22798    lob=new OCILobLocator*[array_size];
22799    p_v=OTL_RCAST(ub1*,lob);
22800    p_ind=new sb2[array_size];
22801    p_rlen=0;
22802    p_rcode=0;
22803    if(connect!=0){
22804     for(i=0;i<array_size;++i){
22805      OCIDescriptorAlloc
22806        (OTL_RCAST(dvoid*,connect->get_envhp()),
22807        OTL_RCAST(dvoid**,&lob[i]),
22808        OTL_SCAST(ub4,OCI_DTYPE_LOB),
22809        0,
22810        0);
22811      lobEmpty=0;
22812      OCIAttrSet
22813       (OTL_RCAST(dvoid*,lob[i]),
22814        OCI_DTYPE_LOB,
22815        OTL_RCAST(dvoid*,&lobEmpty),
22816        0,
22817        OCI_ATTR_LOBEMPTY,
22818        OTL_RCAST(OCIError*,connect->get_errhp()));
22819     }
22820    }else
22821     lob=0;
22822   }else{
22823    if(ftype==otl_var_varchar_long||ftype==otl_var_raw_long){
22824     elem_size=aelem_size+sizeof(sb4);
22825     array_size=1;
22826    }else if(ftype==otl_var_raw){
22827     elem_size=aelem_size+sizeof(short int);
22828     array_size=aarray_size;
22829    }else{
22830     elem_size=aelem_size;
22831     array_size=aarray_size;
22832 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
22833     if((ftype==otl_var_timestamp ||
22834         ftype==otl_var_tz_timestamp ||
22835         ftype==otl_var_ltz_timestamp) &&
22836        apl_tab_flag){
22837       elem_size=sizeof(otl_oracle_date);
22838       aelem_size=elem_size; // sending feedback back to the template class
22839     }
22840 #endif
22841    }
22842 #if defined(OTL_UNICODE)
22843    if(ftype==otl_var_char){
22844      unsigned unicode_buffer_size=
22845        elem_size*OTL_SCAST(unsigned,array_size)*sizeof(OTL_WCHAR);
22846      p_v=new ub1[unicode_buffer_size];
22847      memset(p_v,0,unicode_buffer_size);
22848    } else if(ftype==otl_var_varchar_long){
22849      unsigned unicode_buffer_size=elem_size;
22850      p_v=new ub1[unicode_buffer_size];
22851      memset(p_v,0,unicode_buffer_size);
22852    }else{
22853      p_v=new ub1[elem_size*OTL_SCAST(unsigned,array_size)];
22854      memset(p_v,0,elem_size*OTL_SCAST(unsigned,array_size));
22855    }
22856 #elif defined(OTL_ORA_UTF8)
22857    if(ftype==otl_var_char){
22858      unsigned buffer_size=elem_size*OTL_SCAST(unsigned,array_size);
22859      if(select_stm_flag)
22860        buffer_size*=OTL_UTF8_BYTES_PER_CHAR; // 3 bytes per UTF8 char on SELECT by default
22861      p_v=new ub1[buffer_size];
22862      memset(p_v,0,buffer_size);
22863    } else if(ftype==otl_var_varchar_long){
22864      p_v=new ub1[elem_size];
22865      memset(p_v,0,elem_size);
22866    }else{
22867      p_v=new ub1[elem_size*OTL_SCAST(unsigned,array_size)];
22868      memset(p_v,0,elem_size*OTL_SCAST(unsigned,array_size));
22869    }
22870 #else
22871    p_v=new ub1[elem_size*OTL_SCAST(unsigned,array_size)];
22872    memset(p_v,0,elem_size*OTL_SCAST(unsigned,array_size));
22873 #endif
22874    p_ind=new sb2[array_size];
22875    p_rlen=new ub2[array_size];
22876    p_rcode=new ub2[array_size];
22877    if(ftype==otl_var_varchar_long||ftype==otl_var_raw_long){
22878     if(aelem_size>32767)
22879      p_ind[0]=0;
22880     else
22881     p_ind[0]=OTL_SCAST(short,aelem_size);
22882     p_rcode[0]=0;
22883    }else{
22884     for(i=0;i<array_size;++i){
22885 #if defined(OTL_UNICODE)
22886       if(ftype==otl_var_char){
22887         p_ind[i]=OTL_SCAST(short,elem_size*sizeof(OTL_WCHAR));
22888         p_rlen[i]=OTL_SCAST(short,elem_size*sizeof(OTL_WCHAR));
22889         p_rcode[i]=0;
22890       }else{
22891         p_ind[i]=OTL_SCAST(short,elem_size);
22892         p_rlen[i]=OTL_SCAST(short,elem_size);
22893         p_rcode[i]=0;
22894       }
22895 #else
22896       if(ftype==otl_var_raw){
22897         p_ind[i]=OTL_SCAST(short,elem_size);
22898         p_rlen[i]=OTL_SCAST(short,elem_size);
22899         p_rcode[i]=0;
22900       }else{
22901         p_ind[i]=OTL_SCAST(short,elem_size);
22902         p_rlen[i]=OTL_SCAST(short,elem_size);
22903         p_rcode[i]=0;
22904       }
22905 #endif
22906     }
22907    }
22908   }
22909   max_tab_len=OTL_SCAST(ub4,array_size);
22910   cur_tab_len=0;
22911  }
22912 
22913  void set_pl_tab_len(const int apl_tab_len)
22914  {
22915   max_tab_len=OTL_SCAST(ub4,array_size);
22916   cur_tab_len=OTL_SCAST(ub4,apl_tab_len);
22917  }
22918 
22919  int get_pl_tab_len(void)
22920  {
22921    return OTL_SCAST(int,cur_tab_len);
22922  }
22923 
22924  int get_max_pl_tab_len(void)
22925  {
22926   return OTL_SCAST(int,max_tab_len);
22927  }
22928 
22929  int get_blob_len(const int ndx,int& alen)
22930  {
22931    ub4 blen;
22932    int rc;
22933    alen=0;
22934    rc=OCILobGetLength
22935      (connect->get_svchp(),
22936       connect->get_errhp(),
22937       lob[ndx],
22938       &blen);
22939    alen=OTL_SCAST(int,blen);
22940    if(rc!=OCI_SUCCESS)return 0;
22941    return 1;
22942 
22943  }
22944 
22945   int is_blob_initialized(const int ndx,int& is_init)
22946   {
22947     int rc;
22948     is_init=0;
22949     rc=OCILobLocatorIsInit
22950       (connect->get_envhp(),
22951        connect->get_errhp(),
22952        lob[ndx],
22953        &is_init);
22954     if(rc!=OCI_SUCCESS)
22955       return 0;
22956     else
22957       return 1;
22958   }
22959 
22960  int get_blob
22961  (const int ndx,
22962   unsigned char* abuf,
22963   const int buf_size,
22964   int& len)
22965  {
22966   int byte_buf_size=buf_size;
22967 #if defined(OTL_UNICODE)
22968   if(ftype==otl_var_clob)
22969    byte_buf_size=buf_size*sizeof(OTL_CHAR);
22970 #endif
22971   ub4 amt=byte_buf_size;
22972   ub4 offset=1;
22973   int rc;
22974 #if defined(OTL_UNICODE)
22975   if(ftype==otl_var_clob||ftype==otl_var_nclob)
22976     memset(OTL_RCAST(void*,abuf),0,OTL_SCAST(size_t,buf_size));
22977 #endif
22978   int is_init=0;
22979   rc=OCILobLocatorIsInit
22980     (connect->get_envhp(),
22981      connect->get_errhp(),
22982      lob[ndx],
22983      &is_init);
22984   if (rc!=0) return 0;
22985   if (!is_init){
22986    len=0;
22987    return 1;
22988   }
22989 #if defined(OTL_UNICODE)
22990   if(ftype==otl_var_clob)
22991     csid=OTL_UNICODE_ID;
22992   else
22993     csid=0;
22994 #else
22995   csid=0;
22996 #endif
22997   do{
22998     rc=OCILobRead
22999       (connect->get_svchp(),
23000        connect->get_errhp(),
23001        lob[ndx],
23002        &amt,
23003        offset,
23004        OTL_RCAST(dvoid*,abuf+offset-1),
23005        OTL_SCAST(ub4,byte_buf_size-offset+1),
23006        0,
23007        0,
23008        csid,
23009        OTL_SCAST(ub1,nls_flag?SQLCS_NCHAR:connect->get_char_set()));
23010     offset+=amt;
23011   }while(rc==OCI_NEED_DATA);
23012   len=offset-1;
23013   if(rc!=OCI_SUCCESS){
23014     len=0;
23015     return 0;
23016   }
23017   return 1;
23018  }
23019 
23020  void set_lob_stream_flag(const int flg=1)
23021  {
23022   lob_stream_flag=flg;
23023  }
23024 
23025   int close_lob(void)
23026   {
23027 #if defined(OTL_ORA8I)||defined(OTL_ORA9I)
23028     int rc;
23029     boolean flag=0;
23030     rc=OCILobIsOpen
23031       (connect->get_svchp(),
23032        connect->get_errhp(),
23033        lob[0],
23034        &flag);
23035     if(rc!=OCI_SUCCESS)return 0;
23036     if(flag!=TRUE)return 1;
23037     rc=OCILobClose
23038       (connect->get_svchp(),
23039        connect->get_errhp(),
23040        lob[0]);
23041     if(rc!=OCI_SUCCESS)return 0;
23042 #endif
23043     return 1;
23044   }
23045 
23046  int put_blob(void)
23047  {
23048    if((ftype!=otl_var_clob&&ftype!=otl_var_blob)||
23049      lob_stream_flag||buf==0||buf_len==0)return 1;
23050   int rc;
23051   int byte_buf_len=buf_len;
23052 #if defined(OTL_UNICODE)
23053   if(ftype==otl_var_clob)
23054    byte_buf_len=buf_len*sizeof(OTL_CHAR);
23055 #endif
23056   ub4 amt=OTL_SCAST(ub4,buf_len);
23057   ub4 offset=1;
23058 #if defined(OTL_UNICODE)
23059   if(ftype==otl_var_clob)
23060     csid=OTL_UNICODE_ID;
23061   else
23062     csid=0;
23063 #else
23064   csid=0;
23065 #endif
23066   rc=OCILobWrite
23067     (connect->get_svchp(),
23068      connect->get_errhp(),
23069      lob[0],
23070      &amt,
23071      offset,
23072      OTL_RCAST(dvoid*,buf),
23073      OTL_SCAST(ub4,byte_buf_len),
23074      OCI_ONE_PIECE,
23075      0,
23076      0,
23077      csid,
23078      OTL_SCAST(ub1,nls_flag?SQLCS_NCHAR:connect->get_char_set()));
23079   if(rc!=0)return 0;
23080   return 1;
23081  }
23082 
23083  int read_blob
23084  (otl_long_string& s,
23085   const int andx,
23086   int& aoffset,
23087   int alob_len)
23088  {
23089    ub4 byte_buf_size=s.get_buf_size();
23090 
23091 #if defined(OTL_UNICODE)
23092   if(ftype==otl_var_clob)
23093    byte_buf_size=byte_buf_size*sizeof(OTL_CHAR);
23094 #endif
23095 
23096   ub4& amt=read_blob_amt;
23097   amt=0;
23098   if(aoffset==1)total_read_blob_amt=0;
23099   ub4& offset=total_read_blob_amt;
23100   if(offset==0)offset=1;
23101   int rc;
23102   int is_init=0;
23103   rc=OCILobLocatorIsInit
23104     (connect->get_envhp(),
23105      connect->get_errhp(),
23106       lob[0],
23107       &is_init);
23108   if(rc!=OCI_SUCCESS)return 0;
23109   if(!is_init){
23110    s.set_len(0);
23111    return 1;
23112   }
23113 #if defined(OTL_UNICODE)
23114   if(ftype==otl_var_clob)
23115     csid=OTL_UNICODE_ID;
23116   else
23117     csid=0;
23118 #else
23119   csid=0;
23120 #endif
23121 
23122   rc=OCILobRead
23123     (connect->get_svchp(),
23124      connect->get_errhp(),
23125     lob[andx],
23126     &amt,
23127     offset,
23128     OTL_RCAST(dvoid*,s.v),
23129     OTL_SCAST(ub4,byte_buf_size),
23130     0,
23131     0,
23132     csid,
23133      OTL_SCAST(ub1,nls_flag?SQLCS_NCHAR:connect->get_char_set()));
23134 
23135 #if defined(OTL_UNICODE)
23136   if(ftype==otl_var_clob && aoffset>1 && amt==byte_buf_size)
23137     amt/=sizeof(OTL_CHAR);
23138 #endif
23139 
23140 #if defined(OTL_ORA_UTF8)
23141   switch(rc){
23142   case OCI_SUCCESS:
23143     s.set_len(amt);
23144     offset+=amt;
23145     if(ftype==otl_var_blob)
23146       aoffset+=s.len();
23147     else
23148       aoffset=alob_len+1;
23149     return 1;
23150   case OCI_NEED_DATA:
23151     s.set_len(amt);
23152     offset+=amt;
23153     if(ftype==otl_var_blob)
23154       aoffset+=s.len();
23155     else
23156       aoffset=2;
23157     return 1;
23158   case OCI_ERROR:
23159   default:
23160     s.set_len(0);
23161     return 0;
23162   }
23163 #else
23164   switch(rc){
23165   case OCI_SUCCESS:
23166     if(aoffset==1)
23167       s.set_len(alob_len);
23168     else
23169       s.set_len(alob_len-aoffset+1);
23170     break;
23171   case OCI_NEED_DATA:
23172     s.set_len(amt);
23173     break;
23174   case OCI_ERROR:
23175     s.set_len(0);
23176     break;
23177   }
23178   if(rc==OCI_NEED_DATA||rc==OCI_SUCCESS){
23179     aoffset+=s.len();
23180     return 1;
23181   }else
23182     return 0;
23183 #endif
23184 
23185  }
23186 
23187  int write_blob
23188  (const otl_long_string& s,
23189   const int alob_len,
23190   int& aoffset,
23191   otl_cur0& /* cur */)
23192  {
23193   if(!lob_stream_flag)return 1;
23194   int rc;
23195   int byte_s_length=s.len();
23196 #if defined(OTL_UNICODE)
23197   int byte_lob_len;
23198   if(ftype==otl_var_clob){
23199    byte_lob_len=alob_len*sizeof(OTL_CHAR);
23200    byte_s_length=s.len()*sizeof(OTL_CHAR);
23201   }
23202 #endif
23203   ub4 offset=aoffset;
23204   ub4 amt=0;
23205   ub1 mode;
23206   if(aoffset==1 && alob_len>s.len())
23207    mode=OCI_FIRST_PIECE;
23208   else if(aoffset==1 && alob_len<=s.len()){
23209    mode=OCI_ONE_PIECE;
23210    amt=s.len();
23211   }else if((aoffset-1)+s.len()<alob_len)
23212    mode=OCI_NEXT_PIECE;
23213   else
23214    mode=OCI_LAST_PIECE;
23215 #if defined(OTL_UNICODE)
23216   if(ftype==otl_var_clob)
23217     csid=OTL_UNICODE_ID;
23218   else
23219     csid=0;
23220 #else
23221   csid=0;
23222 #endif
23223   if(mode==OCI_FIRST_PIECE || mode==OCI_ONE_PIECE){
23224     rc=OCILobTrim
23225       (connect->get_svchp(),
23226        connect->get_errhp(),
23227        lob[0],
23228        0);
23229     if(rc!=OCI_SUCCESS)
23230       return 0;
23231   }
23232   if(alob_len==0)return 1;
23233   rc=OCILobWrite
23234     (connect->get_svchp(),
23235      connect->get_errhp(),
23236     lob[0],
23237     OTL_RCAST(ub4*,&amt),
23238     offset,
23239     OTL_RCAST(dvoid*,s.v),
23240     OTL_SCAST(ub4,byte_s_length),
23241     mode,
23242     0,
23243     0,
23244     csid,
23245      OTL_SCAST(ub1,nls_flag?SQLCS_NCHAR:connect->get_char_set()));
23246   if(rc==OCI_NEED_DATA||
23247      rc==OCI_SUCCESS||
23248      rc==OCI_SUCCESS_WITH_INFO){
23249     aoffset+=s.len();
23250    return 1;
23251   }
23252   return 0;
23253  }
23254 
23255  int save_blob
23256  (const unsigned char* abuf,
23257   const int len,
23258   const int extern_buffer_flag)
23259  {
23260   if(extern_buffer_flag){
23261    ext_buf_flag=1;
23262    buf_len=len;
23263    buf=OTL_CCAST(unsigned char*,abuf);
23264   }else{
23265    if(buf!=0&&!ext_buf_flag){
23266     delete[] buf;
23267     buf=0;
23268    }
23269    ext_buf_flag=0;
23270    buf_len=len;
23271 #if defined(OTL_UNICODE)
23272    buf=new ub1[buf_len*sizeof(OTL_CHAR)];
23273    memcpy(buf,abuf,buf_len*sizeof(OTL_CHAR));
23274 #else
23275    buf=new ub1[buf_len];
23276    memcpy(buf,abuf,buf_len);
23277 #endif
23278   }
23279   return 1;
23280  }
23281 
23282  void set_null(int ndx)
23283  {
23284   p_ind[ndx]=-1;
23285  }
23286 
23287  void set_not_null(int ndx, int pelem_size)
23288  {
23289    switch(ftype){
23290    case otl_var_varchar_long:
23291    case otl_var_raw_long:
23292      p_ind[0]=0;
23293      break;
23294    case otl_var_raw:
23295      p_ind[ndx]=OTL_SCAST(short,pelem_size);
23296      break;
23297    case otl_var_clob:
23298    case otl_var_blob:
23299      if(lob_stream_flag==0){
23300        ub4 lobEmpty=0;
23301        OCIAttrSet
23302          (OTL_RCAST(dvoid*,lob[ndx]),
23303           OCI_DTYPE_LOB,
23304           OTL_RCAST(dvoid*,&lobEmpty),
23305           0,
23306           OCI_ATTR_LOBEMPTY,
23307           OTL_RCAST(OCIError*,connect->get_errhp()));
23308      }
23309      break;
23310    default:
23311      p_ind[ndx]=OTL_SCAST(short,pelem_size);
23312      break;
23313    }
23314  }
23315 
23316  void set_len(int len, int ndx)
23317  {
23318   if(ftype==otl_var_varchar_long||ftype==otl_var_raw_long){
23319 #if defined(OTL_UNICODE)
23320    if(ftype==otl_var_varchar_long)
23321     *OTL_RCAST(sb4*,p_v)=len*sizeof(OTL_CHAR);
23322    else
23323     *OTL_RCAST(sb4*,p_v)=len;
23324 #else
23325    *OTL_RCAST(sb4*,p_v)=len;
23326 #endif
23327   }else
23328    p_rlen[ndx]=OTL_SCAST(short,len);
23329  }
23330 
23331  int get_len(int ndx)
23332  {
23333   if(ftype==otl_var_varchar_long||ftype==otl_var_raw_long){
23334    if(p_ind[0]==-1)
23335     return 0;
23336    else{
23337 #if defined(OTL_UNICODE)
23338     if(ftype==otl_var_varchar_long)
23339       return (*OTL_RCAST(sb4*,p_v))/sizeof(OTL_CHAR);
23340     else
23341       return *OTL_RCAST(sb4*,p_v);
23342 #else
23343     return *OTL_RCAST(sb4*,p_v);
23344 #endif
23345    }
23346   }else
23347    return p_rlen[ndx];
23348  }
23349 
23350  int is_null(int ndx)
23351  {
23352   return p_ind[ndx]==-1;
23353  }
23354 
23355  void* val(int ndx,int pelem_size)
23356  {
23357    switch(ftype){
23358 #if defined(OTL_UNICODE)
23359    case otl_var_char:
23360      return OTL_RCAST(void*,&p_v[OTL_SCAST(unsigned,ndx)*
23361                                  pelem_size*sizeof(OTL_WCHAR)]);
23362 #endif
23363 #if defined(OTL_ORA_UTF8)
23364    case otl_var_char:
23365      if(select_stm_flag)
23366        return OTL_RCAST(void*,&p_v[OTL_SCAST(unsigned,ndx)*
23367                                    pelem_size*OTL_UTF8_BYTES_PER_CHAR]);
23368      else
23369        return OTL_RCAST(void*,&p_v[OTL_SCAST(unsigned,ndx)*pelem_size]);
23370 #endif
23371    case otl_var_raw:
23372      return OTL_RCAST(void*,&p_v[(OTL_SCAST(unsigned,ndx))*
23373                                  (pelem_size+sizeof(short int))]);
23374    case otl_var_varchar_long:
23375    case otl_var_raw_long:
23376      return OTL_RCAST(void*,p_v+sizeof(sb4));
23377 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
23378    case otl_var_timestamp:
23379    case otl_var_tz_timestamp:
23380    case otl_var_ltz_timestamp:
23381      if(!pl_tab_flag)
23382        return OTL_RCAST(void*,timestamp[ndx]);
23383 #endif
23384    default:
23385      return OTL_RCAST(void*,&p_v[OTL_SCAST(unsigned,ndx)*pelem_size]);
23386    }
23387  }
23388 
23389  static int int2ext(int int_type)
23390  {
23391   switch(int_type){
23392   case inVarChar2: return extCChar;
23393   case inNumber:   return extFloat;
23394   case inLong:     return extLongVarChar;
23395   case inRowId:    return extCChar;
23396 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
23397   case inDate:     return extTimestamp;
23398   case inTimestamp:return extTimestamp;
23399   case inTimestamp_TZ:return extTimestamp_TZ;
23400   case inTimestamp_LTZ:return extTimestamp_LTZ;
23401   case inIntervalYM:return extCChar;
23402   case inIntervalDS:return extCChar;
23403 #else
23404   case inDate:     return extDate;
23405 #endif
23406   case inRaw:      return extRaw;
23407   case inLongRaw:  return extLongVarRaw;
23408   case inChar:     return extCChar;
23409 #if defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)
23410 #if defined(OTL_ORA_NATIVE_TYPES) && !defined(OTL_ORA_LEGACY_NUMERIC_TYPES)
23411   case inBFloat:   return extBFloat;
23412   case inBDouble:  return extBDouble;
23413 #else
23414   case inBFloat:   return extFloat;
23415   case inBDouble:  return extFloat;
23416 #endif
23417 #endif
23418   case inCLOB:     return extCLOB;
23419   case inBLOB:     return extBLOB;
23420   default:
23421    return otl_unsupported_type;
23422   }
23423  }
23424 
23425  static int datatype_size(int aftype,int maxsz,int int_type,int max_long_size)
23426  {
23427   switch(aftype){
23428   case extCChar:
23429    switch(int_type){
23430 #if defined(OTL_ORA_TIMESTAMP)
23431    case inIntervalYM:
23432      return 30;
23433    case inIntervalDS:
23434      return 30;
23435 #endif
23436    case inRowId:
23437     return 30;
23438    case inDate:
23439     return otl_oracle_date_size;
23440    case inRaw:
23441     return max_long_size;
23442    default:
23443     return maxsz+1;
23444    }
23445 #if (defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)) && defined(OTL_ORA_NATIVE_TYPES) \
23446     && !defined(OTL_ORA_LEGACY_NUMERIC_TYPES)
23447   case extBFloat:
23448   case extBDouble:
23449     return sizeof(double);
23450 #endif
23451   case extLongVarChar:
23452    return max_long_size;
23453   case extLongVarRaw:
23454    return max_long_size;
23455   case extRaw:
23456    return maxsz;
23457   case extCLOB:
23458    return max_long_size;
23459   case extBLOB:
23460    return max_long_size;
23461   case extFloat:
23462    return sizeof(double);
23463 
23464 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
23465   case extDate:
23466    return sizeof(OCIDateTime*);
23467   case extTimestamp:
23468   case extTimestamp_TZ:
23469   case extTimestamp_LTZ:
23470    return sizeof(OCIDateTime*);
23471 #else
23472   case extDate:
23473    return otl_oracle_date_size;
23474 #endif
23475   default:
23476    return 0;
23477   }
23478  }
23479 
23480  static void map_ftype
23481  (otl_column_desc& desc,
23482   const int max_long_size,
23483   int& aftype,
23484   int& aelem_size,
23485   otl_select_struct_override& override,
23486   const int column_ndx,
23487   const int /*connection_type*/)
23488  {int ndx=override.find(column_ndx);
23489   if(ndx==-1){
23490    aftype=int2ext(desc.dbtype);
23491    aelem_size=datatype_size
23492      (aftype,
23493       OTL_SCAST(int,desc.dbsize),
23494       desc.dbtype,
23495       max_long_size);
23496    switch(aftype){
23497 #if (defined(OTL_ORA10G)||defined(OTL_ORA10G_R2))&&defined(OTL_ORA_NATIVE_TYPES)\
23498     &&!defined(OTL_ORA_LEGACY_NUMERIC_TYPES)
23499   case extBFloat:
23500   case extBDouble:
23501     if(override.get_all_mask() & otl_all_num2str){
23502      aftype=otl_var_char;
23503      aelem_size=otl_num_str_size;
23504     }else
23505      aftype=otl_var_double;
23506     break;
23507 #endif
23508    case extCChar:
23509     aftype=otl_var_char;
23510     break;
23511    case extRaw:
23512     aftype=otl_var_raw;
23513     break;
23514    case extFloat:
23515      if(override.get_all_mask() & otl_all_num2str){
23516      aftype=otl_var_char;
23517      aelem_size=otl_num_str_size;
23518     }else
23519      aftype=otl_var_double;
23520     break;
23521    case extLongVarChar:
23522     aftype=otl_var_varchar_long;
23523     break;
23524    case extLongVarRaw:
23525     aftype=otl_var_raw_long;
23526     break;
23527    case extCLOB:
23528     aftype=otl_var_clob;
23529     break;
23530    case extBLOB:
23531     aftype=otl_var_blob;
23532     break;
23533 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
23534    case extDate:
23535    case extTimestamp:
23536      if(override.get_all_mask() & otl_all_date2str){
23537      aftype=otl_var_char;
23538      aelem_size=otl_date_str_size;
23539     }else
23540       aftype=otl_var_timestamp;
23541     break;
23542    case extTimestamp_TZ:
23543      if(override.get_all_mask() & otl_all_date2str){
23544      aftype=otl_var_char;
23545      aelem_size=otl_date_str_size;
23546     }else
23547       aftype=otl_var_tz_timestamp;
23548     break;
23549    case extTimestamp_LTZ:
23550      if(override.get_all_mask() & otl_all_date2str){
23551      aftype=otl_var_char;
23552      aelem_size=otl_date_str_size;
23553     }else
23554       aftype=otl_var_ltz_timestamp;
23555     break;
23556 #else
23557    case extDate:
23558      if(override.get_all_mask() & otl_all_date2str){
23559      aftype=otl_var_char;
23560      aelem_size=otl_date_str_size;
23561     }else
23562      aftype=otl_var_timestamp;
23563     break;
23564 #endif
23565    }
23566   }else{
23567     aftype=override.get_col_type(ndx);
23568    switch(aftype){
23569 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
23570    case otl_var_nchar:
23571 #endif
23572    case otl_var_char:
23573      aelem_size=override.get_col_size(ndx);
23574     break;
23575    case otl_var_raw:
23576      aelem_size=override.get_col_size(ndx);
23577     break;
23578    case otl_var_double:
23579     aelem_size=sizeof(double);
23580     break;
23581    case otl_var_float:
23582     aelem_size=sizeof(float);
23583     break;
23584    case otl_var_int:
23585     aelem_size=sizeof(int);
23586     break;
23587 #if defined(OTL_BIGINT) && defined(OTL_ORA11G_R2)
23588    case otl_var_bigint:
23589     aelem_size=sizeof(OTL_BIGINT);
23590     break;
23591 #endif
23592    case otl_var_unsigned_int:
23593     aelem_size=sizeof(unsigned);
23594     break;
23595    case otl_var_short:
23596     aelem_size=sizeof(short);
23597     break;
23598    case otl_var_long_int:
23599     aelem_size=sizeof(long);
23600     break;
23601    default:
23602      aelem_size=override.get_col_size(ndx);
23603     break;
23604    }
23605   }
23606   desc.otl_var_dbtype=aftype;
23607  }
23608 
23609 private:
23610 
23611   otl_var(const otl_var&):
23612     p_v(0),
23613     p_ind(0),
23614     p_rlen(0),
23615     p_rcode(0),
23616     ftype(0),
23617     array_size(0),
23618     elem_size(0),
23619     nls_flag(false),
23620     lob(0),
23621 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
23622     timestamp(0),
23623 #endif
23624     cda(0),
23625     connect(0),
23626     buf(0),
23627     buf_len(0),
23628     ext_buf_flag(0),
23629     act_elem_size(0),
23630     max_tab_len(0),
23631     cur_tab_len(0),
23632     pl_tab_flag(0),
23633     lob_stream_flag(0),
23634     vparam_type(-1),
23635     lob_len(0),
23636     lob_pos(0),
23637     lob_ftype(0),
23638     otl_adapter(otl_ora8_adapter),
23639     lob_stream_mode(false),
23640     unicode_var_len(0),
23641     csid(0),
23642     csfrm(SQLCS_IMPLICIT),
23643     read_blob_amt(0),
23644     total_read_blob_amt(0),
23645     charz_flag(false),
23646     select_stm_flag(false)
23647  {
23648  }
23649 
23650   otl_var& operator=(const otl_var&)
23651   {
23652     return *this;
23653   }
23654 
23655 };
23656 
23657 class otl_sel;
23658 class otl_refcur_base_cursor;
23659 class otl_refcur_stream;
23660 class otl_ref_cursor;
23661 class otl_ref_select_stream;
23662 #if defined(OTL_ORA_SUBSCRIBE)
23663   class otl_subscriber;
23664 #endif
23665 
23666 class otl_cur: public otl_cur0{
23667 private:
23668 
23669 #if defined(OTL_ORA_SUBSCRIBE)
23670   friend class otl_subscriber;
23671 #endif
23672 
23673   friend class otl_sel;
23674   friend class otl_refcur_base_cursor;
23675   friend class otl_refcur_stream;
23676   friend class otl_ref_cursor;
23677   friend class otl_ref_select_stream;
23678 
23679   OCIStmt* cda; // Statement handle
23680   OCIError* errhp; // Error handle
23681   bool extern_cda;
23682   int status;
23683   int eof_status;
23684   otl_conn* db;
23685   int straight_select;
23686   int pos_nbr;
23687   int commit_on_success;
23688   int last_param_data_token;
23689   int last_sql_param_data_status;
23690   int sql_param_data_count;
23691   bool canceled;
23692   int direct_exec_flag;
23693   int parse_only_flag;
23694   int stm_executed;
23695 
23696 public:
23697 
23698   void set_canceled(const bool acanceld)
23699   {
23700     canceled=acanceld;
23701   }
23702 
23703   void reset_last_param_data_token()
23704   {
23705     last_param_data_token=0;
23706   }
23707 
23708   void reset_last_sql_param_data_status()
23709   {
23710     last_sql_param_data_status=0;
23711   }
23712 
23713   void reset_sql_param_data_count()
23714   {
23715     sql_param_data_count=0;
23716   }
23717 
23718   otl_cur():
23719     cda(0),
23720     errhp(0),
23721     extern_cda(false),
23722     status(0),
23723     eof_status(0),
23724     db(0),
23725     straight_select(1),
23726     pos_nbr(0),
23727     commit_on_success(0),
23728     last_param_data_token(0),
23729     last_sql_param_data_status(0),
23730     sql_param_data_count(0),
23731     canceled(false),
23732     direct_exec_flag(0),
23733     parse_only_flag(0),
23734     stm_executed(0)
23735  {
23736  }
23737 
23738  virtual ~otl_cur(){}
23739 
23740   void set_direct_exec(const int flag)
23741   {
23742     direct_exec_flag=flag;
23743   }
23744 
23745   void set_parse_only(const int flag)
23746   {
23747     parse_only_flag=flag;
23748   }
23749 
23750   ub4 rpc(void)
23751   {
23752     sb4 arpc;
23753     status=OCIAttrGet
23754       (OTL_RCAST(dvoid *,cda),
23755        OTL_SCAST(ub4,OCI_HTYPE_STMT),
23756        OTL_RCAST(dvoid *,&arpc),
23757        0,
23758        OTL_SCAST(ub4,OCI_ATTR_ROW_COUNT),
23759        errhp);
23760     if(status)return 0;
23761     return arpc;
23762   }
23763 
23764  int open(otl_conn& connect,otl_var* var=0)
23765  {
23766   db=&connect;
23767   commit_on_success=db->get_auto_commit();
23768   if(var!=0){
23769    extern_cda=true;
23770    cda=var->get_cda();
23771    status=OCI_SUCCESS;
23772   }else{
23773 #if defined(__GNUC__) && (__GNUC__>=4)
23774     void* temp_cda=&cda;
23775 #endif
23776    status=OCIHandleAlloc
23777      (OTL_RCAST(dvoid *,db->get_envhp()),
23778 #if defined(__GNUC__) && (__GNUC__>=4)
23779      OTL_RCAST(dvoid **,temp_cda),
23780 #else
23781      OTL_RCAST(dvoid **,&cda),
23782 #endif
23783      OCI_HTYPE_STMT,
23784      0,
23785      0);
23786    if(status)return 0;
23787   }
23788 #if defined(__GNUC__) && (__GNUC__>=4)
23789   void* temp_errhp=&errhp;
23790 #endif
23791   status=OCIHandleAlloc
23792     (OTL_RCAST(dvoid *,db->get_envhp()),
23793 #if defined(__GNUC__) && (__GNUC__>=4)
23794     OTL_RCAST(dvoid **,temp_errhp),
23795 #else
23796     OTL_RCAST(dvoid **,&errhp),
23797 #endif
23798     OCI_HTYPE_ERROR,
23799     0,
23800     0);
23801   if(status)return 0;
23802   straight_select=1;
23803   pos_nbr=0;
23804   return 1;
23805  }
23806 
23807  int close(void)
23808  {
23809   if(!extern_cda)
23810    status=OCIHandleFree(OTL_RCAST(dvoid*,cda),OCI_HTYPE_STMT);
23811   status=OCIHandleFree(OTL_RCAST(dvoid*,errhp),OCI_HTYPE_ERROR);
23812   cda=0;
23813   errhp=0;
23814   commit_on_success=0;
23815   return 1;
23816  }
23817 
23818  int parse(const char* stm_text)
23819  {
23820    status=OCIStmtPrepare
23821      (cda,
23822       errhp,
23823       OTL_RCAST(text*,OTL_CCAST(char*,stm_text)),
23824       OTL_SCAST(ub4,strlen(stm_text)),
23825       OTL_SCAST(ub4,OCI_NTV_SYNTAX),
23826       OTL_SCAST(ub4,OCI_DEFAULT));
23827    if(status)return 0;
23828 
23829     if(direct_exec_flag && parse_only_flag){
23830 #if !defined(OCI_PARSE_ONLY)
23831       status=OCIStmtExecute
23832         (db->svchp,
23833          cda,
23834          errhp,
23835          OTL_SCAST(ub4,1),
23836          OTL_SCAST(ub4,0),
23837          0,
23838          0,
23839          0x100);
23840  #else
23841       status=OCIStmtExecute
23842         (db->get_svchp(),
23843          cda,
23844          errhp,
23845          OTL_SCAST(ub4,0),
23846          OTL_SCAST(ub4,0),
23847          0,
23848          0,
23849          OCI_PARSE_ONLY);
23850  #endif
23851       if(status)
23852         return 0;
23853       else
23854         return 1;
23855     }else if(direct_exec_flag && !parse_only_flag){
23856       ub4 mode;
23857       if(commit_on_success)
23858         mode=OCI_COMMIT_ON_SUCCESS;
23859       else
23860         mode=OCI_DEFAULT;
23861 
23862       status=OCIStmtExecute
23863         (db->get_svchp(),
23864          cda,
23865          errhp,
23866          OTL_SCAST(ub4,1),
23867          OTL_SCAST(ub4,0),
23868          0,
23869          0,
23870          mode);
23871       stm_executed=1;
23872       if(status)
23873         return 0;
23874       else
23875         return 1;
23876     }
23877     return 1;
23878  }
23879 
23880  int exec(const int iters,
23881           const int rowoff,
23882           const int /*otl_sql_exec_from_class*/)
23883  {
23884    if(parse_only_flag){
23885      parse_only_flag=0;
23886      return 1;
23887    }else if(!stm_executed){
23888      ub4 mode;
23889      if(commit_on_success)
23890        mode=OCI_COMMIT_ON_SUCCESS;
23891      else
23892        mode=OCI_DEFAULT;
23893      status=OCIStmtExecute
23894        (db->get_svchp(),
23895         cda,
23896         errhp,
23897         OTL_SCAST(ub4,iters),
23898         OTL_SCAST(ub4,rowoff),
23899         0,
23900         0,
23901         mode);
23902      stm_executed=0;
23903      if(status!=OCI_SUCCESS)
23904        return 0;
23905      return 1;
23906    }
23907    return 1;
23908  }
23909 
23910  long get_rpc()
23911  {
23912   return rpc();
23913  }
23914 
23915  int fetch(const otl_stream_buffer_size_type iters,int& eof_data)
23916  {
23917   eof_data=0;
23918   status=OCIStmtFetch
23919    (cda,
23920     errhp,
23921     OTL_SCAST(ub4,iters),
23922     OTL_SCAST(ub4,OCI_FETCH_NEXT),
23923     OTL_SCAST(ub4,OCI_DEFAULT));
23924   eof_status=status;
23925   if(status!=OCI_SUCCESS&&
23926      status!=OCI_SUCCESS_WITH_INFO&&
23927      status!=OCI_NO_DATA)
23928    return 0;
23929   if(status==OCI_NO_DATA){
23930    eof_data=1;
23931    return 1;
23932   }
23933   return 1;
23934  }
23935 
23936  int tmpl_ftype2ora_ftype(const int ftype)
23937  {
23938   switch(ftype){
23939   case otl_var_char:
23940    return extCChar;
23941 #if (defined(OTL_ORA10G)||defined(OTL_ORA10G_R2))&&defined(OTL_ORA_NATIVE_TYPES)\
23942     &&!defined(OTL_ORA_LEGACY_NUMERIC_TYPES)
23943   case otl_var_double:
23944     return extBDouble;
23945   case otl_var_float:
23946     return extBFloat;
23947 #else
23948   case otl_var_double:
23949    return extFloat;
23950   case otl_var_float:
23951    return extFloat;
23952 #endif
23953   case otl_var_int:
23954    return extInt;
23955   case otl_var_unsigned_int:
23956    return extUInt;
23957   case otl_var_short:
23958    return extInt;
23959   case otl_var_long_int:
23960    return extInt;
23961 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
23962     !defined(OTL_BIGINT_TO_STR))
23963   case otl_var_bigint:
23964    return extInt;
23965 #endif
23966 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
23967   case otl_var_timestamp:
23968    return extTimestamp;
23969   case otl_var_tz_timestamp:
23970    return extTimestamp_TZ;
23971   case otl_var_ltz_timestamp:
23972    return extTimestamp_LTZ;
23973 #else
23974   case otl_var_timestamp:
23975    return extDate;
23976 #endif
23977  case otl_var_varchar_long:
23978    return extLongVarChar;
23979   case otl_var_raw_long:
23980    return extLongVarRaw;
23981   case otl_var_raw:
23982    return extRaw;
23983   case otl_var_clob:
23984    return SQLT_CLOB;
23985   case otl_var_blob:
23986    return SQLT_BLOB;
23987   default:
23988    return 0;
23989   }
23990  }
23991 
23992  int bind
23993  (const char* name,
23994   otl_var& v,
23995   const int elem_size,
23996   const int ftype,
23997   const int /*param_type*/,
23998   const int /*name_pos*/,
23999   const int /*connection_type*/,
24000   const int apl_tab_flag)
24001  {OCIBind* bindpp;
24002 
24003   int db_ftype=0;
24004 
24005    if(ftype==otl_var_refcur){
24006     status=OCIBindByName
24007      (cda,
24008       &bindpp,
24009       errhp,
24010       OTL_RCAST(text*,OTL_CCAST(char*,name)),
24011       OTL_SCAST(sb4,strlen(name)),
24012       OTL_RCAST(dvoid*,v.get_cda_ptr()),
24013       0,
24014       SQLT_RSET,
24015       0,
24016       0,
24017       0,
24018       0,
24019       0,
24020       OTL_SCAST(ub4,OCI_DEFAULT));
24021    }else if(ftype!=otl_var_clob&&ftype!=otl_var_blob){
24022      int var_elem_size;
24023 #if defined(OTL_UNICODE)
24024      if(ftype==otl_var_char){
24025        var_elem_size=elem_size*sizeof(OTL_WCHAR); // ###
24026      }
24027      else if(ftype==otl_var_varchar_long)
24028       var_elem_size=elem_size;
24029      else
24030       var_elem_size=elem_size;
24031 #else
24032      if(ftype==otl_var_varchar_long)
24033        var_elem_size=elem_size+sizeof(sb4);
24034      else
24035        var_elem_size=elem_size;
24036 #endif
24037      db_ftype=tmpl_ftype2ora_ftype(ftype);
24038 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
24039      if(ftype==otl_var_timestamp ||
24040         ftype==otl_var_tz_timestamp ||
24041         ftype==otl_var_ltz_timestamp){
24042        if(!apl_tab_flag)
24043          var_elem_size=sizeof(OCIDateTime*);
24044        else if(db_ftype==extTimestamp)
24045          db_ftype=extDate;
24046      }
24047 #endif
24048 #if defined(OTL_UNICODE)
24049      if(ftype==otl_var_char)
24050        db_ftype=SQLT_VCS;
24051 #endif
24052      if(apl_tab_flag){
24053        if(ftype==otl_var_float||ftype==otl_var_double)
24054          db_ftype=extFloat;
24055        status=OCIBindByName
24056          (cda,
24057           &bindpp,
24058           errhp,
24059           OTL_RCAST(text*,OTL_CCAST(char*,name)),
24060           OTL_SCAST(sb4,strlen(name)),
24061           OTL_RCAST(dvoid*,v.p_v),
24062           ftype==otl_var_raw?var_elem_size+sizeof(short):var_elem_size,
24063           OTL_SCAST(ub2,v.charz_flag?extCharZ:db_ftype),
24064           OTL_RCAST(dvoid*,v.p_ind),
24065           0,
24066           0,
24067           OTL_SCAST(ub4,v.max_tab_len),
24068           OTL_RCAST(ub4*,&v.cur_tab_len),
24069           OTL_SCAST(ub4,OCI_DEFAULT));
24070      }else{
24071        status=OCIBindByName
24072          (cda,
24073           &bindpp,
24074           errhp,
24075           OTL_RCAST(text*,OTL_CCAST(char*,name)),
24076           OTL_SCAST(sb4,strlen(name)),
24077           OTL_RCAST(dvoid*,v.p_v),
24078           ftype==otl_var_raw?var_elem_size+sizeof(short):var_elem_size,
24079           OTL_SCAST(ub2,db_ftype),
24080           OTL_RCAST(dvoid*,v.p_ind),
24081           0,
24082           0,
24083           0,
24084           0,
24085           OTL_SCAST(ub4,OCI_DEFAULT));
24086      }
24087     if(status)return 0;
24088 #if defined(OTL_UNICODE)
24089     if(ftype==otl_var_char||ftype==otl_var_varchar_long){
24090       if(ftype!=otl_var_varchar_long){
24091         if(v.nls_flag)
24092           v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24093         else
24094           v.csfrm=OTL_SCAST(ub1,db->char_set_);
24095         status=OCIAttrSet
24096           (bindpp,
24097            OCI_HTYPE_BIND,
24098            &v.csfrm,
24099            0,
24100            OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24101            errhp);
24102         if(status)return 0;
24103       }
24104       v.csid=OTL_UNICODE_ID;
24105       status=OCIAttrSet
24106         (bindpp,
24107          OCI_HTYPE_BIND,
24108          &v.csid,
24109          0,
24110          OCI_ATTR_CHARSET_ID,
24111          errhp);
24112       if(status)return 0;
24113       if(ftype==otl_var_varchar_long)
24114         v.unicode_var_len=elem_size-sizeof(sb4);
24115       else{
24116 #if defined(OTL_ORA_MAX_UNICODE_VARCHAR_SIZE)
24117         if(var_elem_size>OTL_ORA_MAX_UNICODE_VARCHAR_SIZE)
24118           v.unicode_var_len=OTL_ORA_MAX_UNICODE_VARCHAR_SIZE;
24119         else
24120           v.unicode_var_len=var_elem_size;
24121 #else
24122         v.unicode_var_len=var_elem_size;
24123 #endif
24124       }
24125       status=OCIAttrSet
24126         (bindpp,
24127          OCI_HTYPE_BIND,
24128          &v.unicode_var_len,
24129          0,
24130          OCI_ATTR_MAXDATA_SIZE,
24131          errhp);
24132       if(status)return 0;
24133     }
24134 #endif
24135 
24136 #if defined(OTL_ORA_UTF8)
24137     if(ftype==otl_var_char){
24138       if(v.nls_flag)
24139         v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24140       else
24141         v.csfrm=OTL_SCAST(ub1,db->char_set_);
24142       status=OCIAttrSet
24143         (bindpp,
24144          OCI_HTYPE_BIND,
24145          &v.csfrm,
24146          0,
24147          OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24148          errhp);
24149       if(status)return 0;
24150     }
24151 #endif
24152 
24153     return 1;
24154    }else{
24155     status=OCIBindByName
24156      (cda,
24157       &bindpp,
24158       errhp,
24159       OTL_RCAST(text*,OTL_CCAST(char*,name)),
24160       OTL_SCAST(sb4,strlen(name)),
24161       OTL_RCAST(dvoid*,v.p_v),
24162       OTL_SCAST(sb4,-1),
24163       OTL_SCAST(ub2,tmpl_ftype2ora_ftype(ftype)),
24164       OTL_RCAST(dvoid*,v.p_ind),
24165       0,
24166       0,
24167       0,
24168       0,
24169      OTL_SCAST(ub4,OCI_DEFAULT));
24170     if(status)return 0;
24171 #if defined(OTL_UNICODE)
24172     if(ftype==otl_var_clob){
24173       v.csid=OTL_UNICODE_ID;
24174       status=OCIAttrSet
24175         (bindpp,
24176          OCI_HTYPE_BIND,
24177          &v.csid,
24178          0,
24179          OCI_ATTR_CHARSET_ID,
24180          errhp);
24181       if(status)return 0;
24182       if(v.nls_flag)
24183         v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24184       else
24185         v.csfrm=OTL_SCAST(ub1,db->char_set_);
24186       status=OCIAttrSet
24187         (bindpp,
24188          OCI_HTYPE_BIND,
24189          &v.csfrm,
24190          0,
24191          OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24192          errhp);
24193       if(status)return 0;
24194     }
24195 #endif
24196 
24197 #if defined(OTL_ORA_UTF8)
24198     if(ftype==otl_var_clob){
24199       if(v.nls_flag)
24200         v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24201       else
24202         v.csfrm=OTL_SCAST(ub1,db->char_set_);
24203       status=OCIAttrSet
24204         (bindpp,
24205          OCI_HTYPE_BIND,
24206          &v.csfrm,
24207          0,
24208          OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24209          errhp);
24210       if(status)return 0;
24211     }
24212 #endif
24213     return 1;
24214    }
24215   if(status)return 0;
24216   return 1;
24217 
24218  }
24219 
24220  int bind
24221  (const int column_num,
24222   otl_var& v,
24223   const int elem_size,
24224   const int ftype,
24225   const int /*param_type*/)
24226  {OCIDefine *defnp;
24227   int db_ftype=0;
24228 
24229   if(ftype!=otl_var_clob&&ftype!=otl_var_blob){
24230     int var_elem_size;
24231 #if defined(OTL_UNICODE)
24232     if(ftype==otl_var_char)
24233      var_elem_size=elem_size*sizeof(OTL_WCHAR);
24234     else if(ftype==otl_var_varchar_long)
24235      var_elem_size=elem_size+sizeof(sb4);
24236     else
24237      var_elem_size=elem_size;
24238 #elif defined(OTL_ORA_UTF8)
24239     if(ftype==otl_var_char && v.select_stm_flag)
24240       var_elem_size=elem_size*OTL_UTF8_BYTES_PER_CHAR; // 3 bytes per UTF8 char
24241     else if(ftype==otl_var_varchar_long)
24242      var_elem_size=elem_size+sizeof(sb4);
24243     else
24244      var_elem_size=elem_size;
24245 #else
24246     if(ftype==otl_var_varchar_long)
24247       var_elem_size=elem_size+sizeof(sb4);
24248     else
24249       var_elem_size=elem_size;
24250 #endif
24251     db_ftype=tmpl_ftype2ora_ftype(ftype);
24252 #if defined(OTL_UNICODE)
24253      if(ftype==otl_var_char)
24254        db_ftype=SQLT_VCS;
24255 #endif
24256    status=OCIDefineByPos
24257     (cda,
24258      &defnp,
24259      errhp,
24260      OTL_SCAST(ub4,column_num),
24261      OTL_RCAST(dvoid*,v.p_v),
24262      OTL_SCAST(sb4,ftype==otl_var_raw?var_elem_size+sizeof(short):var_elem_size),
24263      OTL_SCAST(ub2,db_ftype),
24264      OTL_RCAST(dvoid*,v.p_ind),
24265      OTL_RCAST(ub2*,v.p_rlen),
24266      OTL_RCAST(ub2*,v.p_rcode),
24267      OCI_DEFAULT);
24268    if(status)return 0;
24269 
24270 #if defined(OTL_ORA_UTF8)
24271    if(ftype==otl_var_char||ftype==otl_var_varchar_long){
24272      if(v.nls_flag)
24273        v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24274      else
24275        v.csfrm=OTL_SCAST(ub1,db->char_set_);
24276      status=OCIAttrSet
24277        (defnp,
24278         OCI_HTYPE_DEFINE,
24279         OTL_RCAST(void*,&v.csfrm),
24280         OTL_SCAST(ub4,0),
24281         OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24282         errhp);
24283      if(status)return 0;
24284    }
24285 #endif
24286 
24287 #if defined(OTL_UNICODE)
24288    if(ftype==otl_var_char||ftype==otl_var_varchar_long){
24289      if(v.nls_flag)
24290        v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24291      else
24292        v.csfrm=OTL_SCAST(ub1,db->char_set_);
24293      status=OCIAttrSet
24294        (defnp,
24295         OCI_HTYPE_DEFINE,
24296         OTL_RCAST(void*,&v.csfrm),
24297         OTL_SCAST(ub4,0),
24298         OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24299         errhp);
24300      if(status)return 0;
24301      v.csid=OTL_UNICODE_ID;
24302      status=OCIAttrSet
24303        (defnp,
24304         OCI_HTYPE_DEFINE,
24305         &v.csid,
24306         0,
24307         OCI_ATTR_CHARSET_ID,
24308         errhp);
24309      if(status)return 0;
24310    }
24311 #endif
24312    return 1;
24313   }else{
24314    status=OCIDefineByPos
24315     (cda,
24316      &defnp,
24317      errhp,
24318      OTL_SCAST(ub4,column_num),
24319      OTL_RCAST(dvoid*,v.p_v),
24320      OTL_SCAST(sb4,-1),
24321      OTL_SCAST(ub2,tmpl_ftype2ora_ftype(ftype)),
24322      OTL_RCAST(dvoid*,v.p_ind),
24323      OTL_RCAST(ub2*,v.p_rlen),
24324      OTL_RCAST(ub2*,v.p_rcode),
24325      OCI_DEFAULT);
24326    if(status)return 0;
24327 #if defined(OTL_UNICODE)
24328    if(ftype==otl_var_char||ftype==otl_var_varchar_long){
24329      v.csid=OTL_UNICODE_ID;
24330      status=OCIAttrSet
24331        (defnp,
24332         OCI_HTYPE_DEFINE,
24333         &v.csid,
24334         0,
24335         OCI_ATTR_CHARSET_ID,
24336         errhp);
24337      if(status)return 0;
24338    }
24339 #endif
24340 #if defined(OTL_ORA_UTF8)
24341    if(ftype==otl_var_clob){
24342      if(v.nls_flag)
24343        v.csfrm=OTL_SCAST(ub1,SQLCS_NCHAR);
24344      else
24345        v.csfrm=OTL_SCAST(ub1,db->char_set_);
24346      status=OCIAttrSet
24347        (defnp,
24348         OCI_HTYPE_DEFINE,
24349         OTL_RCAST(void*,&v.csfrm),
24350         OTL_SCAST(ub4,0),
24351         OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24352         errhp);
24353      if(status)return 0;
24354    }
24355 #endif
24356 
24357    return 1;
24358   }
24359  }
24360 
24361  void set_select_type(const int select_type)
24362  {
24363   straight_select=select_type;
24364  }
24365 
24366  int describe_column
24367  (otl_column_desc& col,
24368   const int column_num,
24369   int& eof_desc)
24370  {
24371   OCIParam* pard;
24372   ub2 dtype;
24373   ub2 dbsize;
24374   sb2 prec;
24375 
24376 #if defined(OTL_ORA8_8I_DESC_COLUMN_SCALE)
24377   ub1 scale;
24378 #else
24379   sb2 scale;
24380 #endif
24381 
24382   ub1 nullok;
24383   text* col_name;
24384   ub4 col_name_len;
24385   ub4 pos_num;
24386 
24387   eof_desc=0;
24388   if(straight_select&&pos_nbr==0){
24389    status=OCIStmtExecute
24390      (db->get_svchp(),
24391      cda,
24392      errhp,
24393      0,
24394      0,
24395      0,
24396      0,
24397      OCI_DESCRIBE_ONLY);
24398    if(status!=OCI_SUCCESS)return 0;
24399    status=OCIAttrGet
24400     (cda,
24401      OCI_HTYPE_STMT,
24402      OTL_RCAST(ub4*,&pos_num),
24403      0,
24404      OTL_SCAST(ub4,OCI_ATTR_PARAM_COUNT),
24405      errhp);
24406    if(status!=OCI_SUCCESS)return 0;
24407    pos_nbr=OTL_SCAST(int,pos_num);
24408   }
24409   if(!straight_select&&pos_nbr==0){
24410    status=OCIAttrGet
24411     (cda,
24412      OCI_HTYPE_STMT,
24413      OTL_RCAST(ub4*,&pos_num),
24414      0,
24415      OTL_SCAST(ub4,OCI_ATTR_PARAM_COUNT),
24416      errhp);
24417    if(status!=OCI_SUCCESS)return 0;
24418    pos_nbr=OTL_SCAST(int,pos_num);
24419   }
24420   if(column_num<1||column_num>pos_nbr){
24421    eof_desc=1;
24422    return 0;
24423   }
24424 #if defined(__GNUC__) && (__GNUC__>=4)
24425   void* temp_pard=&pard;
24426 #endif
24427   status=OCIParamGet
24428    (cda,
24429     OCI_HTYPE_STMT,
24430     errhp,
24431 #if defined(__GNUC__) && (__GNUC__>=4)
24432     OTL_RCAST(void**,temp_pard),
24433 #else
24434     OTL_RCAST(void**,&pard),
24435 #endif
24436     OTL_SCAST(ub4,column_num));
24437   if(status!=OCI_SUCCESS&&status!=OCI_NO_DATA)
24438    return 0;
24439   if(status==OCI_NO_DATA){
24440    eof_desc=1;
24441    return 1;
24442   }
24443   status=OCIAttrGet
24444    (OTL_RCAST(dvoid*,pard),
24445     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24446     OTL_RCAST(dvoid*,&dtype),
24447     0,
24448     OTL_SCAST(ub4,OCI_ATTR_DATA_TYPE),
24449     OTL_RCAST(OCIError*,errhp));
24450   if(status!=OCI_SUCCESS)return 0;
24451 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
24452 #if !defined(OTL_ORA8I)
24453   ub1 charset_form;
24454   status=OCIAttrGet
24455    (OTL_RCAST(dvoid*,pard),
24456     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24457     OTL_RCAST(dvoid*,&charset_form),
24458     0,
24459     OTL_SCAST(ub4,OCI_ATTR_CHARSET_FORM),
24460     OTL_RCAST(OCIError*,errhp));
24461   if(status!=OCI_SUCCESS)return 0;
24462   col.charset_form=OTL_SCAST(int,charset_form);
24463   ub2 char_size;
24464   status=OCIAttrGet
24465    (OTL_RCAST(dvoid*,pard),
24466     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24467     OTL_RCAST(dvoid*,&char_size),
24468     0,
24469     OTL_SCAST(ub4,OCI_ATTR_CHAR_SIZE),
24470     OTL_RCAST(OCIError*,errhp));
24471   if(status!=OCI_SUCCESS)return 0;
24472   col.char_size=OTL_SCAST(int,char_size);
24473 #else
24474   col.char_size=0;
24475 #endif
24476 #endif
24477   col.dbtype=dtype;
24478 #if defined(__GNUC__) && (__GNUC__>=4)
24479   void* temp_col_name=&col_name;
24480 #endif
24481   status=OCIAttrGet
24482    (OTL_RCAST(dvoid*,pard),
24483     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24484 #if defined(__GNUC__) && (__GNUC__>=4)
24485     OTL_RCAST(dvoid**,temp_col_name),
24486 #else
24487     OTL_RCAST(dvoid**,&col_name),
24488 #endif
24489     OTL_RCAST(ub4*,&col_name_len),
24490     OTL_SCAST(ub4,OCI_ATTR_NAME),
24491     OTL_RCAST(OCIError*,errhp));
24492   if(status!=OCI_SUCCESS)return 0;
24493   col.set_name(OTL_RCAST(char*,col_name),col_name_len);
24494   status=OCIAttrGet
24495    (OTL_RCAST(dvoid*,pard),
24496     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24497     OTL_RCAST(dvoid*,&dbsize),
24498     OTL_RCAST(ub4*,0),
24499     OTL_SCAST(ub4,OCI_ATTR_DATA_SIZE),
24500     OTL_RCAST(OCIError*,errhp));
24501   if(status!=OCI_SUCCESS)return 0;
24502   col.dbsize=dbsize;
24503   status=OCIAttrGet
24504    (OTL_RCAST(dvoid*,pard),
24505     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24506     OTL_RCAST(dvoid*,&prec),
24507     0,
24508     OTL_SCAST(ub4,OCI_ATTR_PRECISION),
24509     OTL_RCAST(OCIError*,errhp));
24510   if(status!=OCI_SUCCESS)return 0;
24511   col.prec=prec;
24512   status=OCIAttrGet
24513    (OTL_RCAST(dvoid*,pard),
24514     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24515     OTL_RCAST(dvoid*,&scale),
24516     0,
24517     OTL_SCAST(ub4,OCI_ATTR_SCALE),
24518     OTL_RCAST(OCIError*,errhp));
24519   if(status!=OCI_SUCCESS)return 0;
24520   col.scale=scale;
24521   status=OCIAttrGet
24522    (OTL_RCAST(dvoid*,pard),
24523     OTL_SCAST(ub4,OCI_DTYPE_PARAM),
24524     OTL_RCAST(dvoid*,&nullok),
24525     0,
24526     OTL_SCAST(ub4,OCI_ATTR_IS_NULL),
24527     OTL_RCAST(OCIError*,errhp));
24528   if(status!=OCI_SUCCESS)return 0;
24529   col.nullok=nullok;
24530   return 1;
24531  }
24532 
24533  void error(otl_exc& exception_struct)
24534  {sb4 errcode;
24535   size_t len;
24536 
24537   OTL_STRCPY_S(OTL_RCAST(char*,exception_struct.msg),
24538                sizeof(exception_struct.msg),
24539                "123456789");
24540   OCIErrorGet
24541    (OTL_RCAST(dvoid*,errhp),
24542     OTL_SCAST(ub4,1),
24543     0,
24544     &errcode,
24545     OTL_RCAST(text*,exception_struct.msg),
24546     OTL_SCAST(ub4,sizeof(exception_struct.msg)),
24547     OCI_HTYPE_ERROR);
24548   exception_struct.code=errcode;
24549   len=strlen(OTL_RCAST(char*,exception_struct.msg));
24550   exception_struct.msg[len]=0;
24551 #if defined(OTL_EXCEPTION_ENABLE_ERROR_OFFSET)
24552   ub2 error_offset;
24553   if(OCIAttrGet
24554      (cda,
24555       OCI_HTYPE_STMT,
24556       OTL_RCAST(ub2*,&error_offset),
24557       0,
24558       OTL_SCAST(ub4,OCI_ATTR_PARSE_ERROR_OFFSET),
24559       errhp)==OCI_SUCCESS)
24560     exception_struct.error_offset=OTL_SCAST(int,error_offset);
24561 #endif
24562  }
24563 
24564 private:
24565 
24566   otl_cur(const otl_cur&):
24567     otl_cur0(),
24568     cda(0),
24569     errhp(0),
24570     extern_cda(false),
24571     status(0),
24572     eof_status(0),
24573     db(0),
24574     straight_select(1),
24575     pos_nbr(0),
24576     commit_on_success(0),
24577     last_param_data_token(0),
24578     last_sql_param_data_status(0),
24579     sql_param_data_count(0),
24580     canceled(false),
24581     direct_exec_flag(0),
24582     parse_only_flag(0),
24583     stm_executed(0)
24584  {
24585  }
24586 
24587   otl_cur& operator=(const otl_cur&)
24588   {
24589     return *this;
24590   }
24591 
24592 
24593 };
24594 
24595 
24596 class otl_ref_cursor;
24597 
24598 class otl_sel{
24599 private:
24600 
24601   friend class otl_ref_cursor;
24602   int implicit_cursor;
24603 
24604 public:
24605 
24606   int get_implicit_cursor() const {return implicit_cursor;}
24607 
24608  void set_arr_size
24609  (const int input_arr_size,
24610   int& out_array_size,
24611   int& out_prefetch_array_size)
24612  {
24613    out_array_size=input_arr_size;
24614    out_prefetch_array_size=0;
24615  }
24616 
24617   void set_prefetch_size(const int /*aprefetch_array_size*/)
24618   {
24619   }
24620 
24621  int close_select(otl_cur& /*cur*/)
24622  {
24623   int i=1;
24624   return i;
24625  }
24626 
24627   otl_sel():
24628     implicit_cursor(0)
24629  {
24630  }
24631 
24632  virtual ~otl_sel(){}
24633 
24634   void set_select_type(const int /*atype*/)
24635  {
24636   implicit_cursor=0;
24637  }
24638 
24639   void init(const int /*array_size*/){}
24640 
24641  int first
24642  (otl_cur& cur,
24643   int& cur_row,
24644   int& cur_size,
24645   int& row_count,
24646   int& eof_data,
24647   const int array_size)
24648  {int rc;
24649   eof_data=0;
24650   cur_row=-1;
24651   cur.commit_on_success=0;
24652   rc=cur.exec(0,0,otl_sql_exec_from_select_cursor_class);
24653   if(rc==0)return 0;
24654   rc=cur.fetch(OTL_SCAST(otl_stream_buffer_size_type,array_size),eof_data);
24655   if(rc==0)return 0;
24656   row_count=cur.rpc();
24657   cur_size=row_count;
24658   if(cur_size!=0)cur_row=0;
24659   return 1;
24660  }
24661 
24662  int next
24663  (otl_cur& cur,
24664   int& cur_row,
24665   int& cur_size,
24666   int& row_count,
24667   int& eof_data,
24668   const int array_size)
24669  {int rc;
24670   if(cur_row<cur_size-1){
24671    ++cur_row;
24672    return 1;
24673   }else{
24674    if(eof_data){
24675     cur_row=-1;
24676     cur_size=0;
24677     return 1;
24678    }
24679    cur.commit_on_success=0;
24680    rc=cur.fetch(OTL_SCAST(otl_stream_buffer_size_type,array_size),eof_data);
24681    if(rc==0)return 0;
24682    int temp_rpc=cur.rpc();
24683    cur_size=temp_rpc-row_count;
24684    row_count=temp_rpc;
24685    if(cur_size!=0)cur_row=0;
24686    return 1;
24687   }
24688  }
24689 
24690 private:
24691 
24692   otl_sel(const otl_sel&):
24693     implicit_cursor(0)
24694  {
24695  }
24696 
24697   otl_sel& operator=(const otl_sel&)
24698   {
24699     return *this;
24700   }
24701 
24702 };
24703 
24704 
24705 typedef otl_tmpl_connect
24706   <otl_exc,
24707    otl_conn,
24708    otl_cur> otl_ora8_connect;
24709 
24710 
24711 typedef otl_tmpl_cursor
24712   <otl_exc,
24713    otl_conn,
24714    otl_cur,
24715    otl_var> otl_cursor;
24716 
24717 template <OTL_TYPE_NAME TExceptionStruct,
24718           OTL_TYPE_NAME TConnectStruct,
24719           OTL_TYPE_NAME TCursorStruct,
24720           OTL_TYPE_NAME TVariableStruct>
24721 class otl_tmpl_lob_stream: public otl_lob_stream_generic{
24722 public:
24723 
24724   typedef otl_tmpl_exception
24725   <TExceptionStruct,
24726    TConnectStruct,
24727    TCursorStruct> otl_exception;
24728 
24729  typedef otl_tmpl_variable<TVariableStruct>* p_bind_var;
24730  typedef otl_tmpl_connect
24731          <TExceptionStruct,
24732          TConnectStruct,
24733          TCursorStruct>* p_connect;
24734 
24735  typedef otl_tmpl_cursor
24736          <TExceptionStruct,
24737           TConnectStruct,
24738           TCursorStruct,
24739           TVariableStruct>* p_cursor;
24740 
24741 private:
24742 
24743  p_bind_var bind_var;
24744  p_connect connect;
24745  p_cursor cursor;
24746  otl_long_string* temp_buf;
24747  char* temp_char_buf;
24748 
24749 public:
24750 
24751  void init
24752  (void* avar,void* aconnect,void* acursor,
24753   int andx,
24754   int amode,
24755   const int alob_is_null=0) OTL_NO_THROW
24756  {
24757   connect=OTL_RCAST(p_connect,aconnect);
24758   bind_var=OTL_RCAST(p_bind_var,avar);
24759   cursor=OTL_RCAST(p_cursor,acursor);
24760   mode=amode;
24761   retcode=0;
24762   lob_is_null=alob_is_null;
24763   ndx=andx;
24764   offset=0;
24765   if(amode==otl_lob_stream_write_mode)
24766     lob_len=2147483647;
24767   else
24768     lob_len=0;
24769   eof_flag=0;
24770   in_destructor=0;
24771   if(bind_var)
24772     bind_var->get_var_struct().set_lob_stream_flag();
24773  }
24774 
24775  void set_len(const int new_len=0) OTL_NO_THROW
24776  {
24777   lob_len=new_len;
24778  }
24779 
24780   otl_tmpl_lob_stream() OTL_NO_THROW:
24781   otl_lob_stream_generic(true),
24782    bind_var(0),
24783    connect(0),
24784    cursor(0),
24785    temp_buf(0),
24786    temp_char_buf(0)
24787   {
24788     init(0,0,0,0,otl_lob_stream_zero_mode);
24789   }
24790 
24791   virtual ~otl_tmpl_lob_stream()
24792 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
24793     OTL_THROWS_OTL_EXCEPTION
24794 #endif
24795  {
24796    in_destructor=1;
24797    if(temp_buf){
24798      delete temp_buf;
24799      temp_buf=0;
24800    }
24801    if(temp_char_buf){
24802      delete[] temp_char_buf;
24803      temp_char_buf=0;
24804    }
24805 #if defined(OTL_DESTRUCTORS_DO_NOT_THROW)
24806    try{
24807      close();
24808    }catch(OTL_CONST_EXCEPTION otl_exception&){
24809    }
24810 #else
24811    close();
24812 #endif
24813  }
24814 
24815 #if (defined(OTL_STL) || defined(OTL_ACE) || \
24816      defined(OTL_USER_DEFINED_STRING_CLASS_ON)) && !defined(OTL_UNICODE)
24817   otl_lob_stream_generic& operator<<(const OTL_STRING_CONTAINER& s)
24818     OTL_THROWS_OTL_EXCEPTION
24819   {
24820     otl_long_string temp_s(s.c_str(),
24821                            OTL_SCAST(int,s.length()),
24822                            OTL_SCAST(int,s.length()));
24823     (*this)<<temp_s;
24824     return *this;
24825   }
24826 
24827   void setStringBuffer(const int chunk_size)
24828   {
24829     delete[] temp_char_buf;
24830     temp_char_buf=0;
24831     delete temp_buf;
24832     temp_buf=0;
24833     temp_char_buf=new char[chunk_size+1];
24834     temp_buf=new otl_long_string(temp_char_buf,chunk_size);
24835   }
24836 
24837   otl_lob_stream_generic& operator>>(OTL_STRING_CONTAINER& s)
24838     OTL_THROWS_OTL_EXCEPTION
24839   {
24840     const int TEMP_BUF_SIZE=4096;
24841     if(!temp_char_buf)temp_char_buf=new char[TEMP_BUF_SIZE];
24842     if(!temp_buf)temp_buf=new otl_long_string(temp_char_buf,TEMP_BUF_SIZE-1);
24843     int iters=0;
24844     while(!this->eof()){
24845       ++iters;
24846       (*this)>>(*temp_buf);
24847       temp_char_buf[temp_buf->len()]=0;
24848       if(iters>1)
24849         s+=temp_char_buf;
24850       else
24851         s=temp_char_buf;
24852     }
24853     return *this;
24854   }
24855 #endif
24856 
24857 
24858  otl_lob_stream_generic& operator<<(const otl_long_string& s)
24859    OTL_THROWS_OTL_EXCEPTION
24860  {
24861   if(mode!=otl_lob_stream_write_mode){
24862    const char* stm=0;
24863    char var_info[256];
24864    var_info[0]=0;
24865    if(cursor!=0){
24866      if(cursor->get_stm_label())
24867        stm=cursor->get_stm_label();
24868      else
24869        stm=cursor->get_stm_text();
24870    }
24871    if(bind_var!=0){
24872     otl_var_info_var
24873       (bind_var->get_name(),
24874        bind_var->get_ftype(),
24875        otl_var_long_string,
24876        var_info,
24877        sizeof(var_info));
24878    }
24879    char* vinfo=0;
24880    if(var_info[0]!=0)
24881     vinfo=&var_info[0];
24882    if(this->connect)this->connect->increment_throw_count();
24883    if(this->connect&&this->connect->get_throw_count()>1)return *this;
24884    if(otl_uncaught_exception()) return *this;
24885    throw otl_tmpl_exception
24886     <TExceptionStruct,
24887      TConnectStruct,
24888      TCursorStruct>
24889      (otl_error_msg_9,
24890       otl_error_code_9,
24891       stm,
24892       vinfo);
24893   }
24894   if(offset==0)offset=1;
24895   if((offset-1)+s.len()>lob_len){
24896    char var_info[256];
24897    otl_var_info_var
24898      (bind_var->get_name(),
24899       bind_var->get_ftype(),
24900      otl_var_long_string,
24901      var_info,
24902      sizeof(var_info));
24903    if(this->connect)this->connect->increment_throw_count();
24904    if(this->connect&&this->connect->get_throw_count()>1)return *this;
24905    if(otl_uncaught_exception()) return *this;
24906   char err_msg[1024];
24907   char temp_num[64];
24908   OTL_STRCPY_S(err_msg,sizeof(err_msg),otl_error_msg_7);
24909   OTL_STRCAT_S(err_msg,sizeof(err_msg),", trying to store ");
24910   otl_itoa(s.len(),temp_num);
24911   OTL_STRCAT_S(err_msg,sizeof(err_msg),temp_num);
24912 #if defined(OTL_UNICODE)
24913   OTL_STRCAT_S(err_msg,sizeof(err_msg)," Unicode characters at offset ");
24914 #else
24915   OTL_STRCAT_S(err_msg,sizeof(err_msg)," bytes at offset ");
24916 #endif
24917   otl_itoa(offset,temp_num);
24918   OTL_STRCAT_S(err_msg,sizeof(err_msg),temp_num);
24919   OTL_STRCAT_S(err_msg,sizeof(err_msg),". New length: ");
24920   otl_itoa((offset-1)+s.len(),temp_num);
24921   OTL_STRCAT_S(err_msg,sizeof(err_msg),temp_num);
24922   OTL_STRCAT_S(err_msg,sizeof(err_msg)," would be bigger than length of lob: ");
24923   otl_itoa(lob_len,temp_num);
24924   OTL_STRCAT_S(err_msg,sizeof(err_msg),temp_num);
24925   throw otl_tmpl_exception
24926    <TExceptionStruct,
24927     TConnectStruct,
24928     TCursorStruct>
24929    (err_msg,
24930     otl_error_code_7,
24931     cursor->get_stm_label()?cursor->get_stm_label():
24932     cursor->get_stm_text(),
24933     var_info);
24934   }
24935   if(s.is_last_piece())
24936     lob_len=(offset+s.len()-1);
24937   retcode=bind_var->get_var_struct().write_blob
24938     (s,lob_len,offset,cursor->get_cursor_struct());
24939   if(retcode){
24940    if((offset-1)==lob_len)
24941     close();
24942    return *this;
24943   }
24944   if(this->connect)this->connect->increment_throw_count();
24945   if(this->connect&&this->connect->get_throw_count()>1)return *this;
24946   if(otl_uncaught_exception()) return *this;
24947   throw otl_tmpl_exception
24948     <TExceptionStruct,
24949      TConnectStruct,
24950      TCursorStruct>(connect->get_connect_struct(),
24951                     cursor->get_stm_label()?cursor->get_stm_label():
24952                     cursor->get_stm_text());
24953  }
24954 
24955  otl_lob_stream_generic& operator>>(otl_long_string& s)
24956    OTL_THROWS_OTL_EXCEPTION
24957  {
24958   if(mode!=otl_lob_stream_read_mode){
24959    const char* stm=0;
24960    char var_info[256];
24961    var_info[0]=0;
24962    if(cursor!=0){
24963      if(cursor->get_stm_label())
24964        stm=cursor->get_stm_label();
24965      else
24966        stm=cursor->get_stm_text();
24967    }
24968    if(bind_var!=0){
24969     otl_var_info_var
24970       (bind_var->get_name(),
24971        bind_var->get_ftype(),
24972        otl_var_long_string,
24973        var_info,
24974        sizeof(var_info));
24975    }
24976    char* vinfo=0;
24977    if(var_info[0]!=0)
24978     vinfo=&var_info[0];
24979    if(this->connect)this->connect->increment_throw_count();
24980    if(this->connect&&this->connect->get_throw_count()>1)return *this;
24981    if(otl_uncaught_exception()) return *this;
24982    throw otl_tmpl_exception
24983     <TExceptionStruct,
24984      TConnectStruct,
24985      TCursorStruct>
24986     (otl_error_msg_10,
24987      otl_error_code_10,
24988      stm,
24989      vinfo);
24990   }
24991   if(offset==0&&lob_len==0)
24992    lob_len=len();
24993   if(lob_len==0||(offset-1)==lob_len){
24994    s.set_len(0);
24995    eof_flag=1;
24996    return *this;
24997   }
24998   if(offset==0)offset=1;
24999   retcode=bind_var->get_var_struct().read_blob(s,ndx,offset,lob_len);
25000   if((offset-1)==lob_len)eof_flag=1;
25001   if(retcode){
25002    if(eof()){
25003     close();
25004     eof_flag=1;
25005    }
25006    return *this;
25007   }
25008   if(this->connect)this->connect->increment_throw_count();
25009   if(this->connect&&this->connect->get_throw_count()>1)return *this;
25010   if(otl_uncaught_exception()) return *this;
25011   throw otl_tmpl_exception
25012     <TExceptionStruct,
25013      TConnectStruct,
25014      TCursorStruct>(connect->get_connect_struct(),
25015                     cursor->get_stm_label()?cursor->get_stm_label():
25016                     cursor->get_stm_text());
25017  }
25018 
25019  int eof(void) OTL_NO_THROW
25020  {
25021   if(lob_is_null)return 1;
25022   return eof_flag;
25023  }
25024 
25025  bool is_initialized(void) OTL_THROWS_OTL_EXCEPTION
25026  {
25027   if(cursor==0||connect==0||bind_var==0||lob_is_null)return false;
25028   int is_init=0;
25029   retcode=bind_var->get_var_struct().is_blob_initialized(ndx,is_init);
25030   if(retcode) return is_init!=0;
25031   if(this->connect)this->connect->increment_throw_count();
25032   if(this->connect&&this->connect->get_throw_count()>1)return false;
25033   if(otl_uncaught_exception()) return false;
25034   throw OTL_TMPL_EXCEPTION
25035     (connect->get_connect_struct(),
25036      cursor->get_stm_label()?cursor->get_stm_label():
25037      cursor->get_stm_text());
25038  }
25039 
25040  int len(void) OTL_THROWS_OTL_EXCEPTION
25041  {
25042   if(cursor==0||connect==0||bind_var==0||lob_is_null)return 0;
25043   int alen;
25044   retcode=bind_var->get_var_struct().get_blob_len(ndx,alen);
25045   if(retcode)return alen;
25046   if(this->connect)this->connect->increment_throw_count();
25047   if(this->connect&&this->connect->get_throw_count()>1)return 0;
25048   if(otl_uncaught_exception()) return 0;
25049   throw otl_tmpl_exception
25050     <TExceptionStruct,
25051      TConnectStruct,
25052      TCursorStruct>(connect->get_connect_struct(),
25053                     cursor->get_stm_label()?cursor->get_stm_label():
25054                     cursor->get_stm_text());
25055  }
25056 
25057  void close(void) OTL_THROWS_OTL_EXCEPTION
25058  {
25059   if(in_destructor){
25060    if(mode==otl_lob_stream_read_mode){
25061      bind_var->get_var_struct().set_lob_stream_flag(0);
25062     bind_var->set_not_null(0);
25063    }
25064    return;
25065   }
25066   if(mode==otl_lob_stream_zero_mode)return;
25067   if(mode==otl_lob_stream_read_mode){
25068     if(offset<lob_len-1)
25069       bind_var->get_var_struct().close_lob();
25070     bind_var->get_var_struct().set_lob_stream_flag(0);
25071     bind_var->set_not_null(0);
25072     init(0,0,0,0,otl_lob_stream_zero_mode);
25073   }else{
25074    // write mode
25075    if(!(offset==0&&lob_len==0)&&(offset-1)!=lob_len){
25076      bind_var->get_var_struct().close_lob();
25077      char var_info[256];
25078      char msg_buf[1024];
25079      OTL_STRCPY_S(msg_buf,sizeof(msg_buf),otl_error_msg_8);
25080      otl_var_info_var
25081        (bind_var->get_name(),
25082         bind_var->get_ftype(),
25083         otl_var_long_string,
25084         var_info,
25085         sizeof(var_info));
25086      if(this->connect)this->connect->increment_throw_count();
25087      if(this->connect&&this->connect->get_throw_count()>1)return;
25088      if(otl_uncaught_exception()) return;
25089      throw otl_tmpl_exception
25090        <TExceptionStruct,
25091        TConnectStruct,
25092        TCursorStruct>
25093        (msg_buf,
25094         otl_error_code_8,
25095         cursor->get_stm_label()?cursor->get_stm_label():
25096         cursor->get_stm_text(),
25097         var_info);
25098    }
25099    bind_var->get_var_struct().set_lob_stream_flag(0);
25100    bind_var->set_not_null(0);
25101   }
25102  }
25103 private:
25104 
25105   otl_tmpl_lob_stream(const otl_tmpl_lob_stream&) OTL_NO_THROW:
25106   otl_lob_stream_generic(true),
25107    bind_var(0),
25108    connect(0),
25109    cursor(0),
25110    temp_buf(0),
25111    temp_char_buf(0)
25112   {
25113   }
25114 
25115   otl_tmpl_lob_stream& operator=(const otl_tmpl_lob_stream&)
25116   {
25117     return *this;
25118   }
25119 
25120 };
25121 
25122 typedef otl_tmpl_lob_stream
25123   <otl_exc,
25124    otl_conn,
25125    otl_cur,
25126    otl_var> otl_lob_stream;
25127 
25128 typedef otl_tmpl_exception
25129   <otl_exc,
25130    otl_conn,
25131    otl_cur> otl_exception;
25132 
25133 typedef otl_tmpl_inout_stream
25134  <otl_exc,
25135   otl_conn,
25136   otl_cur,
25137   otl_var,
25138   otl_time0> otl_ora8_inout_stream;
25139 
25140 typedef otl_tmpl_select_stream
25141  <otl_exc,
25142   otl_conn,
25143   otl_cur,
25144   otl_var,
25145   otl_sel,
25146   otl_time0> otl_select_stream;
25147 
25148 
25149 typedef otl_tmpl_ext_hv_decl
25150  <otl_var,
25151   otl_time0,
25152   otl_exc,
25153   otl_conn,
25154   otl_cur> otl_ext_hv_decl;
25155 
25156 const int otl_no_stream_type=0;
25157 const int otl_inout_stream_type=1;
25158 const int otl_refcur_stream_type=2;
25159 const int otl_select_stream_type=3;
25160 const int otl_constant_sql_type=4;
25161 const int otl_mixed_refcur_stream_type=5;
25162 
25163 class otl_connect: public otl_ora8_connect{
25164 protected:
25165 
25166 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
25167  otl_stream_pool sc;
25168 #endif
25169 
25170 public:
25171 
25172 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
25173 
25174   otl_stream_pool& get_sc(){return sc;}
25175 
25176   void set_stream_pool_size(const int max_size=otl_max_default_pool_size)
25177   {
25178     sc.init(max_size);
25179   }
25180 
25181 #endif
25182 
25183 public:
25184 
25185   long direct_exec
25186   (const char* sqlstm,
25187    const int exception_enabled=1)
25188    OTL_THROWS_OTL_EXCEPTION
25189   {
25190     return otl_cursor::direct_exec(*this,sqlstm,exception_enabled);
25191   }
25192 
25193   void syntax_check(const char* sqlstm)
25194    OTL_THROWS_OTL_EXCEPTION
25195   {
25196     otl_cursor::syntax_check(*this,sqlstm);
25197   }
25198 
25199   otl_connect() OTL_NO_THROW:
25200     otl_ora8_connect(),
25201 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
25202     sc(),
25203 #endif
25204     cmd_(0)
25205   {
25206   }
25207 
25208 #if defined(OTL_ORA_OCI_ENV_CREATE)
25209   void set_connect_mode(bool threaded_mode=false)
25210   {
25211     connect_struct.set_threaded_mode(threaded_mode);
25212   }
25213 #endif
25214 
25215 #if defined(OTL_UNICODE) || defined(OTL_ORA_UTF8)
25216  void set_character_set(const int char_set=SQLCS_IMPLICIT)
25217    OTL_THROWS_OTL_EXCEPTION
25218  {
25219   connect_struct.set_char_set(char_set);
25220  }
25221 #endif
25222 
25223  otl_connect(const char* connect_str,
25224              const int aauto_commit=0
25225 #if defined(OTL_ORA_OCI_ENV_CREATE)
25226              ,bool threaded_mode=false
25227 #endif
25228             )
25229    OTL_THROWS_OTL_EXCEPTION
25230    : otl_ora8_connect(),
25231 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
25232      sc(),
25233 #endif
25234      cmd_(0)
25235   {
25236 #if defined(OTL_ORA_OCI_ENV_CREATE)
25237     set_connect_mode(threaded_mode);
25238 #endif
25239     rlogon(connect_str,aauto_commit);
25240   }
25241 
25242  virtual ~otl_connect()
25243 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
25244    OTL_THROWS_OTL_EXCEPTION
25245 #endif
25246   {
25247     if(cmd_){
25248       delete[] cmd_;
25249       cmd_=0;
25250     }
25251 #if defined(OTL_DESTRUCTORS_DO_NOT_THROW)
25252     try{
25253       logoff();
25254     }catch(OTL_CONST_EXCEPTION otl_exception&){
25255     }
25256 #else
25257     logoff();
25258 #endif
25259   }
25260 
25261   const char* getCmd(void) const
25262   {
25263     return cmd_;
25264   }
25265 
25266   otl_connect& operator<<(const char* cmd)
25267   {
25268     if(!connected){
25269       this->rlogon(cmd);
25270     }else{
25271       otl_cursor::direct_exec(*this,cmd);
25272     }
25273     return *this;
25274   }
25275 
25276   otl_connect& operator<<=(const char* cmd)
25277   {
25278     if(cmd_){
25279       delete[] cmd_;
25280       cmd_=0;
25281     }
25282     size_t cmd_len=strlen(cmd);
25283     cmd_=new char[cmd_len+1];
25284     OTL_STRCPY_S(cmd_,cmd_len+1,cmd);
25285     return *this;
25286   }
25287 
25288  static int otl_terminate(void)
25289    OTL_THROWS_OTL_EXCEPTION
25290  {
25291 #if defined(OTL_ORA8)&&!defined(OTL_ORA8I)&&!defined(OTL_ORA9I)
25292    return 1;
25293 #else
25294   return OCITerminate(OCI_DEFAULT)==OCI_SUCCESS;
25295 #endif
25296  }
25297 
25298  void cancel(void)
25299    OTL_THROWS_OTL_EXCEPTION
25300  {
25301   if(!connected)return;
25302   retcode=connect_struct.cancel();
25303   if(!retcode){
25304    increment_throw_count();
25305    if(get_throw_count()>1)return;
25306    if(otl_uncaught_exception()) return;
25307    throw otl_exception(connect_struct);
25308   }
25309  }
25310 
25311 #if defined(OTL_ORA10G_R2)
25312  void commit_nowait(void)
25313    OTL_THROWS_OTL_EXCEPTION
25314  {
25315   if(!connected)return;
25316   retcode=connect_struct.commit_nowait();
25317   if(!retcode){
25318    increment_throw_count();
25319    if(get_throw_count()>1)return;
25320    if(otl_uncaught_exception()) return;
25321    throw otl_exception(connect_struct);
25322   }
25323  }
25324 #endif
25325 
25326 #if defined(OTL_ORA8I) || defined(OTL_ORA9I)
25327   void change_password
25328   (const char* user_name,
25329    const char* old_password,
25330    const char* new_password)
25331     OTL_THROWS_OTL_EXCEPTION
25332   {
25333     throw_count=0;
25334     retcode=connect_struct.change_password
25335       (user_name,
25336        old_password,
25337        new_password);
25338     if(!retcode){
25339       increment_throw_count();
25340       if(get_throw_count()>1)return;
25341       if(otl_uncaught_exception()) return;
25342       throw otl_exception(connect_struct);
25343     }
25344   }
25345 #endif
25346 
25347   void auto_commit_off(void)
25348     OTL_THROWS_OTL_EXCEPTION
25349   {
25350     otl_ora8_connect::auto_commit_off();
25351   }
25352 
25353   void auto_commit_on(void)
25354     OTL_THROWS_OTL_EXCEPTION
25355   {
25356     otl_ora8_connect::auto_commit_on();
25357   }
25358 
25359  void rlogon(OCIEnv *envhp,OCISvcCtx *svchp)
25360    OTL_THROWS_OTL_EXCEPTION
25361  {
25362    if(this->connected){
25363      throw otl_exception(otl_error_msg_30,otl_error_code_30);
25364    }
25365    if(cmd_){
25366      delete[] cmd_;
25367      cmd_=0;
25368    }
25369    connected=0;
25370    long_max_size=32760;
25371    retcode=connect_struct.ext_logon(envhp,svchp,0);
25372    if(retcode)
25373      connected=1;
25374    else{
25375      connected=0;
25376      increment_throw_count();
25377      if(get_throw_count()>1)return;
25378      if(otl_uncaught_exception()) return;
25379      throw otl_exception(connect_struct);
25380    }
25381  }
25382 
25383  void rlogon(const char* connect_str,
25384              const int aauto_commit=0,
25385              const char* xa_server_external_name=0,
25386              const char* xa_server_internal_name=0
25387 #if defined(OTL_ORA_OCI_ENV_CREATE)
25388              ,bool threaded_mode=false
25389 #endif
25390             )
25391    OTL_THROWS_OTL_EXCEPTION
25392  {
25393     if(this->connected){
25394      throw otl_exception(otl_error_msg_30,otl_error_code_30);
25395     }
25396    if(cmd_){
25397      delete[] cmd_;
25398      cmd_=0;
25399    }
25400    if(xa_server_external_name!=0 && xa_server_internal_name!=0){
25401      connect_struct.set_xa_server_external_name
25402        (xa_server_external_name);
25403      connect_struct.set_xa_server_internal_name
25404        (xa_server_internal_name);
25405    }
25406 #if defined(OTL_ORA_OCI_ENV_CREATE)
25407    set_connect_mode(threaded_mode);
25408 #endif
25409    otl_ora8_connect::rlogon(connect_str,aauto_commit);
25410    if(connect_struct.get_last_status()==OCI_SUCCESS_WITH_INFO){
25411      otl_exception ex(connect_struct);
25412      if(ex.code!=0){
25413        increment_throw_count();
25414        if(get_throw_count()>1)return;
25415        if(otl_uncaught_exception()) return;
25416        throw ex;
25417      }
25418    }
25419  }
25420 
25421  void logoff(void)
25422    OTL_THROWS_OTL_EXCEPTION
25423  {
25424 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
25425   if(connected)
25426     sc.init(sc.get_max_size());
25427 #endif
25428   if(!connected){
25429    connect_struct.session_end();
25430    connect_struct.server_detach();
25431   }else{
25432     OTL_TRACE_FUNC(0x1,"otl_connect","logoff","")
25433       if(connect_struct.get_extern_lda())
25434       connect_struct.logoff();
25435     else{
25436       session_end();
25437       server_detach();
25438     }
25439     connected=0;
25440   }
25441  }
25442 
25443  void server_attach(const char* tnsname=0,
25444                     const char* xa_server_external_name=0,
25445                     const char* xa_server_internal_name=0
25446 #if defined(OTL_ORA_OCI_ENV_CREATE)
25447                     ,bool threaded_mode=false
25448 #endif
25449                    )
25450    OTL_THROWS_OTL_EXCEPTION
25451  {
25452    if(cmd_){
25453      delete[] cmd_;
25454      cmd_=0;
25455    }
25456    if(xa_server_external_name!=0 && xa_server_internal_name!=0){
25457      connect_struct.set_xa_server_external_name
25458        (xa_server_external_name);
25459      connect_struct.set_xa_server_internal_name
25460        (xa_server_internal_name);
25461    }
25462    connected=0;
25463    long_max_size=32760;
25464    throw_count=0;
25465 #if defined(OTL_ORA_OCI_ENV_CREATE)
25466    set_connect_mode(threaded_mode);
25467 #endif
25468    retcode=connect_struct.server_attach(tnsname);
25469    if(!retcode){
25470      increment_throw_count();
25471      if(get_throw_count()>1)return;
25472      if(otl_uncaught_exception()) return;
25473      throw otl_exception(connect_struct);
25474    }
25475  }
25476 
25477  void server_detach(void)
25478    OTL_THROWS_OTL_EXCEPTION
25479  {
25480   retcode=connect_struct.server_detach();
25481   if(!retcode){
25482    increment_throw_count();
25483    if(get_throw_count()>1)return;
25484    if(otl_uncaught_exception()) return;
25485    throw otl_exception(connect_struct);
25486   }
25487  }
25488 
25489  void session_begin
25490   (const char* username,
25491    const char* password,
25492    const int auto_commit=0,
25493    const int session_mode=OCI_DEFAULT
25494    // OCI_SYSDBA -- in this mode, the user is authenticated for SYSDBA
25495    // access.
25496    // OCI_SYSOPER -- in this mode, the user is authenticated
25497    // for SYSOPER access.
25498   ) OTL_THROWS_OTL_EXCEPTION
25499  {
25500    if(cmd_){
25501      delete[] cmd_;
25502      cmd_=0;
25503    }
25504    throw_count=0;
25505    retcode=connect_struct.session_begin
25506      (username,password,auto_commit,session_mode);
25507    if(retcode)
25508      connected=1;
25509    else{
25510      connected=0;
25511      increment_throw_count();
25512      if(get_throw_count()>1)return;
25513      if(otl_uncaught_exception()) return;
25514      throw otl_exception(connect_struct);
25515    }
25516    if(connect_struct.get_last_status()==OCI_SUCCESS_WITH_INFO){
25517      otl_exception ex(connect_struct);
25518      if(ex.code!=0){
25519        increment_throw_count();
25520        if(get_throw_count()>1)return;
25521        if(otl_uncaught_exception()) return;
25522        throw ex;
25523      }
25524    }
25525  }
25526 
25527  void session_reopen(const int auto_commit=0)
25528    OTL_THROWS_OTL_EXCEPTION
25529  {
25530   throw_count=0;
25531   if(connect_struct.get_session_begin_count()==0){
25532    connected=0;
25533    increment_throw_count();
25534    if(get_throw_count()>1)return;
25535    if(otl_uncaught_exception()) return;
25536    throw otl_exception(otl_error_msg_11,otl_error_code_11);
25537   }
25538   retcode=connect_struct.session_begin(auto_commit);
25539   if(retcode)
25540    connected=1;
25541   else{
25542    connected=0;
25543    increment_throw_count();
25544    if(get_throw_count()>1)return;
25545    if(otl_uncaught_exception()) return;
25546    throw otl_exception(connect_struct);
25547   }
25548   if(connect_struct.get_last_status()==OCI_SUCCESS_WITH_INFO){
25549     otl_exception ex(connect_struct);
25550     if(ex.code!=0){
25551       increment_throw_count();
25552       if(get_throw_count()>1)return;
25553       if(otl_uncaught_exception()) return;
25554       throw ex;
25555     }
25556   }
25557  }
25558 
25559  void session_end(void)
25560    OTL_THROWS_OTL_EXCEPTION
25561  {
25562 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
25563   if(connected)
25564     sc.init(sc.get_max_size());
25565 #endif
25566   connected=0;
25567   retcode=connect_struct.session_end();
25568   if(!retcode){
25569    increment_throw_count();
25570    if(get_throw_count()>1)return;
25571    if(otl_uncaught_exception()) return;
25572    throw otl_exception(connect_struct);
25573   }
25574  }
25575 
25576 private:
25577 
25578   char* cmd_;
25579 
25580   otl_connect& operator=(const otl_connect&)
25581   {
25582     return *this;
25583   }
25584 
25585   otl_connect(const otl_connect&)
25586     : otl_ora8_connect(),
25587 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
25588       sc(),
25589 #endif
25590       cmd_(0)
25591   {
25592   }
25593 
25594 
25595 };
25596 
25597 typedef otl_tmpl_variable<otl_var> otl_generic_variable;
25598 typedef otl_generic_variable* otl_p_generic_variable;
25599 
25600 class otl_refcur_base_cursor: public
25601  otl_tmpl_cursor
25602   <otl_exc,
25603    otl_conn,
25604    otl_cur,
25605    otl_var> {
25606 
25607 protected:
25608 
25609  int cur_row;
25610  int cur_size;
25611  int row_count;
25612  int array_size;
25613 
25614 public:
25615 
25616  otl_refcur_base_cursor
25617  (otl_connect& db,
25618   otl_var* var,
25619   const char* master_plsql_block,
25620   const otl_stream_buffer_size_type arr_size=1)
25621   :otl_tmpl_cursor
25622   <otl_exc,
25623    otl_conn,
25624    otl_cur,
25625    otl_var>(db,var),
25626    cur_row(-1),
25627    cur_size(0),
25628    row_count(0),
25629    array_size(arr_size)
25630  {
25631   size_t len=strlen(master_plsql_block)+1;
25632   stm_text=new char[len];
25633   OTL_STRCPY_S(stm_text,len,master_plsql_block);
25634  }
25635 
25636  otl_refcur_base_cursor():
25637   otl_tmpl_cursor
25638   <otl_exc,
25639    otl_conn,
25640    otl_cur,
25641    otl_var>(),
25642    cur_row(-1),
25643    cur_size(0),
25644    row_count(0),
25645    array_size(0)
25646  {
25647  }
25648 
25649  virtual ~otl_refcur_base_cursor()
25650  {
25651   delete[] stm_text;
25652   stm_text=0;
25653  }
25654 
25655  void open
25656  (otl_connect& db,
25657   otl_var* var,
25658   const char* master_plsql_block,
25659   const otl_stream_buffer_size_type arr_size=1)
25660  {
25661   cur_row=-1;
25662   row_count=0;
25663   cur_size=0;
25664   array_size=arr_size;
25665   otl_tmpl_cursor
25666   <otl_exc,
25667    otl_conn,
25668    otl_cur,
25669    otl_var>::open(db,var);
25670   size_t len=strlen(master_plsql_block)+1;
25671   stm_text=new char[len];
25672   OTL_STRCPY_S(stm_text,len,master_plsql_block);
25673  }
25674 
25675  void close(void)
25676  {
25677   delete[] stm_text;
25678   stm_text=0;
25679   otl_tmpl_cursor
25680   <otl_exc,
25681    otl_conn,
25682    otl_cur,
25683    otl_var>::close();
25684  }
25685 
25686  int first(void)
25687  {int rc;
25688 
25689   cur_row=-1;
25690   rc=cursor_struct.fetch(OTL_SCAST
25691                          (otl_stream_buffer_size_type,
25692                           array_size),
25693                          eof_data);
25694   if(rc==0){
25695     if(this->adb)this->adb->increment_throw_count();
25696     if(this->adb&&this->adb->get_throw_count()>1)return 0;
25697   if(otl_uncaught_exception()) return 0;
25698    throw otl_exception(cursor_struct,stm_label?stm_label:stm_text);
25699   }
25700   row_count=cursor_struct.rpc();
25701   cur_size=row_count;
25702   if(cur_size!=0)cur_row=0;
25703   return cur_size!=0;
25704  }
25705 
25706  int next(void)
25707  {int rc;
25708   if(cur_row<0)return first();
25709   if(cur_row<cur_size-1)
25710    ++cur_row;
25711   else{
25712    if(otl_tmpl_cursor<otl_exc,otl_conn,otl_cur,otl_var>::eof()){
25713     cur_row=-1;
25714     return 0;
25715    }
25716    rc=cursor_struct.fetch(OTL_SCAST(otl_stream_buffer_size_type,
25717                                     array_size),eof_data);
25718    if(rc==0){
25719      if(this->adb)this->adb->increment_throw_count();
25720      if(this->adb&&this->adb->get_throw_count()>1)return 0;
25721      if(otl_uncaught_exception()) return 0;
25722      throw otl_exception(cursor_struct,stm_label?stm_label:stm_text);
25723    }
25724    cur_size=cursor_struct.rpc()-row_count;
25725    row_count=cursor_struct.rpc();
25726    if(cur_size!=0)cur_row=0;
25727   }
25728   return cur_size!=0;
25729  }
25730 
25731  void bind_col
25732  (const int column_num,
25733   otl_generic_variable& v)
25734  {
25735   if(!connected)return;
25736   v.set_pos(column_num);
25737   otl_refcur_base_cursor::bind(column_num,v);
25738  }
25739 
25740  int describe_select
25741  (otl_column_desc* desc,
25742   int& desc_len)
25743  {int i;
25744   desc_len=0;
25745   cursor_struct.straight_select=0;
25746   for(i=1;describe_column(desc[i-1],i);++i)
25747    ++desc_len;
25748   return 1;
25749  }
25750 
25751 private:
25752 
25753  otl_refcur_base_cursor(const otl_refcur_base_cursor&):
25754   otl_tmpl_cursor
25755   <otl_exc,
25756    otl_conn,
25757    otl_cur,
25758    otl_var>(),
25759    cur_row(-1),
25760    cur_size(0),
25761    row_count(0),
25762    array_size(0)
25763  {
25764  }
25765 
25766  otl_refcur_base_cursor& operator=(const otl_refcur_base_cursor&)
25767  {
25768    return *this;
25769  }
25770 
25771 };
25772 
25773 #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
25774 
25775 #define OTL_ORA_COMMON_READ_STREAM otl_read_stream_interface
25776 #define OTL_ORA_REFCUR_COMMON_READ_STREAM otl_read_stream_interface
25777 
25778 class otl_read_stream_interface{
25779 public:
25780 
25781   virtual ~otl_read_stream_interface(){}
25782 
25783   virtual int is_null(void) OTL_NO_THROW = 0;
25784   virtual void rewind(void) OTL_THROWS_OTL_EXCEPTION = 0;
25785   virtual int eof(void) OTL_NO_THROW = 0;
25786   virtual void skip_to_end_of_row(void) OTL_NO_THROW = 0;
25787 
25788   virtual otl_var_desc* describe_out_vars(int& desc_len) OTL_NO_THROW = 0;
25789   virtual otl_var_desc* describe_next_out_var(void) OTL_NO_THROW = 0;
25790 
25791   virtual otl_read_stream_interface&
25792   operator>>(otl_datetime& s) OTL_THROWS_OTL_EXCEPTION = 0;
25793 
25794 #if !defined(OTL_UNICODE)
25795   virtual otl_read_stream_interface&
25796   operator>>(char& c) OTL_THROWS_OTL_EXCEPTION = 0;
25797 #endif
25798 
25799   virtual otl_read_stream_interface&
25800   operator>>(unsigned char& c) OTL_THROWS_OTL_EXCEPTION = 0;
25801 
25802 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
25803   virtual otl_read_stream_interface&
25804   operator>>(OTL_STRING_CONTAINER& s) OTL_THROWS_OTL_EXCEPTION = 0;
25805 #endif
25806 
25807 #if defined(OTL_UNICODE_STRING_TYPE)
25808   virtual otl_read_stream_interface&
25809   operator>>(OTL_UNICODE_STRING_TYPE& s) OTL_THROWS_OTL_EXCEPTION = 0;
25810 #endif
25811 
25812 #if !defined(OTL_UNICODE)
25813   virtual otl_read_stream_interface&
25814   operator>>(char* s) OTL_THROWS_OTL_EXCEPTION = 0;
25815 #endif
25816 
25817 #if defined(OTL_UNICODE)
25818 
25819  virtual otl_read_stream_interface&
25820  operator>>(OTL_UNICODE_CHAR_TYPE* s) OTL_THROWS_OTL_EXCEPTION = 0;
25821 
25822 #endif
25823 
25824   virtual otl_read_stream_interface&
25825   operator>>(unsigned char* s) OTL_THROWS_OTL_EXCEPTION = 0;
25826 
25827 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
25828     !defined(OTL_BIGINT_TO_STR))
25829   virtual otl_read_stream_interface&
25830   operator>>(OTLBIGINT& f) OTL_THROWS_OTL_EXCEPTION = 0;
25831 #endif
25832 
25833   virtual otl_read_stream_interface&
25834   operator>>(int& n) OTL_THROWS_OTL_EXCEPTION = 0;
25835 
25836   virtual otl_read_stream_interface&
25837   operator>>(unsigned& u) OTL_THROWS_OTL_EXCEPTION = 0;
25838 
25839   virtual otl_read_stream_interface&
25840   operator>>(short& sh) OTL_THROWS_OTL_EXCEPTION = 0;
25841 
25842   virtual otl_read_stream_interface&
25843   operator>>(long int& l) OTL_THROWS_OTL_EXCEPTION = 0;
25844 
25845   virtual otl_read_stream_interface&
25846   operator>>(float& f) OTL_THROWS_OTL_EXCEPTION = 0;
25847 
25848   virtual otl_read_stream_interface&
25849   operator>>(double& d) OTL_THROWS_OTL_EXCEPTION = 0;
25850 
25851   virtual otl_read_stream_interface&
25852   operator>>(otl_long_string& s) OTL_THROWS_OTL_EXCEPTION = 0;
25853 
25854   virtual otl_read_stream_interface&
25855   operator>>(otl_lob_stream& s) OTL_THROWS_OTL_EXCEPTION = 0;
25856 
25857   virtual otl_column_desc*
25858   describe_select(int& desc_len) OTL_NO_THROW = 0;
25859 
25860 };
25861 #else
25862 
25863 #define OTL_ORA_COMMON_READ_STREAM otl_stream
25864 #define OTL_ORA_REFCUR_COMMON_READ_STREAM otl_refcur_stream
25865 
25866 #endif
25867 
25868 class otl_refcur_stream:
25869 #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
25870   public otl_read_stream_interface,
25871 #endif
25872  public otl_refcur_base_cursor{
25873 
25874 protected:
25875 
25876   int delay_next;
25877   int same_sl_flag;
25878   otl_select_struct_override override;
25879 
25880   otl_var_desc* ov;
25881   int ov_len;
25882   int next_ov_ndx;
25883 
25884 
25885 public:
25886 
25887   void skip_to_end_of_row()
25888   {
25889     check_if_executed();
25890     if(eof())return;
25891     while(cur_col<sl_len-1){
25892       ++cur_col;
25893       null_fetched=sl[cur_col].is_null(this->cur_row);
25894     }
25895     ret_code=this->next();
25896     cur_col=0;
25897     if(!eof())
25898       cur_col=-1;
25899   }
25900 
25901 
25902   bool good() const
25903   {
25904     return get_connected()==1;
25905   }
25906 
25907   bool get_lob_stream_flag() const
25908   {
25909     return true;
25910   }
25911 
25912   int get_adb_max_long_size() const
25913   {
25914     return this->adb->get_max_long_size();
25915   }
25916 
25917   void inc_next_ov(void)
25918   {
25919     if(ov_len==0)return;
25920     if(next_ov_ndx<ov_len-1)
25921       ++next_ov_ndx;
25922     else
25923       next_ov_ndx=0;
25924   }
25925 
25926   void set_column_type(const int column_ndx,
25927                        const int col_type,
25928                        const int col_size=0)
25929     OTL_NO_THROW
25930   {
25931     override.add_override(column_ndx,col_type,col_size);
25932   }
25933 
25934   void set_all_column_types(const unsigned mask=0)
25935     OTL_NO_THROW
25936   {
25937     override.set_all_column_types(mask);
25938   }
25939 
25940  void cleanup(void)
25941  {int i;
25942   delete[] sl;
25943   delete[] ov;
25944   for(i=0;i<vl_len;++i)
25945    delete vl[i];
25946   delete[] vl;
25947   delete[] sl_desc;
25948  }
25949 
25950   otl_refcur_stream() OTL_NO_THROW:
25951    otl_refcur_base_cursor(),
25952    delay_next(0),
25953    same_sl_flag(0),
25954    override(),
25955    ov(0),
25956    ov_len(0),
25957    next_ov_ndx(0),
25958    sl_desc(0),
25959    sl_len(),
25960    sl(0),
25961    null_fetched(0),
25962    ret_code(0),
25963    cur_col(0),
25964    cur_in(0),
25965    executed(0),
25966    var_info()
25967  {
25968    init();
25969  }
25970 
25971  otl_refcur_stream
25972  (const otl_stream_buffer_size_type arr_size,
25973   const char* master_plsql_block,
25974   otl_var* var,
25975   otl_connect& db)
25976    OTL_THROWS_OTL_EXCEPTION:
25977    otl_refcur_base_cursor(db,var,master_plsql_block,arr_size),
25978    delay_next(0),
25979    same_sl_flag(0),
25980    override(),
25981    ov(0),
25982    ov_len(0),
25983    next_ov_ndx(0),
25984    sl_desc(0),
25985    sl_len(),
25986     sl(0),
25987    null_fetched(0),
25988    ret_code(0),
25989    cur_col(0),
25990    cur_in(0),
25991    executed(0),
25992    var_info()
25993  {
25994   init();
25995   try{
25996    rewind();
25997    null_fetched=0;
25998   }catch(OTL_CONST_EXCEPTION otl_exception&){
25999    cleanup();
26000    if(this->adb)this->adb->increment_throw_count();
26001    throw;
26002   }
26003  }
26004 
26005  virtual ~otl_refcur_stream()
26006    OTL_THROWS_OTL_EXCEPTION
26007  {
26008   cleanup();
26009   close();
26010  }
26011 
26012 
26013  int is_null(void) OTL_NO_THROW
26014  {
26015   return null_fetched;
26016  }
26017 
26018  int eof(void) OTL_NO_THROW
26019  {
26020   if(delay_next){
26021    look_ahead();
26022    delay_next=0;
26023   }
26024   return !ret_code;
26025  }
26026 
26027  int eof_intern(void)
26028  {
26029   return !ret_code;
26030  }
26031 
26032  void check_if_executed(void){}
26033 
26034   void open
26035   (otl_connect& db,
26036    otl_var* var,
26037    const char* master_plsql_block,
26038    const otl_stream_buffer_size_type arr_size=1)
26039     OTL_THROWS_OTL_EXCEPTION
26040   {
26041     otl_refcur_base_cursor::open(db,var,master_plsql_block,arr_size);
26042     get_select_list();
26043     rewind();
26044     delete[] ov;
26045     ov=new otl_var_desc[sl_len];
26046     ov_len=sl_len;
26047     for(int i=0;i<sl_len;++i){
26048       sl[i].copy_var_desc(ov[i]);
26049       if(sl_desc!=0)
26050         ov[i].copy_name(sl_desc[i].name);
26051     }
26052   }
26053 
26054   void close(void)
26055     OTL_THROWS_OTL_EXCEPTION
26056   {
26057     override.reset();
26058     otl_refcur_base_cursor::close();
26059   }
26060 
26061  otl_refcur_stream& operator>>(otl_time0& t)
26062    OTL_THROWS_OTL_EXCEPTION
26063  {
26064   check_if_executed();
26065   if(eof_intern())return *this;
26066   get_next();
26067   if(check_type(otl_var_timestamp)&&!eof_intern()){
26068 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
26069    void* tm=OTL_RCAST(void*,sl[cur_col].val(this->cur_row));
26070    int rc=sl[cur_col].get_var_struct().read_dt(&t,tm,sizeof(otl_time0));
26071    if(rc==0){
26072     if(this->adb)this->adb->increment_throw_count();
26073     if(this->adb&&this->adb->get_throw_count()>1)return *this;
26074     if(otl_uncaught_exception()) return *this;
26075     throw otl_exception(adb->get_connect_struct(),stm_label?stm_label:stm_text);
26076    }
26077 #else
26078    otl_time0* tm=OTL_RCAST(otl_time0*,sl[cur_col].val(cur_row));
26079    memcpy(OTL_RCAST(void*,&t),tm,otl_oracle_date_size);
26080 #endif
26081    look_ahead();
26082   }
26083   inc_next_ov();
26084   return *this;
26085  }
26086 
26087 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
26088   // already declared
26089 #else
26090  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(otl_datetime& s)
26091    OTL_THROWS_OTL_EXCEPTION
26092  {otl_time0 tmp;
26093   (*this)>>tmp;
26094 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
26095   if((*this).is_null())
26096    s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
26097   else{
26098     s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
26099     s.month=tmp.month;
26100     s.day=tmp.day;
26101     s.hour=tmp.hour-1;
26102     s.minute=tmp.minute-1;
26103     s.second=tmp.second-1;
26104   }
26105 #else
26106   s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
26107   s.month=tmp.month;
26108   s.day=tmp.day;
26109   s.hour=tmp.hour-1;
26110   s.minute=tmp.minute-1;
26111   s.second=tmp.second-1;
26112 #endif
26113   inc_next_ov();
26114   return *this;
26115  }
26116 #endif
26117 
26118  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(char& c)
26119    OTL_THROWS_OTL_EXCEPTION
26120  {
26121   check_if_executed();
26122   if(eof_intern())return *this;
26123   get_next();
26124   if(check_type(otl_var_char)&&!eof_intern()){
26125    c=*OTL_RCAST(char*,sl[cur_col].val(cur_row));
26126 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
26127    if((*this).is_null())
26128      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
26129 #endif
26130    look_ahead();
26131   }
26132   inc_next_ov();
26133   return *this;
26134  }
26135 
26136  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(unsigned char& c)
26137    OTL_THROWS_OTL_EXCEPTION
26138  {
26139 
26140   check_if_executed();
26141   if(eof_intern())return *this;
26142   get_next();
26143   if(check_type(otl_var_char)&&!eof_intern()){
26144    c=*OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
26145 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
26146    if((*this).is_null())
26147      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
26148 #endif
26149    look_ahead();
26150   }
26151   inc_next_ov();
26152   return *this;
26153  }
26154 
26155 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
26156  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(OTL_STRING_CONTAINER& s)
26157    OTL_THROWS_OTL_EXCEPTION
26158  {
26159   check_if_executed();
26160   if(eof_intern())return *this;
26161   get_next();
26162   switch(sl[cur_col].get_ftype()){
26163   case otl_var_char:
26164     if(!eof_intern()){
26165 #if defined(OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL)
26166       if((*this).is_null()){
26167         OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL(s);
26168       }else
26169 #elif defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
26170       if((*this).is_null())
26171         s=OTL_DEFAULT_STRING_NULL_TO_VAL;
26172       else
26173 #endif
26174 #if defined(OTL_ACE)
26175         s.set(OTL_RCAST(char*,sl[cur_col].val(cur_row)),1);
26176 #else
26177         s=OTL_RCAST(char*,sl[cur_col].val(cur_row));
26178 #endif
26179       look_ahead();
26180     }
26181     break;
26182 #if defined(USER_DEFINED_STRING_CLASS) || \
26183     defined(OTL_STL) || defined(OTL_ACE)
26184   case otl_var_varchar_long:
26185   case otl_var_raw_long:
26186     if(!eof_intern()){
26187       unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
26188       int len=sl[cur_col].get_len(cur_row);
26189 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_ACE)
26190       s.assign(OTL_RCAST(char*,c),len);
26191 #elif defined(OTL_ACE)
26192       s.set(OTL_RCAST(char*,c),len,1);
26193 #endif
26194       look_ahead();
26195     }
26196     break;
26197   case otl_var_blob:
26198   case otl_var_clob:
26199     if(!eof_intern()){
26200       int len=0;
26201       int max_long_sz=this->adb->get_max_long_size();
26202       otl_auto_array_ptr<unsigned char> loc_ptr(max_long_sz);
26203       unsigned char* temp_buf=loc_ptr.get_ptr();
26204 
26205       int rc=sl[cur_col].get_var_struct().get_blob
26206         (cur_row,
26207          temp_buf,
26208          max_long_sz,
26209          len);
26210       if(rc==0){
26211         if(this->adb)this->adb->increment_throw_count();
26212         if(this->adb&&this->adb->get_throw_count()>1)return *this;
26213         if(otl_uncaught_exception()) return *this;
26214         throw otl_exception(adb->get_connect_struct(),
26215                             stm_label?stm_label:stm_text);
26216       }
26217 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_ACE)
26218       s.assign(OTL_RCAST(char*,temp_buf),len);
26219 #elif defined(OTL_ACE)
26220       s.set(OTL_RCAST(char*,temp_buf),len,1);
26221 #endif
26222       look_ahead();
26223     }
26224     break;
26225 #endif
26226   default:
26227     check_type(otl_var_char);
26228   } // switch
26229   inc_next_ov();
26230   return *this;
26231  }
26232 #endif
26233 
26234  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(char* s)
26235    OTL_THROWS_OTL_EXCEPTION
26236  {
26237   check_if_executed();
26238   if(eof_intern())return *this;
26239   get_next();
26240   if(check_type(otl_var_char)&&!eof_intern()){
26241    otl_strcpy(OTL_RCAST(unsigned char*,s),
26242               OTL_RCAST(const unsigned char*,sl[cur_col].val(cur_row)));
26243 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
26244    if((*this).is_null())
26245      otl_strcpy(OTL_RCAST(unsigned char*,s),
26246                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL)
26247                );
26248 #endif
26249    look_ahead();
26250   }
26251   inc_next_ov();
26252   return *this;
26253  }
26254 
26255 #if defined(OTL_UNICODE_STRING_TYPE)
26256 
26257  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(OTL_UNICODE_STRING_TYPE& s)
26258    OTL_THROWS_OTL_EXCEPTION
26259  {
26260   check_if_executed();
26261   if(eof_intern())return *this;
26262   get_next();
26263   if(check_type(otl_var_char)&&!eof_intern()){
26264 #if defined(OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR)
26265     OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
26266       (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(cur_row));
26267     OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR(s,temp_s+1,*temp_s);
26268 #else
26269     OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
26270       (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(cur_row));
26271     s.assign(temp_s+1,*temp_s);
26272 #endif
26273 
26274 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
26275    if((*this).is_null())
26276     s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,OTL_DEFAULT_STRING_NULL_TO_VAL);
26277 #endif
26278 
26279     look_ahead();
26280   }
26281   inc_next_ov();
26282   return *this;
26283  }
26284 
26285 #endif
26286 
26287 #if defined(OTL_UNICODE)
26288 
26289  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(OTL_UNICODE_CHAR_TYPE* s)
26290    OTL_THROWS_OTL_EXCEPTION
26291  {
26292   check_if_executed();
26293   if(eof_intern())return *this;
26294   get_next();
26295   if(check_type(otl_var_char)&&!eof_intern()){
26296    otl_strcpy2(OTL_RCAST(unsigned char*,s),
26297                OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row)),
26298                sl[cur_col].get_len(cur_row)
26299              );
26300 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
26301    if((*this).is_null())
26302      otl_strcpy(OTL_RCAST(unsigned char*,s),
26303                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL)
26304                );
26305 #endif
26306    look_ahead();
26307   }
26308   inc_next_ov();
26309   return *this;
26310  }
26311 
26312 #endif
26313 
26314  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(unsigned char* s)
26315    OTL_THROWS_OTL_EXCEPTION
26316  {
26317   check_if_executed();
26318   if(eof_intern())return *this;
26319   get_next();
26320   if(check_type(otl_var_char)&&!eof_intern()){
26321    otl_strcpy2(OTL_RCAST(unsigned char*,s),
26322                OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row)),
26323                sl[cur_col].get_len(cur_row)
26324              );
26325 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
26326    if((*this).is_null())
26327      otl_strcpy(OTL_RCAST(unsigned char*,s),
26328                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL)
26329                );
26330 #endif
26331    look_ahead();
26332   }
26333   inc_next_ov();
26334   return *this;
26335  }
26336 
26337  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(int& n)
26338    OTL_THROWS_OTL_EXCEPTION
26339  {
26340   check_if_executed();
26341   if(eof_intern())return *this;
26342   get_next();
26343   if(!eof_intern()){
26344 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26345     int match_found=otl_numeric_convert_T2
26346       (sl[cur_col].get_ftype(),
26347        sl[cur_col].val(cur_row),
26348        n);
26349 #else
26350     int match_found=otl_numeric_convert_T
26351       (sl[cur_col].get_ftype(),
26352        sl[cur_col].val(cur_row),
26353        n);
26354 #endif
26355    if(!match_found){
26356     if(check_type(otl_var_double,otl_var_int))
26357       n=OTL_PCONV(int,double,sl[cur_col].val(cur_row));
26358    }
26359 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26360    if((*this).is_null())
26361      n=OTL_SCAST(int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26362 #endif
26363    look_ahead();
26364   }
26365   inc_next_ov();
26366   return *this;
26367  }
26368 
26369 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
26370     !defined(OTL_BIGINT_TO_STR))
26371  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(OTL_BIGINT& n)
26372    OTL_THROWS_OTL_EXCEPTION
26373  {
26374   check_if_executed();
26375   if(eof_intern())return *this;
26376   get_next();
26377   if(!eof_intern()){
26378 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26379     int match_found=otl_numeric_convert_T2
26380       (sl[cur_col].get_ftype(),
26381        sl[cur_col].val(cur_row),
26382        n);
26383 #else
26384     int match_found=otl_numeric_convert_T
26385       (sl[cur_col].get_ftype(),
26386        sl[cur_col].val(cur_row),
26387        n);
26388 #endif
26389    if(!match_found){
26390     if(check_type(otl_var_double,otl_var_int))
26391       n=OTL_PCONV(OTL_BIGINT,double,sl[cur_col].val(cur_row));
26392    }
26393 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26394    if((*this).is_null())
26395      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26396 #endif
26397    look_ahead();
26398   }
26399   inc_next_ov();
26400   return *this;
26401  }
26402 #endif
26403 
26404  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(unsigned& u)
26405    OTL_THROWS_OTL_EXCEPTION
26406  {
26407   check_if_executed();
26408   if(eof_intern())return *this;
26409   get_next();
26410   if(!eof_intern()){
26411 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26412    int match_found=otl_numeric_convert_T2
26413      (sl[cur_col].get_ftype(),
26414       sl[cur_col].val(cur_row),
26415       u);
26416 #else
26417    int match_found=otl_numeric_convert_T
26418      (sl[cur_col].get_ftype(),
26419      sl[cur_col].val(cur_row),
26420      u);
26421 #endif
26422    if(!match_found){
26423     if(check_type(otl_var_double,otl_var_unsigned_int))
26424       u=OTL_PCONV(unsigned,double,sl[cur_col].val(cur_row));
26425    }
26426 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26427    if((*this).is_null())
26428      u=OTL_SCAST(unsigned int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26429 #endif
26430    look_ahead();
26431   }
26432   inc_next_ov();
26433   return *this;
26434  }
26435 
26436  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(short& sh)
26437    OTL_THROWS_OTL_EXCEPTION
26438  {
26439   check_if_executed();
26440   if(eof_intern())return *this;
26441   get_next();
26442   if(!eof_intern()){
26443 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26444    int match_found=otl_numeric_convert_T2
26445      (sl[cur_col].get_ftype(),
26446       sl[cur_col].val(cur_row),
26447       sh);
26448 #else
26449    int match_found=otl_numeric_convert_T
26450      (sl[cur_col].get_ftype(),
26451      sl[cur_col].val(cur_row),
26452      sh);
26453 #endif
26454    if(!match_found){
26455     if(check_type(otl_var_double,otl_var_short))
26456       sh=OTL_PCONV(short,double,sl[cur_col].val(cur_row));
26457    }
26458 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26459    if((*this).is_null())
26460      sh=OTL_SCAST(short int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26461 #endif
26462    look_ahead();
26463   }
26464   inc_next_ov();
26465   return *this;
26466  }
26467 
26468  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(long int& l)
26469    OTL_THROWS_OTL_EXCEPTION
26470  {
26471   check_if_executed();
26472   if(eof_intern())return *this;
26473   get_next();
26474   if(!eof_intern()){
26475 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26476    int match_found=otl_numeric_convert_T2
26477      (sl[cur_col].get_ftype(),
26478      sl[cur_col].val(cur_row),
26479      l);
26480 #else
26481    int match_found=otl_numeric_convert_T
26482      (sl[cur_col].get_ftype(),
26483      sl[cur_col].val(cur_row),
26484      l);
26485 #endif
26486    if(!match_found){
26487     if(check_type(otl_var_double,otl_var_long_int))
26488       l=OTL_PCONV(long int,double,sl[cur_col].val(cur_row));
26489    }
26490 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26491    if((*this).is_null())
26492      l=OTL_SCAST(long int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26493 #endif
26494    look_ahead();
26495   }
26496   inc_next_ov();
26497   return *this;
26498  }
26499 
26500  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(float& f)
26501    OTL_THROWS_OTL_EXCEPTION
26502  {
26503   check_if_executed();
26504   if(eof_intern())return *this;
26505   get_next();
26506   if(!eof_intern()){
26507 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26508    int match_found=otl_numeric_convert_T2
26509      (sl[cur_col].get_ftype(),
26510      sl[cur_col].val(cur_row),
26511      f);
26512 #else
26513    int match_found=otl_numeric_convert_T
26514      (sl[cur_col].get_ftype(),
26515      sl[cur_col].val(cur_row),
26516      f);
26517 #endif
26518    if(!match_found){
26519     if(check_type(otl_var_double,otl_var_float))
26520       f=OTL_PCONV(float,double,sl[cur_col].val(cur_row));
26521    }
26522 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26523    if((*this).is_null())
26524      f=OTL_SCAST(float,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26525 #endif
26526    look_ahead();
26527   }
26528   inc_next_ov();
26529   return *this;
26530  }
26531 
26532  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(double& d)
26533    OTL_THROWS_OTL_EXCEPTION
26534  {
26535   check_if_executed();
26536   if(eof_intern())return *this;
26537   get_next();
26538   if(!eof_intern()){
26539 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
26540    int match_found=otl_numeric_convert_T2
26541      (sl[cur_col].get_ftype(),
26542       sl[cur_col].val(cur_row),
26543       d);
26544 #else
26545    int match_found=otl_numeric_convert_T
26546      (sl[cur_col].get_ftype(),
26547      sl[cur_col].val(cur_row),
26548      d);
26549 #endif
26550    if(!match_found){
26551     if(check_type(otl_var_double,otl_var_double))
26552      d=*OTL_RCAST(double*,sl[cur_col].val(cur_row));
26553    }
26554 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
26555    if((*this).is_null())
26556      d=OTL_SCAST(double,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
26557 #endif
26558    look_ahead();
26559   }
26560   inc_next_ov();
26561   return *this;
26562  }
26563 
26564 OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(otl_long_string& s)
26565    OTL_THROWS_OTL_EXCEPTION
26566  {
26567    check_if_executed();
26568    if(eof_intern())return *this;
26569    get_next();
26570    if(!eof_intern()){
26571      switch(sl[cur_col].get_ftype()){
26572      case otl_var_raw_long:
26573      case otl_var_varchar_long:
26574      {
26575        unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
26576        int len=sl[cur_col].get_len(cur_row);
26577        if(len>s.get_buf_size())
26578          len=s.get_buf_size();
26579        otl_memcpy(s.v,c,len,sl[cur_col].get_ftype());
26580        if(sl[cur_col].get_ftype()==otl_var_varchar_long)
26581          s.null_terminate_string(len);
26582        s.set_len(len);
26583        look_ahead();
26584      }
26585      break;
26586      case otl_var_blob:
26587      case otl_var_clob:
26588      {
26589        int len;
26590        int rc=sl[cur_col].get_var_struct().get_blob(cur_row,s.v,s.get_buf_size(),len);
26591        if(rc==0){
26592          if(this->adb)this->adb->increment_throw_count();
26593          if(this->adb&&this->adb->get_throw_count()>1)return *this;
26594          if(otl_uncaught_exception()) return *this;
26595          throw otl_exception(adb->get_connect_struct(),
26596                              stm_label?stm_label:stm_text);
26597        }
26598        s.set_len(len);
26599        if(sl[cur_col].get_ftype()==otl_var_clob)
26600          s.null_terminate_string(len);
26601        look_ahead();
26602      }
26603      break;
26604      case otl_var_raw:
26605      {
26606        unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(this->cur_row));
26607        int len2=OTL_SCAST(int,*OTL_RCAST(unsigned short*,c));
26608        otl_memcpy(s.v,c+sizeof(short int),len2,sl[cur_col].get_ftype());
26609        s.set_len(len2);
26610        look_ahead();
26611      }
26612      break;
26613      }
26614    }
26615    inc_next_ov();
26616    return *this;
26617  }
26618 
26619  OTL_ORA_REFCUR_COMMON_READ_STREAM& operator>>(otl_lob_stream& s)
26620    OTL_THROWS_OTL_EXCEPTION
26621  {
26622   check_if_executed();
26623   if(eof_intern())return *this;
26624   get_next();
26625   if((sl[cur_col].get_ftype()==otl_var_blob||
26626       sl[cur_col].get_ftype()==otl_var_clob)&&
26627      !eof_intern()){
26628    s.init
26629     (&sl[cur_col],
26630      adb,
26631      OTL_RCAST(otl_refcur_base_cursor*,this),
26632      cur_row,
26633      otl_lob_stream_read_mode,
26634      this->is_null());
26635    delay_next=1;
26636   }
26637   inc_next_ov();
26638   return *this;
26639  }
26640 
26641  otl_var_desc* describe_out_vars(int& desc_len)
26642    OTL_NO_THROW
26643  {
26644    desc_len=0;
26645    if(ov==0)return 0;
26646    desc_len=ov_len;
26647    return ov;
26648  }
26649 
26650  otl_var_desc* describe_next_out_var(void)
26651    OTL_NO_THROW
26652  {
26653    if(ov==0)return 0;
26654    return &ov[next_ov_ndx];
26655  }
26656 
26657  int select_list_len(void) OTL_NO_THROW
26658  {
26659   return sl_len;
26660  }
26661 
26662  int column_ftype(int ndx=0) OTL_NO_THROW
26663  {
26664    return sl[ndx].get_ftype();
26665  }
26666 
26667  int column_size(int ndx=0) OTL_NO_THROW
26668  {
26669    return sl[ndx].get_elem_size();
26670  }
26671 
26672  otl_column_desc* describe_select(int& desc_len)
26673    OTL_NO_THROW
26674  {
26675   desc_len=0;
26676   desc_len=sl_len;
26677   return sl_desc;
26678  }
26679 
26680 protected:
26681 
26682  otl_column_desc* sl_desc;
26683  int sl_len;
26684  otl_generic_variable* sl;
26685 
26686  int null_fetched;
26687  int ret_code;
26688  int cur_col;
26689  int cur_in;
26690  int executed;
26691  char var_info[256];
26692 
26693  void init(void)
26694  {
26695    ov=0;
26696    ov_len=0;
26697    next_ov_ndx=0;
26698    same_sl_flag=0;
26699    sl=0;
26700    sl_len=0;
26701    null_fetched=0;
26702    ret_code=0;
26703    sl_desc=0;
26704    executed=0;
26705    cur_in=0;
26706    cur_col=-1;
26707    executed=1;
26708    stm_text=0;
26709    delay_next=0;
26710  }
26711 
26712  void get_next(void)
26713  {
26714   if(cur_col<sl_len-1){
26715    ++cur_col;
26716    null_fetched=sl[cur_col].is_null(cur_row);
26717   }else{
26718    ret_code=next();
26719    cur_col=0;
26720   }
26721  }
26722 
26723   int check_type_throw(int type_code, int actual_data_type)
26724   {
26725     int out_type_code;
26726     if(actual_data_type!=0)
26727       out_type_code=actual_data_type;
26728     else
26729       out_type_code=type_code;
26730     otl_var_info_col
26731       (sl[cur_col].get_pos(),
26732        sl[cur_col].get_ftype(),
26733        out_type_code,
26734        var_info,
26735        sizeof(var_info));
26736     if(this->adb)this->adb->increment_throw_count();
26737     if(this->adb&&this->adb->get_throw_count()>1)return 0;
26738     if(otl_uncaught_exception()) return 0;
26739     throw otl_exception
26740       (otl_error_msg_0,
26741        otl_error_code_0,
26742        stm_label?stm_label:stm_text,
26743        var_info);
26744   }
26745 
26746   int check_type(int type_code, int actual_data_type=0)
26747   {
26748     switch(sl[cur_col].get_ftype()){
26749     case otl_var_timestamp:
26750         case otl_var_tz_timestamp:
26751     case otl_var_ltz_timestamp:
26752       if(type_code==otl_var_timestamp)
26753         return 1;
26754     default:
26755       if(sl[cur_col].get_ftype()==type_code)
26756         return 1;
26757     }
26758     return check_type_throw(type_code,actual_data_type);
26759   }
26760 
26761  void look_ahead(void)
26762  {
26763   if(cur_col==sl_len-1){
26764    ret_code=next();
26765    cur_col=-1;
26766   }
26767  }
26768 
26769  void get_select_list(void)
26770  {
26771    int i,j;
26772 
26773    otl_auto_array_ptr<otl_column_desc> loc_ptr(otl_var_list_size);
26774    otl_column_desc* sl_desc_tmp=loc_ptr.get_ptr();
26775    int sld_tmp_len=0;
26776    int ftype,elem_size;
26777 
26778    sld_tmp_len=0;
26779    cursor_struct.straight_select=0;
26780    for(i=1;describe_column(sl_desc_tmp[i-1],i);++i){
26781      ++sld_tmp_len;
26782      if(sld_tmp_len==loc_ptr.get_arr_size()){
26783        loc_ptr.double_size();
26784        sl_desc_tmp=loc_ptr.get_ptr();
26785      }
26786    }
26787    sl_len=sld_tmp_len;
26788    if(sl){
26789      delete[] sl;
26790      sl=0;
26791    }
26792    sl=new otl_generic_variable[sl_len==0?1:sl_len];
26793    int max_long_size=this->adb->get_max_long_size();
26794    for(j=0;j<sl_len;++j){
26795      otl_generic_variable::map_ftype
26796        (sl_desc_tmp[j],
26797         max_long_size,
26798         ftype,
26799         elem_size,
26800         override,
26801         j+1,
26802         this->adb->get_connect_struct().get_connection_type());
26803      sl[j].copy_pos(j+1);
26804 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
26805      if(sl_desc_tmp[j].charset_form==2)
26806        sl[j].get_var_struct().nls_flag=true;
26807 #endif
26808      sl[j].init(true,
26809                 ftype,
26810                 elem_size,
26811                 OTL_SCAST(otl_stream_buffer_size_type,array_size),
26812                 &adb->get_connect_struct()
26813                );
26814    }
26815    if(sl_desc){
26816      delete[] sl_desc;
26817      sl_desc=0;
26818    }
26819    sl_desc=new otl_column_desc[sl_len==0?1:sl_len];
26820    for(i=0;i<sl_len;++i)
26821      sl_desc[i]=sl_desc_tmp[i];
26822    for(i=0;i<sl_len;++i)bind_col(i+1,sl[i]);
26823  }
26824 
26825 private:
26826 
26827  void rewind(void)
26828    OTL_THROWS_OTL_EXCEPTION
26829  {
26830   ret_code=first();
26831   null_fetched=0;
26832   cur_col=-1;
26833   cur_in=0;
26834   executed=1;
26835   delay_next=0;
26836  }
26837 
26838   otl_refcur_stream& operator=(const otl_refcur_stream&)
26839   {
26840     return *this;
26841   }
26842 
26843   otl_refcur_stream(const otl_refcur_stream&) :
26844 #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
26845     otl_read_stream_interface(),
26846 #endif
26847     otl_refcur_base_cursor(),
26848     delay_next(0),
26849     same_sl_flag(0),
26850     override(),
26851     ov(0),
26852     ov_len(0),
26853     next_ov_ndx(0),
26854     sl_desc(0),
26855     sl_len(),
26856     sl(0),
26857     null_fetched(0),
26858     ret_code(0),
26859     cur_col(0),
26860     cur_in(0),
26861     executed(0),
26862     var_info()
26863  {
26864  }
26865 
26866 };
26867 
26868 class otl_inout_stream: public otl_ora8_inout_stream{
26869 public:
26870 
26871  otl_inout_stream
26872  (otl_stream_buffer_size_type arr_size,
26873   const char* sqlstm,
26874   otl_connect& db,
26875   void* master_stream_ptr,
26876   const bool alob_stream_mode=false,
26877   const char* sqlstm_label=0)
26878   : otl_ora8_inout_stream(arr_size,sqlstm,db,
26879                           master_stream_ptr,
26880                           alob_stream_mode,sqlstm_label),
26881     adb2(&db)
26882  {
26883  }
26884 
26885  otl_inout_stream& operator>>(otl_refcur_stream& str)
26886  {
26887   if(eof())return *this;
26888   if(check_in_type(otl_var_refcur,1)){
26889     if(str.get_connected())str.close();
26890     str.open(*adb2,
26891              &(in_vl[cur_in_x]->get_var_struct()),
26892              stm_text,
26893              OTL_SCAST
26894              (const otl_stream_buffer_size_type,
26895               in_vl[cur_in_x]->get_var_struct().array_size)
26896             );
26897     null_fetched=0;
26898   }
26899   get_in_next();
26900   return *this;
26901  }
26902 
26903 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
26904 
26905  otl_inout_stream& operator>>(OTL_STRING_CONTAINER& s)
26906  {
26907   otl_ora8_inout_stream::operator>>(s);
26908   return *this;
26909  }
26910 
26911  otl_inout_stream& operator<<(const OTL_STRING_CONTAINER& s)
26912  {
26913   otl_ora8_inout_stream::operator<<(s);
26914   return *this;
26915  }
26916 
26917 #endif
26918 
26919  otl_inout_stream& operator<<(const otl_null& n)
26920  {
26921   otl_ora8_inout_stream::operator<<(n);
26922   return *this;
26923  }
26924 
26925 
26926 #if defined(OTL_PL_TAB) && defined(OTL_STL)
26927 
26928  otl_inout_stream& operator>>(otl_pl_vec_generic& tab)
26929  {
26930   otl_ora8_inout_stream::operator>>(tab);
26931   return *this;
26932  }
26933 
26934  otl_inout_stream& operator<<(otl_pl_vec_generic& tab)
26935  {
26936   otl_ora8_inout_stream::operator<<(tab);
26937   return *this;
26938  }
26939 
26940 #endif
26941 
26942  otl_inout_stream& operator>>(otl_pl_tab_generic& tab)
26943  {
26944   otl_ora8_inout_stream::operator>>(tab);
26945   return *this;
26946  }
26947 
26948  otl_inout_stream& operator<<(otl_pl_tab_generic& tab)
26949  {
26950   otl_ora8_inout_stream::operator<<(tab);
26951   return *this;
26952  }
26953 
26954 
26955  otl_inout_stream& operator>>(otl_time0& s)
26956  {
26957   otl_ora8_inout_stream::operator>>(s);
26958   return *this;
26959  }
26960 
26961  otl_inout_stream& operator<<(const otl_time0& s)
26962  {
26963   otl_ora8_inout_stream::operator<<(s);
26964   return *this;
26965  }
26966 
26967  otl_inout_stream& operator>>(char& c)
26968  {
26969   otl_ora8_inout_stream::operator>>(c);
26970   return *this;
26971  }
26972 
26973  otl_inout_stream& operator<<(const char c)
26974  {
26975   otl_ora8_inout_stream::operator<<(c);
26976   return *this;
26977  }
26978 
26979 
26980  otl_inout_stream& operator>>(unsigned char& c)
26981  {
26982   otl_ora8_inout_stream::operator>>(c);
26983   return *this;
26984  }
26985 
26986 #if defined(OTL_UNICODE_STRING_TYPE)
26987  otl_inout_stream& operator>>(OTL_UNICODE_STRING_TYPE& s)
26988  {
26989   otl_ora8_inout_stream::operator>>(s);
26990   return *this;
26991  }
26992 
26993  otl_inout_stream& operator<<(const OTL_UNICODE_STRING_TYPE& s)
26994  {
26995   otl_ora8_inout_stream::operator<<(s);
26996   return *this;
26997  }
26998 #endif
26999 
27000  otl_inout_stream& operator<<(const unsigned char c)
27001  {
27002   otl_ora8_inout_stream::operator<<(c);
27003   return *this;
27004  }
27005 
27006 
27007  otl_inout_stream& operator>>(char* s)
27008  {
27009   otl_ora8_inout_stream::operator>>(s);
27010   return *this;
27011  }
27012 
27013  otl_inout_stream& operator<<(const char* s)
27014  {
27015   otl_ora8_inout_stream::operator<<(s);
27016   return *this;
27017  }
27018 
27019  otl_inout_stream& operator>>(unsigned char* s)
27020  {
27021   otl_ora8_inout_stream::operator>>(s);
27022   return *this;
27023  }
27024 
27025  otl_inout_stream& operator<<(const unsigned char* s)
27026  {
27027   otl_ora8_inout_stream::operator<<(s);
27028   return *this;
27029  }
27030 
27031 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
27032     !defined(OTL_BIGINT_TO_STR))
27033  otl_inout_stream& operator>>(OTL_BIGINT& n)
27034  {
27035 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27036   otl_ora8_inout_stream::operator>>(n);
27037 #else
27038   otl_ora8_inout_stream::operator>><OTL_BIGINT,otl_var_bigint>(n);
27039 #endif
27040   return *this;
27041  }
27042 #endif
27043 
27044  otl_inout_stream& operator>>(int& n)
27045  {
27046 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27047   otl_ora8_inout_stream::operator>>(n);
27048 #else
27049   otl_ora8_inout_stream::operator>><int,otl_var_int>(n);
27050 #endif
27051   return *this;
27052  }
27053 
27054 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
27055     !defined(OTL_BIGINT_TO_STR))
27056  otl_inout_stream& operator<<(const OTL_BIGINT n)
27057  {
27058 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27059    otl_ora8_inout_stream::operator<<(n);
27060 #else
27061   otl_ora8_inout_stream::operator<<<OTL_BIGINT,otl_var_bigint>(n);
27062 #endif
27063   return *this;
27064  }
27065 #endif
27066 
27067  otl_inout_stream& operator<<(const int n)
27068  {
27069 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27070    otl_ora8_inout_stream::operator<<(n);
27071 #else
27072   otl_ora8_inout_stream::operator<<<int,otl_var_int>(n);
27073 #endif
27074   return *this;
27075  }
27076 
27077  otl_inout_stream& operator>>(float& n)
27078  {
27079 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27080   otl_ora8_inout_stream::operator>>(n);
27081 #else
27082   otl_ora8_inout_stream::operator>><float,otl_var_float>(n);
27083 #endif
27084   return *this;
27085  }
27086 
27087  otl_inout_stream& operator<<(const float n)
27088  {
27089 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27090   otl_ora8_inout_stream::operator<<(n);
27091 #else
27092   otl_ora8_inout_stream::operator<<<float,otl_var_float>(n);
27093 #endif
27094   return *this;
27095  }
27096 
27097  otl_inout_stream& operator>>(double& n)
27098  {
27099 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27100   otl_ora8_inout_stream::operator>>(n);
27101 #else
27102   otl_ora8_inout_stream::operator>><double,otl_var_double>(n);
27103 #endif
27104   return *this;
27105  }
27106 
27107  otl_inout_stream& operator<<(const double n)
27108  {
27109 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27110   otl_ora8_inout_stream::operator<<(n);
27111 #else
27112   otl_ora8_inout_stream::operator<<<double,otl_var_double>(n);
27113 #endif
27114   return *this;
27115  }
27116 
27117 
27118  otl_inout_stream& operator>>(short int& n)
27119  {
27120 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27121   otl_ora8_inout_stream::operator>>(n);
27122 #else
27123   otl_ora8_inout_stream::operator>><short,otl_var_short>(n);
27124 #endif
27125   return *this;
27126  }
27127 
27128  otl_inout_stream& operator<<(const short int n)
27129  {
27130 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27131   otl_ora8_inout_stream::operator<<(n);
27132 #else
27133   otl_ora8_inout_stream::operator<<<short,otl_var_short>(n);
27134 #endif
27135   return *this;
27136  }
27137 
27138  otl_inout_stream& operator>>(unsigned int& n)
27139  {
27140 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27141   otl_ora8_inout_stream::operator>>(n);
27142 #else
27143   otl_ora8_inout_stream::operator>><unsigned,otl_var_unsigned_int>(n);
27144 #endif
27145   return *this;
27146  }
27147 
27148  otl_inout_stream& operator<<(const unsigned int n)
27149  {
27150 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27151   otl_ora8_inout_stream::operator<<(n);
27152 #else
27153   otl_ora8_inout_stream::operator<<<unsigned,otl_var_unsigned_int>(n);
27154 #endif
27155   return *this;
27156  }
27157 
27158 
27159  otl_inout_stream& operator>>(long int& n)
27160  {
27161 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27162   otl_ora8_inout_stream::operator>>(n);
27163 #else
27164   otl_ora8_inout_stream::operator>><long,otl_var_long_int>(n);
27165 #endif
27166   return *this;
27167  }
27168 
27169  otl_inout_stream& operator<<(const long int n)
27170  {
27171 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
27172   otl_ora8_inout_stream::operator<<(n);
27173 #else
27174   otl_ora8_inout_stream::operator<<<long,otl_var_long_int>(n);
27175 #endif
27176   return *this;
27177  }
27178 
27179  otl_inout_stream& operator>>(otl_long_string& n)
27180  {
27181   otl_ora8_inout_stream::operator>>(n);
27182   return *this;
27183  }
27184 
27185  otl_inout_stream& operator<<(const otl_long_string& n)
27186  {
27187   otl_ora8_inout_stream::operator<<(n);
27188   return *this;
27189  }
27190 
27191  otl_inout_stream& operator>>(otl_lob_stream& n)
27192  {
27193   otl_ora8_inout_stream::operator>>(n);
27194   return *this;
27195  }
27196 
27197  otl_inout_stream& operator<<(otl_lob_stream& s)
27198  {
27199   otl_ora8_inout_stream::operator<<(s);
27200   return *this;
27201  }
27202 
27203 protected:
27204 
27205  otl_connect* adb2;
27206 
27207 private:
27208 
27209   otl_inout_stream(const otl_inout_stream&):
27210     otl_ora8_inout_stream(),
27211     adb2(0)
27212  {
27213  }
27214 
27215  otl_inout_stream& operator=(const otl_inout_stream&)
27216  {
27217    return *this;
27218  }
27219 
27220 
27221 };
27222 
27223 
27224 // ============ OTL Reference Cursor Streams for Oracle 8 =================
27225 
27226 class otl_cur;
27227 
27228 class otl_ref_cursor: public
27229  otl_tmpl_cursor
27230   <otl_exc,
27231    otl_conn,
27232    otl_cur,
27233    otl_var> {
27234 
27235 protected:
27236 
27237 
27238   friend class otl_cur;
27239   int cur_row;
27240   int cur_size;
27241   int row_count;
27242   int array_size;
27243   otl_select_struct_override local_override;
27244 
27245 public:
27246 
27247  otl_ref_cursor
27248  (otl_connect& db,
27249   const char* cur_placeholder_name,
27250   void* master_stream_ptr,
27251   const otl_stream_buffer_size_type arr_size=1)
27252   :otl_tmpl_cursor
27253   <otl_exc,
27254    otl_conn,
27255    otl_cur,
27256    otl_var>(db),
27257    cur_row(-1),
27258    cur_size(0),
27259    row_count(0),
27260    array_size(arr_size),
27261    local_override(),
27262    sel_cur(),
27263    rvl_len(otl_var_list_size),
27264    rvl(new otl_p_generic_variable[rvl_len]),
27265    vl_cur_len(0),
27266    cur_placeholder(),
27267    master_stream_ptr_(master_stream_ptr)
27268  {int i;
27269   local_override.reset();
27270   for(i=0;i<rvl_len;++i)
27271     rvl[i]=0;
27272   OTL_STRCPY_S(cur_placeholder,sizeof(cur_placeholder),cur_placeholder_name);
27273  }
27274 
27275  otl_ref_cursor():
27276   otl_tmpl_cursor
27277   <otl_exc,
27278    otl_conn,
27279    otl_cur,
27280    otl_var>(),
27281    cur_row(-1),
27282    cur_size(0),
27283    row_count(0),
27284    array_size(0),
27285    local_override(),
27286    sel_cur(),
27287    rvl_len(0),
27288    rvl(),
27289    vl_cur_len(0),
27290   cur_placeholder(),
27291   master_stream_ptr_(0)
27292  {
27293    local_override.reset();
27294  }
27295 
27296  virtual ~otl_ref_cursor()
27297  {
27298   delete[] rvl;
27299   rvl=0;
27300  }
27301 
27302  void open
27303  (otl_connect& db,
27304   const char* cur_placeholder_name,
27305   const otl_stream_buffer_size_type arr_size=1)
27306  {int i;
27307   local_override.reset();
27308   cur_row=-1;
27309   row_count=0;
27310   cur_size=0;
27311   array_size=arr_size;
27312   rvl_len=otl_var_list_size;
27313   vl_cur_len=0;
27314   rvl=new otl_p_generic_variable[rvl_len];
27315   for(i=0;i<rvl_len;++i)rvl[i]=0;
27316   OTL_STRCPY_S(cur_placeholder,sizeof(cur_placeholder),cur_placeholder_name);
27317   if(!sel_cur.get_connected())sel_cur.open(db);
27318   otl_tmpl_cursor
27319   <otl_exc,
27320    otl_conn,
27321    otl_cur,
27322    otl_var>::open(db);
27323  }
27324 
27325  void release_sel_cur(void)
27326  {
27327 #if defined(OTL_ORA8_8I_REFCUR)
27328   return;
27329 #else
27330   char tmp_buf[256];
27331   OCIBind* bindpp;
27332   int rc;
27333 
27334   if(!sel_cur.get_connected())return;
27335   OTL_STRCPY_S(tmp_buf,sizeof(tmp_buf),"begin close ");
27336   OTL_STRCAT_S(tmp_buf,sizeof(tmp_buf),cur_placeholder);
27337   OTL_STRCAT_S(tmp_buf,sizeof(tmp_buf),"; end;");
27338   otl_tmpl_cursor
27339   <otl_exc,
27340    otl_conn,
27341    otl_cur,
27342    otl_var>::parse(tmp_buf);
27343   rc=OCIBindByName
27344    (cursor_struct.cda,
27345     &bindpp,
27346     cursor_struct.errhp,
27347     OTL_RCAST(text*,cur_placeholder),
27348     OTL_SCAST(sb4,strlen(cur_placeholder)),
27349     OTL_RCAST(dvoid*,&sel_cur.get_cursor_struct().cda),
27350     0,
27351     SQLT_RSET,
27352     0,
27353     0,
27354     0,
27355     0,
27356     0,
27357     OTL_SCAST(ub4,OCI_DEFAULT));
27358   if(rc!=0){
27359    if(this->adb)this->adb->increment_throw_count();
27360    if(this->adb&&this->adb->get_throw_count()>1)return;
27361    if(otl_uncaught_exception()) return;
27362    throw otl_exception(cursor_struct,
27363                        stm_label?stm_label:stm_text);
27364   }
27365   otl_tmpl_cursor
27366   <otl_exc,
27367    otl_conn,
27368    otl_cur,
27369      otl_var>::exec(1,0,otl_sql_exec_from_select_cursor_class);
27370 #endif
27371  }
27372 
27373  void close(void)
27374  {
27375    local_override.reset();
27376    delete[] rvl;
27377    rvl=0;
27378    release_sel_cur();
27379    sel_cur.close();
27380    otl_tmpl_cursor
27381      <otl_exc,
27382      otl_conn,
27383      otl_cur,
27384      otl_var>::close();
27385  }
27386 
27387  int first(void)
27388  {int i,rc;
27389   OCIBind* bindpp;
27390 
27391   if(!sel_cur.get_connected()){
27392    sel_cur.open(*adb);
27393    rc=OCIBindByName
27394     (cursor_struct.cda,
27395      &bindpp,
27396      cursor_struct.errhp,
27397      OTL_RCAST(text*,cur_placeholder),
27398      OTL_SCAST(sb4,strlen(cur_placeholder)),
27399      OTL_RCAST(dvoid*,&sel_cur.get_cursor_struct().cda),
27400      0,
27401      SQLT_RSET,
27402      0,
27403      0,
27404      0,
27405      0,
27406      0,
27407      OTL_SCAST(ub4,OCI_DEFAULT));
27408    if(rc!=0){
27409      if(this->adb)this->adb->increment_throw_count();
27410      if(this->adb&&this->adb->get_throw_count()>1)return 0;
27411      if(otl_uncaught_exception()) return 0;
27412      throw otl_exception(cursor_struct,
27413                          stm_label?stm_label:stm_text);
27414    }
27415   }
27416 
27417   if(cur_row==-2)
27418    ; // Special case -- calling describe_select() between parse() and first()
27419   else{
27420 // Executing the PLSQL master block
27421     exec(1,0,otl_sql_exec_from_select_cursor_class);
27422    sel_cur.set_connected(1);
27423   }
27424   cur_row=-1;
27425   for(i=0;i<vl_cur_len;++i)
27426    sel_cur.bind(i+1,*rvl[i]);
27427   rc=sel_cur.get_cursor_struct().fetch
27428     (OTL_SCAST(otl_stream_buffer_size_type,
27429                array_size),sel_cur.get_eof_data_ref());
27430   if(rc==0){
27431     if(this->adb)this->adb->increment_throw_count();
27432     if(this->adb&&this->adb->get_throw_count()>1)return 0;
27433     if(otl_uncaught_exception()) return 0;
27434     throw otl_exception(sel_cur.get_cursor_struct(),
27435                         stm_label?stm_label:stm_text);
27436   }
27437   row_count=sel_cur.get_cursor_struct().rpc();
27438   OTL_TRACE_FIRST_FETCH
27439   cur_size=row_count;
27440   if(cur_size!=0)cur_row=0;
27441   return cur_size!=0;
27442  }
27443 
27444  int next(void)
27445  {int rc;
27446   if(cur_row<0)return first();
27447   if(cur_row<cur_size-1)
27448    ++cur_row;
27449   else{
27450    if(sel_cur.eof()){
27451      cur_row=-1;
27452      return 0;
27453    }
27454    rc=sel_cur.get_cursor_struct().fetch
27455      (OTL_SCAST(otl_stream_buffer_size_type,
27456                 array_size),sel_cur.get_eof_data_ref());
27457    if(rc==0){
27458      if(this->adb)this->adb->increment_throw_count();
27459      if(this->adb&&this->adb->get_throw_count()>1)return 0;
27460      if(otl_uncaught_exception()) return 0;
27461      throw otl_exception(sel_cur.get_cursor_struct(),
27462                          stm_label?stm_label:stm_text);
27463    }
27464    cur_size=sel_cur.get_cursor_struct().rpc()-row_count;
27465    row_count=sel_cur.get_cursor_struct().rpc();
27466    OTL_TRACE_NEXT_FETCH2
27467    if(cur_size!=0)cur_row=0;
27468   }
27469   return cur_size!=0;
27470  }
27471 
27472  void bind
27473  (const int column_num,
27474   otl_generic_variable& v)
27475  {
27476   if(!connected)return;
27477   ++vl_cur_len;
27478   if(vl_cur_len==rvl_len){
27479     int temp_rvl_len=rvl_len*2;
27480     otl_p_generic_variable* temp_rvl=
27481       new otl_p_generic_variable[temp_rvl_len];
27482     int i;
27483     for(i=0;i<rvl_len;++i)
27484       temp_rvl[i]=rvl[i];
27485     for(i=rvl_len+1;i<temp_rvl_len;++i)
27486       temp_rvl[i]=0;
27487     delete[] rvl;
27488     rvl=temp_rvl;
27489     rvl_len=temp_rvl_len;
27490   }
27491   rvl[vl_cur_len-1]=&v;
27492   v.set_pos(column_num);
27493  }
27494 
27495  void bind(otl_generic_variable& v)
27496  {
27497    if(v.get_pos())
27498      bind(v.get_pos(),v);
27499    else if(v.get_name())
27500    otl_tmpl_cursor
27501   <otl_exc,
27502    otl_conn,
27503    otl_cur,
27504    otl_var>::bind(v);
27505  }
27506 
27507  void bind
27508  (const char* name,
27509   otl_generic_variable& v)
27510  {
27511   otl_tmpl_cursor
27512   <otl_exc,
27513    otl_conn,
27514    otl_cur,
27515    otl_var>::bind(name,v);
27516  }
27517 
27518  int describe_select
27519  (otl_column_desc* desc,
27520   int& desc_len)
27521  {int i,rc;
27522   OCIBind* bindpp;
27523 
27524   if(!sel_cur.get_connected()){
27525    sel_cur.open(*adb);
27526    rc=OCIBindByName
27527     (cursor_struct.cda,
27528      &bindpp,
27529      cursor_struct.errhp,
27530      OTL_RCAST(text*,cur_placeholder),
27531      OTL_SCAST(sb4,strlen(cur_placeholder)),
27532      OTL_RCAST(dvoid*,&sel_cur.get_cursor_struct().cda),
27533      0,
27534      SQLT_RSET,
27535      0,
27536      0,
27537      0,
27538      0,
27539      0,
27540      OTL_SCAST(ub4,OCI_DEFAULT));
27541    if(rc!=0){
27542      if(this->adb)this->adb->increment_throw_count();
27543      if(this->adb&&this->adb->get_throw_count()>1)return 0;
27544      if(otl_uncaught_exception()) return 0;
27545      throw otl_exception(cursor_struct,
27546                          stm_label?stm_label:stm_text);
27547    }
27548   }
27549 // Executing the PLSQL master block
27550   exec(1,0,otl_sql_exec_from_select_cursor_class);
27551   sel_cur.set_connected(1);
27552   cur_row=-2; // Special case -- describe_select() before first() or next()
27553   desc_len=0;
27554   sel_cur.get_cursor_struct().straight_select=0;
27555   for(i=1;sel_cur.describe_column(desc[i-1],i);++i)
27556    ++desc_len;
27557   return 1;
27558  }
27559 
27560 public:
27561 
27562  otl_cursor sel_cur;
27563 
27564 protected:
27565 
27566   int rvl_len;
27567   otl_p_generic_variable* rvl;
27568   int vl_cur_len;
27569   char cur_placeholder[64];
27570   void* master_stream_ptr_;
27571 
27572 private:
27573 
27574  otl_ref_cursor(const otl_ref_cursor&)
27575   :otl_tmpl_cursor
27576   <otl_exc,
27577    otl_conn,
27578    otl_cur,
27579    otl_var>(),
27580    cur_row(-1),
27581    cur_size(0),
27582    row_count(0),
27583    array_size(0),
27584    local_override(),
27585    sel_cur(),
27586    rvl_len(0),
27587    rvl(0),
27588    vl_cur_len(0),
27589    cur_placeholder(),
27590    master_stream_ptr_(0)
27591  {
27592  }
27593 
27594  otl_ref_cursor& operator=(const otl_ref_cursor&)
27595  {
27596    return *this;
27597  }
27598 
27599 
27600 };
27601 
27602 class otl_ref_select_stream: public otl_ref_cursor{
27603 
27604 protected:
27605 
27606  otl_select_struct_override *override;
27607  int delay_next;
27608  int same_sl_flag;
27609  long _rfc;
27610 
27611 public:
27612 
27613   void skip_to_end_of_row()
27614   {
27615     check_if_executed();
27616     if(eof())return;
27617     while(cur_col<sl_len-1){
27618       ++cur_col;
27619       null_fetched=sl[cur_col].is_null(this->cur_row);
27620     }
27621     ret_code=this->next();
27622     cur_col=0;
27623     if(!eof())
27624       cur_col=-1;
27625     ++_rfc;
27626   }
27627 
27628 
27629   int get_select_row_count() const
27630   {
27631     return this->cur_row==-1?0:this->cur_size-this->cur_row;
27632   }
27633 
27634   long get_rfc() const {return _rfc;}
27635 
27636  void cleanup(void)
27637  {int i;
27638   delete[] sl;
27639   for(i=0;i<vl_len;++i)
27640    delete vl[i];
27641   delete[] vl;
27642   delete[] sl_desc;
27643  }
27644 
27645  otl_ref_select_stream
27646  (otl_select_struct_override* aoverride,
27647   const otl_stream_buffer_size_type arr_size,
27648   const char* sqlstm,
27649   const char* acur_placeholder,
27650   otl_connect& db,
27651   const char* sqlstm_label=0)
27652    :otl_ref_cursor
27653     (db,
27654      acur_placeholder,
27655      aoverride->get_master_stream_ptr(),
27656      arr_size),
27657     override(0),
27658     delay_next(0),
27659     same_sl_flag(0),
27660     _rfc(0),
27661     sl_desc(0),
27662     sl_len(0),
27663     sl(0),
27664     null_fetched(0),
27665     ret_code(0),
27666     cur_col(0),
27667     cur_in(0),
27668     executed(0),
27669     var_info()
27670  {
27671    if(sqlstm_label!=0){
27672      if(stm_label!=0){
27673        delete[] stm_label;
27674        stm_label=0;
27675      }
27676      size_t len=strlen(sqlstm_label)+1;
27677      stm_label=new char[len];
27678      OTL_STRCPY_S(stm_label,len,sqlstm_label);
27679    }
27680 
27681   init();
27682 
27683   override=aoverride;
27684   {
27685    size_t len=strlen(sqlstm)+1;
27686    stm_text=new char[len];
27687    OTL_STRCPY_S(stm_text,len,sqlstm);
27688    otl_select_struct_override* temp_local_override=&this->local_override;
27689    otl_ext_hv_decl hvd
27690      (this->stm_text,
27691       1,
27692       this->stm_label,
27693       &temp_local_override,
27694       adb
27695      );
27696    hvd.alloc_host_var_list(vl,vl_len,*adb);
27697   }
27698 
27699   try{
27700 
27701    parse();
27702    if(vl_len==0){
27703     rewind();
27704     null_fetched=0;
27705    }
27706   }catch(OTL_CONST_EXCEPTION otl_exception&){
27707    cleanup();
27708    if(this->adb)this->adb->increment_throw_count();
27709    throw;
27710   }
27711 
27712  }
27713 
27714  virtual ~otl_ref_select_stream()
27715  {
27716   cleanup();
27717   close();
27718  }
27719 
27720  void rewind(void)
27721  {
27722    OTL_TRACE_STREAM_EXECUTION
27723    _rfc=0;
27724    get_select_list();
27725    ret_code=first();
27726    null_fetched=0;
27727    cur_col=-1;
27728    cur_in=0;
27729    executed=1;
27730    delay_next=0;
27731  }
27732 
27733   void clean(void)
27734   {
27735     _rfc=0;
27736     null_fetched=0;
27737     cur_col=-1;
27738     cur_in=0;
27739     executed=0;
27740     delay_next=0;
27741   }
27742 
27743  int is_null(void)
27744  {
27745   return null_fetched;
27746  }
27747 
27748  int eof(void)
27749  {
27750   if(delay_next){
27751    look_ahead();
27752    delay_next=0;
27753   }
27754   return !ret_code;
27755  }
27756 
27757  int eof_intern(void)
27758  {
27759   return !ret_code;
27760  }
27761 
27762 
27763  otl_ref_select_stream& operator>>(otl_time0& t)
27764  {
27765   check_if_executed();
27766   if(eof_intern())return *this;
27767   get_next();
27768   if(check_type(otl_var_timestamp)&&!eof_intern()){
27769 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
27770    void* tm=OTL_RCAST(void*,sl[cur_col].val(this->cur_row));
27771    int rc=sl[cur_col].get_var_struct().read_dt(&t,tm,sizeof(otl_time0));
27772    if(rc==0){
27773     if(this->adb)this->adb->increment_throw_count();
27774     if(this->adb&&this->adb->get_throw_count()>1)return *this;
27775     if(otl_uncaught_exception()) return *this;
27776     throw otl_exception(adb->get_connect_struct(),
27777                         stm_label?stm_label:stm_text);
27778    }
27779 #else
27780    otl_time0* tm=OTL_RCAST(otl_time0*,sl[cur_col].val(cur_row));
27781    memcpy(OTL_RCAST(void*,&t),tm,otl_oracle_date_size);
27782 #endif
27783    look_ahead();
27784   }
27785   return *this;
27786  }
27787 
27788  otl_ref_select_stream& operator<<(const otl_time0& t)
27789  {
27790   check_in_var();
27791   if(check_in_type(otl_var_timestamp,otl_oracle_date_size)){
27792 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
27793    void* tm=OTL_RCAST(void*,vl[cur_in]->val());
27794    int rc=vl[cur_in]->get_var_struct().write_dt(tm,&t,sizeof(otl_time0));
27795    if(rc==0){
27796     if(this->adb)this->adb->increment_throw_count();
27797     if(this->adb&&this->adb->get_throw_count()>1)return *this;
27798     if(otl_uncaught_exception()) return *this;
27799     throw otl_exception(adb->get_connect_struct(),
27800                         stm_label?stm_label:stm_text);
27801    }
27802 #else
27803    otl_time0* tm=OTL_RCAST(otl_time0*,vl[cur_in]->val());
27804    memcpy(tm,OTL_RCAST(void*,OTL_CCAST(otl_time0*,&t)),otl_oracle_date_size);
27805 #endif
27806   }
27807   this->vl[cur_in]->set_not_null(0);
27808   get_in_next();
27809   return *this;
27810  }
27811 
27812  otl_ref_select_stream& operator<<(const otl_long_string& s)
27813  {
27814    check_in_var();
27815    if(check_in_type(otl_var_raw,1)){
27816       unsigned char* c=OTL_RCAST(unsigned char*,vl[cur_in]->val());
27817       int len=OTL_CCAST(otl_long_string*,&s)->len();
27818       if(len>this->vl[cur_in]->actual_elem_size()){
27819         otl_var_info_var
27820           (this->vl[cur_in]->get_name(),
27821            this->vl[cur_in]->get_ftype(),
27822            otl_var_raw,
27823            var_info,
27824            sizeof(var_info));
27825         if(this->adb)this->adb->increment_throw_count();
27826         if(this->adb&&this->adb->get_throw_count()>1)return *this;
27827         if(otl_uncaught_exception()) return *this;
27828         throw otl_exception
27829           (otl_error_msg_5,
27830            otl_error_code_5,
27831            this->stm_label?this->stm_label:
27832            this->stm_text,
27833            var_info);
27834       }
27835       this->vl[cur_in]->set_not_null(0);
27836       otl_memcpy
27837         (c+sizeof(unsigned short),
27838          s.v,
27839          len,
27840          this->vl[cur_in]->get_ftype());
27841       *OTL_RCAST(unsigned short*,
27842                  this->vl[cur_in]->val(0))=OTL_SCAST(unsigned short,len);
27843       this->vl[cur_in]->set_len(len,0);
27844    }
27845    get_in_next();
27846    return *this;
27847  }
27848 
27849 
27850 
27851  otl_ref_select_stream& operator>>(char& c)
27852  {
27853   check_if_executed();
27854   if(eof_intern())return *this;
27855   get_next();
27856   if(check_type(otl_var_char)&&!eof_intern()){
27857    c=*OTL_RCAST(char*,sl[cur_col].val(cur_row));
27858    look_ahead();
27859   }
27860   return *this;
27861  }
27862 
27863  otl_ref_select_stream& operator>>(unsigned char& c)
27864  {
27865   check_if_executed();
27866   if(eof_intern())return *this;
27867   get_next();
27868   if(check_type(otl_var_char)&&!eof_intern()){
27869    c=*OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
27870    look_ahead();
27871   }
27872   return *this;
27873  }
27874 
27875 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
27876  otl_ref_select_stream& operator>>(OTL_STRING_CONTAINER& s)
27877  {
27878   check_if_executed();
27879   if(eof_intern())return *this;
27880   get_next();
27881   switch(sl[cur_col].get_ftype()){
27882   case otl_var_char:
27883     if(!eof_intern()){
27884 #if defined(OTL_ACE)
27885       s.set(OTL_RCAST(char*,sl[cur_col].val(cur_row)),1);
27886 #else
27887       s=OTL_RCAST(char*,sl[cur_col].val(cur_row));
27888 #endif
27889       look_ahead();
27890     }
27891     break;
27892 #if defined(USER_DEFINED_STRING_CLASS) || \
27893     defined(OTL_STL) || defined(OTL_ACE)
27894   case otl_var_varchar_long:
27895   case otl_var_raw_long:
27896     if(!eof_intern()){
27897       unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
27898       int len=sl[cur_col].get_len(cur_row);
27899 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_ACE)
27900       s.assign(OTL_RCAST(char*,c),len);
27901 #elif defined(OTL_ACE)
27902       s.set(OTL_RCAST(char*,c),len,1);
27903 #endif
27904       look_ahead();
27905     }
27906     break;
27907   case otl_var_blob:
27908   case otl_var_clob:
27909     if(!eof_intern()){
27910       int len=0;
27911       int max_long_sz=this->adb->get_max_long_size();
27912       otl_auto_array_ptr<unsigned char> loc_ptr(max_long_sz);
27913       unsigned char* temp_buf=loc_ptr.get_ptr();
27914 
27915       int rc=sl[cur_col].get_var_struct().get_blob
27916         (cur_row,
27917          temp_buf,
27918          max_long_sz,
27919          len);
27920       if(rc==0){
27921         if(this->adb)this->adb->increment_throw_count();
27922         if(this->adb&&this->adb->get_throw_count()>1)return *this;
27923         if(otl_uncaught_exception()) return *this;
27924         throw otl_exception(adb->get_connect_struct(),
27925                             stm_label?stm_label:stm_text);
27926       }
27927 #if (defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)) && !defined(OTL_ACE)
27928       s.assign(OTL_RCAST(char*,temp_buf),len);
27929 #elif defined(OTL_ACE)
27930       s.set(OTL_RCAST(char*,temp_buf),len,1);
27931 #endif
27932       look_ahead();
27933     }
27934     break;
27935 #endif
27936   default:
27937     check_type(otl_var_char);
27938   } // switch
27939   return *this;
27940  }
27941 #endif
27942 
27943  otl_ref_select_stream& operator>>(char* s)
27944  {
27945   check_if_executed();
27946   if(eof_intern())return *this;
27947   get_next();
27948   if(check_type(otl_var_char)&&!eof_intern()){
27949    otl_strcpy(OTL_RCAST(unsigned char*,s),
27950               OTL_RCAST(const unsigned char*,sl[cur_col].val(cur_row)));
27951    look_ahead();
27952   }
27953   return *this;
27954  }
27955 
27956 #if defined(OTL_UNICODE_STRING_TYPE)
27957  otl_ref_select_stream& operator>>(OTL_UNICODE_STRING_TYPE& s)
27958  {
27959 
27960     check_if_executed();
27961     if(eof_intern())return *this;
27962     get_next();
27963     switch(sl[cur_col].get_ftype()){
27964     case otl_var_char:
27965       if(!eof_intern()){
27966 
27967 #if defined(OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR)
27968         OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
27969           (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
27970         OTL_UNICODE_STRING_TYPE_CAST_FROM_CHAR(s,temp_s+1,*temp_s);
27971 #else
27972         OTL_UNICODE_CHAR_TYPE* temp_s=OTL_RCAST
27973           (OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
27974         s.assign(temp_s+1,*temp_s);
27975 #endif
27976 
27977         look_ahead();
27978       }
27979       break;
27980     case otl_var_varchar_long:
27981       if(!eof_intern()){
27982         s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,sl[cur_col].val(this->cur_row));
27983         look_ahead();
27984       }
27985       break;
27986     case otl_var_clob:
27987       if(!eof_intern()){
27988         int len=0;
27989         int max_long_sz=this->adb->get_max_long_size();
27990         otl_auto_array_ptr<unsigned short> loc_ptr(max_long_sz);
27991         unsigned char* temp_buf=OTL_RCAST(unsigned char*,loc_ptr.get_ptr());
27992 
27993         int rc=sl[cur_col].get_var_struct().get_blob
27994           (this->cur_row,
27995            temp_buf,
27996            max_long_sz,
27997            len);
27998         if(rc==0){
27999           if(this->adb)this->adb->increment_throw_count();
28000           if(this->adb&&this->adb->get_throw_count()>1)return *this;
28001           if(otl_uncaught_exception()) return *this;
28002           throw otl_exception
28003             (this->adb->get_connect_struct(),
28004              this->stm_label?this->stm_label:
28005              this->stm_text);
28006         }
28007         s=OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,temp_buf);
28008         look_ahead();
28009       }
28010       break;
28011     default:
28012       check_type(otl_var_char);
28013     }
28014     return *this;
28015  }
28016 #endif
28017 
28018  otl_ref_select_stream& operator>>(unsigned char* s)
28019  {
28020   check_if_executed();
28021   if(eof_intern())return *this;
28022   get_next();
28023   if(check_type(otl_var_char)&&!eof_intern()){
28024    otl_strcpy2(OTL_RCAST(unsigned char*,s),
28025                OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row)),
28026                sl[cur_col].get_len(cur_row)
28027              );
28028    look_ahead();
28029   }
28030   return *this;
28031  }
28032 
28033 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
28034 #define OTL_D7(T,T_type)                                \
28035   otl_ref_select_stream& operator>>(T& n)               \
28036   {                                                     \
28037     check_if_executed();                                \
28038     if(eof_intern())return *this;                       \
28039     get_next();                                         \
28040     if(!eof_intern()){                                  \
28041       int match_found=otl_numeric_convert_T<T,T_type>   \
28042         (sl[cur_col].get_ftype(),                       \
28043          sl[cur_col].val(cur_row),                      \
28044          n);                                            \
28045       if(!match_found)                                  \
28046         strict_check_throw(T_type);                     \
28047       look_ahead();                                     \
28048     }                                                   \
28049     return *this;                                       \
28050   }
28051 #else
28052 #define OTL_D7(T,T_type)                                        \
28053   otl_ref_select_stream& operator>>(T& n)                       \
28054   {                                                             \
28055     check_if_executed();                                        \
28056     if(eof_intern())return *this;                               \
28057     get_next();                                                 \
28058     if(!eof_intern()){                                          \
28059       int match_found=otl_numeric_convert_T                     \
28060         (sl[cur_col].get_ftype(),                               \
28061          sl[cur_col].val(cur_row),                              \
28062          n);                                                    \
28063       if(!match_found){                                         \
28064         if(check_type(otl_var_double,T_type))                   \
28065           n=OTL_PCONV(T,double,sl[cur_col].val(cur_row));       \
28066       }                                                         \
28067       look_ahead();                                             \
28068     }                                                           \
28069     return *this;                                               \
28070   }
28071 #endif
28072 
28073 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
28074   OTL_D7(int,otl_var_int)
28075   OTL_D7(unsigned,otl_var_unsigned_int)
28076   OTL_D7(long,otl_var_long_int)
28077   OTL_D7(short,otl_var_short)
28078   OTL_D7(float,otl_var_float)
28079   OTL_D7(double,otl_var_double)
28080 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
28081     !defined(OTL_BIGINT_TO_STR))
28082   OTL_D7(OTL_BIGINT,otl_var_bigint)
28083 #endif
28084 #else
28085   template<OTL_TYPE_NAME T,const int T_type> OTL_D7(T,T_type)
28086 #endif
28087 
28088  otl_ref_select_stream& operator>>(otl_long_string& s)
28089  {
28090   check_if_executed();
28091   if(eof_intern())return *this;
28092   get_next();
28093   switch(sl[cur_col].get_ftype()){
28094   case otl_var_varchar_long:
28095   case otl_var_raw_long:
28096     {
28097       if(!eof_intern()){
28098         unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
28099         int len=sl[cur_col].get_len(cur_row);
28100         if(len>s.get_buf_size())
28101           len=s.get_buf_size();
28102         otl_memcpy(s.v,c,len,sl[cur_col].get_ftype());
28103         s.v[len]=0;
28104         s.set_len(len);
28105         look_ahead();
28106       }
28107     }
28108     break;
28109   case otl_var_raw:
28110     {
28111       if(!eof_intern()){
28112         unsigned char* c=OTL_RCAST(unsigned char*,sl[cur_col].val(cur_row));
28113         int len=OTL_SCAST(int,*OTL_RCAST(unsigned short*,c));
28114         if(len>s.get_buf_size())
28115           len=s.get_buf_size();
28116         otl_memcpy(s.v,c+sizeof(short int),len,sl[cur_col].get_ftype());
28117         s.set_len(len);
28118         look_ahead();
28119       }
28120     }
28121     break;
28122   case otl_var_blob:
28123   case otl_var_clob:
28124     {
28125       if(!eof_intern()){
28126         int len;
28127         int rc=sl[cur_col].get_var_struct().get_blob
28128           (cur_row,s.v,s.get_buf_size(),len);
28129         if(rc==0){
28130           if(this->adb)this->adb->increment_throw_count();
28131           if(this->adb&&this->adb->get_throw_count()>1)return *this;
28132           if(otl_uncaught_exception()) return *this;
28133           throw otl_exception(adb->get_connect_struct(),
28134                               stm_label?stm_label:stm_text);
28135         }
28136         s.set_len(len);
28137         if(sl[cur_col].get_ftype()==otl_var_clob)
28138           s.null_terminate_string(len);
28139         look_ahead();
28140       }
28141     }
28142     break;
28143   }
28144   return *this;
28145  }
28146 
28147  otl_ref_select_stream& operator>>(otl_lob_stream& s)
28148  {
28149   check_if_executed();
28150   if(eof_intern())return *this;
28151   get_next();
28152   if((sl[cur_col].get_ftype()==otl_var_blob||
28153       sl[cur_col].get_ftype()==otl_var_clob)&&
28154      !eof_intern()){
28155    s.init
28156     (&sl[cur_col],
28157      adb,
28158      OTL_RCAST(otl_ref_cursor*,this),
28159      cur_row,
28160      otl_lob_stream_read_mode,
28161      this->is_null());
28162    delay_next=1;
28163   }
28164   return *this;
28165  }
28166 
28167   otl_ref_select_stream& operator<<(const otl_null& /*n*/)
28168   {
28169     check_in_var();
28170     this->vl[cur_in]->set_null(0);
28171     get_in_next();
28172     return *this;
28173   }
28174 
28175  otl_ref_select_stream& operator<<(const char c)
28176  {
28177   check_in_var();
28178   if(check_in_type(otl_var_char,1)){
28179    char* tmp=OTL_RCAST(char*,vl[cur_in]->val());
28180    tmp[0]=c;
28181    tmp[1]=0;
28182   }
28183   this->vl[cur_in]->set_not_null(0);
28184   get_in_next();
28185   return *this;
28186  }
28187 
28188  otl_ref_select_stream& operator<<(const unsigned char c)
28189  {
28190   check_in_var();
28191   if(check_in_type(otl_var_char,1)){
28192    unsigned char* tmp=OTL_RCAST(unsigned char*,vl[cur_in]->val());
28193    tmp[0]=c;
28194    tmp[1]=0;
28195   }
28196   this->vl[cur_in]->set_not_null(0);
28197   get_in_next();
28198   return *this;
28199  }
28200 
28201 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
28202  otl_ref_select_stream& operator<<(const OTL_STRING_CONTAINER& s)
28203  {
28204   check_in_var();
28205   if(check_in_type(otl_var_char,1)){
28206 
28207    int overflow;
28208    otl_strcpy
28209     (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
28210      OTL_RCAST(unsigned char*,OTL_CCAST(char*,s.c_str())),
28211      overflow,
28212      vl[cur_in]->get_elem_size(),
28213      OTL_SCAST(int,s.length())
28214     );
28215    if(overflow){
28216     char temp_var_info[256];
28217     otl_var_info_var
28218       (vl[cur_in]->get_name(),
28219        vl[cur_in]->get_ftype(),
28220        otl_var_char,
28221        temp_var_info,
28222        sizeof(temp_var_info));
28223     if(this->adb)this->adb->increment_throw_count();
28224     if(this->adb&&this->adb->get_throw_count()>1)return *this;
28225     if(otl_uncaught_exception()) return *this;
28226     throw otl_exception
28227      (otl_error_msg_4,
28228       otl_error_code_4,
28229       stm_label?stm_label:stm_text,
28230       temp_var_info);
28231    }
28232 
28233   }
28234   this->vl[cur_in]->set_not_null(0);
28235   get_in_next();
28236   return *this;
28237  }
28238 #endif
28239 
28240 #if defined(OTL_UNICODE_STRING_TYPE)
28241   otl_ref_select_stream& operator<<(const OTL_UNICODE_STRING_TYPE& s)
28242   {
28243     check_in_var();
28244     if(check_in_type(otl_var_char,1)){
28245 
28246       int overflow;
28247       otl_strcpy4
28248         (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
28249          OTL_RCAST(unsigned char*,
28250                    OTL_CCAST(OTL_UNICODE_CHAR_TYPE*,s.c_str())),
28251          overflow,
28252          vl[cur_in]->get_elem_size(),
28253          OTL_SCAST(int,s.length())
28254          );
28255       if(overflow){
28256         char temp_var_info[256];
28257         otl_var_info_var
28258           (vl[cur_in]->get_name(),
28259            vl[cur_in]->get_ftype(),
28260            otl_var_char,
28261            temp_var_info,
28262            sizeof(temp_var_info));
28263         if(this->adb)this->adb->increment_throw_count();
28264         if(this->adb&&this->adb->get_throw_count())return *this;
28265         if(otl_uncaught_exception()) return *this;
28266         throw otl_exception
28267           (otl_error_msg_4,
28268            otl_error_code_4,
28269            stm_label?stm_label:stm_text,
28270            temp_var_info);
28271       }
28272     }
28273     this->vl[cur_in]->set_not_null(0);
28274     get_in_next();
28275     return *this;
28276   }
28277 #endif
28278 
28279  otl_ref_select_stream& operator<<(const char* s)
28280  {
28281   check_in_var();
28282   if(check_in_type(otl_var_char,1)){
28283 
28284    int overflow;
28285    otl_strcpy
28286     (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
28287      OTL_RCAST(unsigned char*,OTL_CCAST(char*,s)),
28288      overflow,
28289      vl[cur_in]->get_elem_size()
28290     );
28291    if(overflow){
28292     char temp_var_info[256];
28293     otl_var_info_var
28294       (vl[cur_in]->get_name(),
28295        vl[cur_in]->get_ftype(),
28296        otl_var_char,
28297        temp_var_info,
28298        sizeof(temp_var_info));
28299     if(this->adb)this->adb->increment_throw_count();
28300     if(this->adb&&this->adb->get_throw_count()>1)return *this;
28301     if(otl_uncaught_exception()) return *this;
28302     throw otl_exception
28303      (otl_error_msg_4,
28304       otl_error_code_4,
28305       stm_label?stm_label:stm_text,
28306       temp_var_info);
28307    }
28308 
28309   }
28310   this->vl[cur_in]->set_not_null(0);
28311   get_in_next();
28312   return *this;
28313  }
28314 
28315  otl_ref_select_stream& operator<<(const unsigned char* s)
28316  {
28317   check_in_var();
28318   if(check_in_type(otl_var_char,1)){
28319 
28320    int overflow;
28321    otl_strcpy4
28322     (OTL_RCAST(unsigned char*,vl[cur_in]->val()),
28323      OTL_CCAST(unsigned char*,s),
28324      overflow,
28325      vl[cur_in]->get_elem_size()
28326     );
28327    if(overflow){
28328     char temp_var_info[256];
28329     otl_var_info_var
28330       (vl[cur_in]->get_name(),
28331        vl[cur_in]->get_ftype(),
28332        otl_var_char,
28333        temp_var_info,
28334        sizeof(temp_var_info));
28335     if(this->adb)this->adb->increment_throw_count();
28336     if(this->adb&&this->adb->get_throw_count()>1)return *this;
28337     if(otl_uncaught_exception()) return *this;
28338     throw otl_exception
28339       (otl_error_msg_4,
28340        otl_error_code_4,
28341        stm_label?stm_label:stm_text,
28342        temp_var_info);
28343    }
28344 
28345   }
28346   this->vl[cur_in]->set_not_null(0);
28347   get_in_next();
28348   return *this;
28349  }
28350 
28351 #define OTL_D8(T,T_type)                        \
28352   otl_ref_select_stream& operator<<(const T n)  \
28353   {                                             \
28354     check_in_var();                             \
28355     if(check_in_type(T_type,sizeof(T))){        \
28356       *OTL_RCAST(T*,vl[cur_in]->val())=n;       \
28357     }                                           \
28358     this->vl[cur_in]->set_not_null(0);          \
28359     get_in_next();                              \
28360     return *this;                               \
28361   }
28362 
28363 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
28364   OTL_D8(int,otl_var_int)
28365   OTL_D8(unsigned,otl_var_unsigned_int)
28366   OTL_D8(long,otl_var_long_int)
28367   OTL_D8(short,otl_var_short)
28368   OTL_D8(float,otl_var_float)
28369   OTL_D8(double,otl_var_double)
28370 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
28371     !defined(OTL_BIGINT_TO_STR))
28372   OTL_D8(OTL_BIGINT,otl_var_bigint)
28373 #endif
28374 #else
28375   template<OTL_TYPE_NAME T,const int T_type> OTL_D8(T,T_type)
28376 #endif
28377 
28378  int select_list_len(void) const
28379  {
28380   return sl_len;
28381  }
28382 
28383  int column_ftype(int ndx=0) const
28384  {
28385    return sl[ndx].get_ftype();
28386  }
28387 
28388  int column_size(int ndx=0) const
28389  {
28390    return sl[ndx].get_elem_size();
28391  }
28392 
28393   int get_sl_len() const {return sl_len; }
28394   otl_generic_variable* get_sl() const {return sl;}
28395   otl_column_desc* get_sl_desc() const {return sl_desc;}
28396 
28397 protected:
28398 
28399  otl_column_desc* sl_desc;
28400  int sl_len;
28401  otl_generic_variable* sl;
28402 
28403  int null_fetched;
28404  int ret_code;
28405  int cur_col;
28406  int cur_in;
28407  int executed;
28408  char var_info[256];
28409 
28410  void init(void)
28411  {
28412   same_sl_flag=0;
28413   sl=0;
28414   sl_len=0;
28415   null_fetched=0;
28416   ret_code=0;
28417   sl_desc=0;
28418   executed=0;
28419   cur_in=0;
28420   stm_text=0;
28421  }
28422 
28423  void get_next(void)
28424  {
28425   if(cur_col<sl_len-1){
28426    ++cur_col;
28427    null_fetched=sl[cur_col].is_null(cur_row);
28428   }else{
28429    ret_code=next();
28430    cur_col=0;
28431   }
28432  }
28433 
28434   int check_type_throw(int type_code, int actual_data_type)
28435   {
28436     int out_type_code;
28437     if(actual_data_type!=0)
28438       out_type_code=actual_data_type;
28439     else
28440       out_type_code=type_code;
28441     otl_var_info_col
28442       (sl[cur_col].get_pos(),
28443        sl[cur_col].get_ftype(),
28444        out_type_code,
28445        var_info,
28446        sizeof(var_info));
28447     if(this->adb)this->adb->increment_throw_count();
28448     if(this->adb&&this->adb->get_throw_count()>1)return 0;
28449   if(otl_uncaught_exception()) return 0;
28450 
28451     throw otl_exception
28452       (otl_error_msg_0,
28453        otl_error_code_0,
28454        stm_label?stm_label:stm_text,
28455        var_info);
28456   }
28457 
28458   int check_type(int type_code, int actual_data_type=0)
28459   {
28460     switch(sl[cur_col].get_ftype()){
28461     case otl_var_timestamp:
28462     case otl_var_tz_timestamp:
28463     case otl_var_ltz_timestamp:
28464       if(type_code==otl_var_timestamp)
28465         return 1;
28466     default:
28467       if(sl[cur_col].get_ftype()==type_code)
28468         return 1;
28469     }
28470     return check_type_throw(type_code,actual_data_type);
28471   }
28472 
28473  void look_ahead(void)
28474  {
28475   if(cur_col==sl_len-1){
28476    ret_code=next();
28477    cur_col=-1;
28478    ++_rfc;
28479   }
28480  }
28481 
28482  void get_select_list(void)
28483  {int i,j,rc;
28484 
28485   otl_auto_array_ptr<otl_column_desc> loc_ptr(otl_var_list_size);
28486   otl_column_desc* sl_desc_tmp=loc_ptr.get_ptr();
28487   int sld_tmp_len=0;
28488   int ftype,elem_size;
28489   OCIBind* bindpp;
28490 
28491   if(!sel_cur.get_connected()){
28492    sel_cur.open(*adb);
28493    rc=OCIBindByName
28494     (cursor_struct.cda,
28495      &bindpp,
28496      cursor_struct.errhp,
28497      OTL_RCAST(text*,cur_placeholder),
28498      OTL_SCAST(sb4,strlen(cur_placeholder)),
28499      OTL_RCAST(dvoid*,&sel_cur.get_cursor_struct().cda),
28500      0,
28501      SQLT_RSET,
28502      0,
28503      0,
28504      0,
28505      0,
28506      0,
28507      OTL_SCAST(ub4,OCI_DEFAULT));
28508    if(rc!=0){
28509     if(this->adb)this->adb->increment_throw_count();
28510     if(this->adb&&this->adb->get_throw_count()>1)return;
28511    if(otl_uncaught_exception()) return;
28512    throw otl_exception(cursor_struct,
28513                        stm_label?stm_label:stm_text);
28514    }
28515   }
28516 
28517   for(i=0;i<vl_len;++i)
28518    otl_tmpl_cursor
28519     <otl_exc,
28520     otl_conn,
28521     otl_cur,
28522     otl_var>::bind(*vl[i]);
28523 // Executing the PLSQL master block
28524   otl_tmpl_cursor
28525   <otl_exc,
28526    otl_conn,
28527    otl_cur,
28528      otl_var>::exec(1,0,otl_sql_exec_from_select_cursor_class);
28529   sel_cur.set_connected(1);
28530   cur_row=-2;
28531   if(same_sl_flag && sl){
28532    // assuming that ref.cur's select list is the same as
28533    // in previous executions of the master block.
28534    for(i=0;i<sl_len;++i)sel_cur.bind(sl[i]);
28535    return;
28536   }else{
28537    sld_tmp_len=0;
28538    sel_cur.get_cursor_struct().straight_select=0;
28539    for(i=1;sel_cur.describe_column(sl_desc_tmp[i-1],i);++i){
28540     ++sld_tmp_len;
28541     if(sld_tmp_len==loc_ptr.get_arr_size()){
28542       loc_ptr.double_size();
28543       sl_desc_tmp=loc_ptr.get_ptr();
28544     }
28545    }
28546    sl_len=sld_tmp_len;
28547    if(sl){
28548     delete[] sl;
28549     sl=0;
28550    }
28551    sl=new otl_generic_variable[sl_len==0?1:sl_len];
28552    int max_long_size=this->adb->get_max_long_size();
28553    for(j=0;j<sl_len;++j){
28554     otl_generic_variable::map_ftype
28555      (sl_desc_tmp[j],
28556       max_long_size,
28557       ftype,
28558       elem_size,
28559       this->local_override.getLen()>0?this->local_override:*override,
28560       j+1,
28561       this->adb->get_connect_struct().get_connection_type());
28562     sl[j].copy_pos(j+1);
28563 #if defined(OTL_ORA_UNICODE)||defined(OTL_ORA_UTF8)
28564      if(sl_desc_tmp[j].charset_form==2)
28565        sl[j].get_var_struct().nls_flag=true;
28566 #endif
28567      sl[j].init(true,
28568                 ftype,
28569                 elem_size,
28570                 OTL_SCAST(otl_stream_buffer_size_type,array_size),
28571                 &adb->get_connect_struct()
28572                );
28573    }
28574    if(sl_desc){
28575     delete[] sl_desc;
28576     sl_desc=0;
28577    }
28578    sl_desc=new otl_column_desc[sl_len==0?1:sl_len];
28579    for(i=0;i<sl_len;++i)
28580      sl_desc[i]=sl_desc_tmp[i];
28581    for(i=0;i<sl_len;++i)sel_cur.bind(sl[i]);
28582   }
28583  }
28584 
28585  void get_in_next(void)
28586  {
28587   if(cur_in==vl_len-1)
28588    rewind();
28589   else{
28590    ++cur_in;
28591    executed=0;
28592   }
28593  }
28594 
28595   int check_in_type_throw(int type_code)
28596   {
28597     otl_var_info_var
28598       (vl[cur_in]->get_name(),
28599        vl[cur_in]->get_ftype(),
28600        type_code,
28601        var_info,
28602        sizeof(var_info));
28603     if(this->adb)this->adb->increment_throw_count();
28604     if(this->adb&&this->adb->get_throw_count()>1)return 0;
28605     if(otl_uncaught_exception()) return 0;
28606 
28607     throw otl_exception
28608       (otl_error_msg_0,
28609        otl_error_code_0,
28610        stm_label?stm_label:stm_text,
28611        var_info);
28612   }
28613 
28614   int check_in_type(int type_code,int tsize)
28615   {
28616     switch(vl[cur_in]->get_ftype()){
28617     case otl_var_char:
28618       if(type_code==otl_var_char)
28619         return 1;
28620     case otl_var_raw:
28621       if(type_code==otl_var_raw)
28622         return 1;
28623     case otl_var_timestamp:
28624     case otl_var_tz_timestamp:
28625     case otl_var_ltz_timestamp:
28626       if(type_code==otl_var_timestamp)
28627         return 1;
28628     default:
28629       if(vl[cur_in]->get_ftype()==type_code &&
28630          vl[cur_in]->get_elem_size()==tsize)
28631         return 1;
28632     }
28633     return check_in_type_throw(type_code);
28634   }
28635 
28636  void check_in_var(void)
28637  {
28638   if(vl_len==0){
28639    if(this->adb)this->adb->increment_throw_count();
28640    if(this->adb&&this->adb->get_throw_count()>1)return;
28641    if(otl_uncaught_exception()) return;
28642    throw otl_exception
28643     (otl_error_msg_1,
28644      otl_error_code_1,
28645      stm_label?stm_label:stm_text,
28646      0);
28647   }
28648  }
28649 
28650  void check_if_executed(void)
28651  {
28652   if(!executed){
28653    if(this->adb)this->adb->increment_throw_count();
28654    if(this->adb&&this->adb->get_throw_count()>1)return;
28655    if(otl_uncaught_exception()) return;
28656    throw otl_exception
28657     (otl_error_msg_2,
28658      otl_error_code_2,
28659      stm_label?stm_label:stm_text,
28660      0);
28661   }
28662  }
28663 
28664 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
28665   void strict_check_throw(int type_code)
28666   {
28667    otl_var_info_col
28668      (sl[cur_col].get_pos(),
28669       sl[cur_col].get_ftype(),
28670       type_code,
28671       var_info,
28672       sizeof(var_info));
28673    if(this->adb)this->adb->increment_throw_count();
28674    if(this->adb&&this->adb->get_throw_count()>1)return;
28675    if(otl_uncaught_exception()) return;
28676    throw otl_exception
28677      (otl_error_msg_0,
28678       otl_error_code_0,
28679       this->stm_label?
28680       this->stm_label:
28681       this->stm_text,
28682       var_info);
28683   }
28684 #endif
28685 
28686 private:
28687 
28688  otl_ref_select_stream
28689  (const otl_ref_select_stream&)
28690    :otl_ref_cursor(),
28691     override(0),
28692     delay_next(0),
28693     same_sl_flag(0),
28694     _rfc(0),
28695     sl_desc(0),
28696     sl_len(0),
28697     sl(0),
28698     null_fetched(0),
28699     ret_code(0),
28700     cur_col(0),
28701     cur_in(0),
28702     executed(0),
28703     var_info()
28704  {
28705  }
28706 
28707  otl_ref_select_stream& operator=(const otl_ref_select_stream&)
28708  {
28709    return *this;
28710  }
28711 
28712 };
28713 
28714 class otl_stream_shell: public otl_stream_shell_generic{
28715 public:
28716 
28717   otl_ref_select_stream* ref_ss;
28718   otl_select_stream* ss;
28719   otl_inout_stream* io;
28720   otl_connect* adb;
28721 
28722   int auto_commit_flag;
28723   bool lob_stream_flag;
28724 
28725   otl_var_desc* iov;
28726   int iov_len;
28727   int next_iov_ndx;
28728 
28729   otl_var_desc* ov;
28730   int ov_len;
28731   int next_ov_ndx;
28732 
28733   bool flush_flag;
28734   int stream_type;
28735 
28736  otl_select_struct_override override;
28737 
28738 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
28739  OTL_STRING_CONTAINER orig_sql_stm;
28740 #endif
28741 
28742   otl_stream_shell():
28743     otl_stream_shell_generic(),
28744     ref_ss(0),
28745     ss(0),
28746     io(0),
28747     adb(0),
28748     auto_commit_flag(0),
28749     lob_stream_flag(false),
28750     iov(0),
28751     iov_len(0),
28752     next_iov_ndx(0),
28753     ov(0),
28754     ov_len(0),
28755     next_ov_ndx(0),
28756     flush_flag(false),
28757     stream_type(otl_no_stream_type),
28758     override()
28759 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
28760     ,orig_sql_stm()
28761 #endif
28762  {
28763    should_delete=0;
28764  }
28765 
28766   otl_stream_shell(const int ashould_delete):
28767     otl_stream_shell_generic(),
28768     ref_ss(0),
28769     ss(0),
28770     io(0),
28771     adb(0),
28772     auto_commit_flag(0),
28773     lob_stream_flag(false),
28774     iov(0),
28775     iov_len(0),
28776     next_iov_ndx(0),
28777     ov(0),
28778     ov_len(0),
28779     next_ov_ndx(0),
28780     flush_flag(true),
28781     stream_type(otl_no_stream_type),
28782     override()
28783 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
28784     ,orig_sql_stm()
28785 #endif
28786  {
28787   should_delete=ashould_delete;
28788  }
28789 
28790  virtual ~otl_stream_shell()
28791  {
28792   if(should_delete){
28793    delete[] iov;
28794    delete[] ov;
28795 
28796    iov=0; iov_len=0;
28797    ov=0; ov_len=0;
28798    next_iov_ndx=0;
28799    next_ov_ndx=0;
28800    override.setLen(0);
28801    flush_flag=true;
28802 
28803    delete ss;
28804    delete io;
28805    delete ref_ss;
28806    ss=0; io=0; ref_ss=0;
28807    adb=0;
28808   }
28809  }
28810 
28811 private:
28812 
28813   otl_stream_shell(const otl_stream_shell&):
28814     otl_stream_shell_generic(),
28815     ref_ss(0),
28816     ss(0),
28817     io(0),
28818     adb(0),
28819     auto_commit_flag(0),
28820     lob_stream_flag(false),
28821     iov(0),
28822     iov_len(0),
28823     next_iov_ndx(0),
28824     ov(0),
28825     ov_len(0),
28826     next_ov_ndx(0),
28827     flush_flag(false),
28828     stream_type(otl_no_stream_type),
28829     override()
28830 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
28831     ,orig_sql_stm()
28832 #endif
28833  {
28834  }
28835 
28836  otl_stream_shell& operator=(const otl_stream_shell&)
28837  {
28838    return *this;
28839  }
28840 
28841 };
28842 
28843 class otl_sp_parm_desc{
28844 public:
28845 
28846  int position;
28847  char arg_name[40];
28848  char in_out[20];
28849  char data_type[40];
28850  char bind_var[128];
28851 
28852   otl_sp_parm_desc():
28853     position(-1),
28854     arg_name(),
28855     in_out(),
28856     data_type(),
28857     bind_var()
28858  {
28859   arg_name[0]=0;
28860   in_out[0]=0;
28861   data_type[0]=0;
28862   bind_var[0]=0;
28863  }
28864 
28865  otl_sp_parm_desc(const otl_sp_parm_desc& r):
28866     position(-1),
28867     arg_name(),
28868     in_out(),
28869     data_type(),
28870     bind_var()
28871  {
28872   copy(r);
28873  }
28874 
28875  otl_sp_parm_desc& operator=(const otl_sp_parm_desc& r)
28876  {
28877   copy(r);
28878   return *this;
28879  }
28880 
28881  ~otl_sp_parm_desc(){}
28882 
28883 protected:
28884 
28885  void copy(const otl_sp_parm_desc& r)
28886  {
28887   position=r.position;
28888   OTL_STRCPY_S(arg_name,sizeof(arg_name),r.arg_name);
28889   OTL_STRCPY_S(in_out,sizeof(in_out),r.in_out);
28890   OTL_STRCPY_S(data_type,sizeof(data_type),r.data_type);
28891   OTL_STRCPY_S(bind_var,sizeof(bind_var),r.bind_var);
28892  }
28893 
28894 };
28895 
28896 class otl_stream
28897 #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
28898   : public otl_read_stream_interface
28899 #endif
28900 {
28901 protected:
28902 
28903   otl_stream_shell* shell;
28904   otl_ptr<otl_stream_shell> shell_pt;
28905   int connected;
28906 
28907   otl_ref_select_stream** ref_ss;
28908   otl_select_stream** ss;
28909   otl_inout_stream** io;
28910   otl_connect** adb;
28911 
28912   int* auto_commit_flag;
28913 
28914   otl_var_desc** iov;
28915   int* iov_len;
28916   int* next_iov_ndx;
28917 
28918   otl_var_desc** ov;
28919   int* ov_len;
28920   int* next_ov_ndx;
28921   int end_marker;
28922   int oper_int_called;
28923   int last_eof_rc;
28924   bool last_oper_was_read_op;
28925 
28926   otl_select_struct_override* override;
28927 
28928   int buf_size_;
28929 
28930   void reset_end_marker(void)
28931   {
28932     last_eof_rc=0;
28933     end_marker=-1;
28934     oper_int_called=0;
28935   }
28936 
28937  static void convert_bind_var_datatype
28938  (char* out_buf,
28939 #if defined(_MSC_VER)
28940 #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
28941   const size_t out_buf_sz,
28942 #else
28943   const size_t /*out_buf_sz*/,
28944 #endif
28945 #else
28946   const size_t /*out_buf_sz*/,
28947 #endif
28948   const char* datatype,
28949   const int varchar_size,
28950   const int all_num2type,
28951   const int refcur_buf_size)
28952  {
28953   out_buf[0]=0;
28954   if(strcmp(datatype,"BINARY_INTEGER")==0||
28955      strcmp(datatype,"NATIVE INTEGER")==0||
28956      strcmp(datatype,"FLOAT")==0||
28957      strcmp(datatype,"NUMBER")==0){
28958    switch(all_num2type){
28959    case otl_var_char:
28960     OTL_STRCPY_S(out_buf,out_buf_sz,"char[50]");
28961     break;
28962    case otl_var_double:
28963     OTL_STRCPY_S(out_buf,out_buf_sz,"double");
28964     break;
28965    case otl_var_float:
28966     OTL_STRCPY_S(out_buf,out_buf_sz,"float");
28967     break;
28968    case otl_var_long_int:
28969     OTL_STRCPY_S(out_buf,out_buf_sz,"long");
28970     break;
28971    case otl_var_int:
28972     OTL_STRCPY_S(out_buf,out_buf_sz,"int");
28973     break;
28974    case otl_var_unsigned_int:
28975     OTL_STRCPY_S(out_buf,out_buf_sz,"unsigned");
28976     break;
28977    case otl_var_short:
28978     OTL_STRCPY_S(out_buf,out_buf_sz,"short");
28979     break;
28980    default:
28981     break;
28982    }
28983   }else if(strcmp(datatype,"DATE")==0)
28984    OTL_STRCPY_S(out_buf,out_buf_sz,"timestamp");
28985 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
28986 else if(strcmp(datatype,"TIMESTAMP")==0)
28987    OTL_STRCPY_S(out_buf,out_buf_sz,"timestamp");
28988 #endif
28989   else if(strcmp(datatype,"VARCHAR2")==0)
28990 #if defined(_MSC_VER)
28991 #if (_MSC_VER >= 1400)
28992    sprintf_s(out_buf,out_buf_sz,"char[%d]",varchar_size);
28993 #else
28994    sprintf(out_buf,"char[%d]",varchar_size);
28995 #endif
28996 #else
28997    sprintf(out_buf,"char[%d]",varchar_size);
28998 #endif
28999   else if(strcmp(datatype,"CHAR")==0)
29000 #if defined(_MSC_VER)
29001 #if (_MSC_VER >= 1400)
29002    sprintf_s(out_buf,out_buf_sz,"char[%d]",varchar_size);
29003 #else
29004    sprintf(out_buf,"char[%d]",varchar_size);
29005 #endif
29006 #else
29007    sprintf(out_buf,"char[%d]",varchar_size);
29008 #endif
29009    else if(strcmp(datatype,"REF CURSOR")==0)
29010 #if defined(_MSC_VER)
29011 #if (_MSC_VER >= 1400)
29012    sprintf_s(out_buf,out_buf_sz,"refcur,out[%d]",refcur_buf_size);
29013 #else
29014    sprintf(out_buf,"refcur,out[%d]",refcur_buf_size);
29015 #endif
29016 #else
29017    sprintf(out_buf,"refcur,out[%d]",refcur_buf_size);
29018 #endif
29019 
29020  }
29021 
29022   void throw_end_of_row()
29023 #if defined(__GNUC__) && (__GNUC__>=4)
29024     __attribute__ ((noreturn))
29025 #endif
29026   {
29027     throw otl_exception
29028       (otl_error_msg_34,
29029        otl_error_code_34,
29030        this->get_stm_text());
29031   }
29032 
29033 public:
29034 
29035   bool get_lob_stream_flag() const
29036   {
29037     if(!shell)
29038       return false;
29039     else
29040       return shell->lob_stream_flag;
29041   }
29042 
29043   int get_adb_max_long_size() const
29044   {
29045     return this->shell->adb->get_max_long_size();
29046   }
29047 
29048 
29049   void check_end_of_row()
29050   {
29051     if(next_ov_ndx==0||(*next_ov_ndx)!=0)
29052       throw_end_of_row();
29053     if(next_iov_ndx==0||(*next_iov_ndx)!=0)
29054       throw_end_of_row();
29055   }
29056 
29057   int get_dirty_buf_len() const
29058   {
29059     switch(shell->stream_type){
29060     case otl_no_stream_type:
29061       return 0;
29062     case otl_inout_stream_type:
29063       return (*io)->get_dirty_buf_len();
29064     case otl_select_stream_type:
29065       return (*ss)->get_select_row_count();
29066     case otl_refcur_stream_type:
29067       return (*ref_ss)->get_select_row_count();
29068     default:
29069       return 0;
29070     }
29071   }
29072 
29073   otl_stream_shell* get_shell(){return shell;}
29074 
29075   int get_connected() const {return connected;}
29076 
29077 
29078   void setBufSize(int buf_size)
29079   {
29080     buf_size_=buf_size;
29081   }
29082 
29083   int getBufSize(void) const
29084   {
29085     return buf_size_;
29086   }
29087 
29088   operator int(void) OTL_THROWS_OTL_EXCEPTION
29089   {
29090     if(shell && shell->lob_stream_flag){
29091       if(this->adb&&*this->adb)(*this->adb)->increment_throw_count();
29092       if(this->adb&&*this->adb&&(*this->adb)->get_throw_count()>1)return 0;
29093       const char* stm_label=0;
29094       const char* stm_text=0;
29095       switch(shell->stream_type){
29096       case otl_no_stream_type:
29097         break;
29098       case otl_inout_stream_type:
29099         stm_label=(*io)->get_stm_label();
29100         stm_text=(*io)->get_stm_text();
29101         break;
29102       case otl_select_stream_type:
29103         stm_label=(*ss)->get_stm_label();
29104         stm_text=(*ss)->get_stm_text();
29105         break;
29106       case otl_refcur_stream_type:
29107         stm_label=(*ref_ss)->get_stm_label();
29108         stm_text=(*ref_ss)->get_stm_text();
29109         break;
29110       }
29111       throw otl_exception
29112         (otl_error_msg_24,
29113          otl_error_code_24,
29114          stm_label?stm_label:stm_text);
29115     }
29116     if(!last_oper_was_read_op){
29117       if(this->adb&&*this->adb)(*this->adb)->increment_throw_count();
29118       if(this->adb&&*this->adb&&(*this->adb)->get_throw_count()>1)return 0;
29119       const char* stm_label=0;
29120       const char* stm_text=0;
29121       switch(shell->stream_type){
29122       case otl_no_stream_type:
29123         break;
29124       case otl_inout_stream_type:
29125         stm_label=(*io)->get_stm_label();
29126         stm_text=(*io)->get_stm_text();
29127         break;
29128       case otl_select_stream_type:
29129         stm_label=(*ss)->get_stm_label();
29130         stm_text=(*ss)->get_stm_text();
29131         break;
29132       case otl_refcur_stream_type:
29133         stm_label=(*ref_ss)->get_stm_label();
29134         stm_text=(*ref_ss)->get_stm_text();
29135         break;
29136       }
29137       throw otl_exception
29138         (otl_error_msg_18,
29139          otl_error_code_18,
29140          stm_label?stm_label:stm_text);
29141     }
29142     if(end_marker==1)return 0;
29143     int rc=0;
29144     int temp_eof=eof();
29145     if(temp_eof && end_marker==-1 && oper_int_called==0){
29146       end_marker=1;
29147       if(last_eof_rc==1)
29148         rc=0;
29149       else
29150         rc=1;
29151     }else if(!temp_eof && end_marker==-1)
29152       rc=1;
29153     else if(temp_eof && end_marker==-1){
29154       end_marker=0;
29155       rc=1;
29156     }else if(temp_eof && end_marker==0){
29157       end_marker=1;
29158       rc=0;
29159     }
29160     if(!oper_int_called)oper_int_called=1;
29161     return rc;
29162   }
29163 
29164 #if !defined(OTL_UNICODE)
29165  static void create_stored_proc_call
29166  (otl_connect& db,
29167   otl_stream& args_strm,
29168   char* sql_stm,
29169   int& stm_type,
29170   char* refcur_placeholder,
29171   const char* proc_name,
29172   const char* package_name,
29173   const char* schema_name=0,
29174   const bool schema_name_included=false,
29175   const int varchar_size=2001,
29176   const int all_num2type=otl_var_double,
29177   const int refcur_buf_size=1)
29178  {
29179   sql_stm[0]=0;
29180   stm_type=otl_no_stream_type;
29181   refcur_placeholder[0]=0;
29182 
29183   char full_name[1024];
29184   char temp_buf[1024];
29185   char temp_buf2[1024];
29186   int i;
29187 
29188   if(package_name==0)
29189 #if defined(_MSC_VER)
29190 #if (_MSC_VER >= 1400)
29191     sprintf_s(full_name,sizeof(full_name),"%s",proc_name);
29192 #else
29193     sprintf(full_name,"%s",proc_name);
29194 #endif
29195 #else
29196     sprintf(full_name,"%s",proc_name);
29197 #endif
29198   else
29199 #if defined(_MSC_VER)
29200 #if (_MSC_VER >= 1400)
29201     sprintf_s(full_name,sizeof(full_name),"%s.%s",package_name,proc_name);
29202 #else
29203     sprintf(full_name,"%s.%s",package_name,proc_name);
29204 #endif
29205 #else
29206     sprintf(full_name,"%s.%s",package_name,proc_name);
29207 #endif
29208   if(schema_name_included&&schema_name!=0){
29209 #if defined(_MSC_VER)
29210 #if (_MSC_VER >= 1400)
29211     sprintf_s(temp_buf,sizeof(temp_buf),"%s.%s",schema_name,full_name);
29212 #else
29213     sprintf(temp_buf,"%s.%s",schema_name,full_name);
29214 #endif
29215 #else
29216     sprintf(temp_buf,"%s.%s",schema_name,full_name);
29217 #endif
29218     OTL_STRCPY_S(full_name,sizeof(full_name),temp_buf);
29219   }
29220 
29221   if(!args_strm.good()){
29222    args_strm.open
29223     (50,
29224      "select position, "
29225      "       lower(':'||nvl(argument_name,'rc__')) argument_name, "
29226      "       in_out, "
29227      "       nvl(data_type,'*') data_type, "
29228      "       ':'||lower(nvl(argument_name,'rc__'))|| "
29229      "       decode(data_type,'REF CURSOR',' ', "
29230      "              '<'||'%s,'|| "
29231      "              decode(in_out,'IN','in', "
29232      "                     'OUT','out', "
29233      "                     'IN/OUT','inout', "
29234      "                     'xxx') "
29235      "              ||'>' "
29236      "             ) || decode(position,0,' := ',' ') "
29237      "       bind_var "
29238      "from all_arguments "
29239      "where object_name=upper(:obj_name<char[50]>) "
29240      "  and (:pkg_name<char[50]> is null and package_name is null or "
29241      " :pkg_name is not null "
29242      " and (package_name=upper(:pkg_name) "
29243      " or package_name = "
29244      " (select package_name from "
29245      " (select table_name as package_name "
29246      " from user_synonyms "
29247      " where synonym_name=upper(:pkg_name) "
29248      " union all "
29249      " select table_name as package_name "
29250      " from all_synonyms "
29251      " where synonym_name=upper(:pkg_name) "
29252      " )"
29253      " where rownum = 1)"
29254      " )) "
29255      "  and ((:owner<char[50]> is null "
29256      "        and owner= "
29257      "            (select owner from "
29258      "              (select user as owner "
29259      "               from user_objects "
29260      "               where (:pkg_name is not null "
29261      "                      and object_name = upper(:pkg_name) "
29262      "                      and object_type = 'PACKAGE') "
29263      "               or (:pkg_name is null "
29264      "                   and object_name = upper(:obj_name) "
29265      "                   and object_type in ('FUNCTION','PROCEDURE')) "
29266      "               union all "
29267      "               select table_owner as owner "
29268      "               from user_synonyms "
29269      "               where (:pkg_name is not null "
29270      "                      and synonym_name = upper(:pkg_name)) "
29271      "               or (:pkg_name is null "
29272      "                   and synonym_name = upper(:obj_name)) "
29273      "               union all "
29274      "               select table_owner as owner "
29275      "               from all_synonyms "
29276      "               where (:pkg_name is not null "
29277      "                      and synonym_name = upper(:pkg_name)) "
29278      "               or (:pkg_name is null "
29279      "                   and synonym_name = upper(:obj_name)) "
29280      "              ) "
29281      "             where rownum = 1) "
29282      "      or "
29283      "       (:owner is not null and owner=upper(:owner))) "
29284      "  and data_level=0 )"
29285      "order by position",
29286      db);
29287   }
29288 
29289   otl_auto_array_ptr< otl_Tptr<otl_sp_parm_desc> > desc(otl_var_list_size);
29290   int desc_len=0;
29291   otl_sp_parm_desc parm;
29292 
29293   args_strm<<proc_name;
29294   if(package_name==0)
29295    args_strm<<otl_null();
29296   else
29297    args_strm<<package_name;
29298   if(schema_name==0)
29299    args_strm<<otl_null();
29300   else
29301    args_strm<<schema_name;
29302   while(!args_strm.eof()){
29303    args_strm>>parm.position;
29304    args_strm>>parm.arg_name;
29305    args_strm>>parm.in_out;
29306    args_strm>>parm.data_type;
29307    args_strm>>parm.bind_var;
29308    ++desc_len;
29309    if(desc_len==desc.get_arr_size()){
29310      int j;
29311      for(j=0;j<desc.get_arr_size();++j)
29312        desc.get_ptr()[j].set_do_not_destroy(true);
29313      desc.double_size();
29314      for(j=0;j<desc.get_arr_size();++j)
29315        desc.get_ptr()[j].set_do_not_destroy(false);
29316    }
29317    desc.get_ptr()[desc_len-1].assign(new otl_sp_parm_desc(parm));
29318   }
29319 
29320   if(desc_len==0){
29321 #if defined(_MSC_VER)
29322 #if (_MSC_VER >= 1400)
29323    sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s",full_name);
29324 #else
29325    sprintf(temp_buf,"procedure %s",full_name);
29326 #endif
29327 #else
29328    sprintf(temp_buf,"procedure %s",full_name);
29329 #endif
29330    {
29331      // last ditch attemp to identify a global SP with no parms
29332      bool global_sp_no_parms=false;
29333      if(schema_name==0){
29334        // schema name is not specified
29335        otl_stream s2
29336          (1,
29337           "select 1 cnt "
29338           "from user_procedures "
29339           "where object_name=UPPER(:obj_name<char[50]>) "
29340           "  and procedure_name is null "
29341           "  and object_type='PROCEDURE' "
29342           "union all "
29343           "select 1 cnt "
29344           "from user_synonyms syn "
29345           "where syn.synonym_name=UPPER(:obj_name) "
29346           "  and exists "
29347           "   (select 'x' "
29348           "    from all_procedures proc "
29349           "	where proc.owner=syn.table_owner "
29350           "	   and proc.object_name=syn.table_name) "
29351           "union all "
29352           "select 1 cnt "
29353           "from all_synonyms syn "
29354           "where syn.synonym_name=UPPER(:obj_name) "
29355           "  and syn.owner='PUBLIC' "
29356           "  and exists "
29357           "   (select 'x' "
29358           "    from all_procedures proc "
29359           "	where proc.owner=syn.table_owner "
29360           "	   and proc.object_name=syn.table_name)",
29361           db);
29362        s2<<proc_name;
29363        global_sp_no_parms=!s2.eof();
29364      }else{
29365        // schema name is specified
29366        otl_stream s2
29367          (1,
29368           "select object_name  "
29369           "from all_procedures "
29370           "where object_name=UPPER(:obj_name<char[50]>) "
29371           "  and procedure_name is null "
29372           "  and object_type='PROCEDURE' "
29373           "  AND owner=UPPER(:owner<char[50]>) "
29374           "union all "
29375           "select synonym_name "
29376           "from all_synonyms syn "
29377           "where syn.synonym_name=UPPER(:obj_name) "
29378           "  AND syn.owner=UPPER(:owner) "
29379           "  and exists "
29380           "   (select 'x' "
29381           "    from all_procedures proc "
29382           "	where proc.owner=syn.table_owner "
29383           "	   and proc.object_name=syn.table_name)",
29384           db);
29385        s2<<proc_name;
29386        s2<<schema_name;
29387        global_sp_no_parms=!s2.eof();
29388      }
29389      if(global_sp_no_parms){
29390        // procedure without any parameters
29391        otl_strcat(sql_stm,"BEGIN ");
29392        otl_strcat(sql_stm,full_name);
29393        otl_strcat(sql_stm,"; END;");
29394        stm_type=otl_constant_sql_type;
29395        return;
29396      }else{
29397        throw otl_exception
29398          (otl_error_msg_13,
29399           otl_error_code_13,
29400           temp_buf);
29401      }
29402    }
29403   }
29404 
29405   if(desc_len==1){
29406     if(desc.get_ptr()[0].get_ptr()->position==1
29407        && desc.get_ptr()[0].get_ptr()->data_type[0]=='*'){
29408     // procedure without any parameters
29409      otl_strcat(sql_stm,"BEGIN ");
29410      otl_strcat(sql_stm,full_name);
29411      otl_strcat(sql_stm,"; END;");
29412      stm_type=otl_constant_sql_type;
29413     return;
29414     }if(desc.get_ptr()[0].get_ptr()->position==1 &&
29415         desc.get_ptr()[0].get_ptr()->data_type[0]!='*'){
29416     // procedure with one parameter
29417       if(strcmp(desc.get_ptr()[0].get_ptr()->data_type,"REF CURSOR")==0){
29418      // procedure with one parameter of refcur type
29419         if(strcmp(desc.get_ptr()[0].get_ptr()->in_out,"IN")==0){
29420       // refcur parameter should be either OUT or IN OUT, not IN.
29421 #if defined(_MSC_VER)
29422 #if (_MSC_VER >= 1400)
29423       sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s",full_name);
29424 #else
29425       sprintf(temp_buf,"procedure %s",full_name);
29426 #endif
29427 #else
29428       sprintf(temp_buf,"procedure %s",full_name);
29429 #endif
29430       throw otl_exception
29431        (otl_error_msg_15,
29432         otl_error_code_15,
29433         temp_buf,0);
29434      }
29435      otl_strcat(sql_stm,"BEGIN ");
29436      otl_strcat(sql_stm,full_name);
29437      otl_strcat(sql_stm,"(");
29438      otl_strcat(sql_stm,desc.get_ptr()[0].get_ptr()->bind_var);
29439      otl_strcat(sql_stm,"); END;");
29440      stm_type=otl_refcur_stream_type;
29441      otl_strcpy(OTL_RCAST(unsigned char*,refcur_placeholder),
29442                 OTL_RCAST(const unsigned char*,desc.get_ptr()[0].get_ptr()->arg_name));
29443      return;
29444     }else{
29445      // procedure with one scalar parameter
29446      convert_bind_var_datatype
29447        (temp_buf,sizeof(temp_buf),desc.get_ptr()[0].get_ptr()->data_type,
29448         varchar_size,all_num2type,refcur_buf_size);
29449      if(temp_buf[0]==0){
29450 #if defined(_MSC_VER)
29451 #if (_MSC_VER >= 1400)
29452       sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s, parameter %s",
29453                 full_name,desc.get_ptr()[0].get_ptr()->arg_name);
29454 #else
29455       sprintf(temp_buf,"procedure %s, parameter %s",
29456               full_name,desc.get_ptr()[0].get_ptr()->arg_name);
29457 #endif
29458 #else
29459       sprintf(temp_buf,"procedure %s, parameter %s",
29460               full_name,desc.get_ptr()[0].get_ptr()->arg_name);
29461 #endif
29462       throw otl_exception
29463        (otl_error_msg_14,
29464         otl_error_code_14,
29465         temp_buf,0);
29466      }
29467 #if defined(_MSC_VER)
29468 #if (_MSC_VER >= 1400)
29469      sprintf_s(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[0].get_ptr()->bind_var,temp_buf);
29470 #else
29471      sprintf(temp_buf2,desc.get_ptr()[0].get_ptr()->bind_var,temp_buf);
29472 #endif
29473 #else
29474      sprintf(temp_buf2,desc.get_ptr()[0].get_ptr()->bind_var,temp_buf);
29475 #endif
29476      otl_strcat(sql_stm,"BEGIN ");
29477      otl_strcat(sql_stm,full_name);
29478      otl_strcat(sql_stm,"(");
29479      otl_strcat(sql_stm,temp_buf2);
29480      otl_strcat(sql_stm,"); END;");
29481      stm_type=otl_inout_stream_type;
29482      refcur_placeholder[0]=0;
29483      return;
29484     }
29485     }else if(desc.get_ptr()[0].get_ptr()->position==0){
29486       if(strcmp(desc.get_ptr()[0].get_ptr()->data_type,"REF CURSOR")==0){
29487      // refcur function without any parameters
29488       otl_strcat(sql_stm,"BEGIN ");
29489       otl_strcat(sql_stm,desc.get_ptr()[0].get_ptr()->bind_var);
29490       otl_strcat(sql_stm," ");
29491       otl_strcat(sql_stm,full_name);
29492       otl_strcat(sql_stm,"; END;");
29493       stm_type=otl_refcur_stream_type;
29494       otl_strcpy(OTL_RCAST(unsigned char*,refcur_placeholder),
29495                  OTL_RCAST(const unsigned char*,desc.get_ptr()[0].get_ptr()->arg_name));
29496       return;
29497     }else{
29498      // scalar function without any parameters
29499      convert_bind_var_datatype
29500        (temp_buf,sizeof(temp_buf),desc.get_ptr()[0].get_ptr()->data_type,
29501         varchar_size,all_num2type,refcur_buf_size);
29502      if(temp_buf[0]==0){
29503 #if defined(_MSC_VER)
29504 #if (_MSC_VER >= 1400)
29505        sprintf_s(temp_buf,sizeof(temp_buf),
29506                  "procedure %s, parameter %s",
29507                  full_name,
29508                  desc.get_ptr()[0].get_ptr()->arg_name);
29509 #else
29510       sprintf(temp_buf,
29511               "procedure %s, parameter %s",
29512               full_name,
29513               desc.get_ptr()[0].get_ptr()->arg_name);
29514 #endif
29515 #else
29516       sprintf(temp_buf,
29517               "procedure %s, parameter %s",
29518               full_name,
29519               desc.get_ptr()[0].get_ptr()->arg_name);
29520 #endif
29521       throw otl_exception
29522        (otl_error_msg_14,
29523         otl_error_code_14,
29524         temp_buf,0);
29525      }
29526 #if defined(_MSC_VER)
29527 #if (_MSC_VER >= 1400)
29528      sprintf_s(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[0].get_ptr()->bind_var,temp_buf);
29529 #else
29530      sprintf(temp_buf2,desc.get_ptr()[0].get_ptr()->bind_var,temp_buf);
29531 #endif
29532 #else
29533      sprintf(temp_buf2,desc.get_ptr()[0].get_ptr()->bind_var,temp_buf);
29534 #endif
29535      otl_strcat(sql_stm,"BEGIN ");
29536      otl_strcat(sql_stm,temp_buf2);
29537      otl_strcat(sql_stm," ");
29538      otl_strcat(sql_stm,full_name);
29539      otl_strcat(sql_stm,"; END;");
29540      stm_type=otl_inout_stream_type;
29541      refcur_placeholder[0]=0;
29542      return;
29543     }
29544    }
29545   }
29546 
29547   // Checking if the procedure is of the "refcur" type
29548   bool refcur_flag=false;
29549   bool refcur_outpar=false;
29550   int refcur_count=0;
29551   bool inpar_only=true;
29552   for(i=0;i<desc_len;++i){
29553    if(inpar_only &&
29554       strcmp(desc.get_ptr()[i].get_ptr()->in_out,"IN")!=0 &&
29555       strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")!=0)
29556     inpar_only=false;
29557    if(strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")==0){
29558     ++refcur_count;
29559     refcur_flag=true;
29560     if(refcur_count>1){
29561       if(refcur_outpar)
29562         refcur_outpar=strcmp(desc.get_ptr()[i].get_ptr()->in_out,"IN")!=0;
29563     }else
29564       refcur_outpar=strcmp(desc.get_ptr()[i].get_ptr()->in_out,"IN")!=0;
29565    }
29566   }
29567   if(refcur_flag){
29568    if(!refcur_outpar){
29569 #if defined(_MSC_VER)
29570 #if (_MSC_VER >= 1400)
29571     sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s",full_name);
29572 #else
29573     sprintf(temp_buf,"procedure %s",full_name);
29574 #endif
29575 #else
29576     sprintf(temp_buf,"procedure %s",full_name);
29577 #endif
29578     throw otl_exception
29579      (otl_error_msg_15,
29580       otl_error_code_15,
29581       temp_buf,0);
29582    }
29583    stm_type=otl_refcur_stream_type;
29584    if(!inpar_only||refcur_count>1)
29585      stm_type=otl_mixed_refcur_stream_type;
29586    refcur_placeholder[0]=0;
29587    sql_stm[0]=0;
29588    bool full_name_printed=false;
29589    for(i=0;i<desc_len;++i){
29590 
29591     if(i==0)otl_strcat(sql_stm,"BEGIN ");
29592     if(stm_type==otl_refcur_stream_type){
29593       // otl_refcur_stream_type
29594       if(strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")==0)
29595         otl_strcpy(OTL_RCAST(unsigned char*,refcur_placeholder),
29596                    OTL_RCAST(const unsigned char*,desc.get_ptr()[i].get_ptr()->arg_name));
29597     }
29598 
29599     // in case of a function, function's return code
29600     if(desc.get_ptr()[i].get_ptr()->position==0){
29601      convert_bind_var_datatype
29602        (temp_buf,sizeof(temp_buf),desc.get_ptr()[i].get_ptr()->data_type,
29603         varchar_size,all_num2type,refcur_buf_size);
29604      if(temp_buf[0]==0&&
29605         strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")!=0){
29606 #if defined(_MSC_VER)
29607 #if (_MSC_VER >= 1400)
29608       sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s, parameter %s",
29609                 full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29610 #else
29611       sprintf(temp_buf,"procedure %s, parameter %s",
29612               full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29613 #endif
29614 #else
29615       sprintf(temp_buf,"procedure %s, parameter %s",
29616               full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29617 #endif
29618       throw otl_exception
29619        (otl_error_msg_14,
29620         otl_error_code_14,
29621         temp_buf,0);
29622      }
29623      if(strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")==0&&
29624         stm_type==otl_refcur_stream_type)
29625          OTL_STRCPY_S(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[i].get_ptr()->bind_var);
29626      else if(strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")==0&&
29627              stm_type==otl_mixed_refcur_stream_type){
29628        desc.get_ptr()[i].get_ptr()->bind_var[strlen(desc.get_ptr()[i].get_ptr()->bind_var)-5]=0;
29629 #if defined(_MSC_VER)
29630 #if (_MSC_VER >= 1400)
29631        sprintf_s(temp_buf2,sizeof(temp_buf2),
29632                  "%s<%s> := ",
29633                  desc.get_ptr()[i].get_ptr()->bind_var,
29634                  temp_buf);
29635 #else
29636        sprintf(temp_buf2,
29637                "%s<%s> := ",
29638                desc.get_ptr()[i].get_ptr()->bind_var,
29639                temp_buf);
29640 #endif
29641 #else
29642        sprintf(temp_buf2,
29643                "%s<%s> := ",
29644                desc.get_ptr()[i].get_ptr()->bind_var,
29645                temp_buf);
29646 #endif
29647      }else
29648 #if defined(_MSC_VER)
29649 #if (_MSC_VER >= 1400)
29650        sprintf_s(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29651 #else
29652      sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29653 #endif
29654 #else
29655      sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29656 #endif
29657      otl_strcat(sql_stm,temp_buf2);
29658     }
29659 
29660     // procedure/function's name
29661     if(!full_name_printed){
29662      otl_strcat(sql_stm,full_name);
29663      otl_strcat(sql_stm,"(");
29664      full_name_printed=true;
29665     }
29666 
29667     if(desc.get_ptr()[i].get_ptr()->position!=0){
29668      // normal parameters
29669      convert_bind_var_datatype
29670        (temp_buf,sizeof(temp_buf),desc.get_ptr()[i].get_ptr()->data_type,
29671         varchar_size,all_num2type,refcur_buf_size);
29672      if(temp_buf[0]==0&&
29673         strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")!=0){
29674 #if defined(_MSC_VER)
29675 #if (_MSC_VER >= 1400)
29676        sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s, parameter %s",
29677                  full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29678 #else
29679       sprintf(temp_buf,"procedure %s, parameter %s",
29680               full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29681 #endif
29682 #else
29683       sprintf(temp_buf,"procedure %s, parameter %s",
29684               full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29685 #endif
29686       throw otl_exception
29687        (otl_error_msg_14,
29688         otl_error_code_14,
29689         temp_buf,0);
29690      }
29691      if(strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")==0&&
29692         stm_type==otl_refcur_stream_type)
29693        OTL_STRCPY_S(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[i].get_ptr()->bind_var);
29694      else if(strcmp(desc.get_ptr()[i].get_ptr()->data_type,"REF CURSOR")==0&&
29695              stm_type==otl_mixed_refcur_stream_type){
29696        desc.get_ptr()[i].get_ptr()->bind_var[strlen(desc.get_ptr()[i].get_ptr()->bind_var)-2]=0;
29697 #if defined(_MSC_VER)
29698 #if (_MSC_VER >= 1400)
29699        sprintf_s(temp_buf2,sizeof(temp_buf2),
29700                  "%s<%s>",
29701                  desc.get_ptr()[i].get_ptr()->bind_var,
29702                  temp_buf);
29703 #else
29704        sprintf(temp_buf2,
29705                "%s<%s>",
29706                desc.get_ptr()[i].get_ptr()->bind_var,
29707                temp_buf);
29708 #endif
29709 #else
29710        sprintf(temp_buf2,
29711                "%s<%s>",
29712                desc.get_ptr()[i].get_ptr()->bind_var,
29713                temp_buf);
29714 #endif
29715      }else
29716 #if defined(_MSC_VER)
29717 #if (_MSC_VER >= 1400)
29718        sprintf_s(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29719 #else
29720      sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29721 #endif
29722 #else
29723      sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29724 #endif
29725      otl_strcat(sql_stm,temp_buf2);
29726     }
29727 
29728     if(i<desc_len-1 && desc.get_ptr()[i].get_ptr()->position!=0)
29729      otl_strcat(sql_stm,",");
29730     else if(i==desc_len-1)
29731      otl_strcat(sql_stm,"); ");
29732 
29733    }
29734    otl_strcat(sql_stm," END;");
29735    return;
29736   }
29737 
29738   // The procedure is of the "general" type
29739   stm_type=otl_inout_stream_type;
29740   refcur_placeholder[0]=0;
29741   sql_stm[0]=0;
29742   bool full_name_printed=false;
29743   for(i=0;i<desc_len;++i){
29744     if(i==0)otl_strcat(sql_stm,"BEGIN ");
29745     // in case of a function, function's return code
29746     if(desc.get_ptr()[i].get_ptr()->position==0){
29747       convert_bind_var_datatype
29748         (temp_buf,sizeof(temp_buf),desc.get_ptr()[i].get_ptr()->data_type,
29749          varchar_size,all_num2type,refcur_buf_size);
29750       if(temp_buf[0]==0){
29751 #if defined(_MSC_VER)
29752 #if (_MSC_VER >= 1400)
29753         sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s, parameter %s",
29754                   full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29755 #else
29756         sprintf(temp_buf,"procedure %s, parameter %s",
29757                 full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29758 #endif
29759 #else
29760         sprintf(temp_buf,"procedure %s, parameter %s",
29761                 full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29762 #endif
29763         throw otl_exception
29764           (otl_error_msg_14,
29765            otl_error_code_14,
29766            temp_buf,0);
29767       }
29768 #if defined(_MSC_VER)
29769 #if (_MSC_VER >= 1400)
29770       sprintf_s(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29771 #else
29772       sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29773 #endif
29774 #else
29775       sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29776 #endif
29777       otl_strcat(sql_stm,temp_buf2);
29778     }
29779     // procedure/function's name
29780     if(!full_name_printed){
29781       otl_strcat(sql_stm,full_name);
29782       otl_strcat(sql_stm,"(");
29783       full_name_printed=true;
29784     }
29785     if(desc.get_ptr()[i].get_ptr()->position!=0){
29786       // normal parameters
29787       convert_bind_var_datatype
29788         (temp_buf,sizeof(temp_buf),desc.get_ptr()[i].get_ptr()->data_type,
29789          varchar_size,all_num2type,refcur_buf_size);
29790       if(temp_buf[0]==0){
29791 #if defined(_MSC_VER)
29792 #if (_MSC_VER >= 1400)
29793         sprintf_s(temp_buf,sizeof(temp_buf),"procedure %s, parameter %s",
29794                   full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29795 #else
29796         sprintf(temp_buf,"procedure %s, parameter %s",
29797                 full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29798 #endif
29799 #else
29800         sprintf(temp_buf,"procedure %s, parameter %s",
29801                 full_name,desc.get_ptr()[i].get_ptr()->arg_name);
29802 #endif
29803         throw otl_exception
29804           (otl_error_msg_14,
29805            otl_error_code_14,
29806            temp_buf,0);
29807       }
29808 #if defined(_MSC_VER)
29809 #if (_MSC_VER >= 1400)
29810       sprintf_s(temp_buf2,sizeof(temp_buf2),desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29811 #else
29812       sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29813 #endif
29814 #else
29815       sprintf(temp_buf2,desc.get_ptr()[i].get_ptr()->bind_var,temp_buf);
29816 #endif
29817       otl_strcat(sql_stm,temp_buf2);
29818     }
29819     if(i<desc_len-1&&desc.get_ptr()[i].get_ptr()->position!=0)
29820       otl_strcat(sql_stm,",");
29821     else if(i==desc_len-1)
29822       otl_strcat(sql_stm,"); ");
29823   }
29824   otl_strcat(sql_stm," END;");
29825 
29826  }
29827 #endif
29828 
29829  int get_stream_type(void) OTL_NO_THROW
29830  {
29831   if(shell==0)
29832     return otl_no_stream_type;
29833   else
29834     return shell->stream_type;
29835  }
29836 
29837  void set_column_type(const int column_ndx,
29838                       const int col_type,
29839                       const int col_size=0) OTL_NO_THROW
29840  {
29841    if(shell==0){
29842      init_stream();
29843      shell->flush_flag=true;
29844    }
29845    override->add_override(column_ndx,col_type,col_size);
29846  }
29847 
29848 
29849   void set_all_column_types(const unsigned mask=0)
29850     OTL_NO_THROW
29851   {
29852     if(shell==0){
29853       init_stream();
29854       shell->flush_flag=true;
29855     }
29856     override->set_all_column_types(mask);
29857  }
29858 
29859  void set_flush(const bool flush_flag=true)
29860    OTL_NO_THROW
29861  {
29862    if(shell==0)init_stream();
29863    shell->flush_flag=flush_flag;
29864  }
29865 
29866   void set_lob_stream_mode(const bool lob_stream_flag=false)
29867     OTL_NO_THROW
29868   {
29869     if(shell==0)return;
29870     shell->lob_stream_flag=lob_stream_flag;
29871   }
29872 
29873  void inc_next_ov(void)
29874  {
29875   if((*ov_len)==0)return;
29876   if((*next_ov_ndx)<(*ov_len)-1)
29877    ++(*next_ov_ndx);
29878   else
29879    (*next_ov_ndx)=0;
29880  }
29881 
29882  void inc_next_iov(void)
29883  {
29884   if((*iov_len)==0)return;
29885   if((*next_iov_ndx)<(*iov_len)-1)
29886    ++(*next_iov_ndx);
29887   else
29888    (*next_iov_ndx)=0;
29889  }
29890 
29891  otl_var_desc* describe_in_vars(int& desc_len)
29892    OTL_NO_THROW
29893  {
29894   desc_len=0;
29895   if(shell==0)return 0;
29896   if(shell->iov==0)return 0;
29897   desc_len=shell->iov_len;
29898   return shell->iov;
29899  }
29900 
29901  otl_var_desc* describe_out_vars(int& desc_len)
29902    OTL_NO_THROW
29903  {
29904   desc_len=0;
29905   if(shell==0)return 0;
29906   if(shell->ov==0)return 0;
29907   desc_len=shell->ov_len;
29908   return shell->ov;
29909  }
29910 
29911  otl_var_desc* describe_next_in_var(void)
29912    OTL_NO_THROW
29913  {
29914   if(shell==0)return 0;
29915   if(shell->iov==0)return 0;
29916   return &(shell->iov[shell->next_iov_ndx]);
29917  }
29918 
29919  otl_var_desc* describe_next_out_var(void)
29920    OTL_NO_THROW
29921  {
29922   if(shell==0)return 0;
29923   if(shell->ov==0)return 0;
29924   return &(shell->ov[shell->next_ov_ndx]);
29925  }
29926 
29927   const char* get_stm_text(void)
29928   {
29929     const char* no_stm_text=OTL_NO_STM_TEXT;
29930     switch(shell->stream_type){
29931     case otl_no_stream_type:
29932       return no_stm_text;
29933     case otl_inout_stream_type:
29934       return (*io)->get_stm_label()?(*io)->get_stm_label():(*io)->get_stm_text();
29935     case otl_select_stream_type:
29936       return (*ss)->get_stm_label()?(*ss)->get_stm_label():(*ss)->get_stm_text();
29937     case otl_refcur_stream_type:
29938       return (*ref_ss)->get_stm_label()?
29939              (*ref_ss)->get_stm_label():(*ref_ss)->get_stm_text();
29940     default:
29941       return no_stm_text;
29942     }
29943   }
29944 
29945  long get_rpc() OTL_THROWS_OTL_EXCEPTION
29946  {
29947    switch(shell->stream_type){
29948    case otl_no_stream_type:
29949      return 0;
29950    case otl_inout_stream_type:
29951      (*adb)->reset_throw_count();
29952      return (*io)->get_rpc();
29953    case otl_select_stream_type:
29954      (*adb)->reset_throw_count();
29955      return (*ss)->get_rfc();
29956    case otl_refcur_stream_type:
29957      (*adb)->reset_throw_count();
29958      return (*ref_ss)->get_rfc();
29959    default:
29960      return 0;
29961    }
29962  }
29963 
29964  void create_var_desc(void)
29965  {int i;
29966   delete[] (*iov);
29967   delete[] (*ov);
29968   (*iov)=0; (*iov_len)=0;
29969   (*ov)=0; (*ov_len)=0;
29970   if((*ss)){
29971     if((*ss)->get_vl_len()>0){
29972       (*iov)=new otl_var_desc[(*ss)->get_vl_len()];
29973       (*iov_len)=(*ss)->get_vl_len();
29974       for(i=0;i<(*ss)->get_vl_len();++i)
29975         (*ss)->get_vl()[i]->copy_var_desc((*iov)[i]);
29976     }
29977     if((*ss)->get_sl_len()>0){
29978       (*ov)=new otl_var_desc[(*ss)->get_sl_len()];
29979       (*ov_len)=(*ss)->get_sl_len();
29980       for(i=0;i<(*ss)->get_sl_len();++i){
29981         (*ss)->get_sl()[i].copy_var_desc((*ov)[i]);
29982         (*ov)[i].copy_name((*ss)->get_sl_desc()[i].name);
29983       }
29984     }
29985   }else if((*io)){
29986     if((*io)->get_vl_len()>0){
29987       (*iov)=new otl_var_desc[(*io)->get_vl_len()];
29988       (*iov_len)=(*io)->get_vl_len();
29989       for(i=0;i<(*io)->get_vl_len();++i)
29990         (*io)->get_vl()[i]->copy_var_desc((*iov)[i]);
29991    }
29992     if((*io)->get_iv_len()>0){
29993       (*ov)=new otl_var_desc[(*io)->get_iv_len()];
29994       (*ov_len)=(*io)->get_iv_len();
29995       for(i=0;i<(*io)->get_iv_len();++i)
29996         (*io)->get_in_vl()[i]->copy_var_desc((*ov)[i]);
29997    }
29998   }else if((*ref_ss)){
29999     if((*ref_ss)->get_vl_len()>0){
30000       (*iov)=new otl_var_desc[(*ref_ss)->get_vl_len()];
30001       (*iov_len)=(*ref_ss)->get_vl_len();
30002       for(i=0;i<(*ref_ss)->get_vl_len();++i)
30003         (*ref_ss)->get_vl()[i]->copy_var_desc((*iov)[i]);
30004    }
30005     if((*ref_ss)->get_sl_len()>0){
30006       (*ov)=new otl_var_desc[(*ref_ss)->get_sl_len()];
30007       (*ov_len)=(*ref_ss)->get_sl_len();
30008       for(i=0;i<(*ref_ss)->get_sl_len();++i){
30009         (*ref_ss)->get_sl()[i].copy_var_desc((*ov)[i]);
30010         (*ov)[i].copy_name((*ref_ss)->get_sl_desc()[i].name);
30011     }
30012    }
30013   }
30014  }
30015 
30016  void init_stream(void)
30017  {
30018    buf_size_=1;
30019    last_oper_was_read_op=false;
30020    shell=0;
30021    shell=new otl_stream_shell(0);
30022    shell_pt.assign(&shell);
30023    connected=0;
30024 
30025    ref_ss=&(shell->ref_ss);
30026    ss=&(shell->ss);
30027    io=&(shell->io);
30028    adb=&(shell->adb);
30029    auto_commit_flag=&(shell->auto_commit_flag);
30030    iov=&(shell->iov);
30031    iov_len=&(shell->iov_len);
30032    next_iov_ndx=&(shell->next_iov_ndx);
30033    ov=&(shell->ov);
30034    ov_len=&(shell->ov_len);
30035    next_ov_ndx=&(shell->next_ov_ndx);
30036    override=&(shell->override);
30037 
30038    (*ref_ss)=0;
30039    (*io)=0;
30040    (*ss)=0;
30041    (*adb)=0;
30042    (*ov)=0;
30043    (*ov_len)=0;
30044    (*next_iov_ndx)=0;
30045    (*next_ov_ndx)=0;
30046    (*auto_commit_flag)=1;
30047    (*iov)=0;
30048    (*iov_len)=0;
30049 
30050  }
30051 
30052  otl_stream
30053  (const otl_stream_buffer_size_type arr_size,
30054   const char* sqlstm,
30055   otl_connect& db,
30056   const char* ref_cur_placeholder=0,
30057   const char* sqlstm_label=0)
30058    OTL_THROWS_OTL_EXCEPTION:
30059  #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
30060    otl_read_stream_interface(),
30061 #endif
30062    shell(0),
30063    shell_pt(),
30064    connected(0),
30065    ref_ss(0),
30066    ss(0),
30067    io(0),
30068    adb(0),
30069    auto_commit_flag(0),
30070    iov(0),
30071    iov_len(0),
30072    next_iov_ndx(0),
30073    ov(0),
30074    ov_len(0),
30075    next_ov_ndx(0),
30076    end_marker(0),
30077    oper_int_called(0),
30078    last_eof_rc(0),
30079    last_oper_was_read_op(false),
30080    override(0),
30081    buf_size_(0)
30082  {
30083   init_stream();
30084 
30085   (*io)=0; (*ss)=0; (*ref_ss)=0;
30086   (*iov)=0; (*iov_len)=0;
30087   (*ov)=0; (*ov_len)=0;
30088   (*auto_commit_flag)=1;
30089   (*next_iov_ndx)=0;
30090   (*next_ov_ndx)=0;
30091   (*adb)=&db;
30092   shell->flush_flag=true;
30093   open(arr_size,sqlstm,db,ref_cur_placeholder,sqlstm_label);
30094  }
30095 
30096  otl_stream() OTL_NO_THROW:
30097  #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
30098    otl_read_stream_interface(),
30099 #endif
30100    shell(0),
30101    shell_pt(),
30102    connected(0),
30103    ref_ss(0),
30104    ss(0),
30105    io(0),
30106    adb(0),
30107    auto_commit_flag(0),
30108    iov(0),
30109    iov_len(0),
30110    next_iov_ndx(0),
30111    ov(0),
30112    ov_len(0),
30113    next_ov_ndx(0),
30114    end_marker(0),
30115    oper_int_called(0),
30116    last_eof_rc(0),
30117    last_oper_was_read_op(false),
30118    override(0),
30119    buf_size_(0)
30120  {
30121   init_stream();
30122   shell->flush_flag=true;
30123  }
30124 
30125  virtual ~otl_stream()
30126 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
30127    OTL_THROWS_OTL_EXCEPTION
30128 #endif
30129  {
30130   if(!connected)return;
30131   try{
30132    if((*io)!=0&&shell->flush_flag==false)
30133      (*io)->set_flush_flag2(false);
30134    close();
30135    if(shell!=0){
30136     if((*io)!=0)
30137       (*io)->set_flush_flag2(true);
30138    }
30139   }catch(OTL_CONST_EXCEPTION otl_exception&){
30140     if(shell!=0){
30141       if((*io)!=0)
30142         (*io)->set_flush_flag2(true);
30143    }
30144 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
30145    clean(1);
30146    if(shell!=0)
30147      shell->set_should_delete(1);
30148    shell_pt.destroy();
30149 #else
30150    shell_pt.destroy();
30151 #endif
30152 #if !defined(OTL_DESTRUCTORS_DO_NOT_THROW)
30153    throw;
30154 #endif
30155   }
30156 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
30157   if((adb && (*adb) && (*adb)->get_throw_count()>0)
30158 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
30159      || otl_uncaught_exception()
30160 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
30161      || otl_uncaught_exception()
30162 #endif
30163      ){
30164    //
30165   }
30166 #else
30167    shell_pt.destroy();
30168 #endif
30169  }
30170 
30171  int eof(void) OTL_NO_THROW
30172  {
30173   if((*io)){
30174    (*adb)->reset_throw_count();
30175    return (*io)->eof();
30176   }else if((*ss)){
30177    (*adb)->reset_throw_count();
30178    return (*ss)->eof();
30179   }else if((*ref_ss)){
30180    (*adb)->reset_throw_count();
30181    return (*ref_ss)->eof();
30182   }else
30183    return 1;
30184  }
30185 
30186   void skip_to_end_of_row()
30187   {
30188     if(next_ov_ndx==0)
30189       return;
30190     if((*ov_len)==0)return;
30191     last_oper_was_read_op=true;
30192     switch(shell->stream_type){
30193     case otl_no_stream_type:
30194       break;
30195     case otl_inout_stream_type:
30196       last_eof_rc=(*io)->eof();
30197       (*io)->skip_to_end_of_row();
30198       break;
30199     case otl_select_stream_type:
30200       last_eof_rc=(*ss)->eof();
30201       (*ss)->skip_to_end_of_row();
30202       break;
30203     case otl_refcur_stream_type:
30204       last_eof_rc=(*ref_ss)->eof();
30205       (*ref_ss)->skip_to_end_of_row();
30206       break;
30207     }
30208     while ((*next_ov_ndx)<(*ov_len)-1)
30209       ++(*next_ov_ndx);
30210   }
30211 
30212 
30213   void reset_to_last_valid_row()
30214   {
30215     if((*io)){
30216       (*adb)->reset_throw_count();
30217       (*io)->reset_to_last_valid_row();
30218     }
30219   }
30220 
30221  void flush(const int rowoff=0,const bool force_flush=false)
30222    OTL_THROWS_OTL_EXCEPTION
30223  {
30224   if((*io)){
30225    (*adb)->reset_throw_count();
30226    (*io)->flush(rowoff,force_flush);
30227   }
30228  }
30229 
30230  void clean(const int clean_up_error_flag=0)
30231    OTL_THROWS_OTL_EXCEPTION
30232  {
30233   if((*io)){
30234    (*adb)->reset_throw_count();
30235    (*io)->clean(clean_up_error_flag);
30236   }else if(*ss){
30237    (*adb)->reset_throw_count();
30238    (*ss)->clean();
30239   }else if(*ref_ss){
30240    (*adb)->reset_throw_count();
30241    (*ref_ss)->clean();
30242   }
30243  }
30244 
30245  void rewind(void)
30246    OTL_THROWS_OTL_EXCEPTION
30247  {
30248   if((*io)){
30249    (*adb)->reset_throw_count();
30250    (*io)->rewind();
30251   }else if((*ss)){
30252    (*adb)->reset_throw_count();
30253    (*ss)->rewind();
30254   }else if((*ref_ss)){
30255    (*adb)->reset_throw_count();
30256    (*ref_ss)->rewind();
30257   }
30258  }
30259 
30260  int is_null(void) OTL_NO_THROW
30261  {
30262   if((*io))
30263    return (*io)->is_null();
30264   else if((*ss))
30265    return (*ss)->is_null();
30266   else if((*ref_ss))
30267    return (*ref_ss)->is_null();
30268   else
30269    return 0;
30270  }
30271 
30272  void set_commit(int auto_commit=0) OTL_NO_THROW
30273  {
30274   (*auto_commit_flag)=auto_commit;
30275   if((*io)){
30276    (*adb)->reset_throw_count();
30277    (*io)->set_commit(auto_commit);
30278   }
30279  }
30280 
30281  void open
30282  (const otl_stream_buffer_size_type arr_size,
30283   const char* sqlstm,
30284   otl_connect& db,
30285   const char* ref_cur_placeholder=0,
30286   const char* sqlstm_label=0)
30287    OTL_THROWS_OTL_EXCEPTION
30288  {
30289    reset_end_marker();
30290    if(this->good()){
30291      const char* temp_stm_text=0;
30292      switch(shell->stream_type){
30293      case otl_no_stream_type:
30294        temp_stm_text=OTL_NO_STM_TEXT;
30295        break;
30296      case otl_inout_stream_type:
30297        temp_stm_text=(*io)->get_stm_label()?(*io)->get_stm_label():(*io)->get_stm_text();
30298        break;
30299      case otl_select_stream_type:
30300        temp_stm_text=(*ss)->get_stm_label()?(*ss)->get_stm_label():(*ss)->get_stm_text();
30301        break;
30302      case otl_refcur_stream_type:
30303        temp_stm_text=(*ref_ss)->get_stm_label()?
30304                      (*ref_ss)->get_stm_label():(*ref_ss)->get_stm_text();
30305        break;
30306      default:
30307        temp_stm_text=OTL_NO_STM_TEXT;
30308        break;
30309      }
30310      throw otl_exception
30311        (otl_error_msg_29,
30312         otl_error_code_29,
30313         temp_stm_text);
30314    }
30315    if(shell==0)
30316     init_stream();
30317    buf_size_=arr_size;
30318    OTL_TRACE_STREAM_OPEN2
30319 #if defined(OTL_STL) && defined(OTL_STREAM_POOLING_ON)
30320   char temp_buf[128];
30321   otl_itoa(arr_size,temp_buf);
30322   OTL_STRING_CONTAINER sql_stm=
30323     OTL_STRING_CONTAINER(temp_buf)+
30324     OTL_STRING_CONTAINER("===>")+sqlstm;
30325   otl_stream_shell_generic* temp_shell=db.get_sc().find(sql_stm);
30326   if(temp_shell){
30327     if(shell!=0)
30328       shell_pt.destroy();
30329    shell=OTL_RCAST(otl_stream_shell*,temp_shell);
30330    ref_ss=&(shell->ref_ss);
30331    ss=&(shell->ss);
30332    io=&(shell->io);
30333    if((*io)!=0)(*io)->set_flush_flag2(true);
30334    adb=&(shell->adb);
30335    auto_commit_flag=&(shell->auto_commit_flag);
30336    iov=&(shell->iov);
30337    iov_len=&(shell->iov_len);
30338    next_iov_ndx=&(shell->next_iov_ndx);
30339    ov=&(shell->ov);
30340    ov_len=&(shell->ov_len);
30341    next_ov_ndx=&(shell->next_ov_ndx);
30342    override=&(shell->override);
30343    override->set_master_stream_ptr(OTL_RCAST(void*,this));
30344    try{
30345      if((*iov_len)==0)this->rewind();
30346    }catch(OTL_CONST_EXCEPTION otl_exception&){
30347      if((*adb))
30348        (*adb)->get_sc().remove(shell,shell->orig_sql_stm);
30349      intern_cleanup();
30350      shell_pt.destroy();
30351      connected=0;
30352      throw;
30353    }
30354    connected=1;
30355    return;
30356   }
30357   shell->orig_sql_stm=sql_stm;
30358 #endif
30359 
30360   delete[] (*iov);
30361   delete[] (*ov);
30362 
30363   (*iov)=0; (*iov_len)=0;
30364   (*ov)=0; (*ov_len)=0;
30365   (*next_iov_ndx)=0;
30366   (*next_ov_ndx)=0;
30367 
30368   char tmp[7];
30369   char* c=OTL_CCAST(char*,sqlstm);
30370 
30371   while(otl_isspace(*c)||(*c)=='(')++c;
30372   OTL_STRNCPY_S(tmp,sizeof(tmp),c,6);
30373   tmp[6]=0;
30374   c=tmp;
30375   while(*c){
30376    *c=OTL_SCAST(char,otl_to_upper(*c));
30377    ++c;
30378   }
30379   if(adb==0)adb=&(shell->adb);
30380   (*adb)=&db;
30381   (*adb)->reset_throw_count();
30382   try{
30383     if((strncmp(tmp,"SELECT",6)==0||
30384         strncmp(tmp,"WITH",4)==0)&&
30385        ref_cur_placeholder==0){
30386       override->set_master_stream_ptr(OTL_RCAST(void*,this));
30387       (*ss)=new otl_select_stream(override,arr_size,
30388                                   sqlstm,db,otl_explicit_select,
30389                                   sqlstm_label);
30390       shell->stream_type=otl_select_stream_type;
30391    }else if(ref_cur_placeholder!=0){
30392       override->set_master_stream_ptr(OTL_RCAST(void*,this));
30393       (*ref_ss)=new otl_ref_select_stream
30394         (override,arr_size,sqlstm,ref_cur_placeholder,
30395          db,sqlstm_label);
30396       shell->stream_type=otl_refcur_stream_type;
30397    }else{
30398     (*io)=new otl_inout_stream
30399       (arr_size,
30400        sqlstm,
30401        db,
30402        OTL_RCAST(void*,this),
30403        false,sqlstm_label);
30404     (*io)->set_flush_flag(shell->flush_flag);
30405     shell->stream_type=otl_inout_stream_type;
30406    }
30407   }catch(OTL_CONST_EXCEPTION otl_exception&){
30408    shell_pt.destroy();
30409    throw;
30410   }
30411   if((*io))(*io)->set_commit((*auto_commit_flag));
30412   create_var_desc();
30413   connected=1;
30414  }
30415 
30416  void intern_cleanup(void)
30417  {
30418   delete[] (*iov);
30419   delete[] (*ov);
30420 
30421   (*iov)=0; (*iov_len)=0;
30422   (*ov)=0; (*ov_len)=0;
30423   (*next_iov_ndx)=0;
30424   (*next_ov_ndx)=0;
30425   override->setLen(0);
30426   switch(shell->stream_type){
30427   case otl_no_stream_type:
30428     break;
30429   case otl_inout_stream_type:
30430     try{
30431       (*io)->flush();
30432       (*io)->close();
30433     }catch(OTL_CONST_EXCEPTION otl_exception&){
30434       clean(1);
30435       (*io)->close();
30436       delete (*io);
30437       (*io)=0;
30438       shell->stream_type=otl_no_stream_type;
30439       throw;
30440     }
30441     delete (*io);
30442     (*io)=0;
30443     shell->stream_type=otl_no_stream_type;
30444     break;
30445   case otl_select_stream_type:
30446     try{
30447       (*ss)->close();
30448     }catch(OTL_CONST_EXCEPTION otl_exception&){
30449       delete (*ss);
30450       (*ss)=0;
30451       shell->stream_type=otl_no_stream_type;
30452       throw;
30453     }
30454     delete (*ss);
30455     (*ss)=0;
30456     shell->stream_type=otl_no_stream_type;
30457     break;
30458   case otl_refcur_stream_type:
30459     try{
30460       (*ref_ss)->close();
30461     }catch(OTL_CONST_EXCEPTION otl_exception&){
30462       delete (*ref_ss);
30463       (*ref_ss)=0;
30464       shell->stream_type=otl_no_stream_type;
30465       throw;
30466     }
30467     delete (*ref_ss);
30468     (*ref_ss)=0;
30469     shell->stream_type=otl_no_stream_type;
30470     break;
30471   }
30472   (*ss)=0; (*io)=0; (*ref_ss)=0;
30473   if(adb!=0)(*adb)=0;
30474   adb=0;
30475  }
30476 
30477 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
30478  void close(const bool save_in_stream_pool=true)
30479 #else
30480  void close(void)
30481 #endif
30482  {
30483   if(shell==0)return;
30484   OTL_TRACE_FUNC(0x4,"otl_stream","close","")
30485 #if (defined(OTL_STL)||defined(OTL_ACE)) && defined(OTL_STREAM_POOLING_ON)
30486   if(save_in_stream_pool&&(*adb)&&
30487 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
30488      !otl_uncaught_exception()&&
30489 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
30490      !otl_uncaught_exception()&&
30491 #endif
30492      (*adb)->get_throw_count()==0){
30493    try{
30494     this->flush();
30495     this->clean(1);
30496    }catch(OTL_CONST_EXCEPTION otl_exception&){
30497     this->clean(1);
30498     throw;
30499    }
30500    if((*adb) && (*adb)->get_throw_count()>0){
30501      (*adb)->get_sc().remove(shell,shell->orig_sql_stm);
30502     intern_cleanup();
30503     shell_pt.destroy();
30504     connected=0;
30505     return;
30506    }
30507 #if defined(OTL_STL) && defined(OTL_UNCAUGHT_EXCEPTION_ON)
30508    if(otl_uncaught_exception()){
30509     if((*adb))
30510       (*adb)->get_sc().remove(shell,shell->orig_sql_stm);
30511     intern_cleanup();
30512     shell_pt.destroy();
30513     connected=0;
30514     return;
30515    }
30516 #elif defined(OTL_UNCAUGHT_EXCEPTION_ON)
30517    if(otl_uncaught_exception()){
30518     if((*adb))
30519       (*adb)->get_sc().remove(shell,shell->orig_sql_stm);
30520     intern_cleanup();
30521     shell_pt.destroy();
30522     connected=0;
30523     return;
30524    }
30525 #endif
30526    (*adb)->get_sc().add(shell,shell->orig_sql_stm.c_str());
30527    shell_pt.disconnect();
30528    connected=0;
30529   }else{
30530    if((*adb))
30531      (*adb)->get_sc().remove(shell,shell->orig_sql_stm);
30532    intern_cleanup();
30533    shell_pt.destroy();
30534    connected=0;
30535   }
30536 #else
30537   intern_cleanup();
30538   connected=0;
30539 #endif
30540  }
30541 
30542  otl_column_desc* describe_select(int& desc_len)
30543    OTL_NO_THROW
30544  {
30545    desc_len=0;
30546    switch(shell->stream_type){
30547    case otl_no_stream_type:
30548      return 0;
30549    case otl_inout_stream_type:
30550      return 0;
30551    case otl_select_stream_type:
30552      (*adb)->reset_throw_count();
30553      desc_len=(*ss)->get_sl_len();
30554      return (*ss)->get_sl_desc();
30555    case otl_refcur_stream_type:
30556      (*adb)->reset_throw_count();
30557      desc_len=(*ref_ss)->get_sl_len();
30558      return (*ref_ss)->get_sl_desc();
30559    default:
30560      return 0;
30561    }
30562  }
30563 
30564  int good(void) OTL_NO_THROW
30565  {
30566   if(!connected)return 0;
30567   if((*io)||(*ss)||(*ref_ss)){
30568    (*adb)->reset_throw_count();
30569    return 1;
30570   }else
30571    return 0;
30572  }
30573 
30574   otl_stream& operator>>(otl_stream& (*pf) (otl_stream&))
30575   {
30576     (*pf)(*this);
30577     return *this;
30578   }
30579 
30580   otl_stream& operator<<(otl_stream& (*pf) (otl_stream&))
30581   {
30582     (*pf)(*this);
30583     return *this;
30584   }
30585 
30586  otl_stream& operator>>(otl_pl_tab_generic& tab)
30587    OTL_THROWS_OTL_EXCEPTION
30588  {
30589   last_oper_was_read_op=true;
30590   if((*io)){
30591    last_eof_rc=(*io)->eof();
30592    (*io)->operator>>(tab);
30593    OTL_TRACE_WRITE(", tab len="<<tab.len(),"operator >>","PL/SQL Tab&")
30594    inc_next_ov();
30595   }
30596   return *this;
30597  }
30598 
30599  otl_stream& operator>>(otl_refcur_stream& s)
30600    OTL_THROWS_OTL_EXCEPTION
30601  {
30602   last_oper_was_read_op=true;
30603   if((*io)){
30604    last_eof_rc=(*io)->eof();
30605    (*io)->operator>>(s);
30606    OTL_TRACE_WRITE(" ref.cur.stream","operator >>","otl_refcur_stream&")
30607    inc_next_ov();
30608   }
30609   return *this;
30610  }
30611 
30612  otl_stream& operator<<(otl_pl_tab_generic& tab)
30613    OTL_THROWS_OTL_EXCEPTION
30614  {
30615   last_oper_was_read_op=false;
30616    reset_end_marker();
30617   if((*io)){
30618    (*io)->operator<<(tab);
30619    OTL_TRACE_READ(", tab len="<<tab.len(),"operator <<","PL/SQL Tab&")
30620    inc_next_iov();
30621   }
30622   return *this;
30623  }
30624 
30625 #if defined(OTL_PL_TAB) && defined(OTL_STL)
30626 
30627  otl_stream& operator>>(otl_pl_vec_generic& vec)
30628    OTL_THROWS_OTL_EXCEPTION
30629  {
30630   last_oper_was_read_op=true;
30631   if((*io)){
30632    last_eof_rc=(*io)->eof();
30633    (*io)->operator>>(vec);
30634    OTL_TRACE_WRITE(", tab len="<<vec.len(),"operator >>","PL/SQL Tab&")
30635    inc_next_ov();
30636   }
30637   return *this;
30638  }
30639 
30640  otl_stream& operator<<(otl_pl_vec_generic& vec)
30641    OTL_THROWS_OTL_EXCEPTION
30642  {
30643   last_oper_was_read_op=false;
30644    reset_end_marker();
30645   if((*io)){
30646    (*io)->operator<<(vec);
30647    OTL_TRACE_READ(", tab len="<<vec.len(),"operator <<","PL/SQL Tab&")
30648    inc_next_iov();
30649   }
30650   return *this;
30651  }
30652 
30653 #endif
30654 
30655  otl_stream& operator<<(otl_lob_stream& s)
30656    OTL_THROWS_OTL_EXCEPTION
30657  {
30658   last_oper_was_read_op=false;
30659    reset_end_marker();
30660   if((*io)){
30661    (*io)->operator<<(s);
30662    OTL_TRACE_READ(", lob stream","operator <<","PL/otl_lob_stream&")
30663    inc_next_iov();
30664   }
30665   return *this;
30666  }
30667 
30668  otl_stream& operator>>(otl_time0& s)
30669    OTL_THROWS_OTL_EXCEPTION
30670  {
30671    last_oper_was_read_op=true;
30672    switch(shell->stream_type){
30673    case otl_no_stream_type:
30674      break;
30675    case otl_inout_stream_type:
30676      {
30677        last_eof_rc=(*io)->eof();
30678        (*io)->operator>>(s);
30679 #if defined(OTL_ORA_TIMESTAMP)
30680        OTL_TRACE_WRITE
30681          (OTL_TRACE_FORMAT_DATETIME(s),
30682           "operator >>",
30683           "otl_datetime&");
30684 #endif
30685        break;
30686      }
30687    case otl_select_stream_type:
30688      {
30689        last_eof_rc=(*ss)->eof();
30690        (*ss)->operator>>(s);
30691 #if defined(OTL_ORA_TIMESTAMP)
30692        OTL_TRACE_WRITE
30693          (OTL_TRACE_FORMAT_DATETIME(s),
30694           "operator >>",
30695           "otl_datetime&");
30696 #endif
30697        break;
30698      }
30699    case otl_refcur_stream_type:
30700      {
30701        last_eof_rc=(*ref_ss)->eof();
30702        (*ref_ss)->operator>>(s);
30703 #if defined(OTL_ORA_TIMESTAMP)
30704        OTL_TRACE_WRITE
30705          (OTL_TRACE_FORMAT_DATETIME(s),
30706           "operator >>",
30707           "otl_datetime&");
30708 #endif
30709        break;
30710      }
30711    }
30712 #if defined(OTL_ORA_TIMESTAMP)
30713    inc_next_ov();
30714 #endif
30715    return *this;
30716  }
30717 
30718  otl_stream& operator<<(const otl_time0& n)
30719    OTL_THROWS_OTL_EXCEPTION
30720  {
30721    last_oper_was_read_op=false;
30722    reset_end_marker();
30723    switch(shell->stream_type){
30724    case otl_no_stream_type:
30725      break;
30726    case otl_inout_stream_type:
30727      {
30728        (*io)->operator<<(n);
30729 #if defined(OTL_ORA_TIMESTAMP)
30730        OTL_TRACE_READ(OTL_TRACE_FORMAT_DATETIME(n),
30731                       "operator <<",
30732                       "otl_datetime&");
30733 #endif
30734        break;
30735      }
30736    case otl_select_stream_type:
30737      {
30738        (*ss)->operator<<(n);
30739 #if defined(OTL_ORA_TIMESTAMP)
30740        OTL_TRACE_READ(OTL_TRACE_FORMAT_DATETIME(n),
30741                       "operator <<",
30742                       "otl_datetime&");
30743 #endif
30744        break;
30745      }
30746    case otl_refcur_stream_type:
30747      {
30748        (*ref_ss)->operator<<(n);
30749        if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
30750 #if defined(OTL_ORA_TIMESTAMP)
30751        OTL_TRACE_READ(OTL_TRACE_FORMAT_DATETIME(n),
30752                       "operator <<",
30753                       "otl_datetime&");
30754 #endif
30755        break;
30756      }
30757    }
30758 #if defined(OTL_ORA_TIMESTAMP)
30759    inc_next_iov();
30760 #endif
30761   return *this;
30762  }
30763 
30764 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
30765   // already declared
30766 #else
30767  OTL_ORA_COMMON_READ_STREAM& operator>>(otl_datetime& s)
30768    OTL_THROWS_OTL_EXCEPTION
30769  {
30770    last_oper_was_read_op=true;
30771 
30772 #if defined(OTL_ORA7_STRING_TO_TIMESTAMP)
30773 
30774   if(describe_next_out_var()->ftype==otl_var_char){
30775 #if defined(OTL_UNICODE)
30776       OTL_CHAR tmp_str[100];
30777 #elif defined(OTL_UNICODE) && defined(OTL_UNICODE_CHAR_TYPE)
30778       OTL_UNICODE_CHAR_TYPE tmp_str[100];
30779 #else
30780       char tmp_str[100];
30781 #endif
30782     (*this)>>tmp_str;
30783 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
30784     if((*this).is_null())
30785       s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
30786     else
30787       OTL_ORA7_STRING_TO_TIMESTAMP(tmp_str,s);
30788 #else
30789     OTL_ORA7_STRING_TO_TIMESTAMP(tmp_str,s);
30790 #endif
30791     OTL_TRACE_WRITE
30792       (OTL_TRACE_FORMAT_DATETIME(s),
30793        "operator >>",
30794        "otl_datetime&");
30795     return *this;
30796   }else{
30797     otl_time0 tmp;
30798     (*this)>>tmp;
30799 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
30800     if((*this).is_null())
30801       s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
30802     else{
30803       s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
30804       s.month=tmp.month;
30805       s.day=tmp.day;
30806       s.hour=tmp.hour-1;
30807       s.minute=tmp.minute-1;
30808       s.second=tmp.second-1;
30809     }
30810 #else
30811     s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
30812     s.month=tmp.month;
30813     s.day=tmp.day;
30814     s.hour=tmp.hour-1;
30815     s.minute=tmp.minute-1;
30816     s.second=tmp.second-1;
30817 #endif
30818     OTL_TRACE_WRITE
30819       (OTL_TRACE_FORMAT_DATETIME(s),
30820        "operator >>",
30821        "otl_datetime&")
30822       inc_next_ov();
30823     return *this;
30824   }
30825 
30826 #else
30827 
30828    otl_time0 tmp;
30829    (*this)>>tmp;
30830 #if defined(OTL_DEFAULT_DATETIME_NULL_TO_VAL)
30831   if((*this).is_null())
30832    s=OTL_DEFAULT_DATETIME_NULL_TO_VAL;
30833   else{
30834    s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
30835    s.month=tmp.month;
30836    s.day=tmp.day;
30837    s.hour=tmp.hour-1;
30838    s.minute=tmp.minute-1;
30839    s.second=tmp.second-1;
30840   }
30841 #else
30842   s.year=(OTL_SCAST(int,tmp.century)-100)*100+(OTL_SCAST(int,tmp.year)-100);
30843   s.month=tmp.month;
30844   s.day=tmp.day;
30845   s.hour=tmp.hour-1;
30846   s.minute=tmp.minute-1;
30847   s.second=tmp.second-1;
30848 #endif
30849   OTL_TRACE_WRITE
30850     (OTL_TRACE_FORMAT_DATETIME(s),
30851      "operator >>",
30852      "otl_datetime&");
30853   inc_next_ov();
30854   return *this;
30855 
30856 #endif
30857 
30858  }
30859 #endif
30860 
30861 #if (defined(OTL_ORA8I)||defined(OTL_ORA9I))&&defined(OTL_ORA_TIMESTAMP)
30862   // already declared
30863 #else
30864  otl_stream& operator<<(const otl_datetime& s)
30865    OTL_THROWS_OTL_EXCEPTION
30866  {
30867   last_oper_was_read_op=false;
30868   reset_end_marker();
30869 #if defined(OTL_ORA7_TIMESTAMP_TO_STRING)
30870     if(describe_next_in_var()->ftype==otl_var_char){
30871 #if defined(OTL_UNICODE)
30872       OTL_CHAR tmp_str[100];
30873 #elif defined(OTL_UNICODE) && defined(OTL_UNICODE_CHAR_TYPE)
30874       OTL_UNICODE_CHAR_TYPE tmp_str[100];
30875 #else
30876       char tmp_str[100];
30877 #endif
30878       OTL_ORA7_TIMESTAMP_TO_STRING(s,tmp_str);
30879       OTL_TRACE_READ
30880        (OTL_TRACE_FORMAT_DATETIME(s),
30881         "operator <<",
30882         "otl_datetime&");
30883      (*this)<<tmp_str;
30884      return *this;
30885    }else{
30886      otl_time0 tmp;
30887      tmp.year=OTL_SCAST(unsigned char, ((s.year%100)+100));
30888      tmp.century=OTL_SCAST(unsigned char, ((s.year/100)+100));
30889      tmp.month=OTL_SCAST(unsigned char, s.month);
30890      tmp.day=OTL_SCAST(unsigned char, s.day);
30891      tmp.hour=OTL_SCAST(unsigned char, (s.hour+1));
30892      tmp.minute=OTL_SCAST(unsigned char, (s.minute+1));
30893      tmp.second=OTL_SCAST(unsigned char, (s.second+1));
30894      OTL_TRACE_READ
30895        (OTL_TRACE_FORMAT_DATETIME(s),
30896         "operator <<",
30897         "otl_datetime&");
30898      (*this)<<tmp;
30899      inc_next_iov();
30900      return *this;
30901    }
30902 #else
30903   otl_time0 tmp;
30904   tmp.year=OTL_SCAST(unsigned char, ((s.year%100)+100));
30905   tmp.century=OTL_SCAST(unsigned char, ((s.year/100)+100));
30906   tmp.month=OTL_SCAST(unsigned char, s.month);
30907   tmp.day=OTL_SCAST(unsigned char, s.day);
30908   tmp.hour=OTL_SCAST(unsigned char, (s.hour+1));
30909   tmp.minute=OTL_SCAST(unsigned char, (s.minute+1));
30910   tmp.second=OTL_SCAST(unsigned char, (s.second+1));
30911   OTL_TRACE_READ
30912     (OTL_TRACE_FORMAT_DATETIME(s),
30913      "operator <<",
30914      "otl_datetime&");
30915   (*this)<<tmp;
30916   inc_next_iov();
30917   return *this;
30918 #endif
30919  }
30920 #endif
30921 
30922 #if !defined(OTL_UNICODE)
30923  OTL_ORA_COMMON_READ_STREAM& operator>>(char& c)
30924    OTL_THROWS_OTL_EXCEPTION
30925  {
30926    last_oper_was_read_op=true;
30927    switch(shell->stream_type){
30928    case otl_no_stream_type:
30929      break;
30930    case otl_inout_stream_type:
30931      last_eof_rc=(*io)->eof();
30932      (*io)->operator>>(c);
30933      break;
30934    case otl_select_stream_type:
30935      last_eof_rc=(*ss)->eof();
30936      (*ss)->operator>>(c);
30937      break;
30938    case otl_refcur_stream_type:
30939      last_eof_rc=(*ref_ss)->eof();
30940      (*ref_ss)->operator>>(c);
30941      break;
30942    }
30943 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
30944    if((*this).is_null())
30945      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
30946 #endif
30947    OTL_TRACE_WRITE("'"<<c<<"'","operator >>","char&")
30948    inc_next_ov();
30949    return *this;
30950  }
30951 #endif
30952 
30953  OTL_ORA_COMMON_READ_STREAM& operator>>(unsigned char& c)
30954    OTL_THROWS_OTL_EXCEPTION
30955  {
30956    last_oper_was_read_op=true;
30957    switch(shell->stream_type){
30958    case otl_no_stream_type:
30959      break;
30960    case otl_inout_stream_type:
30961      last_eof_rc=(*io)->eof();
30962      (*io)->operator>>(c);
30963      break;
30964    case otl_select_stream_type:
30965      last_eof_rc=(*ss)->eof();
30966      (*ss)->operator>>(c);
30967      break;
30968    case otl_refcur_stream_type:
30969      last_eof_rc=(*ref_ss)->eof();
30970      (*ref_ss)->operator>>(c);
30971      break;
30972    }
30973 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
30974    if((*this).is_null())
30975      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
30976 #endif
30977    OTL_TRACE_WRITE("'"<<c<<"'","operator >>","unsigned char&")
30978    inc_next_ov();
30979    return *this;
30980  }
30981 
30982 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
30983  OTL_ORA_COMMON_READ_STREAM& operator>>(OTL_STRING_CONTAINER& s)
30984    OTL_THROWS_OTL_EXCEPTION
30985  {
30986    last_oper_was_read_op=true;
30987    switch(shell->stream_type){
30988    case otl_no_stream_type:
30989      break;
30990    case otl_inout_stream_type:
30991      last_eof_rc=(*io)->eof();
30992      (*io)->operator>>(s);
30993      break;
30994    case otl_select_stream_type:
30995      last_eof_rc=(*ss)->eof();
30996      (*ss)->operator>>(s);
30997      break;
30998    case otl_refcur_stream_type:
30999      last_eof_rc=(*ref_ss)->eof();
31000      (*ref_ss)->operator>>(s);
31001      break;
31002    }
31003 
31004 #if defined(OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL)
31005    if((*this).is_null()){
31006      OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL(s);
31007    }
31008 #elif defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
31009    if((*this).is_null())
31010      s=OTL_DEFAULT_STRING_NULL_TO_VAL;
31011 #endif
31012 
31013    OTL_TRACE_WRITE("\""<<s<<"\"","operator >>","OTL_STRING_CONTAINER&")
31014    inc_next_ov();
31015    return *this;
31016  }
31017 #endif
31018 
31019 #if !defined(OTL_UNICODE)
31020  OTL_ORA_COMMON_READ_STREAM& operator>>(char* s)
31021    OTL_THROWS_OTL_EXCEPTION
31022  {
31023    last_oper_was_read_op=true;
31024    switch(shell->stream_type){
31025    case otl_no_stream_type:
31026      break;
31027    case otl_inout_stream_type:
31028      last_eof_rc=(*io)->eof();
31029      (*io)->operator>>(s);
31030      break;
31031    case otl_select_stream_type:
31032      last_eof_rc=(*ss)->eof();
31033      (*ss)->operator>>(s);
31034      break;
31035    case otl_refcur_stream_type:
31036      last_eof_rc=(*ref_ss)->eof();
31037      (*ref_ss)->operator>>(s);
31038      break;
31039    }
31040 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
31041    if((*this).is_null())
31042      otl_strcpy(OTL_RCAST(unsigned char*,s),
31043                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL));
31044 #endif
31045    OTL_TRACE_WRITE("\""<<s<<"\"","operator >>","char*")
31046    inc_next_ov();
31047    return *this;
31048  }
31049 #endif
31050 
31051 #if defined(OTL_UNICODE_STRING_TYPE)
31052  OTL_ORA_COMMON_READ_STREAM& operator>>(OTL_UNICODE_STRING_TYPE& s)
31053    OTL_THROWS_OTL_EXCEPTION
31054  {
31055    last_oper_was_read_op=true;
31056    switch(shell->stream_type){
31057    case otl_no_stream_type:
31058      break;
31059    case otl_inout_stream_type:
31060      last_eof_rc=(*io)->eof();
31061      (*io)->operator>>(s);
31062      break;
31063    case otl_select_stream_type:
31064      last_eof_rc=(*ss)->eof();
31065      (*ss)->operator>>(s);
31066      break;
31067    case otl_refcur_stream_type:
31068      last_eof_rc=(*ref_ss)->eof();
31069      (*ref_ss)->operator>>(s);
31070      break;
31071    }
31072 #if defined(OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL)
31073    if((*this).is_null()){
31074      OTL_USER_DEFINED_STRING_CLASS_DEFAULT_NULL_TO_VAL(s);
31075    }
31076 #elif defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
31077    if((*this).is_null())
31078      s=OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,
31079                  OTL_DEFAULT_STRING_NULL_TO_VAL);
31080 #endif
31081 
31082    OTL_TRACE_WRITE
31083      ("\""<<s.c_str()<<"\"",
31084       "operator >>",
31085       "OTL_UNICODE_STRING_TYPE&");
31086    inc_next_ov();
31087    return *this;
31088  }
31089 
31090  otl_stream& operator<<(const OTL_UNICODE_STRING_TYPE& s)
31091    OTL_THROWS_OTL_EXCEPTION
31092  {
31093    last_oper_was_read_op=false;
31094    reset_end_marker();
31095    OTL_TRACE_READ("\""<<s.c_str()<<"\"","operator <<","OTL_UNICODE_STRING_TYPE&");
31096    switch(shell->stream_type){
31097    case otl_no_stream_type:
31098      break;
31099    case otl_inout_stream_type:
31100      (*io)->operator<<(s);
31101      break;
31102    case otl_select_stream_type:
31103      (*ss)->operator<<(s);
31104      break;
31105    case otl_refcur_stream_type:
31106      (*ref_ss)->operator<<(s);
31107      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31108      break;
31109    }
31110    inc_next_iov();
31111    return *this;
31112  }
31113 
31114 #endif
31115 
31116  OTL_ORA_COMMON_READ_STREAM& operator>>(unsigned char* s)
31117    OTL_THROWS_OTL_EXCEPTION
31118  {
31119    last_oper_was_read_op=true;
31120    switch(shell->stream_type){
31121    case otl_no_stream_type:
31122      break;
31123    case otl_inout_stream_type:
31124      last_eof_rc=(*io)->eof();
31125      (*io)->operator>>(s);
31126      break;
31127    case otl_select_stream_type:
31128      last_eof_rc=(*ss)->eof();
31129      (*ss)->operator>>(s);
31130      break;
31131    case otl_refcur_stream_type:
31132      last_eof_rc=(*ref_ss)->eof();
31133      (*ref_ss)->operator>>(s);
31134      break;
31135    }
31136 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
31137    if((*this).is_null())
31138      otl_strcpy(OTL_RCAST(unsigned char*,s),
31139                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL)
31140                );
31141 #endif
31142 
31143 #if defined(OTL_UNICODE)
31144    OTL_TRACE_WRITE
31145      ("\""<<OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
31146       "operator >>",
31147       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*")
31148 #else
31149    OTL_TRACE_WRITE("\""<<s<<"\"","operator >>","unsigned char*")
31150 #endif
31151    inc_next_ov();
31152    return *this;
31153  }
31154 
31155 #if defined(OTL_UNICODE)
31156 
31157  OTL_ORA_COMMON_READ_STREAM& operator>>(OTL_UNICODE_CHAR_TYPE* s)
31158    OTL_THROWS_OTL_EXCEPTION
31159  {
31160    last_oper_was_read_op=true;
31161    switch(shell->stream_type){
31162    case otl_no_stream_type:
31163      break;
31164    case otl_inout_stream_type:
31165      last_eof_rc=(*io)->eof();
31166      (*io)->operator>>(OTL_RCAST(unsigned char*,s));
31167      break;
31168    case otl_select_stream_type:
31169      last_eof_rc=(*ss)->eof();
31170      (*ss)->operator>>(OTL_RCAST(unsigned char*,s));
31171      break;
31172    case otl_refcur_stream_type:
31173      last_eof_rc=(*ref_ss)->eof();
31174      (*ref_ss)->operator>>(OTL_RCAST(unsigned char*,s));
31175      break;
31176    }
31177 #if defined(OTL_DEFAULT_STRING_NULL_TO_VAL)
31178    if((*this).is_null())
31179      otl_strcpy(OTL_RCAST(unsigned char*,s),
31180                 OTL_RCAST(const unsigned char*,OTL_DEFAULT_STRING_NULL_TO_VAL));
31181 #endif
31182    OTL_TRACE_WRITE(OTL_RCAST(OTL_UNICODE_CHAR_TYPE*,s),
31183                    "operator >>",
31184                    OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*")
31185    inc_next_ov();
31186    return *this;
31187  }
31188 
31189  OTL_ORA_COMMON_READ_STREAM& operator>>(OTL_UNICODE_CHAR_TYPE& c)
31190    OTL_THROWS_OTL_EXCEPTION
31191  {
31192    OTL_UNICODE_CHAR_TYPE s[1024];
31193    last_oper_was_read_op=true;
31194    switch(shell->stream_type){
31195    case otl_no_stream_type:
31196      break;
31197    case otl_inout_stream_type:
31198      last_eof_rc=(*io)->eof();
31199      (*io)->operator>>(OTL_RCAST(unsigned char*,s));
31200      break;
31201    case otl_select_stream_type:
31202      last_eof_rc=(*ss)->eof();
31203      (*ss)->operator>>(OTL_RCAST(unsigned char*,s));
31204      break;
31205    case otl_refcur_stream_type:
31206      last_eof_rc=(*ref_ss)->eof();
31207      (*ref_ss)->operator>>(OTL_RCAST(unsigned char*,s));
31208      break;
31209    }
31210    c=s[0];
31211 #if defined(OTL_DEFAULT_CHAR_NULL_TO_VAL)
31212    if((*this).is_null())
31213      c=OTL_DEFAULT_CHAR_NULL_TO_VAL;
31214 #endif
31215    OTL_TRACE_WRITE(c,"operator >>",
31216                    OTL_UNICODE_CHAR_TYPE_TRACE_NAME "")
31217    inc_next_ov();
31218    return *this;
31219  }
31220 
31221 #endif
31222 
31223 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
31224     !defined(OTL_BIGINT_TO_STR))
31225  OTL_ORA_COMMON_READ_STREAM& operator>>(OTL_BIGINT& n)
31226    OTL_THROWS_OTL_EXCEPTION
31227  {
31228    last_oper_was_read_op=true;
31229    switch(shell->stream_type){
31230    case otl_no_stream_type:
31231      break;
31232    case otl_inout_stream_type:
31233      last_eof_rc=(*io)->eof();
31234      (*io)->operator>>(n);
31235      break;
31236    case otl_select_stream_type:
31237      last_eof_rc=(*ss)->eof();
31238 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31239      (*ss)->operator>>(n);
31240 #else
31241      (*ss)->operator>><OTL_BIGINT,otl_var_bigint>(n);
31242 #endif
31243      break;
31244    case otl_refcur_stream_type:
31245      last_eof_rc=(*ref_ss)->eof();
31246 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31247      (*ref_ss)->operator>>(n);
31248 #else
31249      (*ref_ss)->operator>><OTL_BIGINT,otl_var_bigint>(n);
31250 #endif
31251      break;
31252    }
31253 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31254    if((*this).is_null())
31255      n=OTL_SCAST(int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31256 #endif
31257    OTL_TRACE_WRITE(n,"operator >>","OTL_BIGINT&")
31258    inc_next_ov();
31259    return *this;
31260  }
31261 
31262 #endif
31263 
31264  OTL_ORA_COMMON_READ_STREAM& operator>>(int& n)
31265    OTL_THROWS_OTL_EXCEPTION
31266  {
31267    last_oper_was_read_op=true;
31268    switch(shell->stream_type){
31269    case otl_no_stream_type:
31270      break;
31271    case otl_inout_stream_type:
31272      last_eof_rc=(*io)->eof();
31273      (*io)->operator>>(n);
31274      break;
31275    case otl_select_stream_type:
31276      last_eof_rc=(*ss)->eof();
31277 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31278      (*ss)->operator>>(n);
31279 #else
31280      (*ss)->operator>><int,otl_var_int>(n);
31281 #endif
31282      break;
31283    case otl_refcur_stream_type:
31284      last_eof_rc=(*ref_ss)->eof();
31285 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31286      (*ref_ss)->operator>>(n);
31287 #else
31288      (*ref_ss)->operator>><int,otl_var_int>(n);
31289 #endif
31290      break;
31291    }
31292 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31293    if((*this).is_null())
31294      n=OTL_SCAST(int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31295 #endif
31296    OTL_TRACE_WRITE(n,"operator >>","int&")
31297    inc_next_ov();
31298    return *this;
31299  }
31300 
31301  OTL_ORA_COMMON_READ_STREAM& operator>>(unsigned& u)
31302    OTL_THROWS_OTL_EXCEPTION
31303  {
31304    last_oper_was_read_op=true;
31305    switch(shell->stream_type){
31306    case otl_no_stream_type:
31307      break;
31308    case otl_inout_stream_type:
31309      last_eof_rc=(*io)->eof();
31310      (*io)->operator>>(u);
31311      break;
31312    case otl_select_stream_type:
31313      last_eof_rc=(*ss)->eof();
31314 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31315      (*ss)->operator>>(u);
31316 #else
31317      (*ss)->operator>><unsigned,otl_var_unsigned_int>(u);
31318 #endif
31319      break;
31320    case otl_refcur_stream_type:
31321      last_eof_rc=(*ref_ss)->eof();
31322 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31323      (*ref_ss)->operator>>(u);
31324 #else
31325      (*ref_ss)->operator>><unsigned,otl_var_unsigned_int>(u);
31326 #endif
31327      break;
31328    }
31329 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31330    if((*this).is_null())
31331      u=OTL_SCAST(unsigned int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31332 #endif
31333    OTL_TRACE_WRITE(u,"operator >>","unsigned&")
31334    inc_next_ov();
31335    return *this;
31336  }
31337 
31338  OTL_ORA_COMMON_READ_STREAM& operator>>(short& sh)
31339    OTL_THROWS_OTL_EXCEPTION
31340  {
31341    last_oper_was_read_op=true;
31342    switch(shell->stream_type){
31343    case otl_no_stream_type:
31344      break;
31345    case otl_inout_stream_type:
31346      last_eof_rc=(*io)->eof();
31347      (*io)->operator>>(sh);
31348      break;
31349    case otl_select_stream_type:
31350      last_eof_rc=(*ss)->eof();
31351 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31352      (*ss)->operator>>(sh);
31353 #else
31354      (*ss)->operator>><short,otl_var_short>(sh);
31355 #endif
31356      break;
31357    case otl_refcur_stream_type:
31358      last_eof_rc=(*ref_ss)->eof();
31359 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31360      (*ref_ss)->operator>>(sh);
31361 #else
31362      (*ref_ss)->operator>><short,otl_var_short>(sh);
31363 #endif
31364      break;
31365    }
31366 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31367    if((*this).is_null())
31368      sh=OTL_SCAST(short int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31369 #endif
31370    OTL_TRACE_WRITE(sh,"operator >>","short int&")
31371    inc_next_ov();
31372    return *this;
31373  }
31374 
31375  OTL_ORA_COMMON_READ_STREAM& operator>>(long int& l)
31376    OTL_THROWS_OTL_EXCEPTION
31377  {
31378    last_oper_was_read_op=true;
31379    switch(shell->stream_type){
31380    case otl_no_stream_type:
31381      break;
31382    case otl_inout_stream_type:
31383      last_eof_rc=(*io)->eof();
31384      (*io)->operator>>(l);
31385      break;
31386    case otl_select_stream_type:
31387      last_eof_rc=(*ss)->eof();
31388 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31389      (*ss)->operator>>(l);
31390 #else
31391      (*ss)->operator>><long,otl_var_long_int>(l);
31392 #endif
31393      break;
31394    case otl_refcur_stream_type:
31395      last_eof_rc=(*ref_ss)->eof();
31396 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31397      (*ref_ss)->operator>>(l);
31398 #else
31399      (*ref_ss)->operator>><long,otl_var_long_int>(l);
31400 #endif
31401      break;
31402    }
31403 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31404    if((*this).is_null())
31405      l=OTL_SCAST(long int,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31406 #endif
31407    OTL_TRACE_WRITE(l,"operator >>","long int&")
31408    inc_next_ov();
31409    return *this;
31410  }
31411 
31412  OTL_ORA_COMMON_READ_STREAM& operator>>(float& f)
31413    OTL_THROWS_OTL_EXCEPTION
31414  {
31415    last_oper_was_read_op=true;
31416    switch(shell->stream_type){
31417    case otl_no_stream_type:
31418      break;
31419    case otl_inout_stream_type:
31420      last_eof_rc=(*io)->eof();
31421      (*io)->operator>>(f);
31422      break;
31423    case otl_select_stream_type:
31424      last_eof_rc=(*ss)->eof();
31425 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31426      (*ss)->operator>>(f);
31427 #else
31428      (*ss)->operator>><float,otl_var_float>(f);
31429 #endif
31430      break;
31431    case otl_refcur_stream_type:
31432      last_eof_rc=(*ref_ss)->eof();
31433 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31434      (*ref_ss)->operator>>(f);
31435 #else
31436      (*ref_ss)->operator>><float,otl_var_float>(f);
31437 #endif
31438      break;
31439    }
31440 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31441    if((*this).is_null())
31442      f=OTL_SCAST(float,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31443 #endif
31444    OTL_TRACE_WRITE(f,"operator >>","float&")
31445    inc_next_ov();
31446    return *this;
31447  }
31448 
31449  OTL_ORA_COMMON_READ_STREAM& operator>>(double& d)
31450    OTL_THROWS_OTL_EXCEPTION
31451  {
31452    last_oper_was_read_op=true;
31453    switch(shell->stream_type){
31454    case otl_no_stream_type:
31455      break;
31456    case otl_inout_stream_type:
31457      last_eof_rc=(*io)->eof();
31458      (*io)->operator>>(d);
31459      break;
31460    case otl_select_stream_type:
31461      last_eof_rc=(*ss)->eof();
31462 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31463      (*ss)->operator>>(d);
31464 #else
31465      (*ss)->operator>><double,otl_var_double>(d);
31466 #endif
31467      break;
31468    case otl_refcur_stream_type:
31469      last_eof_rc=(*ref_ss)->eof();
31470 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31471      (*ref_ss)->operator>>(d);
31472 #else
31473      (*ref_ss)->operator>><double,otl_var_double>(d);
31474 #endif
31475      break;
31476    }
31477 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
31478    if((*this).is_null())
31479    d=OTL_SCAST(double,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
31480 #endif
31481    OTL_TRACE_WRITE(d,"operator >>","double&")
31482    inc_next_ov();
31483    return *this;
31484  }
31485 
31486  OTL_ORA_COMMON_READ_STREAM& operator>>(otl_long_string& s)
31487    OTL_THROWS_OTL_EXCEPTION
31488  {
31489    last_oper_was_read_op=true;
31490    switch(shell->stream_type){
31491    case otl_no_stream_type:
31492      break;
31493    case otl_inout_stream_type:
31494      (*io)->operator>>(s);
31495      break;
31496    case otl_select_stream_type:
31497      (*ss)->operator>>(s);
31498      break;
31499    case otl_refcur_stream_type:
31500      (*ref_ss)->operator>>(s);
31501      break;
31502    }
31503    OTL_TRACE_WRITE(" len="<<s.len(),"operator >>","otl_long_string&")
31504    inc_next_ov();
31505    return *this;
31506  }
31507 
31508  OTL_ORA_COMMON_READ_STREAM& operator>>(otl_lob_stream& s)
31509    OTL_THROWS_OTL_EXCEPTION
31510  {
31511    last_oper_was_read_op=true;
31512    switch(shell->stream_type){
31513    case otl_no_stream_type:
31514      break;
31515    case otl_inout_stream_type:
31516      last_eof_rc=(*io)->eof();
31517      (*io)->operator>>(s);
31518      break;
31519    case otl_select_stream_type:
31520      last_eof_rc=(*ss)->eof();
31521      (*ss)->operator>>(s);
31522      break;
31523    case otl_refcur_stream_type:
31524      last_eof_rc=(*ref_ss)->eof();
31525      (*ref_ss)->operator>>(s);
31526      break;
31527    }
31528    shell->lob_stream_flag=true;
31529    OTL_TRACE_WRITE(" lob stream","operator >>","otl_lob_stream&")
31530    inc_next_ov();
31531    return *this;
31532  }
31533 
31534 #if !defined(OTL_UNICODE)
31535  otl_stream& operator<<(const char c)
31536    OTL_THROWS_OTL_EXCEPTION
31537  {
31538    last_oper_was_read_op=false;
31539    reset_end_marker();
31540    OTL_TRACE_READ("'"<<c<<"'","operator <<","char");
31541    switch(shell->stream_type){
31542    case otl_no_stream_type:
31543      break;
31544    case otl_inout_stream_type:
31545      (*io)->operator<<(c);
31546      break;
31547    case otl_select_stream_type:
31548      (*ss)->operator<<(c);
31549      break;
31550    case otl_refcur_stream_type:
31551      (*ref_ss)->operator<<(c);
31552      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31553      break;
31554    }
31555    inc_next_iov();
31556    return *this;
31557  }
31558 #endif
31559 
31560  otl_stream& operator<<(const unsigned char c)
31561    OTL_THROWS_OTL_EXCEPTION
31562  {
31563    last_oper_was_read_op=false;
31564    reset_end_marker();
31565    OTL_TRACE_READ("'"<<c<<"'","operator <<","unsigned char");
31566    switch(shell->stream_type){
31567    case otl_no_stream_type:
31568      break;
31569    case otl_inout_stream_type:
31570      (*io)->operator<<(c);
31571      break;
31572    case otl_select_stream_type:
31573      (*ss)->operator<<(c);
31574      break;
31575    case otl_refcur_stream_type:
31576      (*ref_ss)->operator<<(c);
31577      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31578      break;
31579    }
31580    inc_next_iov();
31581    return *this;
31582  }
31583 
31584 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
31585  otl_stream& operator<<(const OTL_STRING_CONTAINER& s)
31586    OTL_THROWS_OTL_EXCEPTION
31587  {
31588    last_oper_was_read_op=false;
31589    reset_end_marker();
31590    OTL_TRACE_READ("\""<<s<<"\"","operator <<","OTL_STRING_CONTAINER&");
31591    switch(shell->stream_type){
31592    case otl_no_stream_type:
31593      break;
31594    case otl_inout_stream_type:
31595      (*io)->operator<<(s);
31596      break;
31597    case otl_select_stream_type:
31598      (*ss)->operator<<(s);
31599      break;
31600    case otl_refcur_stream_type:
31601      (*ref_ss)->operator<<(s);
31602      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31603      break;
31604    }
31605    inc_next_iov();
31606    return *this;
31607  }
31608 #endif
31609 
31610 #if !defined(OTL_UNICODE)
31611  otl_stream& operator<<(const char* s)
31612    OTL_THROWS_OTL_EXCEPTION
31613  {
31614    last_oper_was_read_op=false;
31615    reset_end_marker();
31616    OTL_TRACE_READ("\""<<s<<"\"","operator <<","char*");
31617    switch(shell->stream_type){
31618    case otl_no_stream_type:
31619      break;
31620    case otl_inout_stream_type:
31621      (*io)->operator<<(s);
31622      break;
31623    case otl_select_stream_type:
31624      (*ss)->operator<<(s);
31625      break;
31626    case otl_refcur_stream_type:
31627      (*ref_ss)->operator<<(s);
31628      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31629      break;
31630    }
31631    inc_next_iov();
31632    return *this;
31633  }
31634 #endif
31635 
31636  otl_stream& operator<<(const unsigned char* s)
31637    OTL_THROWS_OTL_EXCEPTION
31638  {
31639    last_oper_was_read_op=false;
31640    reset_end_marker();
31641 #if defined(OTL_UNICODE)
31642    OTL_TRACE_READ
31643      ("\""<<OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
31644       "operator <<",
31645       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*");
31646 #else
31647    OTL_TRACE_READ("\""<<s<<"\"","operator <<","unsigned char*");
31648 #endif
31649    switch(shell->stream_type){
31650    case otl_no_stream_type:
31651      break;
31652    case otl_inout_stream_type:
31653      (*io)->operator<<(s);
31654      break;
31655    case otl_select_stream_type:
31656      (*ss)->operator<<(s);
31657      break;
31658    case otl_refcur_stream_type:
31659      (*ref_ss)->operator<<(s);
31660      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31661      break;
31662    }
31663    inc_next_iov();
31664    return *this;
31665  }
31666 
31667 #if defined(OTL_UNICODE)
31668 
31669  otl_stream& operator<<(const OTL_UNICODE_CHAR_TYPE* s)
31670    OTL_THROWS_OTL_EXCEPTION
31671  {
31672    last_oper_was_read_op=false;
31673    reset_end_marker();
31674    OTL_TRACE_READ
31675      ("\""<<OTL_RCAST(const OTL_UNICODE_CHAR_TYPE*,s)<<"\"",
31676       "operator <<",
31677       OTL_UNICODE_CHAR_TYPE_TRACE_NAME "*");
31678    switch(shell->stream_type){
31679    case otl_no_stream_type:
31680      break;
31681    case otl_inout_stream_type:
31682      (*io)->operator<<(OTL_RCAST(const unsigned char*,s));
31683      break;
31684    case otl_select_stream_type:
31685      (*ss)->operator<<(OTL_RCAST(const unsigned char*,s));
31686      break;
31687    case otl_refcur_stream_type:
31688      (*ref_ss)->operator<<(OTL_RCAST(const unsigned char*,s));
31689      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31690      break;
31691    }
31692    inc_next_iov();
31693    return *this;
31694  }
31695 
31696  otl_stream& operator<<(const OTL_UNICODE_CHAR_TYPE c)
31697    OTL_THROWS_OTL_EXCEPTION
31698  {
31699    OTL_UNICODE_CHAR_TYPE s[2];
31700    s[0]=c;
31701    s[1]=0;
31702    (*this)<<s;
31703    return *this;
31704  }
31705 
31706 #endif
31707 
31708 #if defined(OTL_BIGINT) && (defined(OTL_ORA11G_R2)&&!defined(OTL_STR_TO_BIGINT)&&\
31709     !defined(OTL_BIGINT_TO_STR))
31710  otl_stream& operator<<(const OTL_BIGINT n)
31711    OTL_THROWS_OTL_EXCEPTION
31712  {
31713    last_oper_was_read_op=false;
31714    reset_end_marker();
31715    OTL_TRACE_READ(n,"operator <<","OTL_BIGINT");
31716    switch(shell->stream_type){
31717    case otl_no_stream_type:
31718      break;
31719    case otl_inout_stream_type:
31720      (*io)->operator<<(n);
31721      break;
31722    case otl_select_stream_type:
31723 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31724      (*ss)->operator<<(n);
31725 #else
31726      (*ss)->operator<<<OTL_BIGINT,otl_var_bigint>(n);
31727 #endif
31728      break;
31729    case otl_refcur_stream_type:
31730 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31731     (*ref_ss)->operator<<(n);
31732 #else
31733      (*ref_ss)->operator<<<OTL_BIGINT,otl_var_bigint>(n);
31734 #endif
31735      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31736      break;
31737    }
31738    inc_next_iov();
31739    return *this;
31740  }
31741 #endif
31742 
31743  otl_stream& operator<<(const int n)
31744    OTL_THROWS_OTL_EXCEPTION
31745  {
31746    last_oper_was_read_op=false;
31747    reset_end_marker();
31748    OTL_TRACE_READ(n,"operator <<","int");
31749    switch(shell->stream_type){
31750    case otl_no_stream_type:
31751      break;
31752    case otl_inout_stream_type:
31753      (*io)->operator<<(n);
31754      break;
31755    case otl_select_stream_type:
31756 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31757      (*ss)->operator<<(n);
31758 #else
31759      (*ss)->operator<<<int,otl_var_int>(n);
31760 #endif
31761      break;
31762    case otl_refcur_stream_type:
31763 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31764      (*ref_ss)->operator<<(n);
31765 #else
31766      (*ref_ss)->operator<<<int,otl_var_int>(n);
31767 #endif
31768      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31769      break;
31770    }
31771    inc_next_iov();
31772    return *this;
31773  }
31774 
31775  otl_stream& operator<<(const unsigned u)
31776    OTL_THROWS_OTL_EXCEPTION
31777  {
31778    last_oper_was_read_op=false;
31779    reset_end_marker();
31780    OTL_TRACE_READ(u,"operator <<","unsigned");
31781    switch(shell->stream_type){
31782    case otl_no_stream_type:
31783      break;
31784    case otl_inout_stream_type:
31785      (*io)->operator<<(u);
31786      break;
31787    case otl_select_stream_type:
31788 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31789      (*ss)->operator<<(u);
31790 #else
31791      (*ss)->operator<<<unsigned,otl_var_unsigned_int>(u);
31792 #endif
31793      break;
31794    case otl_refcur_stream_type:
31795 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31796      (*ref_ss)->operator<<(u);
31797 #else
31798      (*ref_ss)->operator<<<unsigned,otl_var_unsigned_int>(u);
31799 #endif
31800      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31801      break;
31802    }
31803    inc_next_iov();
31804    return *this;
31805  }
31806 
31807  otl_stream& operator<<(const short sh)
31808    OTL_THROWS_OTL_EXCEPTION
31809  {
31810    last_oper_was_read_op=false;
31811    reset_end_marker();
31812    OTL_TRACE_READ(sh,"operator <<","short int");
31813    switch(shell->stream_type){
31814    case otl_no_stream_type:
31815      break;
31816    case otl_inout_stream_type:
31817      (*io)->operator<<(sh);
31818      break;
31819    case otl_select_stream_type:
31820 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31821      (*ss)->operator<<(sh);
31822 #else
31823      (*ss)->operator<<<short,otl_var_short>(sh);
31824 #endif
31825      break;
31826    case otl_refcur_stream_type:
31827 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31828      (*ref_ss)->operator<<(sh);
31829 #else
31830      (*ref_ss)->operator<<<short,otl_var_short>(sh);
31831 #endif
31832      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31833      break;
31834    }
31835   inc_next_iov();
31836   return *this;
31837  }
31838 
31839  otl_stream& operator<<(const long int l)
31840    OTL_THROWS_OTL_EXCEPTION
31841  {
31842    last_oper_was_read_op=false;
31843    reset_end_marker();
31844    OTL_TRACE_READ(l,"operator <<","long int");
31845    switch(shell->stream_type){
31846    case otl_no_stream_type:
31847      break;
31848    case otl_inout_stream_type:
31849      (*io)->operator<<(l);
31850      break;
31851    case otl_select_stream_type:
31852 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31853      (*ss)->operator<<(l);
31854 #else
31855      (*ss)->operator<<<long,otl_var_long_int>(l);
31856 #endif
31857      break;
31858    case otl_refcur_stream_type:
31859 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31860      (*ref_ss)->operator<<(l);
31861 #else
31862      (*ref_ss)->operator<<<long,otl_var_long_int>(l);
31863 #endif
31864      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31865      break;
31866    }
31867    inc_next_iov();
31868    return *this;
31869  }
31870 
31871  otl_stream& operator<<(const float f)
31872    OTL_THROWS_OTL_EXCEPTION
31873  {
31874    last_oper_was_read_op=false;
31875    reset_end_marker();
31876    OTL_TRACE_READ(f,"operator <<","float");
31877    switch(shell->stream_type){
31878    case otl_no_stream_type:
31879      break;
31880    case otl_inout_stream_type:
31881      (*io)->operator<<(f);
31882      break;
31883    case otl_select_stream_type:
31884 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31885      (*ss)->operator<<(f);
31886 #else
31887      (*ss)->operator<<<float,otl_var_float>(f);
31888 #endif
31889      break;
31890    case otl_refcur_stream_type:
31891 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31892      (*ref_ss)->operator<<(f);
31893 #else
31894      (*ref_ss)->operator<<<float,otl_var_float>(f);
31895 #endif
31896      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31897      break;
31898    }
31899   inc_next_iov();
31900   return *this;
31901  }
31902 
31903  otl_stream& operator<<(const double d)
31904    OTL_THROWS_OTL_EXCEPTION
31905  {
31906    last_oper_was_read_op=false;
31907    reset_end_marker();
31908    OTL_TRACE_READ(d,"operator <<","double");
31909    switch(shell->stream_type){
31910    case otl_no_stream_type:
31911      break;
31912    case otl_inout_stream_type:
31913      (*io)->operator<<(d);
31914      break;
31915    case otl_select_stream_type:
31916 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31917      (*ss)->operator<<(d);
31918 #else
31919      (*ss)->operator<<<double,otl_var_double>(d);
31920 #endif
31921      break;
31922    case otl_refcur_stream_type:
31923 #if defined(OTL_NO_TMPL_MEMBER_FUNC_SUPPORT)
31924      (*ref_ss)->operator<<(d);
31925 #else
31926      (*ref_ss)->operator<<<double,otl_var_double>(d);
31927 #endif
31928      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31929      break;
31930    }
31931    inc_next_iov();
31932    return *this;
31933  }
31934 
31935   otl_stream& operator<<(const otl_null& n)
31936     OTL_THROWS_OTL_EXCEPTION
31937  {
31938    last_oper_was_read_op=false;
31939    reset_end_marker();
31940    OTL_TRACE_READ("NULL","operator <<","otl_null&");
31941    switch(shell->stream_type){
31942    case otl_no_stream_type:
31943      break;
31944    case otl_inout_stream_type:
31945      (*io)->operator<<(n);
31946      break;
31947    case otl_select_stream_type:
31948      (*ss)->operator<<(n);
31949      break;
31950    case otl_refcur_stream_type:
31951      (*ref_ss)->operator<<(n);
31952      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31953      break;
31954    }
31955    inc_next_iov();
31956    return *this;
31957  }
31958 
31959  otl_stream& operator<<(const otl_long_string& d)
31960    OTL_THROWS_OTL_EXCEPTION
31961  {
31962    last_oper_was_read_op=false;
31963    reset_end_marker();
31964    OTL_TRACE_READ(" len="<<d.len(),"operator <<","otl_long_string&");
31965    switch(shell->stream_type){
31966    case otl_no_stream_type:
31967      break;
31968    case otl_inout_stream_type:
31969      (*io)->operator<<(d);
31970      break;
31971    case otl_select_stream_type:
31972      (*ss)->operator<<(d);
31973      break;
31974    case otl_refcur_stream_type:
31975      (*ref_ss)->operator<<(d);
31976      if(!(*ov)&&(*ref_ss)->get_sl()) create_var_desc();
31977      break;
31978    }
31979    inc_next_iov();
31980    return *this;
31981  }
31982 
31983 private:
31984 
31985   otl_stream& operator=(const otl_stream&)
31986   {
31987     return *this;
31988   }
31989 
31990   otl_stream(const otl_stream&):
31991  #if defined(OTL_ORA_DECLARE_COMMON_READ_STREAM_INTERFACE)
31992    otl_read_stream_interface(),
31993 #endif
31994    shell(0),
31995    shell_pt(),
31996    connected(0),
31997    ref_ss(0),
31998    ss(0),
31999    io(0),
32000    adb(0),
32001    auto_commit_flag(0),
32002    iov(0),
32003    iov_len(0),
32004    next_iov_ndx(0),
32005    ov(0),
32006    ov_len(0),
32007    next_ov_ndx(0),
32008    end_marker(0),
32009    oper_int_called(0),
32010    last_eof_rc(0),
32011    last_oper_was_read_op(false),
32012    override(0),
32013    buf_size_(0)
32014   {
32015   }
32016 
32017 #if !defined(OTL_STREAM_NO_PRIVATE_BOOL_OPERATORS)
32018   otl_stream& operator>>(bool&)
32019     OTL_NO_THROW
32020   {
32021    return *this;
32022   }
32023 
32024   otl_stream& operator<<(const bool)
32025     OTL_NO_THROW
32026   {
32027    return *this;
32028   }
32029 
32030 #endif
32031 
32032 #if !defined(OTL_STREAM_NO_PRIVATE_UNSIGNED_LONG_OPERATORS)
32033   otl_stream& operator>>(unsigned long int&)
32034     OTL_NO_THROW
32035   {
32036    return *this;
32037   }
32038 
32039   otl_stream& operator<<(const unsigned long int)
32040     OTL_NO_THROW
32041   {
32042    return *this;
32043   }
32044 #endif
32045 
32046 };
32047 
32048 #if defined(OTL_ORA_SUBSCRIBE)
32049 #if !defined(OTL_ORA_OCI_ENV_CREATE)
32050 #error OTL_ORA_SUBSCRIBE requires #define OTL_ORA_OCI_ENV_CREATE to be enabled
32051 #endif
32052 #if !defined(OTL_ORA_OCI_ENV_CREATE_MODE)
32053 #error OTL_ORA_SUBSCRIBE requires #define OTL_ORA_OCI_ENV_CREATE_MODE to be \
32054 enabled and to have OCI_THREADED|OCI_OBJECT|OCI_EVENTS
32055 #endif
32056 
32057 class otl_subscriber{
32058 public:
32059 
32060   otl_subscriber(otl_connect* adb=0):
32061     db(adb),
32062     subscrhp(0)
32063   {
32064   }
32065 
32066   virtual ~otl_subscriber(void)
32067   {
32068     unsubscribe();
32069   }
32070 
32071   void subscribe(const char *name=0,int port=0,int timeout=1800)
32072   {
32073     if(subscrhp) unsubscribe();
32074     if(!db||(db&&!db->connected))
32075       throw otl_exception
32076         (otl_error_msg_32,
32077          otl_error_code_32);
32078 
32079     OCIEnv *envhp=db->get_connect_struct().get_envhp();
32080     OCIError *errhp=db->get_connect_struct().get_errhp();
32081     OCISvcCtx *svchp=db->get_connect_struct().get_svchp();
32082 
32083     if(port)
32084       check(OCIAttrSet(OTL_RCAST(dvoid*,envhp),
32085                        OTL_SCAST(ub4,OCI_HTYPE_ENV),
32086                        OTL_RCAST(dvoid*,&port),
32087                        0,
32088                        OCI_ATTR_SUBSCR_PORTNO,
32089                        errhp));
32090 
32091     OCISubscription** temp_subscrhp=&subscrhp;
32092     check(OCIHandleAlloc(OTL_RCAST(dvoid*,envhp),
32093                          OTL_RCAST(dvoid**,temp_subscrhp),
32094                          OCI_HTYPE_SUBSCRIPTION,
32095                          OTL_SCAST(size_t,0),
32096                          OTL_RCAST(dvoid**,0)));
32097 
32098     if(name && *name)
32099       check(OCIAttrSet(subscrhp,
32100                        OCI_HTYPE_SUBSCRIPTION,
32101                        OTL_RCAST(void*,OTL_CCAST(char*,name)),
32102                        OTL_SCAST(ub4,strlen(name)),
32103                        OCI_ATTR_SUBSCR_NAME,
32104                        errhp));
32105 
32106     ub4 nspace = OCI_SUBSCR_NAMESPACE_DBCHANGE;
32107     check(OCIAttrSet(subscrhp,
32108                      OCI_HTYPE_SUBSCRIPTION,
32109                      OTL_RCAST(dvoid*,&nspace),
32110                      sizeof(ub4),
32111                      OCI_ATTR_SUBSCR_NAMESPACE,
32112                      errhp));
32113 
32114     check(OCIAttrSet(subscrhp,
32115                      OCI_HTYPE_SUBSCRIPTION,
32116 #if defined(__GNUC__) && (__GNUC__<4)
32117                      (void*)common_notification_callback,
32118 #else
32119                      OTL_RCAST(void*,common_notification_callback),
32120 #endif
32121                      0,
32122                      OCI_ATTR_SUBSCR_CALLBACK,
32123                      errhp));
32124 
32125     int rowids_needed=1;
32126     check(OCIAttrSet(subscrhp,
32127                      OCI_HTYPE_SUBSCRIPTION,
32128                      OTL_RCAST(dvoid*,&rowids_needed),
32129                      sizeof(ub4),
32130                      OCI_ATTR_CHNF_ROWIDS,
32131                      errhp));
32132 
32133     check(OCIAttrSet(subscrhp,
32134                      OTL_SCAST(ub4,OCI_HTYPE_SUBSCRIPTION),
32135                      OTL_RCAST(dvoid*,this),
32136                      0,
32137                      OCI_ATTR_SUBSCR_CTX,
32138                      errhp));
32139 
32140     if(timeout)
32141       check(OCIAttrSet(subscrhp,
32142                        OCI_HTYPE_SUBSCRIPTION,
32143                        OTL_RCAST(dvoid*,&timeout),
32144                        0,
32145                        OCI_ATTR_SUBSCR_TIMEOUT,
32146                        errhp));
32147 
32148     check(OCISubscriptionRegister(svchp,&subscrhp,1,errhp,OCI_DEFAULT));
32149 
32150   }
32151 
32152   void unsubscribe(void)
32153   {
32154     if(!subscrhp) return;
32155     if(!db||(db&&!db->connected))
32156       throw otl_exception
32157         (otl_error_msg_32,
32158          otl_error_code_32);
32159     OCIError *errhp=db->get_connect_struct().get_errhp();
32160     OCISvcCtx *svchp=db->get_connect_struct().get_svchp();
32161     OCISubscriptionUnRegister(svchp,subscrhp,errhp,OCI_DEFAULT);
32162     OCIHandleFree(OTL_RCAST(dvoid*,subscrhp),OCI_HTYPE_SUBSCRIPTION);
32163     subscrhp=0;
32164   }
32165 
32166   void associate_table(const char *table_name)
32167   {
32168     if(!db||(db&&!db->connected))
32169       throw otl_exception
32170         (otl_error_msg_32,
32171          otl_error_code_32);
32172     char sql_stmt[1024];
32173     OTL_STRCPY_S(sql_stmt,sizeof(sql_stmt),"select :i<int> from ");
32174     OTL_STRCAT_S(sql_stmt,sizeof(sql_stmt),table_name);
32175     int arg=0;
32176     otl_stream s(1,sql_stmt,*db);
32177     if(!s.get_shell() || !s.get_shell()->ss)
32178       throw otl_exception(db->get_connect_struct(),sql_stmt);
32179     OCIError *errhp=db->get_connect_struct().get_errhp();
32180     OCIStmt *stmthp=s.get_shell()->ss->get_cursor_struct().cda;
32181     check(OCIAttrSet(stmthp,
32182                      OCI_HTYPE_STMT,
32183                      subscrhp,
32184                      0,
32185                      OCI_ATTR_CHNF_REGHANDLE,
32186                    errhp));
32187     s<<arg;
32188   }
32189 
32190   void associate_query(const char *stmt)
32191   {
32192     if(!db||(db&&!db->connected))
32193       throw otl_exception
32194         (otl_error_msg_32,
32195          otl_error_code_32);
32196     otl_stream s(1,stmt,*db);
32197     if(!s.get_shell() || !s.get_shell()->ss)
32198       throw otl_exception(db->get_connect_struct(),stmt);
32199     OCIError *errhp=db->get_connect_struct().get_errhp();
32200     OCIStmt *stmthp=s.get_shell()->ss->get_cursor_struct().cda;
32201     check(OCIAttrSet(stmthp,
32202                      OCI_HTYPE_STMT,
32203                      subscrhp,
32204                      0,
32205                      OCI_ATTR_CHNF_REGHANDLE,
32206                    errhp));
32207     s<<0;
32208   }
32209 
32210 protected:
32211 
32212   void check(ub4 ret_code)
32213   {
32214     if(ret_code!=OCI_SUCCESS)
32215       throw otl_exception(db->get_connect_struct());
32216   }
32217 
32218   virtual void OnException(OTL_CONST_EXCEPTION otl_exception& e) = 0;
32219   virtual void OnDeRegistration(void) = 0;
32220 
32221   //--- DB events:
32222   virtual void OnStartup(void) = 0;
32223   virtual void OnInstanceShutdown(void) = 0;
32224   virtual void OnAnyInstanceShutdown(void) = 0;
32225 
32226   //--- Table events:
32227   virtual void OnTableInvalidate(text *table_name) = 0;
32228   virtual void OnTableAlter(text *table_name, bool all_rows=false) = 0;
32229   virtual void OnTableDrop(text *table_name, bool all_rows=false) = 0;
32230   virtual void OnTableChange(text *table_name, bool all_rows=false) = 0;
32231 
32232   //--- Row events:
32233   virtual void OnRowInsert( text *table_name, text *row_id ) = 0;
32234   virtual void OnRowUpdate( text *table_name, text *row_id ) = 0;
32235   virtual void OnRowDelete( text *table_name, text *row_id ) = 0;
32236 
32237 protected:
32238   otl_connect* db;
32239 
32240 private:
32241 
32242   OCISubscription *subscrhp;
32243 
32244   void notification_callback
32245   (dvoid* /*payload*/, ub4 /*paylen*/, dvoid *desc, ub4 /*mode*/)
32246   {
32247     if(!db||(db&&!db->connected))
32248       return;
32249     ub4 num_rows = 0;
32250     OCIColl *row_changes=0;
32251     dvoid *row_desc, **row_descp;
32252     dvoid*** temp_row_descp=&row_descp;
32253     text *row_id;
32254     ub4 rowid_size;
32255     unsigned int j;
32256     try{
32257       OCIEnv *envhp=db->get_connect_struct().get_envhp();
32258       OCIError *errhp=db->get_connect_struct().get_errhp();
32259 
32260       //----------------
32261       ub4 notify_type;
32262       check(OCIAttrGet(desc,
32263                        OCI_DTYPE_CHDES,
32264                        &notify_type,
32265                        0,
32266                        OCI_ATTR_CHDES_NFYTYPE,
32267                        errhp));
32268 
32269       switch(notify_type){
32270       case OCI_EVENT_STARTUP:
32271         OnStartup();
32272         return;
32273       case OCI_EVENT_SHUTDOWN:
32274         OnInstanceShutdown();
32275         return;
32276       case OCI_EVENT_SHUTDOWN_ANY:
32277         OnAnyInstanceShutdown();
32278         return;
32279       case OCI_EVENT_DEREG:
32280         OnDeRegistration();
32281         return;
32282       case OCI_EVENT_OBJCHANGE:
32283         break;
32284       default:
32285         return;
32286       }
32287 
32288       OCIColl *table_changes=0;
32289       check(OCIAttrGet(desc,
32290                        OCI_DTYPE_CHDES,
32291                        &table_changes,
32292                        0,
32293                        OCI_ATTR_CHDES_TABLE_CHANGES,
32294                        errhp));
32295       if(!table_changes)return;
32296 
32297       ub4 num_tables=0;
32298       check(OCICollSize(envhp,
32299                         errhp,
32300                         OTL_RCAST(CONST OCIColl*,table_changes),
32301                         OTL_RCAST(sb4*,&num_tables)));
32302       if(!num_tables)return;
32303 
32304       for(unsigned int i=0;i<num_tables;i++){
32305         int exist;
32306         dvoid *elemind=0, *table_desc, **table_descp;
32307         dvoid*** temp_table_descp=&table_descp;
32308         check(OCICollGetElem(envhp,
32309                              errhp,
32310                              table_changes,
32311                              i,
32312                              &exist,
32313                              OTL_RCAST(dvoid**,temp_table_descp),
32314                              &elemind));
32315         table_desc=*table_descp;
32316         text *table_name;
32317         check(OCIAttrGet(table_desc,
32318                          OCI_DTYPE_TABLE_CHDES,
32319                          &table_name,
32320                          0,
32321                          OCI_ATTR_CHDES_TABLE_NAME,
32322                          errhp));
32323 
32324         ub4 table_op;
32325         check(OCIAttrGet(table_desc,
32326                          OCI_DTYPE_TABLE_CHDES,
32327                          OTL_RCAST(dvoid*,&table_op),
32328                          0,
32329                          OCI_ATTR_CHDES_TABLE_OPFLAGS,
32330                          errhp));
32331         bool all_rows=table_op & OCI_OPCODE_ALLROWS;
32332         switch(table_op){
32333         case OCI_OPCODE_ALLROWS:
32334           OnTableInvalidate(table_name);
32335           continue;
32336         case OCI_OPCODE_ALTER:
32337         case (OCI_OPCODE_ALTER+OCI_OPCODE_ALLROWS):
32338           OnTableAlter(table_name,all_rows);
32339           continue;
32340         case OCI_OPCODE_DROP:
32341         case (OCI_OPCODE_DROP+OCI_OPCODE_ALLROWS):
32342           OnTableDrop(table_name,all_rows);
32343           continue;
32344         case (OCI_OPCODE_INSERT+OCI_OPCODE_ALLROWS):
32345         case (OCI_OPCODE_UPDATE+OCI_OPCODE_ALLROWS):
32346         case (OCI_OPCODE_DELETE+OCI_OPCODE_ALLROWS):
32347           OnTableChange(table_name,all_rows);
32348           continue;
32349         case OCI_OPCODE_INSERT:
32350         case OCI_OPCODE_UPDATE:
32351         case OCI_OPCODE_DELETE:
32352           OnTableChange(table_name,all_rows);
32353           break;
32354         }
32355 
32356         row_changes=0;
32357         check(OCIAttrGet(table_desc,
32358                          OCI_DTYPE_TABLE_CHDES,
32359                          &row_changes,
32360                          0,
32361                          OCI_ATTR_CHDES_TABLE_ROW_CHANGES,
32362                          errhp));
32363         if(!row_changes)continue;
32364         num_rows=0;
32365         check(OCICollSize(envhp,errhp,row_changes,OTL_RCAST(sb4*,&num_rows)));
32366         for(j=0;j<num_rows;j++){
32367           elemind=0;
32368           check(OCICollGetElem(envhp,
32369                                errhp,
32370                                row_changes,
32371                                j,
32372                                &exist,
32373                                OTL_RCAST(dvoid**,temp_row_descp),
32374                                &elemind));
32375           row_desc=*row_descp;
32376 
32377           check(OCIAttrGet(row_desc,
32378                            OCI_DTYPE_ROW_CHDES,
32379                            OTL_RCAST(dvoid*,&row_id),
32380                            &rowid_size,
32381                            OCI_ATTR_CHDES_ROW_ROWID,
32382                            errhp));
32383           if(table_op&OCI_OPCODE_INSERT)OnRowInsert(table_name,row_id);
32384           if(table_op&OCI_OPCODE_DELETE)OnRowDelete(table_name,row_id);
32385           if(table_op&OCI_OPCODE_UPDATE)OnRowUpdate(table_name,row_id);
32386         }
32387       }
32388     }catch(OTL_CONST_EXCEPTION otl_exception &e){
32389       OnException(e);
32390     }
32391   }
32392 
32393   static void common_notification_callback
32394   (dvoid *ctx,
32395    OCISubscription* /*subscrhp*/,
32396    dvoid *payload,
32397    ub4 paylen,
32398    dvoid *desc,
32399    ub4 mode)
32400   {
32401     if(!ctx) return;
32402     (OTL_RCAST(otl_subscriber*,ctx))->notification_callback(payload,paylen,desc,mode);
32403   }
32404 
32405 public:
32406   bool is_online(void){ return subscrhp!=0; }
32407 
32408 private:
32409 
32410   otl_subscriber(const otl_subscriber&):
32411     db(0),
32412     subscrhp(0)
32413   {
32414   }
32415 
32416   otl_subscriber& operator=(const otl_subscriber&)
32417   {
32418     return *this;
32419   }
32420 
32421 
32422 };
32423 
32424 #endif
32425 
32426 inline otl_connect& operator>>(otl_connect& connect, otl_stream& s)
32427 {
32428   const char* cmd=connect.getCmd();
32429   const char* invalid_cmd="*** INVALID COMMAND ***";
32430   if(!cmd)
32431     cmd=invalid_cmd;
32432   s.open(s.getBufSize(),cmd,connect);
32433   return connect;
32434 }
32435 
32436 #if (defined(OTL_STL)||defined(OTL_VALUE_TEMPLATE_ON)) \
32437     && defined(OTL_VALUE_TEMPLATE)
32438 template <OTL_TYPE_NAME TData>
32439 otl_stream& operator<<(otl_stream& s, const otl_value<TData>& var)
32440   OTL_THROWS_OTL_EXCEPTION
32441 {
32442  if(var.ind)
32443   s<<otl_null();
32444  else
32445   s<<var.v;
32446  return s;
32447 }
32448 
32449 template <OTL_TYPE_NAME TData>
32450 otl_stream& operator>>(otl_stream& s, otl_value<TData>& var)
32451   OTL_THROWS_OTL_EXCEPTION
32452 {
32453   s>>var.v;
32454   if(s.is_null())
32455     var.ind=true;
32456   else
32457     var.ind=false;
32458   return s;
32459 }
32460 
32461 template <OTL_TYPE_NAME TData>
32462 otl_refcur_stream& operator>>(otl_refcur_stream& s, otl_value<TData>& var)
32463   OTL_THROWS_OTL_EXCEPTION
32464 {
32465   s>>var.v;
32466   if(s.is_null())
32467     var.ind=true;
32468   else
32469     var.ind=false;
32470   return s;
32471 }
32472 
32473 #endif
32474 
32475 typedef otl_tmpl_nocommit_stream
32476 <otl_stream,
32477  otl_connect,
32478  otl_exception> otl_nocommit_stream;
32479 
32480 #if defined(OTL_BIGINT) && defined(OTL_STR_TO_BIGINT) && \
32481     defined(OTL_BIGINT_TO_STR)
32482 
32483 inline otl_stream& operator>>(otl_stream& s, OTL_BIGINT& n)
32484   OTL_THROWS_OTL_EXCEPTION
32485 {
32486   char temp_val[otl_bigint_str_size];
32487 #if defined(OTL_UNICODE)
32488   OTL_CHAR unitemp_val[otl_bigint_str_size];
32489   s>>OTL_RCAST(unsigned char*,unitemp_val);
32490   OTL_CHAR* uc=unitemp_val;
32491   char* c=temp_val;
32492   while(*uc){
32493     *c=OTL_SCAST(char,*uc);
32494     ++uc; ++c;
32495   }
32496   *c=0;
32497 #else
32498   s>>temp_val;
32499 #endif
32500   if(s.is_null()){
32501 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
32502    if(s.is_null())
32503      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
32504 #endif
32505     return s;
32506   }
32507   OTL_STR_TO_BIGINT(temp_val,n)
32508   return s;
32509 }
32510 
32511 inline otl_refcur_stream& operator>>(otl_refcur_stream& s, OTL_BIGINT& n)
32512   OTL_THROWS_OTL_EXCEPTION
32513 {
32514   char temp_val[otl_bigint_str_size];
32515   s>>temp_val;
32516   if(s.is_null()){
32517 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
32518    if(s.is_null())
32519      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
32520 #endif
32521     return s;
32522   }
32523   OTL_STR_TO_BIGINT(temp_val,n)
32524   return s;
32525 }
32526 
32527 inline otl_stream& operator<<(otl_stream& s, const OTL_BIGINT n)
32528   OTL_THROWS_OTL_EXCEPTION
32529 {
32530 #if defined(OTL_UNICODE)
32531   char temp_val[otl_bigint_str_size];
32532   OTL_BIGINT_TO_STR(n,temp_val)
32533   OTL_CHAR unitemp_val[otl_bigint_str_size];
32534   OTL_CHAR* uc=unitemp_val;
32535   char* c=temp_val;
32536   while(*c){
32537     *uc=OTL_SCAST(OTL_CHAR,*c);
32538     ++uc; ++c;
32539   }
32540   *uc=0;
32541   s<<OTL_RCAST(unsigned char*,unitemp_val);
32542 #else
32543   char temp_val[otl_bigint_str_size];
32544   OTL_BIGINT_TO_STR(n,temp_val)
32545   s<<temp_val;
32546 #endif
32547   return s;
32548 }
32549 
32550 #elif defined(OTL_BIGINT) && defined(OTL_ORA_MAP_BIGINT_TO_LONG)
32551 
32552 inline otl_stream& operator>>(otl_stream& s, OTL_BIGINT& n)
32553   OTL_THROWS_OTL_EXCEPTION
32554 {
32555   long temp_val;
32556   s>>temp_val;
32557   if(s.is_null()){
32558 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
32559    if(s.is_null())
32560      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
32561 #endif
32562     return s;
32563   }
32564   n=OTL_SCAST(OTL_BIGINT,temp_val);
32565   return s;
32566 }
32567 
32568 inline otl_refcur_stream& operator>>(otl_refcur_stream& s, OTL_BIGINT& n)
32569   OTL_THROWS_OTL_EXCEPTION
32570 {
32571   long temp_val;
32572   s>>temp_val;
32573   if(s.is_null()){
32574 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
32575    if(s.is_null())
32576      n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
32577 #endif
32578     return s;
32579   }
32580   n=OTL_SCAST(OTL_BIGINT,temp_val);
32581   return s;
32582 }
32583 
32584 inline otl_stream& operator<<(otl_stream& s, const OTL_BIGINT n)
32585   OTL_THROWS_OTL_EXCEPTION
32586 {
32587   long temp_val=OTL_SCAST(long,n);
32588   s<<temp_val;
32589   return s;
32590 }
32591 
32592 #endif
32593 
32594 inline otl_stream& endr(otl_stream& s)
32595 {
32596   s.check_end_of_row();
32597   return s;
32598 }
32599 
32600 OTL_ORA8_NAMESPACE_END
32601 #ifndef __STDC__DEFINED
32602 #undef __STDC__
32603 #endif
32604 #endif
32605 
32606 #if defined(OTL_STL) && !defined(OTL_STLPORT)
32607 
32608 #define STL_INPUT_ITERATOR_TO_DERIVE_FROM
32609 #define STL_OUTPUT_ITERATOR_TO_DERIVE_FROM
32610 
32611 #elif defined(OTL_STLPORT)
32612 
32613 #define STL_INPUT_ITERATOR_TO_DERIVE_FROM       \
32614   : public STD_NAMESPACE_PREFIX iterator        \
32615     <STD_NAMESPACE_PREFIX input_iterator_tag,   \
32616      T,Distance,T*,T&>
32617 
32618 #define STL_OUTPUT_ITERATOR_TO_DERIVE_FROM              \
32619   : public STD_NAMESPACE_PREFIX iterator                \
32620          <STD_NAMESPACE_PREFIX output_iterator_tag,     \
32621            T,void,void,void>
32622 
32623 #endif
32624 
32625 #if defined(OTL_STL) || defined(OTL_STLPORT)
32626 
32627 #define OTL_ITERATORS                                                   \
32628 template <OTL_TYPE_NAME T, OTL_TYPE_NAME Distance=ptrdiff_t>            \
32629 class otl_input_iterator STL_INPUT_ITERATOR_TO_DERIVE_FROM {            \
32630 public:                                                                 \
32631                                                                         \
32632   typedef STD_NAMESPACE_PREFIX input_iterator_tag iterator_category;    \
32633   typedef T                  value_type;                                \
32634   typedef Distance           difference_type;                           \
32635   typedef const T*           pointer;                                   \
32636   typedef const T&           reference;                                 \
32637                                                                         \
32638  otl_stream* stream;                                                    \
32639  T value;                                                               \
32640  int end_marker;                                                        \
32641                                                                         \
32642  void read()                                                            \
32643  {                                                                      \
32644   if(!stream){                                                          \
32645    end_marker=-1;                                                       \
32646    return;                                                              \
32647   }                                                                     \
32648   if(stream->eof()){                                                    \
32649    end_marker=-1;                                                       \
32650    return;                                                              \
32651   }                                                                     \
32652   end_marker=stream->eof();                                             \
32653   if(!end_marker)*stream>>value;                                        \
32654   if(stream->eof())end_marker=1;                                        \
32655  }                                                                      \
32656                                                                         \
32657  otl_input_iterator() : stream(0), value(), end_marker(-1){}            \
32658  otl_input_iterator(otl_stream& s) : stream(&s), value(),end_marker(0){read();} \
32659                                                                         \
32660  const T& operator*() const { return value; }                           \
32661                                                                         \
32662  otl_input_iterator<T, Distance>& operator++(){read(); return *this;}   \
32663                                                                         \
32664  otl_input_iterator<T, Distance> operator++(int)                        \
32665  {                                                                      \
32666   otl_input_iterator<T, Distance> tmp = *this;                          \
32667   read();                                                               \
32668   return tmp;                                                           \
32669  }                                                                      \
32670                                                                         \
32671    otl_input_iterator(const otl_input_iterator& src):                   \
32672    stream(src.stream),value(src.value),end_marker(src.end_marker){}     \
32673                                                                         \
32674   otl_input_iterator& operator=(const otl_input_iterator& src)          \
32675   {                                                                     \
32676     stream=src.stream;                                                  \
32677     value=src.value;                                                    \
32678     end_marker=src.end_marker;                                          \
32679     return *this;                                                       \
32680   }                                                                     \
32681 };                                                                      \
32682                                                                         \
32683 template <OTL_TYPE_NAME T, OTL_TYPE_NAME Distance>                      \
32684 inline STD_NAMESPACE_PREFIX input_iterator_tag iterator_category(       \
32685   const otl_input_iterator<T, Distance>&                                \
32686 )                                                                       \
32687 {                                                                       \
32688   return STD_NAMESPACE_PREFIX input_iterator_tag();                     \
32689 }                                                                       \
32690                                                                         \
32691 template <OTL_TYPE_NAME T, OTL_TYPE_NAME Distance>                      \
32692 inline T* value_type(const otl_input_iterator<T, Distance>&)            \
32693 {                                                                       \
32694  return 0;                                                              \
32695 }                                                                       \
32696                                                                         \
32697 template <OTL_TYPE_NAME T, OTL_TYPE_NAME Distance>                      \
32698 inline Distance* distance_type(const otl_input_iterator<T, Distance>&)  \
32699 {                                                                       \
32700  return 0;                                                              \
32701 }                                                                       \
32702                                                                         \
32703 template <OTL_TYPE_NAME T, OTL_TYPE_NAME Distance>                      \
32704 bool operator==(const otl_input_iterator<T, Distance>& x,               \
32705                 const otl_input_iterator<T, Distance>& y)               \
32706 {                                                                       \
32707   return (x.stream == y.stream && x.end_marker == y.end_marker) ||      \
32708     (x.end_marker == -1 && y.end_marker == -1);                         \
32709 }                                                                       \
32710                                                                         \
32711 template <OTL_TYPE_NAME T, OTL_TYPE_NAME Distance>                      \
32712 bool operator!=(const otl_input_iterator<T, Distance>& x,               \
32713                 const otl_input_iterator<T, Distance>& y)               \
32714 {                                                                       \
32715  return !(x==y);                                                        \
32716 }                                                                       \
32717                                                                         \
32718 template <OTL_TYPE_NAME T>                                              \
32719 class otl_output_iterator STL_OUTPUT_ITERATOR_TO_DERIVE_FROM {          \
32720 protected:                                                              \
32721  otl_stream* stream;                                                    \
32722 public:                                                                 \
32723                                                                         \
32724   typedef STD_NAMESPACE_PREFIX output_iterator_tag iterator_category;   \
32725   typedef void       value_type;                                        \
32726   typedef void       difference_type;                                   \
32727   typedef void       pointer;                                           \
32728   typedef void       reference;                                         \
32729                                                                         \
32730  otl_output_iterator(otl_stream& s) : stream(&s){}                      \
32731  otl_output_iterator<T>& operator=(const T& value)                      \
32732  {                                                                      \
32733   *stream << value;                                                     \
32734   return *this;                                                         \
32735  }                                                                      \
32736  otl_output_iterator<T>& operator*() { return *this; }                  \
32737  otl_output_iterator<T>& operator++() { return *this; }                 \
32738  otl_output_iterator<T> operator++(int) { return *this; }               \
32739                                                                         \
32740 };                                                                      \
32741                                                                         \
32742 template <OTL_TYPE_NAME T>                                              \
32743 inline STD_NAMESPACE_PREFIX output_iterator_tag                         \
32744 iterator_category(const otl_output_iterator<T>&) {                      \
32745   return STD_NAMESPACE_PREFIX output_iterator_tag();                    \
32746 }
32747 
32748 #if defined(OTL_ORA7)
32749 OTL_ORA7_NAMESPACE_BEGIN
32750 OTL_ITERATORS
32751 OTL_ORA7_NAMESPACE_END
32752 #endif
32753 
32754 #if defined(OTL_ORA8)
32755 OTL_ORA8_NAMESPACE_BEGIN
32756 OTL_ITERATORS
32757 OTL_ORA8_NAMESPACE_END
32758 #endif
32759 
32760 #if defined(OTL_ODBC)
32761 OTL_ODBC_NAMESPACE_BEGIN
32762 OTL_ITERATORS
32763 OTL_ODBC_NAMESPACE_END
32764 #endif
32765 
32766 #endif
32767 
32768 #if defined(OTL_STREAM_READ_ITERATOR_ON)
32769 
32770 #if defined(OTL_UNICODE)
32771 #error UNICODE is not supported when #define OTL_STREAM_READ_ITERATOR_ON is enabled
32772 #endif
32773 
32774 #if defined(OTL_STL)
32775 #include <map>
32776 #endif
32777 
32778 #if defined(OTL_ACE)
32779 #include <ace/SString.h>
32780 #include <ace/Array.h>
32781 #include <ace/Functor.h>
32782 #include <ace/RB_Tree.h>
32783 #include <ace/Null_Mutex.h>
32784 #endif
32785 
32786 #if defined(OTL_STL)||defined(OTL_ACE)
32787 class otl_ltcharstar{
32788 public:
32789 #if defined(OTL_STL)
32790  bool
32791 #else
32792  int
32793 #endif
32794  operator()(const char* s1, const char* s2) const
32795  {
32796 #if defined(__BORLANDC__) || defined(_MSC_VER)
32797    return stricmp(s1,s2)<0;
32798 #else
32799 #if defined(__STRICT_ANSI__)
32800    while(otl_to_upper(*s1)==otl_to_upper(*s2)&&*s1){
32801      ++s1;
32802      ++s2;
32803    }
32804    return *s1 < *s2;
32805 #else
32806   return strcasecmp(s1,s2)<0;
32807 #endif
32808 #endif
32809  }
32810 };
32811 #endif
32812 template<OTL_TYPE_NAME OTLStream,
32813          OTL_TYPE_NAME OTLException
32814 #if !defined(OTL_ORA7)
32815          ,OTL_TYPE_NAME OTLLobStream
32816 #endif
32817          >
32818 class otl_stream_read_iterator{
32819 public:
32820 
32821   otl_stream_read_iterator(OTLStream& s)
32822   {
32823     set();
32824     attach(s);
32825   }
32826 
32827   otl_stream_read_iterator():
32828     out_vars_(0),
32829     out_vars_len_(0),
32830     str_(0),
32831     out_vars_arr_(0),
32832     out_vars_null_arr_(0),
32833     out_vars_constructed_(0),
32834     lob_stream_mode_flag_(false)
32835 #if defined(OTL_STL)
32836     ,var_name2pos_map_()
32837 #endif
32838 #if defined(OTL_ACE)
32839     ,var_name2pos_map_()
32840 #endif
32841   {
32842     set();
32843   }
32844 
32845   ~otl_stream_read_iterator()
32846   {
32847     reset();
32848   }
32849 
32850   void attach(OTLStream& s)
32851   {
32852     reset();
32853     str_=&s;
32854     if(!str_->good()){
32855       str_=0;
32856       throw OTLException(otl_error_msg_19,otl_error_code_19);
32857     }
32858     out_vars_=str_->describe_out_vars(out_vars_len_);
32859     if(!out_vars_){
32860       throw OTLException(otl_error_msg_21,otl_error_code_21);
32861     }
32862     lob_stream_mode_flag_=str_->get_lob_stream_flag();
32863     allocate_arrays();
32864   }
32865 
32866   void reattach()
32867   {
32868     if(!str_->good()){
32869       reset();
32870       throw OTLException(otl_error_msg_19,otl_error_code_19);
32871     }
32872     out_vars_=str_->describe_out_vars(out_vars_len_);
32873     if(!out_vars_){
32874       reset();
32875       throw OTLException(otl_error_msg_21,otl_error_code_21);
32876     }else{
32877 #if defined(OTL_STL)
32878       var_name2pos_map_.clear();
32879       for(int i=0;i<out_vars_len_;++i){
32880         const otl_var_desc& curr_var=out_vars_[i];
32881         var_name2pos_map_[curr_var.name]=i;
32882       }
32883 #endif
32884 #if defined(OTL_ACE)
32885       var_name2pos_map_.close();
32886       for(int i=0;i<out_vars_len_;++i){
32887         const otl_var_desc& curr_var=out_vars_[i];
32888         var_name2pos_map_.bind(curr_var.name,i);
32889       }
32890 #endif
32891     }
32892     lob_stream_mode_flag_=str_->get_lob_stream_flag();
32893   }
32894 
32895 
32896   void detach(void)
32897   {
32898     reset();
32899   }
32900 
32901   const otl_var_desc* describe(int& var_desc_len)
32902   {
32903     var_desc_len=out_vars_len_;
32904     return out_vars_;
32905   }
32906 
32907   bool next_row(void)
32908   {
32909     if(str_->eof())return false;
32910     for(int i=0;i<out_vars_len_;++i){
32911       otl_var_desc& curr_var=out_vars_[i];
32912       unsigned char* curr_ptr=out_vars_arr_[i];
32913       switch(curr_var.ftype){
32914       case otl_var_char:
32915         (*str_)>>OTL_RCAST(char*,curr_ptr);
32916         break;
32917       case otl_var_double:
32918         (*str_)>>*OTL_RCAST(double*,curr_ptr);
32919         break;
32920       case otl_var_float:
32921         (*str_)>>*OTL_RCAST(float*,curr_ptr);
32922         break;
32923       case otl_var_int:
32924         (*str_)>>*OTL_RCAST(int*,curr_ptr);
32925         break;
32926       case otl_var_unsigned_int:
32927         (*str_)>>*OTL_RCAST(unsigned*,curr_ptr);
32928         break;
32929       case otl_var_short:
32930         (*str_)>>*OTL_RCAST(short int*,curr_ptr);
32931         break;
32932       case otl_var_long_int:
32933         (*str_)>>*OTL_RCAST(long int*,curr_ptr);
32934         break;
32935       case otl_var_raw:
32936         (*str_)>>*OTL_RCAST(otl_long_string*,curr_ptr);
32937         break;
32938       case otl_var_timestamp:
32939       case otl_var_db2time:
32940       case otl_var_db2date:
32941       case otl_var_tz_timestamp:
32942       case otl_var_ltz_timestamp:
32943         (*str_)>>*OTL_RCAST(otl_datetime*,curr_ptr);
32944         break;
32945       case otl_var_varchar_long:
32946       case otl_var_raw_long:
32947       case otl_var_clob:
32948       case otl_var_blob:
32949 #if !defined(OTL_ORA7)
32950         if(lob_stream_mode_flag_)
32951           (*str_)>>*OTL_RCAST(OTLLobStream*,curr_ptr);
32952         else
32953 #endif
32954           (*str_)>>*OTL_RCAST(otl_long_string*,curr_ptr);
32955         break;
32956 #if defined(OTL_BIGINT)
32957       case otl_var_bigint:
32958         (*str_)>>*OTL_RCAST(OTL_BIGINT*,curr_ptr);
32959         break;
32960 #endif
32961       }
32962       out_vars_null_arr_[i]=str_->is_null()==1;
32963     }
32964     return true;
32965   }
32966 
32967 #if !defined(OTL_ORA7)
32968   void get(const int pos, OTLLobStream*& s)
32969   {
32970     check_pos(pos);
32971     check_type(pos,otl_var_long_string,true);
32972     if(!lob_stream_mode_flag_){
32973       char var_info[255];
32974       otl_var_info_var3
32975         (out_vars_[pos-1].name,
32976          out_vars_[pos-1].ftype,
32977          otl_var_lob_stream,
32978          var_info,
32979          sizeof(var_info));
32980       throw OTLException
32981         (otl_error_msg_25,
32982          otl_error_code_25,
32983          str_->get_stm_text(),
32984          var_info);
32985     }
32986     unsigned char* curr_ptr=out_vars_arr_[pos-1];
32987     s=OTL_RCAST(OTLLobStream*,curr_ptr);
32988   }
32989 #endif
32990 
32991 #if defined(OTL_STL) && !defined(OTL_ORA7)
32992   void get(const char* var_name,OTLLobStream*& n)
32993   {
32994     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
32995     check_name(it,var_name);
32996     get((*it).second+1,n);
32997   }
32998 #endif
32999 
33000 #if defined(OTL_ACE) && !defined(OTL_ORA7)
33001   void get(const char* var_name,OTLLobStream*& n)
33002   {
33003     var_name2pos_map_type::ENTRY* it=0;
33004     var_name2pos_map_.find(var_name,it);
33005     check_name(it,var_name);
33006     get(it->item()+1,n);
33007   }
33008 #endif
33009 
33010   void get(const int pos, char& c)
33011   {
33012     check_pos(pos);
33013     check_type(pos,otl_var_char);
33014     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33015     c=OTL_SCAST(char,*curr_ptr);
33016   }
33017 
33018 #if defined(OTL_STL)
33019   void get(const char* var_name, char& n)
33020   {
33021     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33022     check_name(it,var_name);
33023     get((*it).second+1,n);
33024   }
33025 #endif
33026 
33027 #if defined(OTL_ACE)
33028   void get(const char* var_name, char& n)
33029   {
33030     var_name2pos_map_type::ENTRY* it=0;
33031     var_name2pos_map_.find(var_name,it);
33032     check_name(it,var_name);
33033     get(it->item()+1,n);
33034   }
33035 #endif
33036 
33037   void get(const int pos, unsigned char& c)
33038   {
33039     check_pos(pos);
33040     check_type(pos,otl_var_char);
33041     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33042     c=*curr_ptr;
33043   }
33044 
33045 #if defined(OTL_STL)
33046   void get(const char* var_name, unsigned char& n)
33047   {
33048     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33049     check_name(it,var_name);
33050     get((*it).second+1,n);
33051   }
33052 #endif
33053 
33054 #if defined(OTL_ACE)
33055   void get(const char* var_name, unsigned char& n)
33056   {
33057     var_name2pos_map_type::ENTRY* it=0;
33058     var_name2pos_map_.find(var_name,it);
33059     check_name(it,var_name);
33060     get(it->item()+1,n);
33061   }
33062 #endif
33063 
33064   void get(const int pos, char* s)
33065   {
33066     check_pos(pos);
33067     check_type(pos,otl_var_char);
33068     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33069     otl_strcpy(OTL_RCAST(unsigned char*,s),
33070                OTL_RCAST(const unsigned char*,curr_ptr));
33071   }
33072 
33073 #if defined(OTL_STL)
33074   void get(const char* var_name, char* n)
33075   {
33076     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33077     check_name(it,var_name);
33078     get((*it).second+1,n);
33079   }
33080 #endif
33081 
33082 #if defined(OTL_ACE)
33083   void get(const char* var_name, char* n)
33084   {
33085     var_name2pos_map_type::ENTRY* it=0;
33086     var_name2pos_map_.find(var_name,it);
33087     check_name(it,var_name);
33088     get(it->item()+1,n);
33089   }
33090 #endif
33091 
33092   void get(const int pos, unsigned char* s)
33093   {
33094     check_pos(pos);
33095     check_type(pos,otl_var_char);
33096     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33097     otl_strcpy(OTL_RCAST(unsigned char*,s),OTL_RCAST(const unsigned char*,curr_ptr));
33098   }
33099 
33100 #if defined(OTL_STL)
33101   void get(const char* var_name, unsigned char* n)
33102   {
33103     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33104     check_name(it,var_name);
33105     get((*it).second+1,n);
33106   }
33107 #endif
33108 
33109 #if defined(OTL_ACE)
33110   void get(const char* var_name, unsigned char* n)
33111   {
33112     var_name2pos_map_type::ENTRY* it=0;
33113     var_name2pos_map_.find(var_name,it);
33114     check_name(it,var_name);
33115     get(it->item()+1,n);
33116   }
33117 #endif
33118 
33119 
33120   void get(const int pos, unsigned int& n)
33121   {
33122     check_pos(pos);
33123     void* curr_ptr=out_vars_arr_[pos-1];
33124 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33125     int match_found=otl_numeric_convert_T<unsigned,otl_var_unsigned_int>
33126       (out_vars_[pos-1].ftype,
33127        curr_ptr,
33128        n);
33129 #else
33130     int match_found=otl_numeric_convert_T
33131       (out_vars_[pos-1].ftype,
33132        curr_ptr,
33133        n);
33134 #endif
33135     if(match_found)return;
33136     check_type(pos,otl_var_unsigned_int);
33137   }
33138 
33139 #if defined(OTL_STL)
33140   void get(const char* var_name, unsigned int& n)
33141   {
33142     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33143     check_name(it,var_name);
33144     get((*it).second+1,n);
33145   }
33146 #endif
33147 
33148 #if defined(OTL_ACE)
33149   void get(const char* var_name, unsigned int& n)
33150   {
33151     var_name2pos_map_type::ENTRY* it=0;
33152     var_name2pos_map_.find(var_name,it);
33153     check_name(it,var_name);
33154     get(it->item()+1,n);
33155   }
33156 #endif
33157 
33158   void get(const int pos, int& n)
33159   {
33160     check_pos(pos);
33161     void* curr_ptr=out_vars_arr_[pos-1];
33162 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33163     int match_found=otl_numeric_convert_T<int,otl_var_int>
33164       (out_vars_[pos-1].ftype,
33165        curr_ptr,
33166        n);
33167 #else
33168     int match_found=otl_numeric_convert_T
33169       (out_vars_[pos-1].ftype,
33170        curr_ptr,
33171        n);
33172 #endif
33173     if(match_found)return;
33174     check_type(pos,otl_var_unsigned_int);
33175   }
33176 
33177 #if defined(OTL_STL)
33178   void get(const char* var_name, int& n)
33179   {
33180     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33181     check_name(it,var_name);
33182     get((*it).second+1,n);
33183   }
33184 #endif
33185 
33186 #if defined(OTL_ACE)
33187   void get(const char* var_name, int& n)
33188   {
33189     var_name2pos_map_type::ENTRY* it=0;
33190     var_name2pos_map_.find(var_name,it);
33191     check_name(it,var_name);
33192     get(it->item()+1,n);
33193   }
33194 #endif
33195 
33196   void get(const int pos, short int& n)
33197   {
33198     check_pos(pos);
33199     void* curr_ptr=out_vars_arr_[pos-1];
33200 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33201     int match_found=otl_numeric_convert_T<short,otl_var_short>
33202       (out_vars_[pos-1].ftype,
33203        curr_ptr,
33204        n);
33205 #else
33206     int match_found=otl_numeric_convert_T
33207       (out_vars_[pos-1].ftype,
33208        curr_ptr,
33209        n);
33210 #endif
33211     if(match_found)return;
33212     check_type(pos,otl_var_short);
33213   }
33214 
33215 #if defined(OTL_STL)
33216   void get(const char* var_name, short int& n)
33217   {
33218     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33219     check_name(it,var_name);
33220     get((*it).second+1,n);
33221   }
33222 #endif
33223 
33224 #if defined(OTL_ACE)
33225   void get(const char* var_name, short int& n)
33226   {
33227     var_name2pos_map_type::ENTRY* it=0;
33228     var_name2pos_map_.find(var_name,it);
33229     check_name(it,var_name);
33230     get(it->item()+1,n);
33231   }
33232 #endif
33233 
33234   void get(const int pos, long int& n)
33235   {
33236     check_pos(pos);
33237     void* curr_ptr=out_vars_arr_[pos-1];
33238 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33239     int match_found=otl_numeric_convert_T<long int,otl_var_long_int>
33240       (out_vars_[pos-1].ftype,
33241        curr_ptr,
33242        n);
33243 #else
33244     int match_found=otl_numeric_convert_T
33245       (out_vars_[pos-1].ftype,
33246        curr_ptr,
33247        n);
33248 #endif
33249     if(match_found)return;
33250     check_type(pos,otl_var_long_int);
33251   }
33252 
33253 #if defined(OTL_STL)
33254   void get(const char* var_name, long int& n)
33255   {
33256     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33257     check_name(it,var_name);
33258     get((*it).second+1,n);
33259   }
33260 #endif
33261 
33262 #if defined(OTL_ACE)
33263   void get(const char* var_name, long int& n)
33264   {
33265     var_name2pos_map_type::ENTRY* it=0;
33266     var_name2pos_map_.find(var_name,it);
33267     check_name(it,var_name);
33268     get(it->item()+1,n);
33269   }
33270 #endif
33271 
33272   void get(const int pos, float& n)
33273   {
33274     check_pos(pos);
33275     void* curr_ptr=out_vars_arr_[pos-1];
33276 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33277     int match_found=otl_numeric_convert_T<float,otl_var_float>
33278       (out_vars_[pos-1].ftype,
33279        curr_ptr,
33280        n);
33281 #else
33282     int match_found=otl_numeric_convert_T
33283       (out_vars_[pos-1].ftype,
33284        curr_ptr,
33285        n);
33286 #endif
33287     if(match_found)return;
33288     check_type(pos,otl_var_double);
33289   }
33290 
33291 #if defined(OTL_STL)
33292   void get(const char* var_name, float& n)
33293   {
33294     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33295     check_name(it,var_name);
33296     get((*it).second+1,n);
33297   }
33298 #endif
33299 
33300 #if defined(OTL_ACE)
33301   void get(const char* var_name, float& n)
33302   {
33303     var_name2pos_map_type::ENTRY* it=0;
33304     var_name2pos_map_.find(var_name,it);
33305     check_name(it,var_name);
33306     get(it->item()+1,n);
33307   }
33308 #endif
33309 
33310   void get(const int pos, double& n)
33311   {
33312     check_pos(pos);
33313     void* curr_ptr=out_vars_arr_[pos-1];
33314 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33315     int match_found=otl_numeric_convert_T<double,otl_var_double>
33316       (out_vars_[pos-1].ftype,
33317        curr_ptr,
33318        n);
33319 #else
33320     int match_found=otl_numeric_convert_T
33321       (out_vars_[pos-1].ftype,
33322        curr_ptr,
33323        n);
33324 #endif
33325     if(match_found)return;
33326     check_type(pos,otl_var_double);
33327   }
33328 
33329 #if defined(OTL_STL)
33330   void get(const char* var_name, double& n)
33331   {
33332     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33333     check_name(it,var_name);
33334     get((*it).second+1,n);
33335   }
33336 #endif
33337 
33338 #if defined(OTL_ACE)
33339   void get(const char* var_name, double& n)
33340   {
33341     var_name2pos_map_type::ENTRY* it=0;
33342     var_name2pos_map_.find(var_name,it);
33343     check_name(it,var_name);
33344     get(it->item()+1,n);
33345   }
33346 #endif
33347 
33348 
33349 #if defined(OTL_BIGINT)
33350   void get(const int pos, OTL_BIGINT& n)
33351   {
33352     check_pos(pos);
33353     void* curr_ptr=out_vars_arr_[pos-1];
33354 #if defined(OTL_STRICT_NUMERIC_TYPE_CHECK_ON_SELECT)
33355     int match_found=otl_numeric_convert_T<OTL_BIGINT,otl_var_bigint>
33356       (out_vars_[pos-1].ftype,
33357        curr_ptr,
33358        n);
33359 #else
33360     int match_found=otl_numeric_convert_T
33361       (out_vars_[pos-1].ftype,
33362        curr_ptr,
33363        n);
33364 #endif
33365     if(match_found)return;
33366 #if defined(OTL_STR_TO_BIGINT) && defined(OTL_BIGINT_TO_STR)
33367     if(out_vars_[pos-1].ftype==otl_var_char){
33368       char* temp_val=OTL_RCAST(char*,curr_ptr);
33369 #if defined(OTL_DEFAULT_NUMERIC_NULL_TO_VAL)
33370       if(is_null(pos)){
33371         n=OTL_SCAST(OTL_BIGINT,OTL_DEFAULT_NUMERIC_NULL_TO_VAL);
33372         return;
33373       }
33374 #endif
33375       OTL_STR_TO_BIGINT(temp_val,n);
33376       return;
33377     }
33378     check_type(pos,otl_var_bigint);
33379 #else
33380     check_type(pos,otl_var_bigint);
33381 #endif
33382   }
33383 
33384 #if defined(OTL_STL)
33385   void get(const char* var_name, OTL_BIGINT& n)
33386   {
33387     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33388     check_name(it,var_name);
33389     get((*it).second+1,n);
33390   }
33391 #endif
33392 
33393 #if defined(OTL_ACE)
33394   void get(const char* var_name, OTL_BIGINT& n)
33395   {
33396     var_name2pos_map_type::ENTRY* it=0;
33397     var_name2pos_map_.find(var_name,it);
33398     check_name(it,var_name);
33399     get(it->item()+1,n);
33400   }
33401 #endif
33402 
33403 #endif
33404 
33405   bool is_null(const int pos)
33406   {
33407     check_pos(pos);
33408     return out_vars_null_arr_[pos-1];
33409   }
33410 
33411 #if defined(OTL_STL)
33412   bool is_null(const char* var_name)
33413   {
33414     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33415     check_name(it,var_name);
33416     return is_null((*it).second+1);
33417   }
33418 #endif
33419 
33420 #if defined(OTL_ACE)
33421   bool is_null(const char* var_name)
33422   {
33423     var_name2pos_map_type::ENTRY* it=0;
33424     var_name2pos_map_.find(var_name,it);
33425     check_name(it,var_name);
33426     return is_null(it->item()+1);
33427   }
33428 #endif
33429 
33430 #if defined(OTL_STL) || defined(USER_DEFINED_STRING_CLASS)
33431   void get(const int pos, OTL_STRING_CONTAINER& s)
33432   {
33433     check_pos(pos);
33434     otl_var_desc& curr_var=out_vars_[pos-1];
33435     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33436     switch(curr_var.ftype){
33437     case otl_var_varchar_long:
33438     case otl_var_raw_long:
33439     case otl_var_clob:
33440     case otl_var_blob:
33441       {
33442         otl_long_string* ls=OTL_RCAST(otl_long_string*,curr_ptr);
33443         int len=ls->len();
33444         s.assign(OTL_RCAST(char*,ls->v),len);
33445       }
33446       break;
33447     case otl_var_char:
33448       s=OTL_RCAST(char*,curr_ptr);
33449       break;
33450     default:
33451       {
33452         char var_info[255];
33453         otl_var_info_var3
33454           (out_vars_[pos-1].name,
33455            out_vars_[pos-1].ftype,
33456            otl_var_char,
33457            var_info,
33458            sizeof(var_info));
33459         throw OTLException
33460           (otl_error_msg_23,
33461            otl_error_code_23,
33462            str_->get_stm_text(),
33463            var_info);
33464       }
33465     }
33466   }
33467 #endif
33468 
33469 #if defined(OTL_STL)
33470   void get(const char* var_name, OTL_STRING_CONTAINER& n)
33471   {
33472     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33473     check_name(it,var_name);
33474     get((*it).second+1,n);
33475   }
33476 #endif
33477 
33478 #if defined(OTL_ACE)
33479   void get(const char* var_name, OTL_STRING_CONTAINER& n)
33480   {
33481     var_name2pos_map_type::ENTRY* it=0;
33482     var_name2pos_map_.find(var_name,it);
33483     check_name(it,var_name);
33484     get(it->item()+1,n);
33485   }
33486 #endif
33487 
33488 
33489   void get(const int pos, otl_long_string& s)
33490   {
33491     check_pos(pos);
33492     check_type(pos,otl_var_long_string);
33493     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33494     s=*OTL_RCAST(otl_long_string*,curr_ptr);
33495   }
33496 
33497 #if defined(OTL_STL)
33498   void get(const char* var_name, otl_long_string& n)
33499   {
33500     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33501     check_name(it,var_name);
33502     get((*it).second+1,n);
33503   }
33504 #endif
33505 
33506 #if defined(OTL_ACE)
33507   void get(const char* var_name, otl_long_string& n)
33508   {
33509     var_name2pos_map_type::ENTRY* it=0;
33510     var_name2pos_map_.find(var_name,it);
33511     check_name(it,var_name);
33512     get(it->item()+1,n);
33513   }
33514 #endif
33515 
33516   void get(const int pos, otl_long_string*& s)
33517   {
33518     check_pos(pos);
33519     check_type(pos,otl_var_long_string);
33520     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33521     s=OTL_RCAST(otl_long_string*,curr_ptr);
33522   }
33523 
33524 #if defined(OTL_STL)
33525   void get(const char* var_name, otl_long_string*& n)
33526   {
33527     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33528     check_name(it,var_name);
33529     get((*it).second+1,n);
33530   }
33531 #endif
33532 
33533 #if defined(OTL_ACE)
33534   void get(const char* var_name, otl_long_string*& n)
33535   {
33536     var_name2pos_map_type::ENTRY* it=0;
33537     var_name2pos_map_.find(var_name,it);
33538     check_name(it,var_name);
33539     get(it->item()+1,n);
33540   }
33541 #endif
33542 
33543   void get(const int pos, otl_datetime& s)
33544   {
33545     check_pos(pos);
33546     check_type(pos,otl_var_timestamp);
33547     unsigned char* curr_ptr=out_vars_arr_[pos-1];
33548     s=*OTL_RCAST(otl_datetime*,curr_ptr);
33549   }
33550 
33551 #if defined(OTL_STL)
33552   void get(const char* var_name, otl_datetime& n)
33553   {
33554     var_name2pos_map_type::iterator it=var_name2pos_map_.find(var_name);
33555     check_name(it,var_name);
33556     get((*it).second+1,n);
33557   }
33558 #endif
33559 
33560 #if defined(OTL_ACE)
33561   void get(const char* var_name, otl_datetime& n)
33562   {
33563     var_name2pos_map_type::ENTRY* it=0;
33564     var_name2pos_map_.find(var_name,it);
33565     check_name(it,var_name);
33566     get(it->item()+1,n);
33567   }
33568 #endif
33569 
33570 protected:
33571 
33572   otl_var_desc* out_vars_;
33573   int out_vars_len_;
33574   OTLStream* str_;
33575   unsigned char** out_vars_arr_;
33576   bool* out_vars_null_arr_;
33577   bool out_vars_constructed_;
33578   bool lob_stream_mode_flag_;
33579 
33580 #if defined(OTL_STL)
33581   typedef STD_NAMESPACE_PREFIX
33582     map<const char*,int,otl_ltcharstar> var_name2pos_map_type;
33583   var_name2pos_map_type var_name2pos_map_;
33584 #endif
33585 
33586 #if defined(OTL_ACE)
33587   typedef
33588   ACE_RB_Tree<const char*,
33589               int,
33590               otl_ltcharstar,
33591               ACE_Null_Mutex> var_name2pos_map_type;
33592   var_name2pos_map_type var_name2pos_map_;
33593 #endif
33594 
33595   void check_pos(const int pos)
33596   {
33597     int actual_pos=pos-1;
33598     if(actual_pos<0 || actual_pos>out_vars_len_-1){
33599       throw OTLException
33600         (otl_error_msg_22,
33601          otl_error_code_22,
33602          str_->get_stm_text());
33603     }
33604   }
33605 
33606 #if defined(OTL_STL)
33607   void check_name(var_name2pos_map_type::iterator& it, const char* var_name)
33608   {
33609     if(it==var_name2pos_map_.end())
33610       throw OTLException
33611         (otl_error_msg_26,
33612          otl_error_code_26,
33613          str_->get_stm_text(),
33614          var_name);
33615   }
33616 #endif
33617 
33618 #if defined(OTL_ACE)
33619   void check_name(var_name2pos_map_type::ENTRY* it,const char* var_name)
33620   {
33621     if(!it){
33622       throw OTLException
33623         (otl_error_msg_26,
33624          otl_error_code_26,
33625          str_->get_stm_text(),
33626          var_name);
33627     }
33628   }
33629 #endif
33630 
33631   void check_type(const int pos,
33632                   const int type_code,
33633                   const bool lob_stream_arg=false)
33634   {
33635     switch(out_vars_[pos-1].ftype){
33636     case otl_var_timestamp:
33637     case otl_var_tz_timestamp:
33638     case otl_var_ltz_timestamp:
33639       if(type_code==otl_var_timestamp)
33640         return;
33641     case otl_var_varchar_long:
33642     case otl_var_raw_long:
33643     case otl_var_clob:
33644     case otl_var_blob:
33645       if(type_code==otl_var_long_string)
33646         return;
33647     case otl_var_raw:
33648       if(type_code==otl_var_long_string &&
33649          lob_stream_mode_flag_ &&
33650          lob_stream_arg){
33651         char var_info1[255];
33652         otl_var_info_var4
33653           (out_vars_[pos-1].name,
33654            out_vars_[pos-1].ftype,
33655            otl_var_lob_stream,
33656            var_info1,
33657            sizeof(var_info1));
33658         throw OTLException
33659           (otl_error_msg_28,
33660            otl_error_code_28,
33661            str_->get_stm_text(),
33662            var_info1);
33663       }else
33664         return;
33665     default:
33666       if(out_vars_[pos-1].ftype==type_code)
33667         return;
33668     }
33669     char var_info2[255];
33670     otl_var_info_var3
33671       (out_vars_[pos-1].name,
33672        out_vars_[pos-1].ftype,
33673        type_code,
33674        var_info2,
33675        sizeof(var_info2));
33676     throw OTLException
33677       (otl_error_msg_23,
33678        otl_error_code_23,
33679        str_->get_stm_text(),
33680        var_info2);
33681   }
33682 
33683   void set(void)
33684   {
33685     out_vars_=0;
33686     out_vars_len_=0;
33687     str_=0;
33688     out_vars_arr_=0;
33689     out_vars_null_arr_=0;
33690     out_vars_constructed_=false;
33691     lob_stream_mode_flag_=false;
33692   }
33693 
33694   void reset(void)
33695   {
33696     if(out_vars_constructed_){
33697       for(int i=0;i<out_vars_len_;++i){
33698         switch(out_vars_[i].ftype){
33699         case otl_var_char:
33700           delete[] OTL_RCAST(char*,out_vars_arr_[i]);
33701           break;
33702         case otl_var_double:
33703           delete OTL_RCAST(double*,out_vars_arr_[i]);
33704           break;
33705         case otl_var_float:
33706           delete OTL_RCAST(float*,out_vars_arr_[i]);
33707           break;
33708         case otl_var_int:
33709           delete OTL_RCAST(int*,out_vars_arr_[i]);
33710           break;
33711         case otl_var_unsigned_int:
33712           delete OTL_RCAST(unsigned*,out_vars_arr_[i]);
33713           break;
33714         case otl_var_short:
33715           delete OTL_RCAST(short int*,out_vars_arr_[i]);
33716           break;
33717         case otl_var_long_int:
33718           delete OTL_RCAST(long int*,out_vars_arr_[i]);
33719           break;
33720 #if defined(OTL_BIGINT)
33721         case otl_var_bigint:
33722           delete OTL_RCAST(OTL_BIGINT*,out_vars_arr_[i]);
33723           break;
33724 #endif
33725         case otl_var_raw:
33726           delete OTL_RCAST(otl_long_string*,out_vars_arr_[i]);
33727           break;
33728         case otl_var_varchar_long:
33729         case otl_var_raw_long:
33730         case otl_var_clob:
33731         case otl_var_blob:
33732 #if !defined(OTL_ORA7)
33733           if(lob_stream_mode_flag_)
33734             delete OTL_RCAST(OTLLobStream*,out_vars_arr_[i]);
33735           else
33736 #endif
33737             delete OTL_RCAST(otl_long_string*,out_vars_arr_[i]);
33738           break;
33739         case otl_var_timestamp:
33740           delete OTL_RCAST(otl_datetime*,out_vars_arr_[i]);
33741           break;
33742         default:
33743           break;
33744         }
33745         out_vars_arr_[i]=0;
33746       }
33747       out_vars_constructed_=false;
33748     }
33749     delete[] out_vars_arr_;
33750     delete[] out_vars_null_arr_;
33751 #if defined(OTL_STL)||defined(OTL_ACE)
33752     var_name2pos_map_.clear();
33753 #endif
33754     set();
33755   }
33756 
33757   int calculate_buffer_size
33758   (const otl_var_desc* var,
33759    const int vars_len)
33760   {
33761     for(int i=0;i<vars_len;++i){
33762       const otl_var_desc& curr_var=var[i];
33763       if(curr_var.ftype==otl_var_refcur||curr_var.pl_tab_flag)
33764         throw OTLException(otl_error_msg_20,otl_error_code_20);
33765     }
33766     return vars_len;
33767   }
33768 
33769   void allocate_arrays(void)
33770   {
33771     if(out_vars_){
33772       out_vars_null_arr_=new bool[out_vars_len_];
33773       int buf_size=calculate_buffer_size(out_vars_,out_vars_len_);
33774       out_vars_arr_=new unsigned char*[buf_size];
33775       construct_elements();
33776     }
33777   }
33778 
33779   void construct_elements(void)
33780   {
33781     for(int i=0;i<out_vars_len_;++i){
33782       out_vars_null_arr_[i]=true;
33783       const otl_var_desc& curr_var=out_vars_[i];
33784       switch(curr_var.ftype){
33785       case otl_var_char:
33786         {
33787           char* ptr=new char[curr_var.elem_size];
33788           *ptr=0;
33789           out_vars_arr_[i]=OTL_RCAST(unsigned char*,ptr);
33790         }
33791         break;
33792       case otl_var_raw:
33793         out_vars_arr_[i]=
33794           OTL_RCAST(unsigned char*,new otl_long_string(curr_var.elem_size));
33795         break;
33796       case otl_var_double:
33797         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new double(0));
33798         break;
33799       case otl_var_float:
33800         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new float(0));
33801         break;
33802       case otl_var_int:
33803         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new int(0));
33804         break;
33805       case otl_var_unsigned_int:
33806         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new unsigned(0));
33807         break;
33808       case otl_var_short:
33809         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new short(0));
33810         break;
33811       case otl_var_long_int:
33812         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new long(0));
33813         break;
33814       case otl_var_timestamp:
33815       case otl_var_db2time:
33816       case otl_var_db2date:
33817       case otl_var_tz_timestamp:
33818       case otl_var_ltz_timestamp:
33819         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new otl_datetime);
33820         break;
33821       case otl_var_varchar_long:
33822       case otl_var_raw_long:
33823       case otl_var_clob:
33824       case otl_var_blob:
33825 #if !defined(OTL_ORA7)
33826         if(lob_stream_mode_flag_)
33827           out_vars_arr_[i]=OTL_RCAST(unsigned char*,new OTLLobStream());
33828         else
33829 #endif
33830           out_vars_arr_[i]=
33831             OTL_RCAST(unsigned char*,
33832                       new otl_long_string
33833                       (str_->get_adb_max_long_size()));
33834         break;
33835 #if defined(OTL_BIGINT)
33836       case otl_var_bigint:
33837         out_vars_arr_[i]=OTL_RCAST(unsigned char*,new OTL_BIGINT(0));
33838         break;
33839 #endif
33840       }
33841 #if defined(OTL_STL)
33842       var_name2pos_map_[curr_var.name]=i;
33843 #endif
33844 #if defined(OTL_ACE)
33845       var_name2pos_map_.bind(curr_var.name,i);
33846 #endif
33847     }
33848     out_vars_constructed_=true;
33849   }
33850 
33851 private:
33852 
33853   otl_stream_read_iterator(const otl_stream_read_iterator&):
33854     out_vars_(0),
33855     out_vars_len_(0),
33856     str_(0),
33857     out_vars_arr_(0),
33858     out_vars_null_arr_(0),
33859     out_vars_constructed_(0),
33860     lob_stream_mode_flag_(false)
33861 #if defined(OTL_STL)
33862     ,var_name2pos_map_()
33863 #endif
33864 #if defined(OTL_ACE)
33865     ,var_name2pos_map_()
33866 #endif
33867   {
33868   }
33869 
33870   otl_stream_read_iterator& operator=(const otl_stream_read_iterator&)
33871   {
33872     return *this;
33873   }
33874 
33875 };
33876 
33877 #endif
33878 
33879 #if defined(OTL_ORA_TEXT_ON)&&defined(text)
33880 #undef text
33881 #endif
33882 
33883 #endif
33884