1/*
2 *
3 *  iodbc.h
4 *
5 *  $Id: iodbc.h,v 1.12 2007/10/08 13:04:32 source Exp $
6 *
7 *  Configuration
8 *
9 *  The iODBC driver manager.
10 *
11 *  Copyright (C) 1995 by Ke Jin <kejin@empress.com>
12 *  Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com>
13 *  All Rights Reserved.
14 *
15 *  This software is released under the terms of either of the following
16 *  licenses:
17 *
18 *      - GNU Library General Public License (see LICENSE.LGPL)
19 *      - The BSD License (see LICENSE.BSD).
20 *
21 *  Note that the only valid version of the LGPL license as far as this
22 *  project is concerned is the original GNU Library General Public License
23 *  Version 2, dated June 1991.
24 *
25 *  While not mandated by the BSD license, any patches you make to the
26 *  iODBC source code may be contributed back into the iODBC project
27 *  at your discretion. Contributions will benefit the Open Source and
28 *  Data Access community as a whole. Submissions may be made at:
29 *
30 *      http://www.iodbc.org
31 *
32 *
33 *  GNU Library Generic Public License Version 2
34 *  ============================================
35 *  This library is free software; you can redistribute it and/or
36 *  modify it under the terms of the GNU Library General Public
37 *  License as published by the Free Software Foundation; only
38 *  Version 2 of the License dated June 1991.
39 *
40 *  This library is distributed in the hope that it will be useful,
41 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
42 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43 *  Library General Public License for more details.
44 *
45 *  You should have received a copy of the GNU Library General Public
46 *  License along with this library; if not, write to the Free
47 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
48 *
49 *
50 *  The BSD License
51 *  ===============
52 *  Redistribution and use in source and binary forms, with or without
53 *  modification, are permitted provided that the following conditions
54 *  are met:
55 *
56 *  1. Redistributions of source code must retain the above copyright
57 *     notice, this list of conditions and the following disclaimer.
58 *  2. Redistributions in binary form must reproduce the above copyright
59 *     notice, this list of conditions and the following disclaimer in
60 *     the documentation and/or other materials provided with the
61 *     distribution.
62 *  3. Neither the name of OpenLink Software Inc. nor the names of its
63 *     contributors may be used to endorse or promote products derived
64 *     from this software without specific prior written permission.
65 *
66 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
67 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
68 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
69 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
70 *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
71 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
72 *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
73 *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
74 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
75 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
76 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
77 */
78
79#ifndef	_IODBC_H
80#define _IODBC_H
81
82#ifdef HAVE_CONFIG_H
83#include <config.h>
84#endif
85
86#ifndef VERSION
87#define VERSION		"3.52.6"
88#define MAJ_VERSION	"3"
89#define MIN_VERSION	"52"
90#endif
91
92#ifndef IODBC_BUILD
93#define IODBC_BUILD 6071008	/* 0001.0928 */
94#endif
95
96#if	!defined(WINDOWS) && !defined(WIN32_SYSTEM)
97#define _UNIX_
98
99#include <stdlib.h>
100#include <stdio.h>
101#include <string.h>
102#include <sys/types.h>
103
104#define MEM_ALLOC(size)	(malloc((size_t)(size)))
105#define MEM_FREE(ptr)	{if(ptr) free(ptr);}
106
107#define STRCPY(t, s)	(strcpy((char*)(t), (char*)(s)))
108#define STRNCPY(t,s,n)	(strncpy((char*)(t), (char*)(s), (size_t)(n)))
109#define STRCAT(t, s)	(strcat((char*)(t), (char*)(s)))
110#define STRNCAT(t,s,n)	(strncat((char*)(t), (char*)(s), (size_t)(n)))
111#define STREQ(a, b)	(strcmp((char*)(a), (char*)(b)) == 0)
112#define STRNEQ(a, b, n)		(strncmp((char*)(a), (char*)(b), (size_t)(n)) == 0)
113#define STRLEN(str)	((str)? strlen((char*)(str)):0)
114#define STRDUP(t)		(strdup((char*)(t)))
115#define STRCASEEQ(a, b)		(strcasecmp((char*)(a), (char*)(b)) == 0)
116#define STRNCASEEQ(a, b, n)	(strncasecmp((char*)(a), (char*)(b), (size_t)(n)) == 0)
117
118#define WCSCPY(t, s)		(wcscpy((wchar_t*)(t), (wchar_t*)(s)))
119#define WCSNCPY(t,s,n)		(wcsncpy((wchar_t*)(t), (wchar_t*)(s), (size_t)(n)))
120#define WCSCAT(t, s)		(wcscat((wchar_t*)(t), (wchar_t*)(s)))
121#define WCSNCAT(t,s,n)		(wcsncat((wchar_t*)(t), (wchar_t*)(s), (size_t)(n)))
122#define WCSEQ(a, b)		(wcscmp((wchar_t*)(a), (wchar_t*)(b)) == 0)
123#define WCSNEQ(a, b, n)		(wcsncmp((wchar_t*)(a), (wchar_t*)(b), (size_t)(n)) == 0)
124#define WCSLEN(str)		((str)? wcslen((wchar_t*)(str)):0)
125#define WCSDUP(t)		(wcsdup((wchar_t*)(t)))
126#define WCSCASEEQ(a, b)		(wcscasecmp((wchar_t*)(a), (wchar_t*)(b)) == 0)
127#define WCSNCASEEQ(a, b, n)	(wcsncasecmp((wchar_t*)(a), (wchar_t*)(b), (size_t)(n)) == 0)
128
129
130#define EXPORT
131#define CALLBACK
132#define FAR
133
134#ifndef WIN32
135#define UNALIGNED
136#endif
137
138/*
139 *  If not defined, use this as the system default odbc.ini file
140 */
141#if !defined(SYS_ODBC_INI) || (defined(__APPLE__) && !defined(ODBC_INI_APP))
142# if defined(__BEOS__)
143# 	define SYS_ODBC_INI "/boot/beos/etc/odbc.ini"
144# elif defined(_MAC)
145# 	ifdef __POWERPC__
146# 		define SYS_ODBC_INI "Boot:System Folder:Preferences:ODBC Preferences PPC"
147# 	else
148# 		define SYS_ODBC_INI "Boot:System Folder:Preferences:ODBC Preferences"
149# 	endif
150# elif defined(__APPLE__)
151# 	define SYS_ODBC_INI "/etc/odbc.ini"
152# 	define ODBC_INI_APP "/Library/ODBC/odbc.ini"
153# else
154# 	define SYS_ODBC_INI "/etc/odbc.ini"
155# endif
156#endif
157
158#if !defined(SYS_ODBCINST_INI) || (defined(__APPLE__) && !defined(ODBCINST_INI_APP))
159#  if defined(__BEOS__)
160#    define SYS_ODBCINST_INI	"/boot/beos/etc/odbcinst.ini"
161#  elif defined(macintosh)
162#  elif defined(__APPLE__)
163#    define SYS_ODBCINST_INI	"/etc/odbcinst.ini"
164#    define ODBCINST_INI_APP	"/Library/ODBC/odbcinst.ini"
165#  else
166#    define SYS_ODBCINST_INI	"/etc/odbcinst.ini"
167#  endif
168#endif
169
170#endif /* _UNIX_ */
171
172#if	defined(WINDOWS) || defined(WIN32_SYSTEM)
173#include <windows.h>
174#include <windowsx.h>
175
176#ifdef	_MSVC_
177#define MEM_ALLOC(size)	(fmalloc((size_t)(size)))
178#define MEM_FREE(ptr)	((ptr)? ffree((PTR)(ptr)):0)
179#define STRCPY(t, s)	(fstrcpy((char FAR*)(t), (char FAR*)(s)))
180#define STRNCPY(t,s,n)	(fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
181#define STRLEN(str)	((str)? fstrlen((char FAR*)(str)):0)
182#define STREQ(a, b)	(fstrcmp((char FAR*)(a), (char FAR*)(b) == 0))
183#define STRCAT(t, s)	(strcat((char*)(t), (char*)(s)))
184#define STRNCAT(t,s,n)	(strncat((char*)(t), (char*)(s), (size_t)(n)))
185#define STRNCMP(t,s,n)	(strncmp((char*)(t), (char*)(s), (size_t)(n)))
186#endif
187
188#ifdef	_BORLAND_
189#define MEM_ALLOC(size)	(farmalloc((unsigned long)(size)))
190#define MEM_FREE(ptr)	((ptr)? farfree((void far*)(ptr)):0)
191#define STRCPY(t, s)	(_fstrcpy((char FAR*)(t), (char FAR*)(s)))
192#define STRNCPY(t,s,n)	(_fstrncpy((char FAR*)(t), (char FAR*)(s), (size_t)(n)))
193#define STRLEN(str)     ((str)? _fstrlen((char FAR*)(str)):0)
194#define STREQ(a, b)     (_fstrcmp((char FAR*)(a), (char FAR*)(b) == 0))
195#define STRCAT(t, s)	(strcat((char*)(t), (char*)(s)))
196#define STRNCAT(t,s,n)	(strncat((char*)(t), (char*)(s), (size_t)(n)))
197#define STRNCMP(t,s,n)	(strncmp((char*)(t), (char*)(s), (size_t)(n)))
198#endif
199
200#endif /* WINDOWS */
201
202#ifdef VMS
203/*
204 *  VMS also defines _UNIX_ above. This is OK for iODBC since all used UNIX
205 *  interfaces are supported.
206 *  The DEC C RTL actually supports dlopen(), etc, but I have made my own
207 *  implementation that supports:
208 *     - Proper error messages from dlopen()
209 *     - The ability to place the driver in other directories than SYS$SHARE:
210 *     - Neither implementation can do dlopen(NULL,), but my implementation
211 *       will not crash in this case.
212 *  To use old DEC C dlopen() implementation, remove the following define.
213 */
214#define DLDAPI_VMS_IODBC	/* Use enhanced dlopen() */
215#endif
216
217#define SYSERR		(-1)
218
219#ifndef	NULL
220#define NULL		((void *)0UL)
221#endif
222
223/*
224 *  Map generic pointer to internal pointer
225 */
226#define STMT(stmt, var) \
227	STMT_t *stmt = (STMT_t *)var
228
229#define CONN(con, var) \
230	DBC_t *con = (DBC_t *)var
231
232#define GENV(genv, var) \
233	GENV_t *genv = (GENV_t *)var
234
235#define ENVR(env, var) \
236	ENV_t *env = (ENV_t *)var
237
238#define DESC(desc, var) \
239	DESC_t *desc = (DESC_t *)var
240
241#define NEW_VAR(type, var) \
242	type *var = (type *)MEM_ALLOC(sizeof(type))
243
244
245/* these are deprecated defines from the odbc headers */
246#define SQL_CONNECT_OPT_DRVR_START      1000
247
248#endif /* _IODBC_H */
249