]> granicus.if.org Git - postgresql/blob - src/interfaces/odbc/psqlodbc.c
Provide some initial support for building the ODBC driver for
[postgresql] / src / interfaces / odbc / psqlodbc.c
1 /*--------
2  * Module:                      psqlodbc.c
3  *
4  * Description:         This module contains the main entry point (DllMain)
5  *                                      for the library.  It also contains functions to get
6  *                                      and set global variables for the driver in the registry.
7  *
8  * Classes:                     n/a
9  *
10  * API functions:       none
11  *
12  * Comments:            See "notice.txt" for copyright and license information.
13  *--------
14  */
15
16 #include "psqlodbc.h"
17 #include "dlg_specific.h"
18
19 #ifdef WIN32
20 #include <winsock.h>
21 #endif
22
23 GLOBAL_VALUES globals;
24
25 RETCODE SQL_API SQLDummyOrdinal(void);
26
27 #ifdef WIN32
28 HINSTANCE NEAR s_hModule;               /* Saved module handle. */
29
30 /*      This is where the Driver Manager attaches to this Driver */
31 BOOL            WINAPI
32 DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
33 {
34         WORD            wVersionRequested;
35         WSADATA         wsaData;
36
37         switch (ul_reason_for_call)
38         {
39                 case DLL_PROCESS_ATTACH:
40                         s_hModule = hInst;      /* Save for dialog boxes */
41
42                         /* Load the WinSock Library */
43                         wVersionRequested = MAKEWORD(1, 1);
44
45                         if (WSAStartup(wVersionRequested, &wsaData))
46                                 return FALSE;
47
48                         /* Verify that this is the minimum version of WinSock */
49                         if (LOBYTE(wsaData.wVersion) != 1 ||
50                                 HIBYTE(wsaData.wVersion) != 1)
51                         {
52                                 WSACleanup();
53                                 return FALSE;
54                         }
55
56                         getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
57                         break;
58
59                 case DLL_THREAD_ATTACH:
60                         break;
61
62                 case DLL_PROCESS_DETACH:
63                         WSACleanup();
64                         return TRUE;
65
66                 case DLL_THREAD_DETACH:
67                         break;
68
69                 default:
70                         break;
71         }
72
73         return TRUE;
74
75         UNREFERENCED_PARAMETER(lpReserved);
76 }
77
78 #else                                                   /* not WIN32 */
79
80 #ifndef TRUE
81 #define TRUE    (BOOL)1
82 #endif
83 #ifndef FALSE
84 #define FALSE   (BOOL)0
85 #endif
86
87 #ifdef __GNUC__
88
89 /* This function is called at library initialization time.      */
90
91 static BOOL
92 __attribute__((constructor))
93 init(void)
94 {
95         getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
96         return TRUE;
97 }
98
99 #else                                                   /* not __GNUC__ */
100
101 /*
102  * These two functions do shared library initialziation on UNIX, well at least
103  * on Linux. I don't know about other systems.
104  */
105 BOOL
106 _init(void)
107 {
108         getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
109         return TRUE;
110 }
111
112 BOOL
113 _fini(void)
114 {
115         return TRUE;
116 }
117
118 #endif   /* not __GNUC__ */
119
120 #endif   /* not WIN32 */
121
122
123 /*
124  *      This function is used to cause the Driver Manager to
125  *      call functions by number rather than name, which is faster.
126  *      The ordinal value of this function must be 199 to have the
127  *      Driver Manager do this.  Also, the ordinal values of the
128  *      functions must match the value of fFunction in SQLGetFunctions()
129  */
130 RETCODE SQL_API
131 SQLDummyOrdinal(void)
132 {
133         return SQL_SUCCESS;
134 }