1 #ifndef _DRIVERMANAGER_H
2 #define _DRIVERMANAGER_H
3 
4 #define ODBCVER 0x0380
5 
6 #ifdef HAVE_SYS_TYPES_H
7 #include <sys/types.h>
8 #endif
9 #ifdef HAVE_PWD_H
10 #include <pwd.h>
11 #endif
12 #include <ltdl.h>
13 #ifdef HAVE_STRING_H
14 #include <string.h>
15 #endif
16 #ifdef HAVE_TIME_H
17 #include <time.h>
18 #endif
19 
20 #ifdef HAVE_SYNCH_H
21 #include <synch.h>
22 #endif
23 
24 #ifdef HAVE_LIBPTH
25 #include <pth.h>
26 #elif HAVE_LIBPTHREAD
27 #include <pthread.h>
28 #elif HAVE_LIBTHREAD
29 #include <thread.h>
30 #endif
31 
32 #define SQL_NOUNICODEMAP
33 #define  UNICODE
34 
35 #include <log.h>
36 #include <ini.h>
37 #include <odbcinstext.h>
38 #include <sqlext.h>                     /* THIS WILL BRING IN sql.h and
39                                            sqltypes.h AS WELL AS PROVIDE
40                                            MS EXTENSIONS */
41 #include <sqlucode.h>
42 #include "__stats.h"
43 
44 /*
45  * iconv support
46  */
47 
48 #ifdef HAVE_ICONV
49 #include <stdlib.h>
50 #include <iconv.h>
51 #endif
52 
53 #ifdef UNICODE_ENCODING
54 #define DEFAULT_ICONV_ENCODING      UNICODE_ENCODING
55 #else
56 #define DEFAULT_ICONV_ENCODING      "auto-search"
57 #endif
58 
59 #define ERROR_PREFIX        "[unixODBC]"
60 #define DM_ERROR_PREFIX     "[Driver Manager]"
61 #define LOG_MESSAGE_LEN     128         /* length of string to display in log */
62 
63 /*
64  * SQLSetStmt/ConnectionAttr limits
65  */
66 
67 #define SQL_CONN_DRIVER_MIN     20000
68 #define SQL_STMT_DRIVER_MIN     20000
69 
70 /*
71  * its possible that the driver has a different definition of a handle to the driver
72  * manager, DB2 64bit is a example of this
73  */
74 
75 #define DRV_SQLHANDLE			SQLHANDLE
76 #define DRV_SQLHDESC			SQLHDESC
77 
78 /*
79  * DEFAULT FILE NAMES
80  *
81  */
82 
83 /*
84  * magic numbers
85  */
86 
87 #define HENV_MAGIC      19289
88 #define HDBC_MAGIC      19290
89 #define HSTMT_MAGIC     19291
90 #define HDESC_MAGIC     19292
91 
92 /*
93  * states
94  */
95 
96 #define STATE_E0        0
97 #define STATE_E1        1
98 #define STATE_E2        2
99 
100 #define STATE_C0        0
101 #define STATE_C1        1
102 #define STATE_C2        2
103 #define STATE_C3        3
104 #define STATE_C4        4
105 #define STATE_C5        5
106 #define STATE_C6        6
107 
108 #define STATE_S0        0
109 #define STATE_S1        1
110 #define STATE_S2        2
111 #define STATE_S3        3
112 #define STATE_S4        4
113 #define STATE_S5        5
114 #define STATE_S6        6
115 #define STATE_S7        7
116 #define STATE_S8        8
117 #define STATE_S9        9
118 #define STATE_S10       10
119 #define STATE_S11       11
120 #define STATE_S12       12
121 
122 #define STATE_S13       13          /* SQLExecute/SQLExecDirect/SQLMoreResult  returned SQL_PARAM_DATA_AVAILABLE */
123 #define STATE_S14       14          /* SQL_PARAM_DATA_AVAILABLE version of S9, Must Get */
124 #define STATE_S15       15          /* SQL_PARAM_DATA_AVAILABLE version of S10, Can Get */
125 
126 #define STATE_D0        0
127 #define STATE_D1i       1
128 #define STATE_D1e       2
129 
130 /*
131  * rules to extract diag/error record from driver
132  */
133 #define DEFER_R0        0            /* Not defer extracting diag/err record from driver. Use this as default */
134 #define DEFER_R1        1            /* defer extracting diag/err record from driver when SQL_SUCCESS_WITH_INFO is returned */
135 #define DEFER_R2        2            /* defer extracting diag/err record from driver when SQL_ERROR is returned */
136 #define DEFER_R3        3            /* defer extracting diag/err record from driver when SQL_SUCCESS_WITH_INFO or SQL_ERROR is returned */
137 
138 /*
139  * structure to contain the loaded lib entry points
140  */
141 
142 struct driver_func
143 {
144     int         ordinal;
145     char        *name;
146     void        *dm_func;               /* this is to fix what seems a bug in */
147 			                            /* some dlopen implemnations where dlsym */
148 					                    /* will return the driver manager func */
149 					                    /* not the driver one */
150     void        *dm_funcW;
151     SQLRETURN   (*func)();
152     SQLRETURN   (*funcW)();             /* function with a unicode W */
153     SQLRETURN   (*funcA)();             /* function with a unicode A */
154     int         can_supply;             /* this is used to indicate that */
155                                         /* the DM can execute the function */
156                                         /* even if the driver does not */
157                                         /* supply it */
158 };
159 
160 typedef struct error
161 {
162     SQLWCHAR    sqlstate[ 6 ];
163     SQLWCHAR    *msg;
164     SQLINTEGER  native_error;
165     int         return_val;
166     SQLRETURN   diag_column_number_ret;
167     SQLRETURN   diag_row_number_ret;
168     SQLRETURN   diag_class_origin_ret;
169     SQLRETURN   diag_subclass_origin_ret;
170     SQLRETURN   diag_connection_name_ret;
171     SQLRETURN   diag_server_name_ret;
172     SQLINTEGER  diag_column_number;
173     SQLLEN      diag_row_number;
174     SQLWCHAR    diag_class_origin[ 128 ];
175     SQLWCHAR    diag_subclass_origin[ 128 ];
176     SQLWCHAR    diag_connection_name[ 128 ];
177     SQLWCHAR    diag_server_name[ 128 ];
178     struct error *next;
179     struct error *prev;
180 
181 } ERROR;
182 
183 typedef struct error_header
184 {
185     int         error_count;
186     ERROR       *error_list_head;
187     ERROR       *error_list_tail;
188     int         internal_count;
189     ERROR       *internal_list_head;
190     ERROR       *internal_list_tail;
191 } EHEADER;
192 
193 typedef struct error_head
194 {
195     EHEADER     sql_error_head;
196     EHEADER     sql_diag_head;
197     void        *owning_handle;
198     int         handle_type;
199     SQLRETURN   return_code;
200     SQLINTEGER  header_set;
201     SQLRETURN   diag_cursor_row_count_ret;
202     SQLRETURN   diag_dynamic_function_ret;
203     SQLRETURN   diag_dynamic_function_code_ret;
204     SQLRETURN   diag_number_ret;
205     SQLRETURN   diag_row_count_ret;
206     SQLLEN      diag_cursor_row_count;
207     SQLWCHAR    diag_dynamic_function[ 128 ];
208     SQLINTEGER  diag_dynamic_function_code;
209     SQLLEN      diag_number;
210     SQLLEN      diag_row_count;
211     int         defer_extract;   /* determine the extraction of driver's message for
212                                            SQLGetDiagRec or SQLGetDiagField.
213                                            0 by default is not deferred */
214     SQLRETURN   ret_code_deferred; /* used for deferring extraction */
215 } EHEAD;
216 
217 struct log_structure
218 {
219     char    *program_name;
220     char    *log_file_name;
221     int     log_flag;
222     int     pid_logging;            /* the log path specifies a directory, and a */
223                                     /* log file per pid is created */
224     int     ref_count;              /* number of times dm_log_open()'d without dm_log_close() */
225 };
226 
227 extern struct log_structure log_info;
228 
229 /*
230  * save connection attr untill after the connect, and then pass on
231  */
232 
233 struct save_attr
234 {
235     int                 attr_type;
236     char                *str_attr;
237     int                 str_len;
238     intptr_t            intptr_attr;
239     struct save_attr    *next;
240 };
241 
242 /*
243  * attribute extension support
244  */
245 
246 struct attr_set
247 {
248     char            *keyword;
249     char            *value;
250     int             override;
251     int             attribute;
252     int             is_int_type;
253     int             int_value;
254     struct attr_set *next;
255 };
256 
257 struct attr_struct
258 {
259     int             count;
260     struct attr_set *list;
261 };
262 
263 int __parse_attribute_string( struct attr_struct *attr_str,
264     char *str, int str_len );
265 void __release_attr_str( struct attr_struct *attr_str );
266 void __set_attributes( void *handle, int type );
267 void __set_local_attributes( void *handle, int type );
268 void *__attr_override( void *handle, int type, int attribute, void * value, SQLINTEGER *string_length );
269 void *__attr_override_wide( void *handle, int type, int attribute, void * value, SQLINTEGER *string_length, SQLWCHAR *buffer );
270 
271 /*
272  * use this to maintain a list of the drivers that are loaded under this env,
273  * and to decide if we want to call SQLAllocHandle( SQL_ENV ) om them
274  */
275 
276 struct env_lib_struct
277 {
278     char            *lib_name;
279     DRV_SQLHANDLE   env_handle;
280     int             count;
281     struct env_lib_struct   *next;
282 };
283 
284 typedef struct environment
285 {
286     int             type;               /* magic number */
287     struct environment *next_class_list;/* static list of all env handles */
288     char            msg[ LOG_MSG_MAX ];	/* buff to format msgs */
289     int             state;              /* state of environment */
290     int             version_set;        /* whether ODBC version has been set */
291     SQLINTEGER      requested_version;  /* SQL_OV_ODBC2 or SQL_OV_ODBC3 */
292     int             connection_count;   /* number of hdbc of this env */
293     int             sql_driver_count;   /* used for SQLDrivers */
294     EHEAD           error;              /* keep track of errors */
295     SQLINTEGER      connection_pooling; /* does connection pooling operate */
296     SQLINTEGER      cp_match;
297     int             fetch_mode;         /* for SQLDataSources */
298     int             entry;
299     void            *sh;                /* statistics handle */
300     int             driver_act_ver;     /* real version of the driver */
301     struct env_lib_struct *env_lib_list;/* use this to avoid multiple AllocEnv in the driver */
302 } *DMHENV;
303 
304 
305 #ifdef FAST_HANDLE_VALIDATE
306     struct statement;
307 #endif
308 
309 
310 /*
311  * connection pooling attributes
312  */
313 
314 typedef struct connection
315 {
316     int             type;               /* magic number */
317     struct connection *next_class_list; /* static list of all dbc handles */
318     char            msg[ LOG_MSG_MAX ]; /* buff to format msgs */
319     int             state;              /* state of connection */
320     DMHENV          environment;        /* environment that own's the
321                                            connection */
322 #ifdef FAST_HANDLE_VALIDATE
323     struct statement *statements;       /* List of statements owned by this
324                                            connection */
325 #endif
326 
327     void            *dl_handle;         /* handle of the loaded lib */
328     char            dl_name[ 256 ];     /* name of loaded lib */
329     struct driver_func *functions;      /* entry points */
330     struct driver_func  ini_func;       /* optinal start end functions */
331     struct driver_func  fini_func;
332     int             unicode_driver;     /* do we use the W functions in the */
333                                         /* driver ? */
334     DRV_SQLHANDLE 	driver_env;         /* environment handle in client */
335     DRV_SQLHANDLE   driver_dbc;         /* connection handle in client */
336     int             driver_version;     /* required version of the connected */
337                                         /* driver */
338     int             driver_act_ver;     /* real version of the driver */
339     int             statement_count;    /* number of statements on this dbc */
340     EHEAD           error;              /* keep track of errors */
341     char            dsn[ SQL_MAX_DSN_LENGTH + 1 ];  /* where we are connected */
342     int             access_mode;        /* variables set via SQLSetConnectAttr */
343     int             access_mode_set;
344     int             login_timeout;
345     int             login_timeout_set;
346     int             auto_commit;
347     int             auto_commit_set;
348     int             async_enable;
349     int             async_enable_set;
350     int             auto_ipd;
351     int             auto_ipd_set;
352     int             connection_timeout;
353     int             connection_timeout_set;
354     int             metadata_id;
355     int             metadata_id_set;
356     int             packet_size;
357     int             packet_size_set;
358     SQLLEN          quite_mode;
359     int             quite_mode_set;
360     int             txn_isolation;
361     int             txn_isolation_set;
362 
363     SQLINTEGER      cursors;
364     void            *cl_handle;         /* handle to the cursor lib */
365     int             trace;
366     char            tracefile[ INI_MAX_PROPERTY_VALUE + 1 ];
367 #ifdef HAVE_LIBPTH
368     pth_mutex_t     mutex;              /* protect the object */
369     int             protection_level;
370 #elif HAVE_LIBPTHREAD
371     pthread_mutex_t mutex;              /* protect the object */
372     int             protection_level;
373 #elif HAVE_LIBTHREAD
374     mutex_t mutex;              		/* protect the object */
375     int             protection_level;
376 #endif
377     int             ex_fetch_mapping;   /* disable SQLFetch -> SQLExtendedFetch */
378     int             disable_gf;         /* dont call SQLGetFunctions in the driver */
379     int             dont_dlclose;       /* disable dlclosing of the handle */
380     int             bookmarks_on;       /* bookmarks are set on */
381     void            *pooled_connection; /* points to t connection pool structure */
382     int             pooling_timeout;
383     int             ttl;
384     char            driver_connect_string[ 1024 ];
385     int             dsn_length;
386     char            server[ 128 ];
387     int             server_length;
388     char            user[ 128 ];
389     int             user_length;
390     char            password[ 128 ];
391     int             password_length;
392     char            cli_year[ 5 ];
393     struct attr_struct  env_attribute;      /* Extended attribute set info */
394     struct attr_struct  dbc_attribute;
395     struct attr_struct  stmt_attribute;
396     struct save_attr    *save_attr;         /* SQLConnectAttr before connect */
397 #ifdef HAVE_ICONV
398     iconv_t         iconv_cd_uc_to_ascii;   /* in and out conversion descriptor */
399     iconv_t         iconv_cd_ascii_to_uc;
400     char            unicode_string[ 64 ];   /* name of unicode conversion */
401 #endif
402     struct env_lib_struct *env_list_ent;    /* pointer to reference in the env list */
403     char            probe_sql[ 512 ];       /* SQL to use to check a pool is valid */
404 	int				threading_level;		/* level of thread protection the DM proves */
405 	int				cbs_found;				/* Have we queried the driver for the effect of a */
406 	SQLSMALLINT		ccb_value;				/* COMMIT or a ROLLBACK */
407 	SQLSMALLINT		crb_value;
408 } *DMHDBC;
409 
410 typedef struct connection_pool
411 {
412     char    driver_connect_string[ 1024 ];
413     int     dsn_length;
414     char    server[ 128 ];
415     int     server_length;
416     char    user[ 128 ];
417     int     user_length;
418     char    password[ 128 ];
419     int     password_length;
420     time_t  expiry_time;
421     int     ttl;
422     int     timeout;
423     int     in_use;
424     struct  connection_pool *next;
425     struct  connection connection;
426     int     cursors;
427 } CPOOL;
428 
429 typedef struct descriptor
430 {
431     int             type;               /* magic number */
432     struct descriptor *next_class_list; /* static list of all desc handles */
433     char            msg[ LOG_MSG_MAX ]; /* buff to format msgs */
434     int             state;              /* state of descriptor */
435 
436 #ifdef FAST_HANDLE_VALIDATE
437     struct descriptor *prev_class_list;/* static list of all desc handles */
438 #endif
439 
440     EHEAD           error;              /* keep track of errors */
441     DRV_SQLHDESC    driver_desc;        /* driver descriptor */
442     DMHDBC          connection;         /* DM connection that owns this */
443     int             implicit;           /* created by a AllocStmt */
444     void            *associated_with;   /* statement that this is a descriptor of */
445 #ifdef HAVE_LIBPTH
446     pth_mutex_t     mutex;              /* protect the object */
447 #elif HAVE_LIBPTHREAD
448     pthread_mutex_t mutex;              /* protect the object */
449 #elif HAVE_LIBTHREAD
450     mutex_t mutex;              		/* protect the object */
451 #endif
452 } *DMHDESC;
453 
454 typedef struct statement
455 {
456     int             type;               /* magic number */
457     struct statement *next_class_list;  /* static list of all stmt handles */
458     char            msg[ LOG_MSG_MAX ]; /* buff to format msgs */
459     int             state;              /* state of statement */
460 #ifdef FAST_HANDLE_VALIDATE
461     struct statement *prev_class_list;  /* static list of all stmt handles */
462     struct statement *next_conn_list;   /* Single linked list storing statements
463                                            owned by "connection" connection */
464 #endif
465     DMHDBC          connection;         /* DM connection that owns this */
466     DRV_SQLHANDLE   driver_stmt;        /* statement in the driver */
467     SQLSMALLINT     hascols;            /* is there a result set */
468     int             prepared;           /* the statement has been prepared */
469     int             interupted_func;    /* current function running async */
470                                         /* or NEED_DATA */
471     int             interupted_state;   /* state we went into need data or */
472                                         /* still executing from */
473     int             bookmarks_on;       /* bookmarks are set on */
474     EHEAD           error;              /* keep track of errors */
475     SQLINTEGER      metadata_id;
476     DMHDESC         ipd;                /* current descriptors */
477     DMHDESC         apd;
478     DMHDESC         ird;
479     DMHDESC         ard;
480     DMHDESC         implicit_ipd;       /* implicit descriptors */
481     DMHDESC         implicit_apd;
482     DMHDESC         implicit_ird;
483     DMHDESC         implicit_ard;
484     SQLULEN		    *fetch_bm_ptr;      /* Saved for ODBC3 to ODBC2 mapping */
485     SQLULEN     	*row_ct_ptr;        /* row count ptr */
486     SQLUSMALLINT    *row_st_arr;        /* row status array */
487     SQLULEN     	row_array_size;
488 	SQLPOINTER      valueptr;           /* Default buffer for SQLParamData() */
489 
490 #ifdef HAVE_LIBPTH
491     pth_mutex_t     mutex;              /* protect the object */
492 #elif HAVE_LIBPTHREAD
493     pthread_mutex_t mutex;              /* protect the object */
494 #elif HAVE_LIBTHREAD
495     mutex_t mutex;              		/* protect the object */
496 
497 #endif
498 
499     int             eod;                /* when in S6 has EOD been returned */
500 } *DMHSTMT;
501 
502 #if defined ( HAVE_LIBPTHREAD ) || defined ( HAVE_LIBTHREAD ) || defined ( HAVE_LIBPTH )
503 #define TS_LEVEL0   0           /* no implicit protection, only for */
504                                 /* dm internal structures */
505 #define TS_LEVEL1   1           /* protection on a statement level */
506 #define TS_LEVEL2   2           /* protection on a connection level */
507 #define TS_LEVEL3   3           /* protection on a environment level */
508 #endif
509 
510 void mutex_lib_entry( void );
511 void mutex_lib_exit( void );
512 
513 void mutex_pool_entry( void );
514 void mutex_pool_exit( void );
515 
516 void mutex_iconv_entry( void );
517 void mutex_iconv_exit( void );
518 
519 typedef struct connection_pair
520 {
521     char            *name;
522     char            *value;
523     struct connection_pair *next;
524 } *connection_attribute;
525 
526 /*
527  * defined down here to get the DMHDBC definition
528  */
529 
530 void __handle_attr_extensions( DMHDBC connection, char *dsn, char *driver_name );
531 
532 /*
533  * handle allocation functions
534  */
535 
536 DMHENV __alloc_env( void );
537 int __validate_env( DMHENV );
538 void __release_env( DMHENV environment );
539 
540 DMHDBC __alloc_dbc( void );
541 int __validate_dbc( DMHDBC );
542 void __release_dbc( DMHDBC connection );
543 
544 DMHSTMT __alloc_stmt( void );
545 void __register_stmt ( DMHDBC connection, DMHSTMT statement );
546 void __set_stmt_state ( DMHDBC connection, SQLSMALLINT cb_value );
547 int __validate_stmt( DMHSTMT );
548 void __release_stmt( DMHSTMT );
549 
550 DMHDESC __alloc_desc( void );
551 int __validate_desc( DMHDESC );
552 void __release_desc( DMHDESC );
553 
554 /*
555  * generic functions
556  */
557 
558 SQLRETURN __SQLAllocHandle( SQLSMALLINT handle_type,
559            SQLHANDLE input_handle,
560            SQLHANDLE *output_handle,
561            SQLINTEGER requested_version );
562 
563 SQLRETURN __SQLFreeHandle( SQLSMALLINT handle_type,
564            SQLHANDLE handle );
565 
566 SQLRETURN __SQLGetInfo( SQLHDBC connection_handle,
567 		 	SQLUSMALLINT info_type,
568 			SQLPOINTER info_value,
569 			SQLSMALLINT buffer_length,
570 			SQLSMALLINT *string_length );
571 
572 int __connect_part_one( DMHDBC connection, char *driver_lib, char *driver_name, int *warnings );
573 void __disconnect_part_one( DMHDBC connection );
574 int __connect_part_two( DMHDBC connection );
575 void __disconnect_part_two( DMHDBC connection );
576 void __disconnect_part_three( DMHDBC connection );
577 void __disconnect_part_four( DMHDBC connection );
578 DMHDBC __get_dbc_root( void );
579 
580 void  __check_for_function( DMHDBC connection,
581         SQLUSMALLINT function_id,
582         SQLUSMALLINT *supported );
583 
584 int __clean_stmt_from_dbc( DMHDBC connection );
585 int __clean_desc_from_dbc( DMHDBC connection );
586 void __map_error_state( char * state, int requested_version );
587 void __map_error_state_w( SQLWCHAR * wstate, int requested_version );
588 
589 /*
590  * mapping from ODBC 2 <-> 3 datetime types
591  */
592 
593 #define MAP_SQL_DM2D 	0
594 #define MAP_SQL_D2DM 	1
595 #define MAP_C_DM2D 	2
596 #define MAP_C_D2DM 	3
597 
598 SQLSMALLINT __map_type( int map, DMHDBC connection, SQLSMALLINT type);
599 
600 /*
601  * error functions
602  */
603 
604 typedef enum error_id
605 {
606     ERROR_01000,
607     ERROR_01004,
608     ERROR_01S02,
609     ERROR_01S06,
610     ERROR_07005,
611     ERROR_07009,
612     ERROR_08002,
613     ERROR_08003,
614     ERROR_24000,
615     ERROR_25000,
616     ERROR_25S01,
617     ERROR_S1000,
618     ERROR_S1003,
619     ERROR_S1010,
620     ERROR_S1011,
621     ERROR_S1107,
622     ERROR_S1108,
623     ERROR_S1C00,
624     ERROR_HY001,
625     ERROR_HY003,
626     ERROR_HY004,
627     ERROR_HY007,
628     ERROR_HY009,
629     ERROR_HY010,
630     ERROR_HY011,
631     ERROR_HY012,
632     ERROR_HY013,
633     ERROR_HY017,
634     ERROR_HY024,
635     ERROR_HY090,
636     ERROR_HY092,
637     ERROR_HY095,
638     ERROR_HY097,
639     ERROR_HY098,
640     ERROR_HY099,
641     ERROR_HY100,
642     ERROR_HY101,
643     ERROR_HY103,
644     ERROR_HY105,
645     ERROR_HY106,
646     ERROR_HY110,
647     ERROR_HY111,
648     ERROR_HYC00,
649     ERROR_IM001,
650     ERROR_IM002,
651     ERROR_IM003,
652     ERROR_IM004,
653     ERROR_IM005,
654     ERROR_IM010,
655     ERROR_IM012,
656     ERROR_SL004,
657     ERROR_SL009,
658     ERROR_SL010,
659     ERROR_SL008,
660     ERROR_HY000,
661     ERROR_IM011
662 } error_id;
663 
664 #define IGNORE_THREAD       (-1)
665 
666 #define function_return(l,h,r,d)    function_return_ex(l,h,r,FALSE,d)
667 
668 #define SUBCLASS_ODBC           0
669 #define SUBCLASS_ISO            1
670 
671 void __post_internal_error( EHEAD *error_handle,
672         error_id, char *txt, int connection_mode );
673 void __post_internal_error_api( EHEAD *error_handle,
674         error_id, char *txt, int connection_mode, int calling_api );
675 void __post_internal_error_ex( EHEAD *error_handle,
676         SQLCHAR *sqlstate,
677         SQLINTEGER native_error,
678         SQLCHAR *message_text,
679         int class_origin,
680         int subclass_origin );
681 void __post_internal_error_ex_noprefix( EHEAD *error_handle,
682         SQLCHAR *sqlstate,
683         SQLINTEGER native_error,
684         SQLCHAR *message_text,
685         int class_origin,
686         int subclass_origin );
687 void __post_internal_error_ex_w( EHEAD *error_handle,
688         SQLWCHAR *sqlstate,
689         SQLINTEGER native_error,
690         SQLWCHAR *message_text,
691         int class_origin,
692         int subclass_origin );
693 void __post_internal_error_ex_w_noprefix( EHEAD *error_handle,
694         SQLWCHAR *sqlstate,
695         SQLINTEGER native_error,
696         SQLWCHAR *message_text,
697         int class_origin,
698         int subclass_origin );
699 
700 void extract_error_from_driver( EHEAD * error_handle,
701         DMHDBC hdbc,
702         int ret_code,
703         int save_to_diag );
704 
705 int function_return_nodrv( int level, void *handle, int ret_code );
706 int function_return_ex( int level, void * handle, int ret_code, int save_to_diag, int defer_type );
707 void function_entry( void *handle );
708 void setup_error_head( EHEAD *error_header, void *handle, int handle_type );
709 void clear_error_head( EHEAD *error_header );
710 SQLWCHAR *ansi_to_unicode_copy( SQLWCHAR * dest, char *src, SQLINTEGER buffer_len, DMHDBC connection, int *wlen );
711 SQLWCHAR *ansi_to_unicode_alloc( SQLCHAR *str, SQLINTEGER len, DMHDBC connection, int *wlen );
712 char *unicode_to_ansi_copy( char* dest, int dest_len, SQLWCHAR *src, SQLINTEGER len, DMHDBC connection, int *clen );
713 char *unicode_to_ansi_alloc( SQLWCHAR *str, SQLINTEGER len, DMHDBC connection, int *clen );
714 int unicode_setup( DMHDBC connection );
715 void unicode_shutdown( DMHDBC connection );
716 char * __get_return_status( SQLRETURN ret, SQLCHAR *buffer );
717 char * __sql_as_text( SQLINTEGER type );
718 char * __c_as_text( SQLINTEGER type );
719 char * __string_with_length( SQLCHAR *out, SQLCHAR *str, SQLINTEGER len );
720 char * __string_with_length_pass( SQLCHAR *out, SQLCHAR *str, SQLINTEGER len );
721 char * __string_with_length_hide_pwd( SQLCHAR *out, SQLCHAR *str, SQLINTEGER len );
722 char * __wstring_with_length( SQLCHAR *out, SQLWCHAR *str, SQLINTEGER len );
723 char * __wstring_with_length_pass( SQLCHAR *out, SQLWCHAR *str, SQLINTEGER len );
724 char * __wstring_with_length_hide_pwd( SQLCHAR *out, SQLWCHAR *str, SQLINTEGER len );
725 SQLWCHAR *wide_strcpy( SQLWCHAR *str1, SQLWCHAR *str2 );
726 SQLWCHAR *wide_strncpy( SQLWCHAR *str1, SQLWCHAR *str2, int buffer_length );
727 SQLWCHAR *wide_strcat( SQLWCHAR *str1, SQLWCHAR *str2 );
728 SQLWCHAR *wide_strdup( SQLWCHAR *str1 );
729 int wide_strlen( SQLWCHAR *str1 );
730 int wide_ansi_strncmp( SQLWCHAR *str1, char *str2, int len );
731 char * __get_pid( SQLCHAR *str );
732 char * __iptr_as_string( SQLCHAR *s, SQLINTEGER *ptr );
733 char * __ptr_as_string( SQLCHAR *s, SQLLEN *ptr );
734 char * __sptr_as_string( SQLCHAR *s, SQLSMALLINT *ptr );
735 char * __info_as_string( SQLCHAR *s, SQLINTEGER typ );
736 void __clear_internal_error( struct error *error_handle );
737 char * __data_as_string( SQLCHAR *s, SQLINTEGER type,
738         SQLLEN *ptr, SQLPOINTER buf );
739 char * __sdata_as_string( SQLCHAR *s, SQLINTEGER type,
740         SQLSMALLINT *ptr, SQLPOINTER buf );
741 char * __idata_as_string( SQLCHAR *s, SQLINTEGER type,
742         SQLINTEGER *ptr, SQLPOINTER buf );
743 char * __col_attr_as_string( SQLCHAR *s, SQLINTEGER type );
744 char * __fid_as_string( SQLCHAR *s, SQLINTEGER fid );
745 char * __con_attr_as_string( SQLCHAR *s, SQLINTEGER type );
746 char * __env_attr_as_string( SQLCHAR *s, SQLINTEGER type );
747 char * __stmt_attr_as_string( SQLCHAR *s, SQLINTEGER type );
748 char * __desc_attr_as_string( SQLCHAR *s, SQLINTEGER type );
749 char * __diag_attr_as_string( SQLCHAR *s, SQLINTEGER type );
750 char * __type_as_string( SQLCHAR *s, SQLSMALLINT type );
751 DMHDBC __get_connection( EHEAD * head );
752 DRV_SQLHANDLE __get_driver_handle( EHEAD * head );
753 int __get_version( EHEAD * head );
754 int dm_check_connection_attrs( DMHDBC connection, SQLINTEGER attribute, SQLPOINTER value );
755 int dm_check_statement_attrs( DMHSTMT statement, SQLINTEGER attribute, SQLPOINTER value );
756 int __check_stmt_from_dbc( DMHDBC connection, int state );
757 #define MAX_STATE_ARGS  8
758 int __check_stmt_from_dbc_v( DMHDBC connection, int statecount, ... );
759 int __check_stmt_from_desc( DMHDESC desc, int state );
760 int __check_stmt_from_desc_ird( DMHDESC desc, int state );
761 
762 /*
763  * These are passed to the cursor lib as helper functions
764  */
765 
766 struct driver_helper_funcs
767 {
768     void (*__post_internal_error_ex)( EHEAD *error_header,
769             SQLCHAR *sqlstate,
770             SQLINTEGER native_error,
771             SQLCHAR *message_text,
772             int class_origin,
773             int subclass_origin );
774 
775     void (*__post_internal_error)( EHEAD *error_handle,
776         error_id id, char *txt, int connection_mode );
777     void (*dm_log_write)( char *function_name, int line, int type, int severity,
778         char *message );
779 };
780 
781 /*
782  * thread protection funcs
783  */
784 
785 #if defined ( HAVE_LIBPTHREAD ) || defined ( HAVE_LIBTHREAD ) || defined ( HAVE_LIBPTH )
786 
787 void thread_protect( int type, void *handle );
788 void thread_release( int type, void *handle );
789 
790 #else
791 
792 #define thread_protect(a,b)
793 #define thread_release(a,b)
794 
795 #endif
796 
797 void dbc_change_thread_support( DMHDBC connection, int level );
798 
799 #ifdef WITH_HANDLE_REDIRECT
800 
801 void *find_parent_handle( DRV_SQLHANDLE hand, int type );
802 
803 #endif
804 
805 /*
806  * lookup functions
807  */
808 
809 char *__find_lib_name( char *dsn, char *lib_name, char *driver_name );
810 
811 /*
812  * setup the cursor library
813  */
814 
815 SQLRETURN SQL_API CLConnect( DMHDBC connection, struct driver_helper_funcs * );
816 
817 /*
818  * connection string functions
819  */
820 
821 struct con_pair
822 {
823     char            *keyword;
824     char            *attribute;
825     char            *identifier;
826     struct con_pair *next;
827 };
828 
829 struct con_struct
830 {
831     int             count;
832     struct con_pair *list;
833 };
834 
835 void __generate_connection_string( struct con_struct *con_str, char *str, int str_len );
836 int __parse_connection_string( struct con_struct *con_str,
837     char *str, int str_len );
838 int __parse_connection_string_w( struct con_struct *con_str,
839     SQLWCHAR *str, int str_len );
840 char * __get_attribute_value( struct con_struct * con_str, char * keyword );
841 void __release_conn( struct con_struct *con_str );
842 void __get_attr( char ** cp, char ** keyword, char ** value );
843 struct con_pair * __get_pair( char ** cp );
844 int __append_pair( struct con_struct *con_str, char *kword, char *value );
845 void __handle_attr_extensions_cs( DMHDBC connection, struct con_struct *con_str );
846 void __strip_from_pool( DMHENV env );
847 
848 void extract_diag_error_w( int htype,
849                             DRV_SQLHANDLE handle,
850                             DMHDBC connection,
851                             EHEAD *head,
852                             int return_code,
853                             int save_to_diag );
854 
855 void extract_diag_error( int htype,
856                             DRV_SQLHANDLE handle,
857                             DMHDBC connection,
858                             EHEAD *head,
859                             int return_code,
860                             int save_to_diag );
861 
862 void extract_sql_error_w( DRV_SQLHANDLE henv,
863                             DRV_SQLHANDLE hdbc,
864                             DRV_SQLHANDLE hstmt,
865                             DMHDBC connection,
866                             EHEAD *head,
867                             int return_code );
868 
869 void extract_sql_error( DRV_SQLHANDLE henv,
870                             DRV_SQLHANDLE hdbc,
871                             DRV_SQLHANDLE hstmt,
872                             DMHDBC connection,
873                             EHEAD *head,
874                             int return_code );
875 /*
876  * the following two are part of a effort to get a particular unicode driver working
877  */
878 
879 SQLINTEGER map_ca_odbc3_to_2( SQLINTEGER field_identifier );
880 SQLINTEGER map_ca_odbc2_to_3( SQLINTEGER field_identifier );
881 
882 /*
883  * check the type passed to SQLBindCol is a valid C_TYPE
884  */
885 
886 int check_target_type( int c_type, int connection_mode);
887 
888 /*
889  * entry exit functions in drivers
890  */
891 
892 #define ODBC_INI_FUNCTION           "SQLDriverLoad"
893 #define ODBC_FINI_FUNCTION          "SQLDriverUnload"
894 
895 /*
896  * driver manager logging functions
897  */
898 
899 void dm_log_open( char *program_name, char *log_file, int pid_logging );
900 
901 void dm_log_write( char *function_name, int line, int type, int severity, char *message );
902 void dm_log_write_diag( char *message );
903 
904 void dm_log_close( void );
905 
906 /*
907  * connection pooling functions
908  */
909 
910 int search_for_pool( DMHDBC connection,
911            SQLCHAR *server_name,
912            SQLSMALLINT name_length1,
913            SQLCHAR *user_name,
914            SQLSMALLINT name_length2,
915            SQLCHAR *authentication,
916            SQLSMALLINT name_length3,
917            SQLCHAR *connect_string,
918            SQLSMALLINT connect_string_length );
919 
920 void return_to_pool( DMHDBC connection );
921 
922 /*
923  * Macros to check and call functions in the driver
924  */
925 
926 #define DM_SQLALLOCCONNECT          0
927 #define CHECK_SQLALLOCCONNECT(con)  (con->functions[0].func!=NULL)
928 #define SQLALLOCCONNECT(con,env,oh)\
929                                     (con->functions[0].func)(env,oh)
930 
931 #define DM_SQLALLOCENV              1
932 #define CHECK_SQLALLOCENV(con)      (con->functions[1].func!=NULL)
933 #define SQLALLOCENV(con,oh)\
934                                     (con->functions[1].func)(oh)
935 
936 #define DM_SQLALLOCHANDLE           2
937 #define CHECK_SQLALLOCHANDLE(con)   (con->functions[2].func!=NULL)
938     /*
939      * if the function is in the cursor lib, pass a additional
940      * arg that allows the cursor lib to get the dm handle
941      */
942 #define SQLALLOCHANDLE(con,ht,ih,oh,dmh)\
943             (con->cl_handle?\
944                     (con->functions[2].func)(ht,ih,oh,dmh):\
945                     (con->functions[2].func)(ht,ih,oh))
946 
947 #define DM_SQLALLOCSTMT             3
948 #define CHECK_SQLALLOCSTMT(con)     (con->functions[3].func!=NULL)
949 #define SQLALLOCSTMT(con,dbc,oh,dmh)\
950             (con->cl_handle?\
951                     (con->functions[3].func)(dbc,oh,dmh):\
952                     (con->functions[3].func)(dbc,oh))
953 
954 #define DM_SQLALLOCHANDLESTD        4
955 
956 #define DM_SQLBINDCOL               5
957 #define CHECK_SQLBINDCOL(con)       (con->functions[5].func!=NULL)
958 #define SQLBINDCOL(con,stmt,cn,tt,tvp,bl,sli)\
959                                     (con->functions[5].func)\
960                                         (stmt,cn,tt,tvp,bl,sli)
961 
962 #define DM_SQLBINDPARAM             6
963 #define CHECK_SQLBINDPARAM(con)     (con->functions[6].func!=NULL)
964 #define SQLBINDPARAM(con,stmt,pn,vt,pt,cs,dd,pvp,ind)\
965                                     (con->functions[6].func)\
966                                         (stmt,pn,vt,pt,cs,dd,pvp,ind)
967 
968 #define DM_SQLBINDPARAMETER         7
969 #define CHECK_SQLBINDPARAMETER(con) (con->functions[7].func!=NULL)
970 #define SQLBINDPARAMETER(con,stmt,pn,typ,vt,pt,cs,dd,pvp,bl,ind)\
971                                     (con->functions[7].func)\
972                                         (stmt,pn,typ,vt,pt,cs,dd,pvp,bl,ind)
973 
974 #define DM_SQLBROWSECONNECT         8
975 #define CHECK_SQLBROWSECONNECT(con) (con->functions[8].func!=NULL)
976 #define SQLBROWSECONNECT(con,dbc,ics,sl1,ocs,bl,sl2)\
977                                     (con->functions[8].func)\
978                                     (dbc,ics,sl1,ocs,bl,sl2)
979 #define CHECK_SQLBROWSECONNECTW(con) (con->functions[8].funcW!=NULL)
980 #define SQLBROWSECONNECTW(con,dbc,ics,sl1,ocs,bl,sl2)\
981                                     (con->functions[8].funcW)\
982                                     (dbc,ics,sl1,ocs,bl,sl2)
983 
984 #define DM_SQLBULKOPERATIONS        9
985 #define CHECK_SQLBULKOPERATIONS(con)    (con->functions[9].func!=NULL)
986 #define SQLBULKOPERATIONS(con,stmt,op)\
987                                     (con->functions[9].func)(stmt,op)
988 
989 #define DM_SQLCANCEL                10
990 #define CHECK_SQLCANCEL(con)        (con->functions[10].func!=NULL)
991 #define SQLCANCEL(con,stmt)\
992                                     (con->functions[10].func)(stmt)
993 
994 #define DM_SQLCLOSECURSOR           11
995 #define CHECK_SQLCLOSECURSOR(con)   (con->functions[11].func!=NULL)
996 #define SQLCLOSECURSOR(con,stmt)\
997                                     (con->functions[11].func)(stmt)
998 
999 #define DM_SQLCOLATTRIBUTE          12
1000 #define CHECK_SQLCOLATTRIBUTE(con)  (con->functions[12].func!=NULL)
1001 #define SQLCOLATTRIBUTE(con,stmt,cn,fi,cap,bl,slp,nap)\
1002                                     (con->functions[12].func)\
1003                                         (stmt,cn,fi,cap,bl,slp,nap)
1004 #define CHECK_SQLCOLATTRIBUTEW(con)  (con->functions[12].funcW!=NULL)
1005 #define SQLCOLATTRIBUTEW(con,stmt,cn,fi,cap,bl,slp,nap)\
1006                                     (con->functions[12].funcW)\
1007                                         (stmt,cn,fi,cap,bl,slp,nap)
1008 
1009 #define DM_SQLCOLATTRIBUTES         13
1010 #define CHECK_SQLCOLATTRIBUTES(con) (con->functions[13].func!=NULL)
1011 #define SQLCOLATTRIBUTES(con,stmt,cn,fi,cap,bl,slp,nap)\
1012                                     (con->functions[13].func)\
1013                                         (stmt,cn,fi,cap,bl,slp,nap)
1014 #define CHECK_SQLCOLATTRIBUTESW(con) (con->functions[13].funcW!=NULL)
1015 #define SQLCOLATTRIBUTESW(con,stmt,cn,fi,cap,bl,slp,nap)\
1016                                     (con->functions[13].funcW)\
1017                                         (stmt,cn,fi,cap,bl,slp,nap)
1018 
1019 #define DM_SQLCOLUMNPRIVILEGES      14
1020 #define CHECK_SQLCOLUMNPRIVILEGES(con)  (con->functions[14].func!=NULL)
1021 #define SQLCOLUMNPRIVILEGES(con,stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)\
1022                                     (con->functions[14].func)\
1023                                         (stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)
1024 #define CHECK_SQLCOLUMNPRIVILEGESW(con)  (con->functions[14].funcW!=NULL)
1025 #define SQLCOLUMNPRIVILEGESW(con,stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)\
1026                                     (con->functions[14].funcW)\
1027                                         (stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)
1028 
1029 #define DM_SQLCOLUMNS               15
1030 #define CHECK_SQLCOLUMNS(con)       (con->functions[15].func!=NULL)
1031 #define SQLCOLUMNS(con,stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)\
1032                                     (con->functions[15].func)\
1033                                         (stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)
1034 #define CHECK_SQLCOLUMNSW(con)       (con->functions[15].funcW!=NULL)
1035 #define SQLCOLUMNSW(con,stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)\
1036                                     (con->functions[15].funcW)\
1037                                         (stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)
1038 
1039 #define DM_SQLCONNECT               16
1040 #define CHECK_SQLCONNECT(con)       (con->functions[16].func!=NULL)
1041 #define SQLCONNECT(con,dbc,dsn,l1,uid,l2,at,l3)\
1042                                     (con->functions[16].func)\
1043                                     (dbc,dsn,l1,uid,l2,at,l3)
1044 #define CHECK_SQLCONNECTW(con)       (con->functions[16].funcW!=NULL)
1045 #define SQLCONNECTW(con,dbc,dsn,l1,uid,l2,at,l3)\
1046                                     (con->functions[16].funcW)\
1047                                     (dbc,dsn,l1,uid,l2,at,l3)
1048 
1049 #define DM_SQLCOPYDESC              17
1050 #define CHECK_SQLCOPYDESC(con)      (con->functions[17].func!=NULL)
1051 #define SQLCOPYDESC(con,sd,td)\
1052                                     (con->functions[17].func)(sd,td)
1053 
1054 #define DM_SQLDATASOURCES           18
1055 
1056 #define DM_SQLDESCRIBECOL           19
1057 #define CHECK_SQLDESCRIBECOL(con)   (con->functions[19].func!=NULL)
1058 #define SQLDESCRIBECOL(con,stmt,cnum,cn,bli,nl,dt,cs,dd,n)\
1059                                     (con->functions[19].func)\
1060                                         (stmt,cnum,cn,bli,nl,dt,cs,dd,n)
1061 #define CHECK_SQLDESCRIBECOLW(con)   (con->functions[19].funcW!=NULL)
1062 #define SQLDESCRIBECOLW(con,stmt,cnum,cn,bli,nl,dt,cs,dd,n)\
1063                                     (con->functions[19].funcW)\
1064                                         (stmt,cnum,cn,bli,nl,dt,cs,dd,n)
1065 
1066 #define DM_SQLDESCRIBEPARAM         20
1067 #define CHECK_SQLDESCRIBEPARAM(con) (con->functions[20].func!=NULL)
1068 #define SQLDESCRIBEPARAM(con,stmt,pn,dtp,psp,ddp,np)\
1069                                     (con->functions[20].func)\
1070                                         (stmt,pn,dtp,psp,ddp,np)
1071 
1072 #define DM_SQLDISCONNECT            21
1073 #define CHECK_SQLDISCONNECT(con)    (con->functions[21].func!=NULL)
1074 #define SQLDISCONNECT(con,dbc)\
1075                                     (con->functions[21].func)(dbc)
1076 
1077 #define DM_SQLDRIVERCONNECT         22
1078 #define CHECK_SQLDRIVERCONNECT(con) (con->functions[22].func!=NULL)
1079 #define SQLDRIVERCONNECT(con,dbc,wh,ics,sl1,ocs,bl,sl2p,dc)\
1080                                     (con->functions[22].func)\
1081                                         (dbc,wh,ics,sl1,ocs,bl,sl2p,dc)
1082 
1083 #define CHECK_SQLDRIVERCONNECTW(con) (con->functions[22].funcW!=NULL)
1084 #define SQLDRIVERCONNECTW(con,dbc,wh,ics,sl1,ocs,bl,sl2p,dc)\
1085                                      (con->functions[22].funcW)\
1086                                         (dbc,wh,ics,sl1,ocs,bl,sl2p,dc)
1087 
1088 #define DM_SQLDRIVERS               23
1089 
1090 #define DM_SQLENDTRAN               24
1091 #define CHECK_SQLENDTRAN(con)       (con->functions[24].func!=NULL)
1092 #define SQLENDTRAN(con,ht,h,op)\
1093                                     (con->functions[24].func)(ht,h,op)
1094 
1095 #define DM_SQLERROR                 25
1096 #define CHECK_SQLERROR(con)         (con->functions[25].func!=NULL)
1097 #define SQLERROR(con,env,dbc,stmt,st,nat,msg,mm,pcb)\
1098                                     (con->functions[25].func)\
1099                                         (env,dbc,stmt,st,nat,msg,mm,pcb)
1100 #define CHECK_SQLERRORW(con)         (con->functions[25].funcW!=NULL)
1101 #define SQLERRORW(con,env,dbc,stmt,st,nat,msg,mm,pcb)\
1102                                      (con->functions[25].funcW)\
1103                                         (env,dbc,stmt,st,nat,msg,mm,pcb)
1104 
1105 #define DM_SQLEXECDIRECT            26
1106 #define CHECK_SQLEXECDIRECT(con)    (con->functions[26].func!=NULL)
1107 #define SQLEXECDIRECT(con,stmt,sql,len)\
1108                                     (con->functions[26].func)(stmt,sql,len)
1109 #define CHECK_SQLEXECDIRECTW(con)    (con->functions[26].funcW!=NULL)
1110 #define SQLEXECDIRECTW(con,stmt,sql,len)\
1111                                     (con->functions[26].funcW)(stmt,sql,len)
1112 
1113 #define DM_SQLEXECUTE               27
1114 #define CHECK_SQLEXECUTE(con)       (con->functions[27].func!=NULL)
1115 #define SQLEXECUTE(con,stmt)\
1116                                     (con->functions[27].func)(stmt)
1117 
1118 #define DM_SQLEXTENDEDFETCH         28
1119 #define CHECK_SQLEXTENDEDFETCH(con) (con->functions[28].func!=NULL)
1120 #define SQLEXTENDEDFETCH(con,stmt,fo,of,rcp,ssa)\
1121                                     (con->functions[28].func)\
1122                                         (stmt,fo,of,rcp,ssa)
1123 
1124 #define DM_FETCH                    29
1125 #define CHECK_SQLFETCH(con)         (con->functions[29].func!=NULL)
1126 #define SQLFETCH(con,stmt)\
1127                                     (con->functions[29].func)(stmt)
1128 
1129 #define DM_SQLFETCHSCROLL           30
1130 #define CHECK_SQLFETCHSCROLL(con)   (con->functions[30].func!=NULL)
1131 #define SQLFETCHSCROLL(con,stmt,or,of)\
1132                                     (con->functions[30].func)\
1133                                         (stmt,or,of)
1134 
1135 #define DM_SQLFOREIGNKEYS           31
1136 #define CHECK_SQLFOREIGNKEYS(con)   (con->functions[31].func!=NULL)
1137 #define SQLFOREIGNKEYS(con,stmt,cn,nl1,sn,nl2,tn,nl3,fcn,nl4,fsn,nl5,ftn,nl6)\
1138                                     (con->functions[31].func)\
1139                                         (stmt,cn,nl1,sn,nl2,tn,nl3,fcn,nl4,fsn,nl5,ftn,nl6)
1140 #define CHECK_SQLFOREIGNKEYSW(con)   (con->functions[31].funcW!=NULL)
1141 #define SQLFOREIGNKEYSW(con,stmt,cn,nl1,sn,nl2,tn,nl3,fcn,nl4,fsn,nl5,ftn,nl6)\
1142                                     (con->functions[31].funcW)\
1143                                         (stmt,cn,nl1,sn,nl2,tn,nl3,fcn,nl4,fsn,nl5,ftn,nl6)
1144 
1145 #define DM_SQLFREEENV               32
1146 #define CHECK_SQLFREEENV(con)       (con->functions[32].func!=NULL)
1147 #define SQLFREEENV(con,env)\
1148                                     (con->functions[32].func)(env)
1149 
1150 #define DM_SQLFREEHANDLE            33
1151 #define CHECK_SQLFREEHANDLE(con)    (con->functions[33].func!=NULL)
1152 #define SQLFREEHANDLE(con,typ,env)\
1153                                     (con->functions[33].func)(typ,env)
1154 
1155 #define DM_SQLFREESTMT              34
1156 #define CHECK_SQLFREESTMT(con)      (con->functions[34].func!=NULL)
1157 #define SQLFREESTMT(con,stmt,opt)\
1158                                     (con->functions[34].func)(stmt,opt)
1159 
1160 #define DM_SQLFREECONNECT           35
1161 #define CHECK_SQLFREECONNECT(con)   (con->functions[35].func!=NULL)
1162 #define SQLFREECONNECT(con,dbc)\
1163                                     (con->functions[35].func)(dbc)
1164 
1165 #define DM_SQLGETCONNECTATTR        36
1166 #define CHECK_SQLGETCONNECTATTR(con)    (con->functions[36].func!=NULL)
1167 #define SQLGETCONNECTATTR(con,dbc,at,vp,bl,slp)\
1168                                     (con->functions[36].func)\
1169                                         (dbc,at,vp,bl,slp)
1170 #define CHECK_SQLGETCONNECTATTRW(con)    (con->functions[36].funcW!=NULL)
1171 #define SQLGETCONNECTATTRW(con,dbc,at,vp,bl,slp)\
1172                                     (con->functions[36].funcW)\
1173                                         (dbc,at,vp,bl,slp)
1174 
1175 #define DM_SQLGETCONNECTOPTION      37
1176 #define CHECK_SQLGETCONNECTOPTION(con)  (con->functions[37].func!=NULL)
1177 #define SQLGETCONNECTOPTION(con,dbc,at,val)\
1178                                     (con->functions[37].func)\
1179                                         (dbc,at,val)
1180 #define CHECK_SQLGETCONNECTOPTIONW(con)  (con->functions[37].funcW!=NULL)
1181 #define SQLGETCONNECTOPTIONW(con,dbc,at,val)\
1182                                     (con->functions[37].funcW)\
1183                                         (dbc,at,val)
1184 
1185 #define DM_SQLGETCURSORNAME         38
1186 #define CHECK_SQLGETCURSORNAME(con) (con->functions[38].func!=NULL)
1187 #define SQLGETCURSORNAME(con,stmt,cn,bl,nlp)\
1188                                     (con->functions[38].func)\
1189                                         (stmt,cn,bl,nlp)
1190 #define CHECK_SQLGETCURSORNAMEW(con) (con->functions[38].funcW!=NULL)
1191 #define SQLGETCURSORNAMEW(con,stmt,cn,bl,nlp)\
1192                                     (con->functions[38].funcW)\
1193                                         (stmt,cn,bl,nlp)
1194 
1195 #define DM_SQLGETDATA               39
1196 #define CHECK_SQLGETDATA(con)       (con->functions[39].func!=NULL)
1197 #define SQLGETDATA(con,stmt,cn,tt,tvp,bl,sli)\
1198                                     (con->functions[39].func)\
1199                                         (stmt,cn,tt,tvp,bl,sli)
1200 
1201 #define DM_SQLGETDESCFIELD          40
1202 #define CHECK_SQLGETDESCFIELD(con)  (con->functions[40].func!=NULL)
1203 #define SQLGETDESCFIELD(con,des,rn,fi,vp,bl,slp)\
1204                                     (con->functions[40].func)\
1205                                         (des,rn,fi,vp,bl,slp)
1206 #define CHECK_SQLGETDESCFIELDW(con)  (con->functions[40].funcW!=NULL)
1207 #define SQLGETDESCFIELDW(con,des,rn,fi,vp,bl,slp)\
1208                                     (con->functions[40].funcW)\
1209                                         (des,rn,fi,vp,bl,slp)
1210 
1211 #define DM_SQLGETDESCREC            41
1212 #define CHECK_SQLGETDESCREC(con)    (con->functions[41].func!=NULL)
1213 #define SQLGETDESCREC(con,des,rn,n,bl,slp,tp,stp,lp,pp,sp,np)\
1214                                     (con->functions[41].func)\
1215                                         (des,rn,n,bl,slp,tp,stp,lp,pp,sp,np)
1216 #define CHECK_SQLGETDESCRECW(con)    (con->functions[41].funcW!=NULL)
1217 #define SQLGETDESCRECW(con,des,rn,n,bl,slp,tp,stp,lp,pp,sp,np)\
1218                                     (con->functions[41].funcW)\
1219                                         (des,rn,n,bl,slp,tp,stp,lp,pp,sp,np)
1220 
1221 #define DM_SQLGETDIAGFIELD          42
1222 #define CHECK_SQLGETDIAGFIELD(con)  (con->functions[42].func!=NULL)
1223 #define SQLGETDIAGFIELD(con,typ,han,rn,di,dip,bl,slp)\
1224                                     (con->functions[42].func)\
1225                                         (typ,han,rn,di,dip,bl,slp)
1226 #define CHECK_SQLGETDIAGFIELDW(con)  (con->functions[42].funcW!=NULL)
1227 #define SQLGETDIAGFIELDW(con,typ,han,rn,di,dip,bl,slp)\
1228                                     (con->functions[42].funcW)\
1229                                         (typ,han,rn,di,dip,bl,slp)
1230 
1231 #define DM_SQLGETENVATTR            43
1232 #define CHECK_SQLGETENVATTR(con)    (con->functions[43].func!=NULL)
1233 #define SQLGETENVATTR(con,env,attr,val,len,ol)\
1234                                     (con->functions[43].func)\
1235                                     (env,attr,val,len,ol)
1236 
1237 #define DM_SQLGETFUNCTIONS          44
1238 #define CHECK_SQLGETFUNCTIONS(con)  (con->functions[44].func!=NULL)
1239 #define SQLGETFUNCTIONS(con,dbc,id,ptr)\
1240                                     (con->functions[44].func)\
1241                                         (dbc,id,ptr)
1242 
1243 #define DM_SQLGETINFO               45
1244 #define CHECK_SQLGETINFO(con)       (con->functions[45].func!=NULL)
1245 #define SQLGETINFO(con,dbc,it,ivo,bl,slp)\
1246                                     (con->functions[45].func)\
1247                                         (dbc,it,ivo,bl,slp)
1248 #define CHECK_SQLGETINFOW(con)       (con->functions[45].funcW!=NULL)
1249 #define SQLGETINFOW(con,dbc,it,ivo,bl,slp)\
1250                                     (con->functions[45].funcW)\
1251                                         (dbc,it,ivo,bl,slp)
1252 
1253 #define DM_SQLGETSTMTATTR           46
1254 #define CHECK_SQLGETSTMTATTR(con)   (con->functions[46].func!=NULL)
1255 #define SQLGETSTMTATTR(con,stmt,at,vp,bl,slp)\
1256                                     (con->functions[46].func)\
1257                                         (stmt,at,vp,bl,slp)
1258 #define CHECK_SQLGETSTMTATTRW(con)   (con->functions[46].funcW!=NULL)
1259 #define SQLGETSTMTATTRW(con,stmt,at,vp,bl,slp)\
1260                                     (con->functions[46].funcW)\
1261                                         (stmt,at,vp,bl,slp)
1262 #define DM_SQLGETSTMTOPTION         47
1263 #define CHECK_SQLGETSTMTOPTION(con) (con->functions[47].func!=NULL)
1264 #define SQLGETSTMTOPTION(con,stmt,op,val)\
1265                                     (con->functions[47].func)\
1266                                         (stmt,op,val)
1267 #define CHECK_SQLGETSTMTOPTIONW(con) (con->functions[47].funcW!=NULL)
1268 #define SQLGETSTMTOPTIONW(con,stmt,op,val)\
1269                                     (con->functions[47].funcW)\
1270                                         (stmt,op,val)
1271 
1272 #define DM_SQLGETTYPEINFO           48
1273 #define CHECK_SQLGETTYPEINFO(con)   (con->functions[48].func!=NULL)
1274 #define SQLGETTYPEINFO(con,stmt,typ)\
1275                                     (con->functions[48].func)(stmt,typ)
1276 #define CHECK_SQLGETTYPEINFOW(con)   (con->functions[48].funcW!=NULL)
1277 #define SQLGETTYPEINFOW(con,stmt,typ)\
1278                                     (con->functions[48].funcW)(stmt,typ)
1279 
1280 #define DM_SQLMORERESULTS           49
1281 #define CHECK_SQLMORERESULTS(con)   (con->functions[49].func!=NULL)
1282 #define SQLMORERESULTS(con,stmt)\
1283                                     (con->functions[49].func)(stmt)
1284 
1285 #define DM_SQLNATIVESQL             50
1286 #define CHECK_SQLNATIVESQL(con)     (con->functions[50].func!=NULL)
1287 #define SQLNATIVESQL(con,dbc,ist,tl,ost,bl,tlp)\
1288                                     (con->functions[50].func)\
1289                                         (dbc,ist,tl,ost,bl,tlp)
1290 #define CHECK_SQLNATIVESQLW(con)     (con->functions[50].funcW!=NULL)
1291 #define SQLNATIVESQLW(con,dbc,ist,tl,ost,bl,tlp)\
1292                                     (con->functions[50].funcW)\
1293                                         (dbc,ist,tl,ost,bl,tlp)
1294 
1295 #define DM_SQLNUMPARAMS             51
1296 #define CHECK_SQLNUMPARAMS(con)     (con->functions[51].func!=NULL)
1297 #define SQLNUMPARAMS(con,stmt,cnt)\
1298                                     (con->functions[51].func)(stmt,cnt)
1299 
1300 #define DM_SQLNUMRESULTCOLS         52
1301 #define CHECK_SQLNUMRESULTCOLS(con) (con->functions[52].func!=NULL)
1302 #define SQLNUMRESULTCOLS(con,stmt,cnt)\
1303                                     (con->functions[52].func)(stmt,cnt)
1304 
1305 #define DM_SQLPARAMDATA             53
1306 #define CHECK_SQLPARAMDATA(con)     (con->functions[53].func!=NULL)
1307 #define SQLPARAMDATA(con,stmt,val)\
1308                                     (con->functions[53].func)(stmt,val)
1309 
1310 #define DM_SQLPARAMOPTIONS          54
1311 #define CHECK_SQLPARAMOPTIONS(con)  (con->functions[54].func!=NULL)
1312 #define SQLPARAMOPTIONS(con,stmt,cr,pi)\
1313                                     (con->functions[54].func)(stmt,cr,pi)
1314 
1315 #define DM_SQLPREPARE               55
1316 #define CHECK_SQLPREPARE(con)       (con->functions[55].func!=NULL)
1317 #define SQLPREPARE(con,stmt,sql,len)\
1318                                     (con->functions[55].func)(stmt,sql,len)
1319 #define CHECK_SQLPREPAREW(con)       (con->functions[55].funcW!=NULL)
1320 #define SQLPREPAREW(con,stmt,sql,len)\
1321                                     (con->functions[55].funcW)(stmt,sql,len)
1322 
1323 #define DM_SQLPRIMARYKEYS           56
1324 #define CHECK_SQLPRIMARYKEYS(con)   (con->functions[56].func!=NULL)
1325 #define SQLPRIMARYKEYS(con,stmt,cn,nl1,sn,nl2,tn,nl3)\
1326                                     (con->functions[56].func)\
1327                                         (stmt,cn,nl1,sn,nl2,tn,nl3)
1328 #define CHECK_SQLPRIMARYKEYSW(con)   (con->functions[56].funcW!=NULL)
1329 #define SQLPRIMARYKEYSW(con,stmt,cn,nl1,sn,nl2,tn,nl3)\
1330                                     (con->functions[56].funcW)\
1331                                         (stmt,cn,nl1,sn,nl2,tn,nl3)
1332 
1333 #define DM_SQLPROCEDURECOLUMNS      57
1334 #define CHECK_SQLPROCEDURECOLUMNS(con)  (con->functions[57].func!=NULL)
1335 #define SQLPROCEDURECOLUMNS(con,stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)\
1336                                     (con->functions[57].func)\
1337                                         (stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)
1338 #define CHECK_SQLPROCEDURECOLUMNSW(con)  (con->functions[57].funcW!=NULL)
1339 #define SQLPROCEDURECOLUMNSW(con,stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)\
1340                                     (con->functions[57].funcW)\
1341                                         (stmt,cn,nl1,sn,nl2,tn,nl3,col,nl4)
1342 
1343 #define DM_SQLPROCEDURES            58
1344 #define CHECK_SQLPROCEDURES(con)    (con->functions[58].func!=NULL)
1345 #define SQLPROCEDURES(con,stmt,cn,nl1,sn,nl2,tn,nl3)\
1346                                     (con->functions[58].func)\
1347                                         (stmt,cn,nl1,sn,nl2,tn,nl3)
1348 #define CHECK_SQLPROCEDURESW(con)    (con->functions[58].funcW!=NULL)
1349 #define SQLPROCEDURESW(con,stmt,cn,nl1,sn,nl2,tn,nl3)\
1350                                     (con->functions[58].funcW)\
1351                                         (stmt,cn,nl1,sn,nl2,tn,nl3)
1352 
1353 #define DM_SQLPUTDATA               59
1354 #define CHECK_SQLPUTDATA(con)       (con->functions[59].func!=NULL)
1355 #define SQLPUTDATA(con,stmt,d,p)\
1356                                     (con->functions[59].func)(stmt,d,p)
1357 
1358 #define DM_SQLROWCOUNT              60
1359 #define CHECK_SQLROWCOUNT(con)      (con->functions[60].func!=NULL)
1360 #define DEF_SQLROWCOUNT(con,stmt,cnt)\
1361                                     (con->functions[60].func)(stmt,cnt)
1362 
1363 #define DM_SQLSETCONNECTATTR        61
1364 #define CHECK_SQLSETCONNECTATTR(con)    (con->functions[61].func!=NULL)
1365 #define SQLSETCONNECTATTR(con,dbc,at,vp,sl)\
1366                                     (con->functions[61].func)\
1367                                         (dbc,at,vp,sl)
1368 #define CHECK_SQLSETCONNECTATTRW(con)    (con->functions[61].funcW!=NULL)
1369 #define SQLSETCONNECTATTRW(con,dbc,at,vp,sl)\
1370                                     (con->functions[61].funcW)\
1371                                         (dbc,at,vp,sl)
1372 
1373 #define DM_SQLSETCONNECTOPTION      62
1374 #define CHECK_SQLSETCONNECTOPTION(con)  (con->functions[62].func!=NULL)
1375 #define SQLSETCONNECTOPTION(con,dbc,op,p)\
1376                                     (con->functions[62].func)\
1377                                         (dbc,op,p)
1378 #define CHECK_SQLSETCONNECTOPTIONW(con)  (con->functions[62].funcW!=NULL)
1379 #define SQLSETCONNECTOPTIONW(con,dbc,op,p)\
1380                                     (con->functions[62].funcW)\
1381                                         (dbc,op,p)
1382 
1383 #define DM_SQLSETCURSORNAME         63
1384 #define CHECK_SQLSETCURSORNAME(con) (con->functions[63].func!=NULL)
1385 #define SQLSETCURSORNAME(con,stmt,nam,len)\
1386                                     (con->functions[63].func)(stmt,nam,len)
1387 #define CHECK_SQLSETCURSORNAMEW(con) (con->functions[63].funcW!=NULL)
1388 #define SQLSETCURSORNAMEW(con,stmt,nam,len)\
1389                                     (con->functions[63].funcW)(stmt,nam,len)
1390 
1391 #define DM_SQLSETDESCFIELD          64
1392 #define CHECK_SQLSETDESCFIELD(con)  (con->functions[64].func!=NULL)
1393 #define SQLSETDESCFIELD(con,des,rn,fi,vp,bl)\
1394                                     (con->functions[64].func)\
1395                                     (des,rn,fi,vp,bl)
1396 #define CHECK_SQLSETDESCFIELDW(con)  (con->functions[64].funcW!=NULL)
1397 #define SQLSETDESCFIELDW(con,des,rn,fi,vp,bl)\
1398                                     (con->functions[64].funcW)\
1399                                     (des,rn,fi,vp,bl)
1400 
1401 #define DM_SQLSETDESCREC            65
1402 #define CHECK_SQLSETDESCREC(con)    (con->functions[65].func!=NULL)
1403 #define SQLSETDESCREC(con,des,rn,t,st,l,p,sc,dp,slp,ip)\
1404                                     (con->functions[65].func)\
1405                                         (des,rn,t,st,l,p,sc,dp,slp,ip)
1406 
1407 #define DM_SQLSETENVATTR            66
1408 #define CHECK_SQLSETENVATTR(con)    (con->functions[66].func!=NULL)
1409 #define SQLSETENVATTR(con,env,attr,val,len)\
1410                                     (con->functions[66].func)(env,attr,val,len)
1411 
1412 #define DM_SQLSETPARAM              67
1413 #define CHECK_SQLSETPARAM(con)      (con->functions[67].func!=NULL)
1414 #define SQLSETPARAM(con,stmt,pn,vt,pt,lp,ps,pv,sli)\
1415                                     (con->functions[67].func)\
1416                                         (stmt,pn,vt,pt,lp,ps,pv,sli)
1417 
1418 #define DM_SQLSETPOS                68
1419 #define CHECK_SQLSETPOS(con)        (con->functions[68].func!=NULL)
1420 #define SQLSETPOS(con,stmt,rn,op,lt)\
1421                                     (con->functions[68].func)\
1422                                         (stmt,rn,op,lt)
1423 
1424 #define DM_SQLSETSCROLLOPTIONS      69
1425 #define CHECK_SQLSETSCROLLOPTIONS(con)  (con->functions[69].func!=NULL)
1426 #define SQLSETSCROLLOPTIONS(con,stmt,fc,cr,rs)\
1427                                     (con->functions[69].func)\
1428                                         (stmt,fc,cr,rs)
1429 #define DM_SQLSETSTMTATTR           70
1430 #define CHECK_SQLSETSTMTATTR(con)   (con->functions[70].func!=NULL)
1431 #define SQLSETSTMTATTR(con,stmt,attr,vp,sl)\
1432                                     (con->functions[70].func)\
1433                                         (stmt,attr,vp,sl)
1434 #define CHECK_SQLSETSTMTATTRW(con)   (con->functions[70].funcW!=NULL)
1435 #define SQLSETSTMTATTRW(con,stmt,attr,vp,sl)\
1436                                     (con->functions[70].funcW)\
1437                                         (stmt,attr,vp,sl)
1438 
1439 #define DM_SQLSETSTMTOPTION         71
1440 #define CHECK_SQLSETSTMTOPTION(con) (con->functions[71].func!=NULL)
1441 #define SQLSETSTMTOPTION(con,stmt,op,val)\
1442                                     (con->functions[71].func)\
1443                                         (stmt,op,val)
1444 
1445 #define CHECK_SQLSETSTMTOPTIONW(con)   (con->functions[71].funcW!=NULL)
1446 #define SQLSETSTMTOPTIONW(con,stmt,op,val)\
1447                                     (con->functions[71].funcW)\
1448                                         (stmt,op,val)
1449 
1450 #define DM_SQLSPECIALCOLUMNS        72
1451 #define CHECK_SQLSPECIALCOLUMNS(con)    (con->functions[72].func!=NULL)
1452 #define SQLSPECIALCOLUMNS(con,stmt,it,cn,nl1,sn,nl2,tn,nl3,s,n)\
1453                                     (con->functions[72].func)\
1454                                         (stmt,it,cn,nl1,sn,nl2,tn,nl3,s,n)
1455 #define CHECK_SQLSPECIALCOLUMNSW(con)    (con->functions[72].funcW!=NULL)
1456 #define SQLSPECIALCOLUMNSW(con,stmt,it,cn,nl1,sn,nl2,tn,nl3,s,n)\
1457                                     (con->functions[72].funcW)\
1458                                         (stmt,it,cn,nl1,sn,nl2,tn,nl3,s,n)
1459 
1460 #define DM_SQLSTATISTICS            73
1461 #define CHECK_SQLSTATISTICS(con)    (con->functions[73].func!=NULL)
1462 #define SQLSTATISTICS(con,stmt,cn,nl1,sn,nl2,tn,nl3,un,res)\
1463                                     (con->functions[73].func)\
1464                                         (stmt,cn,nl1,sn,nl2,tn,nl3,un,res)
1465 #define CHECK_SQLSTATISTICSW(con)    (con->functions[73].funcW!=NULL)
1466 #define SQLSTATISTICSW(con,stmt,cn,nl1,sn,nl2,tn,nl3,un,res)\
1467                                     (con->functions[73].funcW)\
1468                                         (stmt,cn,nl1,sn,nl2,tn,nl3,un,res)
1469 
1470 #define DM_SQLTABLEPRIVILEGES       74
1471 #define CHECK_SQLTABLEPRIVILEGES(con)   (con->functions[74].func!=NULL)
1472 #define SQLTABLEPRIVILEGES(con,stmt,cn,nl1,sn,nl2,tn,nl3)\
1473                                     (con->functions[74].func)\
1474                                         (stmt,cn,nl1,sn,nl2,tn,nl3)
1475 #define CHECK_SQLTABLEPRIVILEGESW(con)   (con->functions[74].funcW!=NULL)
1476 #define SQLTABLEPRIVILEGESW(con,stmt,cn,nl1,sn,nl2,tn,nl3)\
1477                                     (con->functions[74].funcW)\
1478                                         (stmt,cn,nl1,sn,nl2,tn,nl3)
1479 
1480 #define DM_SQLTABLES                75
1481 #define CHECK_SQLTABLES(con)        (con->functions[75].func!=NULL)
1482 #define SQLTABLES(con,stmt,cn,nl1,sn,nl2,tn,nl3,tt,nl4)\
1483                                     (con->functions[75].func)\
1484                                         (stmt,cn,nl1,sn,nl2,tn,nl3,tt,nl4)
1485 #define CHECK_SQLTABLESW(con)        (con->functions[75].funcW!=NULL)
1486 #define SQLTABLESW(con,stmt,cn,nl1,sn,nl2,tn,nl3,tt,nl4)\
1487                                     (con->functions[75].funcW)\
1488                                         (stmt,cn,nl1,sn,nl2,tn,nl3,tt,nl4)
1489 
1490 #define DM_SQLTRANSACT              76
1491 #define CHECK_SQLTRANSACT(con)      (con->functions[76].func!=NULL)
1492 #define SQLTRANSACT(con,eh,ch,op)\
1493                                     (con->functions[76].func)(eh,ch,op)
1494 
1495 
1496 #define DM_SQLGETDIAGREC            77
1497 #define CHECK_SQLGETDIAGREC(con)    (con->functions[77].func!=NULL)
1498 #define SQLGETDIAGREC(con,typ,han,rn,st,nat,msg,bl,tlp)\
1499                                     (con->functions[77].func)\
1500                                         (typ,han,rn,st,nat,msg,bl,tlp)
1501 #define CHECK_SQLGETDIAGRECW(con)    (con->functions[77].funcW!=NULL)
1502 #define SQLGETDIAGRECW(con,typ,han,rn,st,nat,msg,bl,tlp)\
1503                                     (con->functions[77].funcW)\
1504                                         (typ,han,rn,st,nat,msg,bl,tlp)
1505 
1506 #define DM_SQLCANCELHANDLE          78
1507 #define CHECK_SQLCANCELHANDLE(con)  (con->functions[78].func!=NULL)
1508 #define SQLCANCELHANDLE(con,typ,han)\
1509                                     (con->functions[78].func)\
1510                                         (typ,han)
1511 
1512 #endif
1513