1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ORealDriver.hxx"
30 #include "odbc/ODriver.hxx"
31 #include "odbc/OTools.hxx"
32 #include "odbc/OFunctions.hxx"
33 #include "diagnose_ex.h"
35 namespace connectivity
37 sal_Bool
LoadFunctions(oslModule pODBCso
);
38 sal_Bool
LoadLibrary_ODBC3(::rtl::OUString
&_rPath
);
39 // extern declaration of the function pointer
40 extern T3SQLAllocHandle pODBC3SQLAllocHandle
;
41 extern T3SQLConnect pODBC3SQLConnect
;
42 extern T3SQLDriverConnect pODBC3SQLDriverConnect
;
43 extern T3SQLBrowseConnect pODBC3SQLBrowseConnect
;
44 extern T3SQLDataSources pODBC3SQLDataSources
;
45 extern T3SQLDrivers pODBC3SQLDrivers
;
46 extern T3SQLGetInfo pODBC3SQLGetInfo
;
47 extern T3SQLGetFunctions pODBC3SQLGetFunctions
;
48 extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo
;
49 extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr
;
50 extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr
;
51 extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr
;
52 extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr
;
53 extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr
;
54 extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr
;
55 //extern T3SQLSetDescField pODBC3SQLSetDescField;
56 //extern T3SQLGetDescField pODBC3SQLGetDescField;
57 //extern T3SQLGetDescRec pODBC3SQLGetDescRec;
58 //extern T3SQLSetDescRec pODBC3SQLSetDescRec;
59 extern T3SQLPrepare pODBC3SQLPrepare
;
60 extern T3SQLBindParameter pODBC3SQLBindParameter
;
61 //extern T3SQLGetCursorName pODBC3SQLGetCursorName;
62 extern T3SQLSetCursorName pODBC3SQLSetCursorName
;
63 extern T3SQLExecute pODBC3SQLExecute
;
64 extern T3SQLExecDirect pODBC3SQLExecDirect
;
65 //extern T3SQLNativeSql pODBC3SQLNativeSql;
66 extern T3SQLDescribeParam pODBC3SQLDescribeParam
;
67 extern T3SQLNumParams pODBC3SQLNumParams
;
68 extern T3SQLParamData pODBC3SQLParamData
;
69 extern T3SQLPutData pODBC3SQLPutData
;
70 extern T3SQLRowCount pODBC3SQLRowCount
;
71 extern T3SQLNumResultCols pODBC3SQLNumResultCols
;
72 extern T3SQLDescribeCol pODBC3SQLDescribeCol
;
73 extern T3SQLColAttribute pODBC3SQLColAttribute
;
74 extern T3SQLBindCol pODBC3SQLBindCol
;
75 extern T3SQLFetch pODBC3SQLFetch
;
76 extern T3SQLFetchScroll pODBC3SQLFetchScroll
;
77 extern T3SQLGetData pODBC3SQLGetData
;
78 extern T3SQLSetPos pODBC3SQLSetPos
;
79 extern T3SQLBulkOperations pODBC3SQLBulkOperations
;
80 extern T3SQLMoreResults pODBC3SQLMoreResults
;
81 //extern T3SQLGetDiagField pODBC3SQLGetDiagField;
82 extern T3SQLGetDiagRec pODBC3SQLGetDiagRec
;
83 extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges
;
84 extern T3SQLColumns pODBC3SQLColumns
;
85 extern T3SQLForeignKeys pODBC3SQLForeignKeys
;
86 extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys
;
87 extern T3SQLProcedureColumns pODBC3SQLProcedureColumns
;
88 extern T3SQLProcedures pODBC3SQLProcedures
;
89 extern T3SQLSpecialColumns pODBC3SQLSpecialColumns
;
90 extern T3SQLStatistics pODBC3SQLStatistics
;
91 extern T3SQLTablePrivileges pODBC3SQLTablePrivileges
;
92 extern T3SQLTables pODBC3SQLTables
;
93 extern T3SQLFreeStmt pODBC3SQLFreeStmt
;
94 extern T3SQLCloseCursor pODBC3SQLCloseCursor
;
95 extern T3SQLCancel pODBC3SQLCancel
;
96 extern T3SQLEndTran pODBC3SQLEndTran
;
97 extern T3SQLDisconnect pODBC3SQLDisconnect
;
98 extern T3SQLFreeHandle pODBC3SQLFreeHandle
;
99 extern T3SQLGetCursorName pODBC3SQLGetCursorName
;
100 extern T3SQLNativeSql pODBC3SQLNativeSql
;
105 class ORealObdcDriver
: public ODBCDriver
108 virtual oslGenericFunction
getOdbcFunction(sal_Int32 _nIndex
) const;
109 virtual SQLHANDLE
EnvironmentHandle(::rtl::OUString
&_rPath
);
111 ORealObdcDriver(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
) : ODBCDriver(_rxFactory
) {}
114 //------------------------------------------------------------------
115 oslGenericFunction
ORealObdcDriver::getOdbcFunction(sal_Int32 _nIndex
) const
117 oslGenericFunction pFunction
= NULL
;
120 case ODBC3SQLAllocHandle
:
121 pFunction
= (oslGenericFunction
)pODBC3SQLAllocHandle
;
123 case ODBC3SQLConnect
:
124 pFunction
= (oslGenericFunction
)pODBC3SQLConnect
;
126 case ODBC3SQLDriverConnect
:
127 pFunction
= (oslGenericFunction
)pODBC3SQLDriverConnect
;
129 case ODBC3SQLBrowseConnect
:
130 pFunction
= (oslGenericFunction
)pODBC3SQLBrowseConnect
;
132 case ODBC3SQLDataSources
:
133 pFunction
= (oslGenericFunction
)pODBC3SQLDataSources
;
135 case ODBC3SQLDrivers
:
136 pFunction
= (oslGenericFunction
)pODBC3SQLDrivers
;
138 case ODBC3SQLGetInfo
:
140 pFunction
= (oslGenericFunction
)pODBC3SQLGetInfo
;
142 case ODBC3SQLGetFunctions
:
144 pFunction
= (oslGenericFunction
)pODBC3SQLGetFunctions
;
146 case ODBC3SQLGetTypeInfo
:
148 pFunction
= (oslGenericFunction
)pODBC3SQLGetTypeInfo
;
150 case ODBC3SQLSetConnectAttr
:
152 pFunction
= (oslGenericFunction
)pODBC3SQLSetConnectAttr
;
154 case ODBC3SQLGetConnectAttr
:
156 pFunction
= (oslGenericFunction
)pODBC3SQLGetConnectAttr
;
158 case ODBC3SQLSetEnvAttr
:
160 pFunction
= (oslGenericFunction
)pODBC3SQLSetEnvAttr
;
162 case ODBC3SQLGetEnvAttr
:
164 pFunction
= (oslGenericFunction
)pODBC3SQLGetEnvAttr
;
166 case ODBC3SQLSetStmtAttr
:
168 pFunction
= (oslGenericFunction
)pODBC3SQLSetStmtAttr
;
170 case ODBC3SQLGetStmtAttr
:
172 pFunction
= (oslGenericFunction
)pODBC3SQLGetStmtAttr
;
174 case ODBC3SQLPrepare
:
176 pFunction
= (oslGenericFunction
)pODBC3SQLPrepare
;
178 case ODBC3SQLBindParameter
:
180 pFunction
= (oslGenericFunction
)pODBC3SQLBindParameter
;
182 case ODBC3SQLSetCursorName
:
184 pFunction
= (oslGenericFunction
)pODBC3SQLSetCursorName
;
186 case ODBC3SQLExecute
:
188 pFunction
= (oslGenericFunction
)pODBC3SQLExecute
;
190 case ODBC3SQLExecDirect
:
192 pFunction
= (oslGenericFunction
)pODBC3SQLExecDirect
;
194 case ODBC3SQLDescribeParam
:
196 pFunction
= (oslGenericFunction
)pODBC3SQLDescribeParam
;
198 case ODBC3SQLNumParams
:
200 pFunction
= (oslGenericFunction
)pODBC3SQLNumParams
;
202 case ODBC3SQLParamData
:
204 pFunction
= (oslGenericFunction
)pODBC3SQLParamData
;
206 case ODBC3SQLPutData
:
208 pFunction
= (oslGenericFunction
)pODBC3SQLPutData
;
210 case ODBC3SQLRowCount
:
212 pFunction
= (oslGenericFunction
)pODBC3SQLRowCount
;
214 case ODBC3SQLNumResultCols
:
216 pFunction
= (oslGenericFunction
)pODBC3SQLNumResultCols
;
218 case ODBC3SQLDescribeCol
:
220 pFunction
= (oslGenericFunction
)pODBC3SQLDescribeCol
;
222 case ODBC3SQLColAttribute
:
224 pFunction
= (oslGenericFunction
)pODBC3SQLColAttribute
;
226 case ODBC3SQLBindCol
:
228 pFunction
= (oslGenericFunction
)pODBC3SQLBindCol
;
232 pFunction
= (oslGenericFunction
)pODBC3SQLFetch
;
234 case ODBC3SQLFetchScroll
:
236 pFunction
= (oslGenericFunction
)pODBC3SQLFetchScroll
;
238 case ODBC3SQLGetData
:
240 pFunction
= (oslGenericFunction
)pODBC3SQLGetData
;
244 pFunction
= (oslGenericFunction
)pODBC3SQLSetPos
;
246 case ODBC3SQLBulkOperations
:
248 pFunction
= (oslGenericFunction
)pODBC3SQLBulkOperations
;
250 case ODBC3SQLMoreResults
:
252 pFunction
= (oslGenericFunction
)pODBC3SQLMoreResults
;
254 case ODBC3SQLGetDiagRec
:
256 pFunction
= (oslGenericFunction
)pODBC3SQLGetDiagRec
;
258 case ODBC3SQLColumnPrivileges
:
260 pFunction
= (oslGenericFunction
)pODBC3SQLColumnPrivileges
;
262 case ODBC3SQLColumns
:
264 pFunction
= (oslGenericFunction
)pODBC3SQLColumns
;
266 case ODBC3SQLForeignKeys
:
268 pFunction
= (oslGenericFunction
)pODBC3SQLForeignKeys
;
270 case ODBC3SQLPrimaryKeys
:
272 pFunction
= (oslGenericFunction
)pODBC3SQLPrimaryKeys
;
274 case ODBC3SQLProcedureColumns
:
276 pFunction
= (oslGenericFunction
)pODBC3SQLProcedureColumns
;
278 case ODBC3SQLProcedures
:
280 pFunction
= (oslGenericFunction
)pODBC3SQLProcedures
;
282 case ODBC3SQLSpecialColumns
:
284 pFunction
= (oslGenericFunction
)pODBC3SQLSpecialColumns
;
286 case ODBC3SQLStatistics
:
288 pFunction
= (oslGenericFunction
)pODBC3SQLStatistics
;
290 case ODBC3SQLTablePrivileges
:
292 pFunction
= (oslGenericFunction
)pODBC3SQLTablePrivileges
;
296 pFunction
= (oslGenericFunction
)pODBC3SQLTables
;
298 case ODBC3SQLFreeStmt
:
300 pFunction
= (oslGenericFunction
)pODBC3SQLFreeStmt
;
302 case ODBC3SQLCloseCursor
:
304 pFunction
= (oslGenericFunction
)pODBC3SQLCloseCursor
;
308 pFunction
= (oslGenericFunction
)pODBC3SQLCancel
;
310 case ODBC3SQLEndTran
:
312 pFunction
= (oslGenericFunction
)pODBC3SQLEndTran
;
314 case ODBC3SQLDisconnect
:
316 pFunction
= (oslGenericFunction
)pODBC3SQLDisconnect
;
318 case ODBC3SQLFreeHandle
:
320 pFunction
= (oslGenericFunction
)pODBC3SQLFreeHandle
;
322 case ODBC3SQLGetCursorName
:
324 pFunction
= (oslGenericFunction
)pODBC3SQLGetCursorName
;
326 case ODBC3SQLNativeSql
:
328 pFunction
= (oslGenericFunction
)pODBC3SQLNativeSql
;
331 OSL_FAIL("Function unknown!");
336 //------------------------------------------------------------------
337 ::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
)
339 return *(new ORealObdcDriver(_rxFactory
));
341 // -----------------------------------------------------------------------------
342 // ODBC Environment (common for all Connections):
343 SQLHANDLE
ORealObdcDriver::EnvironmentHandle(::rtl::OUString
&_rPath
)
345 // Is (for this instance) already a Enviroment made?
346 if (!m_pDriverHandle
)
348 SQLHANDLE h
= SQL_NULL_HANDLE
;
349 // allocate Environment
351 // load ODBC-DLL now:
352 if (!LoadLibrary_ODBC3(_rPath
) || N3SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&h
) != SQL_SUCCESS
)
353 return SQL_NULL_HANDLE
;
355 // Save in global Structure
357 SQLRETURN nError
= N3SQLSetEnvAttr(h
, SQL_ATTR_ODBC_VERSION
,(SQLPOINTER
) SQL_OV_ODBC3
, SQL_IS_UINTEGER
);
358 OSL_UNUSED( nError
);
359 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER);
362 return m_pDriverHandle
;
364 // -----------------------------------------------------------------------------
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */