DCL 3.7.4
Loading...
Searching...
No Matches
ODBCModuleMain.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef _MSC_VER
4 #pragma comment(lib, "odbc32.lib")
5 #pragma comment(lib, "msodbcsql18.lib")
6#endif
7
8#include <string.h> // strchr
9#include <locale.h> // setlocale
10#include <dcl/_stdlib.h> // setenv
11
12#ifdef _MSC_VER
13#include <windows.h>
14#endif
15#include <sql.h>
16
17#include <dcl/Object.h>
18#if __DCL_HAVE_ALLOC_DEBUG
19#undef __DCL_ALLOC_LEVEL
20#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
21#endif
22
23#include <dcl/SQLCore.h>
24#include "ODBCConnection.h"
25
26#define __TRACE_THIS 0
27#if __TRACE_THIS
28#define __DCL_TRACE0_N __DCL_TRACE0
29#define __DCL_TRACE1_N __DCL_TRACE1
30#define __DCL_TRACE2_N __DCL_TRACE2
31#define __DCL_TRACE3_N __DCL_TRACE3
32#define __DCL_TRACE4_N __DCL_TRACE4
33#else
34#define __DCL_TRACE0_N(fmt)
35#define __DCL_TRACE1_N(fmt, arg)
36#define __DCL_TRACE2_N(fmt, arg1, arg2)
37#define __DCL_TRACE3_N(fmt, arg1, arg2, arg3)
38#define __DCL_TRACE4_N(fmt, arg1, arg2, arg3, arg4)
39#endif
40
41#if __DCL_HAVE_THIS_FILE__
42#undef __THIS_FILE__
43static const char_t __THIS_FILE__[] = __T("dcl/sql/ODBCModuleMain.cpp");
44#endif
45
46/*
47#ifdef _WINDOWS
48BOOL APIENTRY DllMain( HANDLE hModule,
49 DWORD ul_reason_for_call,
50 LPVOID lpReserved
51)
52{
53 switch (ul_reason_for_call) {
54 case DLL_PROCESS_ATTACH:
55 case DLL_PROCESS_DETACH:
56 return TRUE;
57 case DLL_THREAD_ATTACH:
58 case DLL_THREAD_DETACH:
59 break;
60 }
61 return FALSE;
62}
63#endif
64*/
65
66__DCL_BEGIN_NAMESPACE
67
68static const wchar_t* _serverTitle = __T("ODBC");
69
71{
72 return new ODBCConnection(_serverTitle);
73}
74
76{
77 /*
78 * Windows mingw-w64-*-x86_64-unixodbc
79 * LDFLAGS += -lodbc unixODBC
80 * - odbcinst: SQLGetPrivateProfileString failed with Unable to find component name.
81 * - mingw에서 동작하지 않는다.
82 * LDFLAGS += -lodbc32 Windows Native
83 * - Windows/System32/odbcad32.exe
84 * - mingw에서도 이것을 사용해야 한다.
85 * Windows에서 다음의 환경변수 설정이 적용되지 않는다.
86 *
87 * LANG에 UTF-8이 없는 경우 LANG을 변경한다.
88 */
89 ByteStringBuilder sb;
90 char* lang = getenv("LANG");
91 if (!lang) {
92 // current locale
93 lang = setlocale(LC_CTYPE, NULL);
94 if (!(lang && strchr(lang, '.'))) {
95 // set default locale
96 lang = setlocale(LC_ALL, "");
97 }
98 }
99 if (lang) {
100 ByteString lang_ = ByteString(lang);
101 ByteString lower = lang_.toLowerCase();
102 if (!lower.contains("utf8")) {
103 if (lower.contains("ko") || lower.contains("kr")) {
104 sb.append("ko_KR");
105 }
106 else {
107 size_t index = lang_.indexOf(L'.');
108 sb.append(index == (size_t) -1 ?
109 lang_ : lang_.substring(0, index));
110 }
111 sb.append(".UTF-8");
112 }
113 }
114 else {
115 sb = "C.UTF-8";
116 }
117
118 setenv("CLIENT_LOCALE", "en_US.UTF8", 0); // Informix
119 setenv("NLS_LANG", "AMERICAN_AMERICA.UTF8", 0); // Oracle
120
121 if (sb.length() > 0) {
122 ByteString langUTF8 = sb.toByteString();
123 __DCL_TRACE1_N(L"setenv LANG=[%hs]\n", langUTF8.data());
124 return setenv("LANG", langUTF8, 1) == 0;;
125 }
126 return true;
127}
128
130{
131 return true;
132}
133
134extern "C"
135{
138{
139 // DCL common members
140 sizeof(SQL::DRIVER_MODULE), // structure size
144 DCL_SQL_DRIVER_MODULE, // module type
145 __T("DCL SQL Adapter for ODBC"),
146
147 // private members
149 _serverTitle,
154};
155
156}
157
158__DCL_END_NAMESPACE
159
160#ifdef __WINNT_NEW_DELETE_OVERRIDE
161#undef new
162__WINNT_NEW_DELETE_OVERRIDE
163#endif
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
#define DCL_DSO_ENTRY_POINT
Definition Config.h:356
#define DCL_BUILD_FLAG
Definition Config.h:362
#define DCL_SQL_DRIVER_MODULE
Definition Config.h:353
wchar_t char_t
Definition Config.h:247
#define DCL_DSO_EXPORT
Definition Config.h:99
bool ModuleInitialize()
bool ModuleCleanup()
SQL::Connection * CreateConnectionInstance()
bool ModuleInitialize()
#define __DCL_TRACE1_N(fmt, arg)
bool ModuleCleanup()
SQL::Connection * CreateConnectionInstance()
#define __T(str)
Definition Object.h:60
#define DCL_SQL_VERSION
#define __BUILD_TIMESTAMP__
#define DCL_VERSION
#define DCL_SQL_VERSION_STRING