1/*
2 *  itrace.h
3 *
4 *  $Id: itrace.h,v 1.13 2006/09/25 11:36:26 source Exp $
5 *
6 *  Trace functions
7 *
8 *  The iODBC driver manager.
9 *
10 *  Copyright (C) 1995 by Ke Jin <kejin@empress.com>
11 *  Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com>
12 *  All Rights Reserved.
13 *
14 *  This software is released under the terms of either of the following
15 *  licenses:
16 *
17 *      - GNU Library General Public License (see LICENSE.LGPL)
18 *      - The BSD License (see LICENSE.BSD).
19 *
20 *  Note that the only valid version of the LGPL license as far as this
21 *  project is concerned is the original GNU Library General Public License
22 *  Version 2, dated June 1991.
23 *
24 *  While not mandated by the BSD license, any patches you make to the
25 *  iODBC source code may be contributed back into the iODBC project
26 *  at your discretion. Contributions will benefit the Open Source and
27 *  Data Access community as a whole. Submissions may be made at:
28 *
29 *      http://www.iodbc.org
30 *
31 *
32 *  GNU Library Generic Public License Version 2
33 *  ============================================
34 *  This library is free software; you can redistribute it and/or
35 *  modify it under the terms of the GNU Library General Public
36 *  License as published by the Free Software Foundation; only
37 *  Version 2 of the License dated June 1991.
38 *
39 *  This library is distributed in the hope that it will be useful,
40 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
41 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
42 *  Library General Public License for more details.
43 *
44 *  You should have received a copy of the GNU Library General Public
45 *  License along with this library; if not, write to the Free
46 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
47 *
48 *
49 *  The BSD License
50 *  ===============
51 *  Redistribution and use in source and binary forms, with or without
52 *  modification, are permitted provided that the following conditions
53 *  are met:
54 *
55 *  1. Redistributions of source code must retain the above copyright
56 *     notice, this list of conditions and the following disclaimer.
57 *  2. Redistributions in binary form must reproduce the above copyright
58 *     notice, this list of conditions and the following disclaimer in
59 *     the documentation and/or other materials provided with the
60 *     distribution.
61 *  3. Neither the name of OpenLink Software Inc. nor the names of its
62 *     contributors may be used to endorse or promote products derived
63 *     from this software without specific prior written permission.
64 *
65 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
66 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
67 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
68 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
69 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
70 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
71 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
72 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
73 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
74 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
75 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
76 */
77
78#ifndef	_ITRACE_H
79#define _ITRACE_H
80
81/*
82 *  Trace function prototypes
83 */
84#include "trace/proto.h"
85
86extern int ODBCSharedTraceFlag;
87
88
89/*
90 *  Usefull macros
91 */
92#ifdef NO_TRACING
93#define TRACE(X)
94#else
95#define TRACE(X)	if (ODBCSharedTraceFlag) X
96#endif
97
98#define TRACE_ENTER	0, retcode
99#define TRACE_LEAVE	1, retcode
100
101#define CALL_DRIVER(hdbc, errHandle, ret, proc, plist) \
102    {\
103	DBC_t *	t_pdbc = (DBC_t *)(hdbc);\
104	ENV_t * t_penv = (ENV_t *)(t_pdbc->henv);\
105\
106	if (!t_penv->thread_safe) MUTEX_LOCK (t_penv->drv_lock); \
107\
108	ret = proc plist; \
109	if (errHandle) ((GENV_t *)(errHandle))->rc = ret; \
110\
111	if (!t_penv->thread_safe) MUTEX_UNLOCK (t_penv->drv_lock); \
112    }
113
114
115#define CALL_UDRIVER(hdbc, errHandle, retcode, hproc, unicode_driver, procid, plist) \
116    { \
117	if (unicode_driver) \
118	{ \
119	    /* SQL_XXX_W */ \
120	    hproc = _iodbcdm_getproc (hdbc, procid ## W); \
121	} \
122	else \
123	{ \
124	    /* SQL_XXX */   \
125	    /* SQL_XXX_A */ \
126	    hproc = _iodbcdm_getproc (hdbc, procid); \
127	    if (hproc == SQL_NULL_HPROC) \
128	        hproc = _iodbcdm_getproc (hdbc, procid ## A); \
129	    } \
130        if (hproc != SQL_NULL_HPROC) \
131	      { \
132	    CALL_DRIVER (hdbc, errHandle, retcode, hproc, plist) \
133	} \
134    }
135
136#endif
137
138
139#define GET_HPROC(hdbc, hproc, procid) \
140    { \
141      /* SQL_XXX */   \
142      /* SQL_XXX_A */ \
143      hproc = _iodbcdm_getproc (hdbc, procid); \
144      if (hproc == SQL_NULL_HPROC) \
145        hproc = _iodbcdm_getproc (hdbc, procid ## A); \
146    }
147
148
149#define GET_UHPROC(hdbc, hproc, procid, unicode_driver) \
150    { \
151      if (unicode_driver) \
152        { \
153	  /* SQL_XXX_W */ \
154	  hproc = _iodbcdm_getproc (hdbc, procid ## W); \
155        } \
156      else \
157        { \
158          /* SQL_XXX */   \
159          /* SQL_XXX_A */ \
160          hproc = _iodbcdm_getproc (hdbc, procid); \
161          if (hproc == SQL_NULL_HPROC) \
162            hproc = _iodbcdm_getproc (hdbc, procid ## A); \
163        } \
164    }
165
166