1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 //--------------------------------------------------------------------------
28 #include "odbc/OFunctions.hxx"
29 #include <osl/process.h>
30 
31 // Implib-Definitionen fuer ODBC-DLL/shared library:
32 
33 namespace connectivity
34 {
35 	T3SQLAllocHandle pODBC3SQLAllocHandle;
36 T3SQLConnect pODBC3SQLConnect;
37 T3SQLDriverConnect pODBC3SQLDriverConnect;
38 T3SQLBrowseConnect pODBC3SQLBrowseConnect;
39 T3SQLDataSources pODBC3SQLDataSources;
40 T3SQLDrivers pODBC3SQLDrivers;
41 T3SQLGetInfo pODBC3SQLGetInfo;
42 T3SQLGetFunctions pODBC3SQLGetFunctions;
43 T3SQLGetTypeInfo pODBC3SQLGetTypeInfo;
44 T3SQLSetConnectAttr pODBC3SQLSetConnectAttr;
45 T3SQLGetConnectAttr pODBC3SQLGetConnectAttr;
46 T3SQLSetEnvAttr pODBC3SQLSetEnvAttr;
47 T3SQLGetEnvAttr pODBC3SQLGetEnvAttr;
48 T3SQLSetStmtAttr pODBC3SQLSetStmtAttr;
49 T3SQLGetStmtAttr pODBC3SQLGetStmtAttr;
50 //T3SQLSetDescField pODBC3SQLSetDescField;
51 //T3SQLGetDescField pODBC3SQLGetDescField;
52 //T3SQLGetDescRec pODBC3SQLGetDescRec;
53 //T3SQLSetDescRec pODBC3SQLSetDescRec;
54 T3SQLPrepare pODBC3SQLPrepare;
55 T3SQLBindParameter pODBC3SQLBindParameter;
56 //T3SQLGetCursorName pODBC3SQLGetCursorName;
57 T3SQLSetCursorName pODBC3SQLSetCursorName;
58 T3SQLExecute pODBC3SQLExecute;
59 T3SQLExecDirect pODBC3SQLExecDirect;
60 //T3SQLNativeSql pODBC3SQLNativeSql;
61 T3SQLDescribeParam pODBC3SQLDescribeParam;
62 T3SQLNumParams pODBC3SQLNumParams;
63 T3SQLParamData pODBC3SQLParamData;
64 T3SQLPutData pODBC3SQLPutData;
65 T3SQLRowCount pODBC3SQLRowCount;
66 T3SQLNumResultCols pODBC3SQLNumResultCols;
67 T3SQLDescribeCol pODBC3SQLDescribeCol;
68 T3SQLColAttribute pODBC3SQLColAttribute;
69 T3SQLBindCol pODBC3SQLBindCol;
70 T3SQLFetch pODBC3SQLFetch;
71 T3SQLFetchScroll pODBC3SQLFetchScroll;
72 T3SQLGetData pODBC3SQLGetData;
73 T3SQLSetPos pODBC3SQLSetPos;
74 T3SQLBulkOperations pODBC3SQLBulkOperations;
75 T3SQLMoreResults pODBC3SQLMoreResults;
76 //T3SQLGetDiagField pODBC3SQLGetDiagField;
77 T3SQLGetDiagRec pODBC3SQLGetDiagRec;
78 T3SQLColumnPrivileges pODBC3SQLColumnPrivileges;
79 T3SQLColumns pODBC3SQLColumns;
80 T3SQLForeignKeys pODBC3SQLForeignKeys;
81 T3SQLPrimaryKeys pODBC3SQLPrimaryKeys;
82 T3SQLProcedureColumns pODBC3SQLProcedureColumns;
83 T3SQLProcedures pODBC3SQLProcedures;
84 T3SQLSpecialColumns pODBC3SQLSpecialColumns;
85 T3SQLStatistics pODBC3SQLStatistics;
86 T3SQLTablePrivileges pODBC3SQLTablePrivileges;
87 T3SQLTables pODBC3SQLTables;
88 T3SQLFreeStmt pODBC3SQLFreeStmt;
89 T3SQLCloseCursor pODBC3SQLCloseCursor;
90 T3SQLCancel pODBC3SQLCancel;
91 T3SQLEndTran pODBC3SQLEndTran;
92 T3SQLDisconnect pODBC3SQLDisconnect;
93 T3SQLFreeHandle pODBC3SQLFreeHandle;
94 T3SQLGetCursorName pODBC3SQLGetCursorName;
95 T3SQLNativeSql pODBC3SQLNativeSql;
96 
97 sal_Bool LoadFunctions(oslModule pODBCso);
98 // -------------------------------------------------------------------------
99 // Dynamisches Laden der DLL/shared lib und Adressen der Funktionen besorgen:
100 // Liefert sal_True bei Erfolg.
LoadLibrary_ODBC3(::rtl::OUString & _rPath)101 sal_Bool LoadLibrary_ODBC3(::rtl::OUString &_rPath)
102 {
103 	static sal_Bool bLoaded = sal_False;
104 	static oslModule pODBCso = NULL;
105 
106 	if (bLoaded)
107 		return sal_True;
108 #ifdef WNT
109 	_rPath = ::rtl::OUString::createFromAscii("ODBC32.DLL");
110 #endif
111 #ifdef UNX
112  #ifdef MACOSX
113  	_rPath = ::rtl::OUString::createFromAscii("libiodbc.dylib");
114  #else
115 	_rPath = ::rtl::OUString::createFromAscii("libodbc.so.1");
116 	pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW );
117 	if ( !pODBCso )
118 		_rPath = ::rtl::OUString::createFromAscii("libodbc.so");
119  #endif   /* MACOSX */
120 #endif
121 #ifdef OS2
122 	_rPath = ::rtl::OUString::createFromAscii("ODBC");
123 #endif
124 
125 	if ( !pODBCso )
126 		pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW );
127 	if( !pODBCso)
128 #ifdef OS2
129 	{
130 		delete pODBCso;
131 		_rPath = ::rtl::OUString::createFromAscii("WOD402");
132 		pODBCso = osl_loadModule( _rPath.pData,SAL_LOADMODULE_NOW );
133 		if( !pODBCso)
134 			return sal_False;
135 	}
136 #else
137 		return sal_False;
138 #endif
139 
140 	return bLoaded = LoadFunctions(pODBCso);
141 }
142 // -------------------------------------------------------------------------
143 
LoadFunctions(oslModule pODBCso)144 sal_Bool LoadFunctions(oslModule pODBCso)
145 {
146 
147 	if( ( pODBC3SQLAllocHandle	=	(T3SQLAllocHandle)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLAllocHandle").pData )) == NULL )
148 		return sal_False;
149 	if( ( pODBC3SQLConnect		=	(T3SQLConnect)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLConnect").pData )) == NULL )
150 		return sal_False;
151 	if( ( pODBC3SQLDriverConnect =	(T3SQLDriverConnect)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDriverConnect").pData )) == NULL )
152 		return sal_False;
153 	if( ( pODBC3SQLBrowseConnect =   (T3SQLBrowseConnect)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBrowseConnect").pData )) == NULL )
154 		return sal_False;
155 	if(( pODBC3SQLDataSources	=   (T3SQLDataSources)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDataSources").pData )) == NULL )
156 		return sal_False;
157 	if(( pODBC3SQLDrivers		=   (T3SQLDrivers)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDrivers").pData )) == NULL )
158 		return sal_False;
159 	if( ( pODBC3SQLGetInfo		=	(T3SQLGetInfo)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetInfo").pData )) == NULL )
160 		return sal_False;
161 	if(( pODBC3SQLGetFunctions	=	(T3SQLGetFunctions)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetFunctions").pData )) == NULL )
162 		return sal_False;
163 	if( ( pODBC3SQLGetTypeInfo	=	(T3SQLGetTypeInfo)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetTypeInfo").pData )) == NULL )
164 		return sal_False;
165 	if( ( pODBC3SQLSetConnectAttr	=	(T3SQLSetConnectAttr)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetConnectAttr").pData )) == NULL )
166 		return sal_False;
167 	if( ( pODBC3SQLGetConnectAttr	=	(T3SQLGetConnectAttr)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetConnectAttr").pData )) == NULL )
168 		return sal_False;
169 	if( ( pODBC3SQLSetEnvAttr	=	(T3SQLSetEnvAttr)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetEnvAttr").pData )) == NULL )
170 		return sal_False;
171 	if( ( pODBC3SQLGetEnvAttr	=	(T3SQLGetEnvAttr)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetEnvAttr").pData )) == NULL )
172 		return sal_False;
173 	if( ( pODBC3SQLSetStmtAttr	=	(T3SQLSetStmtAttr)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetStmtAttr").pData )) == NULL )
174 		return sal_False;
175 	if( ( pODBC3SQLGetStmtAttr	=	(T3SQLGetStmtAttr)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetStmtAttr").pData )) == NULL )
176 		return sal_False;
177 	/*if( ( pODBC3SQLSetDescField	=	(T3SQLSetDescField)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetDescField").pData )) == NULL )
178 		return sal_False;
179 	if( ( pODBC3SQLGetDescField	=	(T3SQLGetDescField)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDescField").pData )) == NULL )
180 		return sal_False;*/
181 	/*if( ( pODBC3SQLGetDescRec	=	(T3SQLGetDescRec)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDescRec").pData )) == NULL )
182 		return sal_False;
183 	if( ( pODBC3SQLSetDescRec	=	(T3SQLSetDescRec)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetDescRec").pData )) == NULL )
184 		return sal_False;*/
185 	if( ( pODBC3SQLPrepare		=	(T3SQLPrepare)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLPrepare").pData )) == NULL )
186 		return sal_False;
187 	if( ( pODBC3SQLBindParameter =	(T3SQLBindParameter)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBindParameter").pData )) == NULL )
188 		return sal_False;
189 //	if( ( pODBC3SQLGetCursorName =	(T3SQLGetCursorName)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetCursorName").pData )) == NULL )
190 //		return sal_False;
191 	if( ( pODBC3SQLSetCursorName =	(T3SQLSetCursorName)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetCursorName").pData )) == NULL )
192 		return sal_False;
193 	if( ( pODBC3SQLExecute		=	(T3SQLExecute)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLExecute").pData )) == NULL )
194 		return sal_False;
195 	if( ( pODBC3SQLExecDirect	=	(T3SQLExecDirect)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLExecDirect").pData )) == NULL )
196 		return sal_False;
197 	/*if( ( pODBC3SQLNativeSql		=	(T3SQLNativeSql)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNativeSql").pData )) == NULL )
198 		return sal_False;*/
199 	if( ( pODBC3SQLDescribeParam =   (T3SQLDescribeParam)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDescribeParam").pData )) == NULL )
200 		return sal_False;
201 	if( ( pODBC3SQLNumParams		=	(T3SQLNumParams)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNumParams").pData )) == NULL )
202 		return sal_False;
203 	if( ( pODBC3SQLParamData		=	(T3SQLParamData)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLParamData").pData )) == NULL )
204 		return sal_False;
205 	if( ( pODBC3SQLPutData		=	(T3SQLPutData)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLPutData").pData )) == NULL )
206 		return sal_False;
207 	if( ( pODBC3SQLRowCount		=	(T3SQLRowCount)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLRowCount").pData )) == NULL )
208 		return sal_False;
209 	if( ( pODBC3SQLNumResultCols =	(T3SQLNumResultCols)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNumResultCols").pData )) == NULL )
210 		return sal_False;
211 	if( ( pODBC3SQLDescribeCol	=	(T3SQLDescribeCol)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDescribeCol").pData )) == NULL )
212 		return sal_False;
213 	if( ( pODBC3SQLColAttribute =	(T3SQLColAttribute)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLColAttribute").pData )) == NULL )
214 		return sal_False;
215 	if( ( pODBC3SQLBindCol		=	(T3SQLBindCol)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBindCol").pData )) == NULL )
216 		return sal_False;
217 	if( ( pODBC3SQLFetch			=	(T3SQLFetch)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFetch").pData )) == NULL )
218 		return sal_False;
219 	if( ( pODBC3SQLFetchScroll	=	(T3SQLFetchScroll)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFetchScroll").pData )) == NULL )
220 		return sal_False;
221 	if( ( pODBC3SQLGetData		=	(T3SQLGetData)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetData").pData )) == NULL )
222 		return sal_False;
223 	if( ( pODBC3SQLSetPos		=	(T3SQLSetPos)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSetPos").pData )) == NULL )
224 		return sal_False;
225 	if( ( pODBC3SQLBulkOperations	=	(T3SQLBulkOperations)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLBulkOperations").pData )) == NULL )
226 		return sal_False;
227 	if( ( pODBC3SQLMoreResults	=	(T3SQLMoreResults)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLMoreResults").pData )) == NULL )
228 		return sal_False;
229 	/*if( ( pODBC3SQLGetDiagField	=	(T3SQLGetDiagField)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDiagField").pData )) == NULL )
230 		return sal_False;*/
231 	if( ( pODBC3SQLGetDiagRec	=	(T3SQLGetDiagRec)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetDiagRec").pData )) == NULL )
232 		return sal_False;
233 	if( ( pODBC3SQLColumnPrivileges = (T3SQLColumnPrivileges)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLColumnPrivileges").pData )) == NULL )
234 		return sal_False;
235 	if( ( pODBC3SQLColumns		=	(T3SQLColumns)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLColumns").pData )) == NULL )
236 		return sal_False;
237 	if( ( pODBC3SQLForeignKeys	=	(T3SQLForeignKeys)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLForeignKeys").pData )) == NULL )
238 		return sal_False;
239 	if( ( pODBC3SQLPrimaryKeys	=	(T3SQLPrimaryKeys)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLPrimaryKeys").pData )) == NULL )
240 		return sal_False;
241 	if( ( pODBC3SQLProcedureColumns =  (T3SQLProcedureColumns)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLProcedureColumns").pData )) == NULL )
242 		return sal_False;
243 	if( ( pODBC3SQLProcedures	=	(T3SQLProcedures)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLProcedures").pData )) == NULL )
244 		return sal_False;
245 	if( ( pODBC3SQLSpecialColumns =  (T3SQLSpecialColumns)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLSpecialColumns").pData )) == NULL )
246 		return sal_False;
247 	if( ( pODBC3SQLStatistics	=   (T3SQLStatistics)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLStatistics").pData )) == NULL )
248 		return sal_False;
249 	if( ( pODBC3SQLTablePrivileges =	(T3SQLTablePrivileges)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLTablePrivileges").pData )) == NULL )
250 		return sal_False;
251 	if( ( pODBC3SQLTables		=   (T3SQLTables)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLTables").pData )) == NULL )
252 		return sal_False;
253 	if( ( pODBC3SQLFreeStmt		=	(T3SQLFreeStmt)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFreeStmt").pData )) == NULL )
254 		return sal_False;
255 	if( ( pODBC3SQLCloseCursor	=	(T3SQLCloseCursor)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLCloseCursor").pData )) == NULL )
256 		return sal_False;
257 	if( ( pODBC3SQLCancel		=	(T3SQLCancel)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLCancel").pData )) == NULL )
258 		return sal_False;
259 	if( ( pODBC3SQLEndTran		=	(T3SQLEndTran)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLEndTran").pData )) == NULL )
260 		return sal_False;
261 	if( ( pODBC3SQLDisconnect	=	(T3SQLDisconnect)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLDisconnect").pData )) == NULL )
262 		return sal_False;
263 	if( ( pODBC3SQLFreeHandle	=	(T3SQLFreeHandle)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLFreeHandle").pData )) == NULL )
264 		return sal_False;
265 	if( ( pODBC3SQLGetCursorName	=	(T3SQLGetCursorName)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLGetCursorName").pData )) == NULL )
266 		return sal_False;
267 	if( ( pODBC3SQLNativeSql	=	(T3SQLNativeSql)osl_getFunctionSymbol(pODBCso, ::rtl::OUString::createFromAscii("SQLNativeSql").pData )) == NULL )
268 		return sal_False;
269 
270 	return sal_True;
271 }
272 // -------------------------------------------------------------------------
273 
274 }
275 
276 
277 
278