1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ORealDriver.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ORealDriver.hxx"
34 #include "odbc/ODriver.hxx"
35 #include "odbc/OTools.hxx"
36 #include "odbc/OFunctions.hxx"
37 #include "diagnose_ex.h"
39 namespace connectivity
41 sal_Bool
LoadFunctions(oslModule pODBCso
);
42 sal_Bool
LoadLibrary_ODBC3(::rtl::OUString
&_rPath
);
43 // extern declaration of the function pointer
44 extern T3SQLAllocHandle pODBC3SQLAllocHandle
;
45 extern T3SQLConnect pODBC3SQLConnect
;
46 extern T3SQLDriverConnect pODBC3SQLDriverConnect
;
47 extern T3SQLBrowseConnect pODBC3SQLBrowseConnect
;
48 extern T3SQLDataSources pODBC3SQLDataSources
;
49 extern T3SQLDrivers pODBC3SQLDrivers
;
50 extern T3SQLGetInfo pODBC3SQLGetInfo
;
51 extern T3SQLGetFunctions pODBC3SQLGetFunctions
;
52 extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo
;
53 extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr
;
54 extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr
;
55 extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr
;
56 extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr
;
57 extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr
;
58 extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr
;
59 //extern T3SQLSetDescField pODBC3SQLSetDescField;
60 //extern T3SQLGetDescField pODBC3SQLGetDescField;
61 //extern T3SQLGetDescRec pODBC3SQLGetDescRec;
62 //extern T3SQLSetDescRec pODBC3SQLSetDescRec;
63 extern T3SQLPrepare pODBC3SQLPrepare
;
64 extern T3SQLBindParameter pODBC3SQLBindParameter
;
65 //extern T3SQLGetCursorName pODBC3SQLGetCursorName;
66 extern T3SQLSetCursorName pODBC3SQLSetCursorName
;
67 extern T3SQLExecute pODBC3SQLExecute
;
68 extern T3SQLExecDirect pODBC3SQLExecDirect
;
69 //extern T3SQLNativeSql pODBC3SQLNativeSql;
70 extern T3SQLDescribeParam pODBC3SQLDescribeParam
;
71 extern T3SQLNumParams pODBC3SQLNumParams
;
72 extern T3SQLParamData pODBC3SQLParamData
;
73 extern T3SQLPutData pODBC3SQLPutData
;
74 extern T3SQLRowCount pODBC3SQLRowCount
;
75 extern T3SQLNumResultCols pODBC3SQLNumResultCols
;
76 extern T3SQLDescribeCol pODBC3SQLDescribeCol
;
77 extern T3SQLColAttribute pODBC3SQLColAttribute
;
78 extern T3SQLBindCol pODBC3SQLBindCol
;
79 extern T3SQLFetch pODBC3SQLFetch
;
80 extern T3SQLFetchScroll pODBC3SQLFetchScroll
;
81 extern T3SQLGetData pODBC3SQLGetData
;
82 extern T3SQLSetPos pODBC3SQLSetPos
;
83 extern T3SQLBulkOperations pODBC3SQLBulkOperations
;
84 extern T3SQLMoreResults pODBC3SQLMoreResults
;
85 //extern T3SQLGetDiagField pODBC3SQLGetDiagField;
86 extern T3SQLGetDiagRec pODBC3SQLGetDiagRec
;
87 extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges
;
88 extern T3SQLColumns pODBC3SQLColumns
;
89 extern T3SQLForeignKeys pODBC3SQLForeignKeys
;
90 extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys
;
91 extern T3SQLProcedureColumns pODBC3SQLProcedureColumns
;
92 extern T3SQLProcedures pODBC3SQLProcedures
;
93 extern T3SQLSpecialColumns pODBC3SQLSpecialColumns
;
94 extern T3SQLStatistics pODBC3SQLStatistics
;
95 extern T3SQLTablePrivileges pODBC3SQLTablePrivileges
;
96 extern T3SQLTables pODBC3SQLTables
;
97 extern T3SQLFreeStmt pODBC3SQLFreeStmt
;
98 extern T3SQLCloseCursor pODBC3SQLCloseCursor
;
99 extern T3SQLCancel pODBC3SQLCancel
;
100 extern T3SQLEndTran pODBC3SQLEndTran
;
101 extern T3SQLDisconnect pODBC3SQLDisconnect
;
102 extern T3SQLFreeHandle pODBC3SQLFreeHandle
;
103 extern T3SQLGetCursorName pODBC3SQLGetCursorName
;
104 extern T3SQLNativeSql pODBC3SQLNativeSql
;
109 class ORealObdcDriver
: public ODBCDriver
112 virtual oslGenericFunction
getOdbcFunction(sal_Int32 _nIndex
) const;
113 virtual SQLHANDLE
EnvironmentHandle(::rtl::OUString
&_rPath
);
115 ORealObdcDriver(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
) : ODBCDriver(_rxFactory
) {}
118 //------------------------------------------------------------------
119 oslGenericFunction
ORealObdcDriver::getOdbcFunction(sal_Int32 _nIndex
) const
121 oslGenericFunction pFunction
= NULL
;
124 case ODBC3SQLAllocHandle
:
125 pFunction
= (oslGenericFunction
)pODBC3SQLAllocHandle
;
127 case ODBC3SQLConnect
:
128 pFunction
= (oslGenericFunction
)pODBC3SQLConnect
;
130 case ODBC3SQLDriverConnect
:
131 pFunction
= (oslGenericFunction
)pODBC3SQLDriverConnect
;
133 case ODBC3SQLBrowseConnect
:
134 pFunction
= (oslGenericFunction
)pODBC3SQLBrowseConnect
;
136 case ODBC3SQLDataSources
:
137 pFunction
= (oslGenericFunction
)pODBC3SQLDataSources
;
139 case ODBC3SQLDrivers
:
140 pFunction
= (oslGenericFunction
)pODBC3SQLDrivers
;
142 case ODBC3SQLGetInfo
:
144 pFunction
= (oslGenericFunction
)pODBC3SQLGetInfo
;
146 case ODBC3SQLGetFunctions
:
148 pFunction
= (oslGenericFunction
)pODBC3SQLGetFunctions
;
150 case ODBC3SQLGetTypeInfo
:
152 pFunction
= (oslGenericFunction
)pODBC3SQLGetTypeInfo
;
154 case ODBC3SQLSetConnectAttr
:
156 pFunction
= (oslGenericFunction
)pODBC3SQLSetConnectAttr
;
158 case ODBC3SQLGetConnectAttr
:
160 pFunction
= (oslGenericFunction
)pODBC3SQLGetConnectAttr
;
162 case ODBC3SQLSetEnvAttr
:
164 pFunction
= (oslGenericFunction
)pODBC3SQLSetEnvAttr
;
166 case ODBC3SQLGetEnvAttr
:
168 pFunction
= (oslGenericFunction
)pODBC3SQLGetEnvAttr
;
170 case ODBC3SQLSetStmtAttr
:
172 pFunction
= (oslGenericFunction
)pODBC3SQLSetStmtAttr
;
174 case ODBC3SQLGetStmtAttr
:
176 pFunction
= (oslGenericFunction
)pODBC3SQLGetStmtAttr
;
178 case ODBC3SQLPrepare
:
180 pFunction
= (oslGenericFunction
)pODBC3SQLPrepare
;
182 case ODBC3SQLBindParameter
:
184 pFunction
= (oslGenericFunction
)pODBC3SQLBindParameter
;
186 case ODBC3SQLSetCursorName
:
188 pFunction
= (oslGenericFunction
)pODBC3SQLSetCursorName
;
190 case ODBC3SQLExecute
:
192 pFunction
= (oslGenericFunction
)pODBC3SQLExecute
;
194 case ODBC3SQLExecDirect
:
196 pFunction
= (oslGenericFunction
)pODBC3SQLExecDirect
;
198 case ODBC3SQLDescribeParam
:
200 pFunction
= (oslGenericFunction
)pODBC3SQLDescribeParam
;
202 case ODBC3SQLNumParams
:
204 pFunction
= (oslGenericFunction
)pODBC3SQLNumParams
;
206 case ODBC3SQLParamData
:
208 pFunction
= (oslGenericFunction
)pODBC3SQLParamData
;
210 case ODBC3SQLPutData
:
212 pFunction
= (oslGenericFunction
)pODBC3SQLPutData
;
214 case ODBC3SQLRowCount
:
216 pFunction
= (oslGenericFunction
)pODBC3SQLRowCount
;
218 case ODBC3SQLNumResultCols
:
220 pFunction
= (oslGenericFunction
)pODBC3SQLNumResultCols
;
222 case ODBC3SQLDescribeCol
:
224 pFunction
= (oslGenericFunction
)pODBC3SQLDescribeCol
;
226 case ODBC3SQLColAttribute
:
228 pFunction
= (oslGenericFunction
)pODBC3SQLColAttribute
;
230 case ODBC3SQLBindCol
:
232 pFunction
= (oslGenericFunction
)pODBC3SQLBindCol
;
236 pFunction
= (oslGenericFunction
)pODBC3SQLFetch
;
238 case ODBC3SQLFetchScroll
:
240 pFunction
= (oslGenericFunction
)pODBC3SQLFetchScroll
;
242 case ODBC3SQLGetData
:
244 pFunction
= (oslGenericFunction
)pODBC3SQLGetData
;
248 pFunction
= (oslGenericFunction
)pODBC3SQLSetPos
;
250 case ODBC3SQLBulkOperations
:
252 pFunction
= (oslGenericFunction
)pODBC3SQLBulkOperations
;
254 case ODBC3SQLMoreResults
:
256 pFunction
= (oslGenericFunction
)pODBC3SQLMoreResults
;
258 case ODBC3SQLGetDiagRec
:
260 pFunction
= (oslGenericFunction
)pODBC3SQLGetDiagRec
;
262 case ODBC3SQLColumnPrivileges
:
264 pFunction
= (oslGenericFunction
)pODBC3SQLColumnPrivileges
;
266 case ODBC3SQLColumns
:
268 pFunction
= (oslGenericFunction
)pODBC3SQLColumns
;
270 case ODBC3SQLForeignKeys
:
272 pFunction
= (oslGenericFunction
)pODBC3SQLForeignKeys
;
274 case ODBC3SQLPrimaryKeys
:
276 pFunction
= (oslGenericFunction
)pODBC3SQLPrimaryKeys
;
278 case ODBC3SQLProcedureColumns
:
280 pFunction
= (oslGenericFunction
)pODBC3SQLProcedureColumns
;
282 case ODBC3SQLProcedures
:
284 pFunction
= (oslGenericFunction
)pODBC3SQLProcedures
;
286 case ODBC3SQLSpecialColumns
:
288 pFunction
= (oslGenericFunction
)pODBC3SQLSpecialColumns
;
290 case ODBC3SQLStatistics
:
292 pFunction
= (oslGenericFunction
)pODBC3SQLStatistics
;
294 case ODBC3SQLTablePrivileges
:
296 pFunction
= (oslGenericFunction
)pODBC3SQLTablePrivileges
;
300 pFunction
= (oslGenericFunction
)pODBC3SQLTables
;
302 case ODBC3SQLFreeStmt
:
304 pFunction
= (oslGenericFunction
)pODBC3SQLFreeStmt
;
306 case ODBC3SQLCloseCursor
:
308 pFunction
= (oslGenericFunction
)pODBC3SQLCloseCursor
;
312 pFunction
= (oslGenericFunction
)pODBC3SQLCancel
;
314 case ODBC3SQLEndTran
:
316 pFunction
= (oslGenericFunction
)pODBC3SQLEndTran
;
318 case ODBC3SQLDisconnect
:
320 pFunction
= (oslGenericFunction
)pODBC3SQLDisconnect
;
322 case ODBC3SQLFreeHandle
:
324 pFunction
= (oslGenericFunction
)pODBC3SQLFreeHandle
;
326 case ODBC3SQLGetCursorName
:
328 pFunction
= (oslGenericFunction
)pODBC3SQLGetCursorName
;
330 case ODBC3SQLNativeSql
:
332 pFunction
= (oslGenericFunction
)pODBC3SQLNativeSql
;
335 OSL_ENSURE(0,"Function unknown!");
340 //------------------------------------------------------------------
341 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
ODBCDriver_CreateInstance(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
) throw( ::com::sun::star::uno::Exception
)
343 return *(new ORealObdcDriver(_rxFactory
));
345 // -----------------------------------------------------------------------------
346 // ODBC Environment (gemeinsam fuer alle Connections):
347 SQLHANDLE
ORealObdcDriver::EnvironmentHandle(::rtl::OUString
&_rPath
)
349 // Ist (fuer diese Instanz) bereits ein Environment erzeugt worden?
350 if (!m_pDriverHandle
)
352 SQLHANDLE h
= SQL_NULL_HANDLE
;
353 // Environment allozieren
355 // ODBC-DLL jetzt laden:
356 if (!LoadLibrary_ODBC3(_rPath
) || N3SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&h
) != SQL_SUCCESS
)
357 return SQL_NULL_HANDLE
;
359 // In globaler Struktur merken ...
361 SQLRETURN nError
= N3SQLSetEnvAttr(h
, SQL_ATTR_ODBC_VERSION
,(SQLPOINTER
) SQL_OV_ODBC3
, SQL_IS_UINTEGER
);
362 OSL_UNUSED( nError
);
363 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
366 return m_pDriverHandle
;
368 // -----------------------------------------------------------------------------