~ubuntu-branches/ubuntu/trusty/psqlodbc/trusty-proposed

« back to all changes in this revision

Viewing changes to psqlodbc.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-10-24 07:21:55 UTC
  • mfrom: (16.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131024072155-xlf5odyk3iblcd51
Tags: 1:09.02.0100-2ubuntu1
* Merge with Debian unstable. Remaining Ubuntu changes:
  - debian/tests: Disable iodbc test and dependency, as in Ubuntu iodbc and
    unixodbc are not installable in parallel, and iodbc is obsolete and
    should be removed at some point.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#ifdef  WIN32
17
 
#ifdef  _DEBUG
18
 
#include <crtdbg.h>
19
 
#endif /* _DEBUG */
20
 
#endif /* WIN32 */
21
 
#include "psqlodbc.h"
22
 
#include "dlg_specific.h"
23
 
#include "environ.h"
24
 
 
25
 
#ifdef WIN32
26
 
#include "loadlib.h"
27
 
int     platformId = 0;
28
 
#endif
29
 
 
30
 
static int      exepgm = 0;
31
 
BOOL isMsAccess() {return 1 == exepgm;}
32
 
BOOL isMsQuery() {return 2 == exepgm;}
33
 
BOOL isSqlServr() {return 3 == exepgm;}
34
 
 
35
 
GLOBAL_VALUES globals;
36
 
 
37
 
RETCODE SQL_API SQLDummyOrdinal(void);
38
 
 
39
 
#if defined(WIN_MULTITHREAD_SUPPORT)
40
 
extern  CRITICAL_SECTION        conns_cs, common_cs;
41
 
#elif defined(POSIX_MULTITHREAD_SUPPORT)
42
 
extern  pthread_mutex_t         conns_cs, common_cs;
43
 
 
44
 
#ifdef  POSIX_THREADMUTEX_SUPPORT
45
 
#ifdef  PG_RECURSIVE_MUTEXATTR
46
 
static  pthread_mutexattr_t     recur_attr;
47
 
const   pthread_mutexattr_t*    getMutexAttr(void)
48
 
{
49
 
        static int      init = 1;
50
 
 
51
 
        if (init)
52
 
        {
53
 
                if (0 != pthread_mutexattr_init(&recur_attr))
54
 
                        return NULL;
55
 
                if (0 != pthread_mutexattr_settype(&recur_attr, PG_RECURSIVE_MUTEXATTR))
56
 
                        return NULL;
57
 
        }
58
 
        init = 0;
59
 
 
60
 
        return  &recur_attr;
61
 
}
62
 
#else
63
 
const   pthread_mutexattr_t*    getMutexAttr(void)
64
 
{
65
 
        return NULL;
66
 
}
67
 
#endif /* PG_RECURSIVE_MUTEXATTR */
68
 
#endif /* POSIX_THREADMUTEX_SUPPORT */
69
 
#endif /* WIN_MULTITHREAD_SUPPORT */
70
 
 
71
 
int     initialize_global_cs(void)
72
 
{
73
 
        static  int     init = 1;
74
 
 
75
 
        if (!init)
76
 
                return 0;
77
 
        init = 0;
78
 
#ifdef  WIN32
79
 
#ifdef  _DEBUG
80
 
#ifdef  _MEMORY_DEBUG_
81
 
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
82
 
#endif /* _MEMORY_DEBUG_ */
83
 
#endif /* _DEBUG */
84
 
#endif /* WIN32 */
85
 
#ifdef  POSIX_THREADMUTEX_SUPPORT
86
 
        getMutexAttr();
87
 
#endif /* POSIX_THREADMUTEX_SUPPORT */
88
 
        InitializeLogging();
89
 
        INIT_CONNS_CS;
90
 
        INIT_COMMON_CS;
91
 
 
92
 
        return 0;
93
 
}
94
 
 
95
 
static void finalize_global_cs(void)
96
 
{
97
 
        DELETE_COMMON_CS;
98
 
        DELETE_CONNS_CS;
99
 
        FinalizeLogging();
100
 
#ifdef  _DEBUG
101
 
#ifdef  _MEMORY_DEBUG_
102
 
        // _CrtDumpMemoryLeaks();
103
 
#endif /* _MEMORY_DEBUG_ */
104
 
#endif /* _DEBUG */
105
 
}
106
 
 
107
 
#ifdef WIN32
108
 
HINSTANCE NEAR s_hModule;               /* Saved module handle. */
109
 
/*      This is where the Driver Manager attaches to this Driver */
110
 
BOOL            WINAPI
111
 
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
112
 
{
113
 
        switch (ul_reason_for_call)
114
 
        {
115
 
                case DLL_PROCESS_ATTACH:
116
 
                        s_hModule = hInst;      /* Save for dialog boxes */
117
 
 
118
 
                        if (initialize_global_cs() == 0)
119
 
                        {
120
 
                                char    pathname[_MAX_PATH], fname[_MAX_FNAME];
121
 
                                OSVERSIONINFO   osversion;
122
 
                                
123
 
                                getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
124
 
                                if (GetModuleFileName(NULL, pathname, sizeof(pathname)) > 0)
125
 
                                {
126
 
                                        _splitpath(pathname, NULL, NULL, fname, NULL);
127
 
                                        if (stricmp(fname, "msaccess") == 0)
128
 
                                                exepgm = 1;
129
 
                                        else if (strnicmp(fname, "msqry", 5) == 0)
130
 
                                                exepgm = 2;
131
 
                                        else if (strnicmp(fname, "sqlservr", 8) == 0)
132
 
                                                exepgm = 3;
133
 
                                }
134
 
                                osversion.dwOSVersionInfoSize = sizeof(osversion);
135
 
                                if (GetVersionEx(&osversion))
136
 
                                {
137
 
                                        platformId=osversion.dwPlatformId;
138
 
                                }
139
 
                                mylog("exe name=%s plaformId=%d\n", fname, platformId);
140
 
                        }
141
 
                        break;
142
 
 
143
 
                case DLL_THREAD_ATTACH:
144
 
                        break;
145
 
 
146
 
                case DLL_PROCESS_DETACH:
147
 
                        mylog("DETACHING PROCESS\n");
148
 
                        CleanupDelayLoadedDLLs();
149
 
                        /* my(q)log is unavailable from here */
150
 
                        finalize_global_cs();
151
 
                        return TRUE;
152
 
 
153
 
                case DLL_THREAD_DETACH:
154
 
                        break;
155
 
 
156
 
                default:
157
 
                        break;
158
 
        }
159
 
 
160
 
        return TRUE;
161
 
 
162
 
        UNREFERENCED_PARAMETER(lpReserved);
163
 
}
164
 
 
165
 
#else                                                   /* not WIN32 */
166
 
 
167
 
#ifdef __GNUC__
168
 
 
169
 
/* This function is called at library initialization time.      */
170
 
 
171
 
static BOOL
172
 
__attribute__((constructor))
173
 
init(void)
174
 
{
175
 
        initialize_global_cs();
176
 
        getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
177
 
        return TRUE;
178
 
}
179
 
 
180
 
#else                                                   /* not __GNUC__ */
181
 
 
182
 
/*
183
 
 * These two functions do shared library initialziation on UNIX, well at least
184
 
 * on Linux. I don't know about other systems.
185
 
 */
186
 
BOOL
187
 
_init(void)
188
 
{
189
 
        initialize_global_cs();
190
 
        getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
191
 
        return TRUE;
192
 
}
193
 
 
194
 
BOOL
195
 
_fini(void)
196
 
{
197
 
        finalize_global_cs();
198
 
        return TRUE;
199
 
}
200
 
#endif   /* not __GNUC__ */
201
 
#endif   /* not WIN32 */
202
 
 
203
 
 
204
 
/*
205
 
 *      This function is used to cause the Driver Manager to
206
 
 *      call functions by number rather than name, which is faster.
207
 
 *      The ordinal value of this function must be 199 to have the
208
 
 *      Driver Manager do this.  Also, the ordinal values of the
209
 
 *      functions must match the value of fFunction in SQLGetFunctions()
210
 
 */
211
 
RETCODE         SQL_API
212
 
SQLDummyOrdinal(void)
213
 
{
214
 
        return SQL_SUCCESS;
215
 
}
 
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 "readme.txt" for copyright and license information.
 
13
 *--------
 
14
 */
 
15
 
 
16
#ifdef  WIN32
 
17
#ifdef  _DEBUG
 
18
#include <crtdbg.h>
 
19
#endif /* _DEBUG */
 
20
#endif /* WIN32 */
 
21
#include "psqlodbc.h"
 
22
#include "dlg_specific.h"
 
23
#include "environ.h"
 
24
 
 
25
#ifdef WIN32
 
26
#include "loadlib.h"
 
27
int     platformId = 0;
 
28
#endif
 
29
 
 
30
static int      exepgm = 0;
 
31
BOOL isMsAccess() {return 1 == exepgm;}
 
32
BOOL isMsQuery() {return 2 == exepgm;}
 
33
BOOL isSqlServr() {return 3 == exepgm;}
 
34
 
 
35
GLOBAL_VALUES globals;
 
36
 
 
37
RETCODE SQL_API SQLDummyOrdinal(void);
 
38
 
 
39
#if defined(WIN_MULTITHREAD_SUPPORT)
 
40
extern  CRITICAL_SECTION        conns_cs, common_cs;
 
41
#elif defined(POSIX_MULTITHREAD_SUPPORT)
 
42
extern  pthread_mutex_t         conns_cs, common_cs;
 
43
 
 
44
#ifdef  POSIX_THREADMUTEX_SUPPORT
 
45
#ifdef  PG_RECURSIVE_MUTEXATTR
 
46
static  pthread_mutexattr_t     recur_attr;
 
47
const   pthread_mutexattr_t*    getMutexAttr(void)
 
48
{
 
49
        static int      init = 1;
 
50
 
 
51
        if (init)
 
52
        {
 
53
                if (0 != pthread_mutexattr_init(&recur_attr))
 
54
                        return NULL;
 
55
                if (0 != pthread_mutexattr_settype(&recur_attr, PG_RECURSIVE_MUTEXATTR))
 
56
                        return NULL;
 
57
        }
 
58
        init = 0;
 
59
 
 
60
        return  &recur_attr;
 
61
}
 
62
#else
 
63
const   pthread_mutexattr_t*    getMutexAttr(void)
 
64
{
 
65
        return NULL;
 
66
}
 
67
#endif /* PG_RECURSIVE_MUTEXATTR */
 
68
#endif /* POSIX_THREADMUTEX_SUPPORT */
 
69
#endif /* WIN_MULTITHREAD_SUPPORT */
 
70
 
 
71
int     initialize_global_cs(void)
 
72
{
 
73
        static  int     init = 1;
 
74
 
 
75
        if (!init)
 
76
                return 0;
 
77
        init = 0;
 
78
#ifdef  WIN32
 
79
#ifdef  _DEBUG
 
80
#ifdef  _MEMORY_DEBUG_
 
81
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
 
82
#endif /* _MEMORY_DEBUG_ */
 
83
#endif /* _DEBUG */
 
84
#endif /* WIN32 */
 
85
#ifdef  POSIX_THREADMUTEX_SUPPORT
 
86
        getMutexAttr();
 
87
#endif /* POSIX_THREADMUTEX_SUPPORT */
 
88
        InitializeLogging();
 
89
        INIT_CONNS_CS;
 
90
        INIT_COMMON_CS;
 
91
 
 
92
        return 0;
 
93
}
 
94
 
 
95
static void finalize_global_cs(void)
 
96
{
 
97
        DELETE_COMMON_CS;
 
98
        DELETE_CONNS_CS;
 
99
        FinalizeLogging();
 
100
#ifdef  _DEBUG
 
101
#ifdef  _MEMORY_DEBUG_
 
102
        // _CrtDumpMemoryLeaks();
 
103
#endif /* _MEMORY_DEBUG_ */
 
104
#endif /* _DEBUG */
 
105
}
 
106
 
 
107
#ifdef WIN32
 
108
HINSTANCE NEAR s_hModule;               /* Saved module handle. */
 
109
/*      This is where the Driver Manager attaches to this Driver */
 
110
BOOL            WINAPI
 
111
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
 
112
{
 
113
        switch (ul_reason_for_call)
 
114
        {
 
115
                case DLL_PROCESS_ATTACH:
 
116
                        s_hModule = hInst;      /* Save for dialog boxes */
 
117
 
 
118
                        if (initialize_global_cs() == 0)
 
119
                        {
 
120
                                char    pathname[_MAX_PATH], fname[_MAX_FNAME];
 
121
                                OSVERSIONINFO   osversion;
 
122
                                
 
123
                                getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
 
124
                                if (GetModuleFileName(NULL, pathname, sizeof(pathname)) > 0)
 
125
                                {
 
126
                                        _splitpath(pathname, NULL, NULL, fname, NULL);
 
127
                                        if (stricmp(fname, "msaccess") == 0)
 
128
                                                exepgm = 1;
 
129
                                        else if (strnicmp(fname, "msqry", 5) == 0)
 
130
                                                exepgm = 2;
 
131
                                        else if (strnicmp(fname, "sqlservr", 8) == 0)
 
132
                                                exepgm = 3;
 
133
                                }
 
134
                                osversion.dwOSVersionInfoSize = sizeof(osversion);
 
135
                                if (GetVersionEx(&osversion))
 
136
                                {
 
137
                                        platformId=osversion.dwPlatformId;
 
138
                                }
 
139
                                mylog("exe name=%s plaformId=%d\n", fname, platformId);
 
140
                        }
 
141
                        break;
 
142
 
 
143
                case DLL_THREAD_ATTACH:
 
144
                        break;
 
145
 
 
146
                case DLL_PROCESS_DETACH:
 
147
                        mylog("DETACHING PROCESS\n");
 
148
                        CleanupDelayLoadedDLLs();
 
149
                        /* my(q)log is unavailable from here */
 
150
                        finalize_global_cs();
 
151
                        return TRUE;
 
152
 
 
153
                case DLL_THREAD_DETACH:
 
154
                        break;
 
155
 
 
156
                default:
 
157
                        break;
 
158
        }
 
159
 
 
160
        return TRUE;
 
161
 
 
162
        UNREFERENCED_PARAMETER(lpReserved);
 
163
}
 
164
 
 
165
#else                                                   /* not WIN32 */
 
166
 
 
167
#ifdef __GNUC__
 
168
 
 
169
/* Shared library initializer and destructor, using gcc's attributes */
 
170
 
 
171
static void
 
172
__attribute__((constructor))
 
173
psqlodbc_init(void)
 
174
{
 
175
        initialize_global_cs();
 
176
        getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
 
177
}
 
178
 
 
179
static void
 
180
__attribute__((destructor))
 
181
psqlodbc_fini(void)
 
182
{
 
183
        finalize_global_cs();
 
184
}
 
185
 
 
186
#else                                                   /* not __GNUC__ */
 
187
 
 
188
/* Shared library initialization on non-gcc systems. */
 
189
BOOL
 
190
_init(void)
 
191
{
 
192
        initialize_global_cs();
 
193
        getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
 
194
        return TRUE;
 
195
}
 
196
 
 
197
BOOL
 
198
_fini(void)
 
199
{
 
200
        finalize_global_cs();
 
201
        return TRUE;
 
202
}
 
203
#endif   /* not __GNUC__ */
 
204
#endif   /* not WIN32 */
 
205
 
 
206
 
 
207
/*
 
208
 *      This function is used to cause the Driver Manager to
 
209
 *      call functions by number rather than name, which is faster.
 
210
 *      The ordinal value of this function must be 199 to have the
 
211
 *      Driver Manager do this.  Also, the ordinal values of the
 
212
 *      functions must match the value of fFunction in SQLGetFunctions()
 
213
 */
 
214
RETCODE         SQL_API
 
215
SQLDummyOrdinal(void)
 
216
{
 
217
        return SQL_SUCCESS;
 
218
}