psqlodbc.c 2.61 KB
Newer Older
1
/* Module:			psqlodbc.c
2
 *
3 4 5
 * Description:		This module contains the main entry point (DllMain) for the library.
 *					It also contains functions to get and set global variables for the
 *					driver in the registry.
6
 *
7
 * Classes:			n/a
8
 *
9
 * API functions:	none
10
 *
11
 * Comments:		See "notice.txt" for copyright and license information.
12 13
 *
 */
14

Byron Nikolaidis's avatar
Byron Nikolaidis committed
15
#ifdef HAVE_CONFIG_H
16
#include "config.h"
Byron Nikolaidis's avatar
Byron Nikolaidis committed
17 18
#endif

19
#include "psqlodbc.h"
20
#include "dlg_specific.h"
Byron Nikolaidis's avatar
Byron Nikolaidis committed
21

22
#ifndef WIN32
Byron Nikolaidis's avatar
Byron Nikolaidis committed
23 24 25 26
#include "iodbc.h"
#include "isql.h"
#include "isqlext.h"
#else
27 28 29 30
#include <winsock.h>
#include <windows.h>
#include <sql.h>
#include <odbcinst.h>
Byron Nikolaidis's avatar
Byron Nikolaidis committed
31
#endif
32

33
GLOBAL_VALUES globals;
34

35 36 37
RETCODE SQL_API SQLDummyOrdinal(void);

#ifdef WIN32
38
HINSTANCE NEAR s_hModule;		/* Saved module handle. */
39 40

/*	This is where the Driver Manager attaches to this Driver */
41 42
BOOL WINAPI
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
43
{
44 45
	WORD		wVersionRequested;
	WSADATA		wsaData;
46

47 48 49 50
	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			s_hModule = hInst;	/* Save for dialog boxes */
51

52 53
			/* Load the WinSock Library */
			wVersionRequested = MAKEWORD(1, 1);
54

55 56
			if (WSAStartup(wVersionRequested, &wsaData))
				return FALSE;
57

58 59 60 61
			/* Verify that this is the minimum version of WinSock */
			if (LOBYTE(wsaData.wVersion) != 1 ||
				HIBYTE(wsaData.wVersion) != 1)
			{
62

63 64 65
				WSACleanup();
				return FALSE;
			}
66

67 68
			getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
			break;
69

70 71
		case DLL_THREAD_ATTACH:
			break;
72

73
		case DLL_PROCESS_DETACH:
74

75
			WSACleanup();
76

77
			return TRUE;
78

79 80
		case DLL_THREAD_DETACH:
			break;
81

82 83
		default:
			break;
84 85
	}

86 87 88
	return TRUE;

	UNREFERENCED_PARAMETER(lpReserved);
89 90
}

91
#else							/* not WIN32 */
Byron Nikolaidis's avatar
Byron Nikolaidis committed
92 93 94 95 96 97 98 99

#ifndef TRUE
#define TRUE	(BOOL)1
#endif
#ifndef FALSE
#define FALSE	(BOOL)0
#endif

100 101
#ifdef __GNUC__

102
/* This function is called at library initialization time.	*/
103 104 105 106 107 108 109 110 111

static BOOL
__attribute__((constructor))
init(void)
{
	getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
	return TRUE;
}

112
#else							/* not __GNUC__ */
113

Byron Nikolaidis's avatar
Byron Nikolaidis committed
114 115 116 117 118 119
/* These two functions do shared library initialziation on UNIX, well at least
 * on Linux. I don't know about other systems.
 */
BOOL
_init(void)
{
120
	getGlobalDefaults(DBMS_NAME, ODBCINST_INI, FALSE);
Byron Nikolaidis's avatar
Byron Nikolaidis committed
121 122 123 124 125 126 127 128 129
	return TRUE;
}

BOOL
_fini(void)
{
	return TRUE;
}

130
#endif	 /* not __GNUC__ */
Peter Eisentraut's avatar
Peter Eisentraut committed
131

132
#endif	 /* not WIN32 */
Byron Nikolaidis's avatar
Byron Nikolaidis committed
133

134 135 136 137 138 139
/*	This function is used to cause the Driver Manager to
	call functions by number rather than name, which is faster.
	The ordinal value of this function must be 199 to have the
	Driver Manager do this.  Also, the ordinal values of the
	functions must match the value of fFunction in SQLGetFunctions()
*/
140 141
RETCODE SQL_API
SQLDummyOrdinal(void)
142 143 144
{
	return SQL_SUCCESS;
}