1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "ORealDriver.hxx" 31 #include "odbc/ODriver.hxx" 32 #include "odbc/OTools.hxx" 33 #include "odbc/OFunctions.hxx" 34 #include "diagnose_ex.h" 35 36 namespace connectivity 37 { 38 sal_Bool LoadFunctions(oslModule pODBCso); 39 sal_Bool LoadLibrary_ODBC3(::rtl::OUString &_rPath); 40 // extern declaration of the function pointer 41 extern T3SQLAllocHandle pODBC3SQLAllocHandle; 42 extern T3SQLConnect pODBC3SQLConnect; 43 extern T3SQLDriverConnect pODBC3SQLDriverConnect; 44 extern T3SQLBrowseConnect pODBC3SQLBrowseConnect; 45 extern T3SQLDataSources pODBC3SQLDataSources; 46 extern T3SQLDrivers pODBC3SQLDrivers; 47 extern T3SQLGetInfo pODBC3SQLGetInfo; 48 extern T3SQLGetFunctions pODBC3SQLGetFunctions; 49 extern T3SQLGetTypeInfo pODBC3SQLGetTypeInfo; 50 extern T3SQLSetConnectAttr pODBC3SQLSetConnectAttr; 51 extern T3SQLGetConnectAttr pODBC3SQLGetConnectAttr; 52 extern T3SQLSetEnvAttr pODBC3SQLSetEnvAttr; 53 extern T3SQLGetEnvAttr pODBC3SQLGetEnvAttr; 54 extern T3SQLSetStmtAttr pODBC3SQLSetStmtAttr; 55 extern T3SQLGetStmtAttr pODBC3SQLGetStmtAttr; 56 //extern T3SQLSetDescField pODBC3SQLSetDescField; 57 //extern T3SQLGetDescField pODBC3SQLGetDescField; 58 //extern T3SQLGetDescRec pODBC3SQLGetDescRec; 59 //extern T3SQLSetDescRec pODBC3SQLSetDescRec; 60 extern T3SQLPrepare pODBC3SQLPrepare; 61 extern T3SQLBindParameter pODBC3SQLBindParameter; 62 //extern T3SQLGetCursorName pODBC3SQLGetCursorName; 63 extern T3SQLSetCursorName pODBC3SQLSetCursorName; 64 extern T3SQLExecute pODBC3SQLExecute; 65 extern T3SQLExecDirect pODBC3SQLExecDirect; 66 //extern T3SQLNativeSql pODBC3SQLNativeSql; 67 extern T3SQLDescribeParam pODBC3SQLDescribeParam; 68 extern T3SQLNumParams pODBC3SQLNumParams; 69 extern T3SQLParamData pODBC3SQLParamData; 70 extern T3SQLPutData pODBC3SQLPutData; 71 extern T3SQLRowCount pODBC3SQLRowCount; 72 extern T3SQLNumResultCols pODBC3SQLNumResultCols; 73 extern T3SQLDescribeCol pODBC3SQLDescribeCol; 74 extern T3SQLColAttribute pODBC3SQLColAttribute; 75 extern T3SQLBindCol pODBC3SQLBindCol; 76 extern T3SQLFetch pODBC3SQLFetch; 77 extern T3SQLFetchScroll pODBC3SQLFetchScroll; 78 extern T3SQLGetData pODBC3SQLGetData; 79 extern T3SQLSetPos pODBC3SQLSetPos; 80 extern T3SQLBulkOperations pODBC3SQLBulkOperations; 81 extern T3SQLMoreResults pODBC3SQLMoreResults; 82 //extern T3SQLGetDiagField pODBC3SQLGetDiagField; 83 extern T3SQLGetDiagRec pODBC3SQLGetDiagRec; 84 extern T3SQLColumnPrivileges pODBC3SQLColumnPrivileges; 85 extern T3SQLColumns pODBC3SQLColumns; 86 extern T3SQLForeignKeys pODBC3SQLForeignKeys; 87 extern T3SQLPrimaryKeys pODBC3SQLPrimaryKeys; 88 extern T3SQLProcedureColumns pODBC3SQLProcedureColumns; 89 extern T3SQLProcedures pODBC3SQLProcedures; 90 extern T3SQLSpecialColumns pODBC3SQLSpecialColumns; 91 extern T3SQLStatistics pODBC3SQLStatistics; 92 extern T3SQLTablePrivileges pODBC3SQLTablePrivileges; 93 extern T3SQLTables pODBC3SQLTables; 94 extern T3SQLFreeStmt pODBC3SQLFreeStmt; 95 extern T3SQLCloseCursor pODBC3SQLCloseCursor; 96 extern T3SQLCancel pODBC3SQLCancel; 97 extern T3SQLEndTran pODBC3SQLEndTran; 98 extern T3SQLDisconnect pODBC3SQLDisconnect; 99 extern T3SQLFreeHandle pODBC3SQLFreeHandle; 100 extern T3SQLGetCursorName pODBC3SQLGetCursorName; 101 extern T3SQLNativeSql pODBC3SQLNativeSql; 102 103 104 namespace odbc 105 { 106 class ORealObdcDriver : public ODBCDriver 107 { 108 protected: 109 virtual oslGenericFunction getOdbcFunction(sal_Int32 _nIndex) const; 110 virtual SQLHANDLE EnvironmentHandle(::rtl::OUString &_rPath); 111 public: 112 ORealObdcDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) : ODBCDriver(_rxFactory) {} 113 }; 114 115 //------------------------------------------------------------------ 116 oslGenericFunction ORealObdcDriver::getOdbcFunction(sal_Int32 _nIndex) const 117 { 118 oslGenericFunction pFunction = NULL; 119 switch(_nIndex) 120 { 121 case ODBC3SQLAllocHandle: 122 pFunction = (oslGenericFunction)pODBC3SQLAllocHandle; 123 break; 124 case ODBC3SQLConnect: 125 pFunction = (oslGenericFunction)pODBC3SQLConnect; 126 break; 127 case ODBC3SQLDriverConnect: 128 pFunction = (oslGenericFunction)pODBC3SQLDriverConnect; 129 break; 130 case ODBC3SQLBrowseConnect: 131 pFunction = (oslGenericFunction)pODBC3SQLBrowseConnect; 132 break; 133 case ODBC3SQLDataSources: 134 pFunction = (oslGenericFunction)pODBC3SQLDataSources; 135 break; 136 case ODBC3SQLDrivers: 137 pFunction = (oslGenericFunction)pODBC3SQLDrivers; 138 break; 139 case ODBC3SQLGetInfo: 140 141 pFunction = (oslGenericFunction)pODBC3SQLGetInfo; 142 break; 143 case ODBC3SQLGetFunctions: 144 145 pFunction = (oslGenericFunction)pODBC3SQLGetFunctions; 146 break; 147 case ODBC3SQLGetTypeInfo: 148 149 pFunction = (oslGenericFunction)pODBC3SQLGetTypeInfo; 150 break; 151 case ODBC3SQLSetConnectAttr: 152 153 pFunction = (oslGenericFunction)pODBC3SQLSetConnectAttr; 154 break; 155 case ODBC3SQLGetConnectAttr: 156 157 pFunction = (oslGenericFunction)pODBC3SQLGetConnectAttr; 158 break; 159 case ODBC3SQLSetEnvAttr: 160 161 pFunction = (oslGenericFunction)pODBC3SQLSetEnvAttr; 162 break; 163 case ODBC3SQLGetEnvAttr: 164 165 pFunction = (oslGenericFunction)pODBC3SQLGetEnvAttr; 166 break; 167 case ODBC3SQLSetStmtAttr: 168 169 pFunction = (oslGenericFunction)pODBC3SQLSetStmtAttr; 170 break; 171 case ODBC3SQLGetStmtAttr: 172 173 pFunction = (oslGenericFunction)pODBC3SQLGetStmtAttr; 174 break; 175 case ODBC3SQLPrepare: 176 177 pFunction = (oslGenericFunction)pODBC3SQLPrepare; 178 break; 179 case ODBC3SQLBindParameter: 180 181 pFunction = (oslGenericFunction)pODBC3SQLBindParameter; 182 break; 183 case ODBC3SQLSetCursorName: 184 185 pFunction = (oslGenericFunction)pODBC3SQLSetCursorName; 186 break; 187 case ODBC3SQLExecute: 188 189 pFunction = (oslGenericFunction)pODBC3SQLExecute; 190 break; 191 case ODBC3SQLExecDirect: 192 193 pFunction = (oslGenericFunction)pODBC3SQLExecDirect; 194 break; 195 case ODBC3SQLDescribeParam: 196 197 pFunction = (oslGenericFunction)pODBC3SQLDescribeParam; 198 break; 199 case ODBC3SQLNumParams: 200 201 pFunction = (oslGenericFunction)pODBC3SQLNumParams; 202 break; 203 case ODBC3SQLParamData: 204 205 pFunction = (oslGenericFunction)pODBC3SQLParamData; 206 break; 207 case ODBC3SQLPutData: 208 209 pFunction = (oslGenericFunction)pODBC3SQLPutData; 210 break; 211 case ODBC3SQLRowCount: 212 213 pFunction = (oslGenericFunction)pODBC3SQLRowCount; 214 break; 215 case ODBC3SQLNumResultCols: 216 217 pFunction = (oslGenericFunction)pODBC3SQLNumResultCols; 218 break; 219 case ODBC3SQLDescribeCol: 220 221 pFunction = (oslGenericFunction)pODBC3SQLDescribeCol; 222 break; 223 case ODBC3SQLColAttribute: 224 225 pFunction = (oslGenericFunction)pODBC3SQLColAttribute; 226 break; 227 case ODBC3SQLBindCol: 228 229 pFunction = (oslGenericFunction)pODBC3SQLBindCol; 230 break; 231 case ODBC3SQLFetch: 232 233 pFunction = (oslGenericFunction)pODBC3SQLFetch; 234 break; 235 case ODBC3SQLFetchScroll: 236 237 pFunction = (oslGenericFunction)pODBC3SQLFetchScroll; 238 break; 239 case ODBC3SQLGetData: 240 241 pFunction = (oslGenericFunction)pODBC3SQLGetData; 242 break; 243 case ODBC3SQLSetPos: 244 245 pFunction = (oslGenericFunction)pODBC3SQLSetPos; 246 break; 247 case ODBC3SQLBulkOperations: 248 249 pFunction = (oslGenericFunction)pODBC3SQLBulkOperations; 250 break; 251 case ODBC3SQLMoreResults: 252 253 pFunction = (oslGenericFunction)pODBC3SQLMoreResults; 254 break; 255 case ODBC3SQLGetDiagRec: 256 257 pFunction = (oslGenericFunction)pODBC3SQLGetDiagRec; 258 break; 259 case ODBC3SQLColumnPrivileges: 260 261 pFunction = (oslGenericFunction)pODBC3SQLColumnPrivileges; 262 break; 263 case ODBC3SQLColumns: 264 265 pFunction = (oslGenericFunction)pODBC3SQLColumns; 266 break; 267 case ODBC3SQLForeignKeys: 268 269 pFunction = (oslGenericFunction)pODBC3SQLForeignKeys; 270 break; 271 case ODBC3SQLPrimaryKeys: 272 273 pFunction = (oslGenericFunction)pODBC3SQLPrimaryKeys; 274 break; 275 case ODBC3SQLProcedureColumns: 276 277 pFunction = (oslGenericFunction)pODBC3SQLProcedureColumns; 278 break; 279 case ODBC3SQLProcedures: 280 281 pFunction = (oslGenericFunction)pODBC3SQLProcedures; 282 break; 283 case ODBC3SQLSpecialColumns: 284 285 pFunction = (oslGenericFunction)pODBC3SQLSpecialColumns; 286 break; 287 case ODBC3SQLStatistics: 288 289 pFunction = (oslGenericFunction)pODBC3SQLStatistics; 290 break; 291 case ODBC3SQLTablePrivileges: 292 293 pFunction = (oslGenericFunction)pODBC3SQLTablePrivileges; 294 break; 295 case ODBC3SQLTables: 296 297 pFunction = (oslGenericFunction)pODBC3SQLTables; 298 break; 299 case ODBC3SQLFreeStmt: 300 301 pFunction = (oslGenericFunction)pODBC3SQLFreeStmt; 302 break; 303 case ODBC3SQLCloseCursor: 304 305 pFunction = (oslGenericFunction)pODBC3SQLCloseCursor; 306 break; 307 case ODBC3SQLCancel: 308 309 pFunction = (oslGenericFunction)pODBC3SQLCancel; 310 break; 311 case ODBC3SQLEndTran: 312 313 pFunction = (oslGenericFunction)pODBC3SQLEndTran; 314 break; 315 case ODBC3SQLDisconnect: 316 317 pFunction = (oslGenericFunction)pODBC3SQLDisconnect; 318 break; 319 case ODBC3SQLFreeHandle: 320 321 pFunction = (oslGenericFunction)pODBC3SQLFreeHandle; 322 break; 323 case ODBC3SQLGetCursorName: 324 325 pFunction = (oslGenericFunction)pODBC3SQLGetCursorName; 326 break; 327 case ODBC3SQLNativeSql: 328 329 pFunction = (oslGenericFunction)pODBC3SQLNativeSql; 330 break; 331 default: 332 OSL_ENSURE(0,"Function unknown!"); 333 } 334 return pFunction; 335 } 336 337 //------------------------------------------------------------------ 338 ::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 { 340 return *(new ORealObdcDriver(_rxFactory)); 341 } 342 // ----------------------------------------------------------------------------- 343 // ODBC Environment (gemeinsam fuer alle Connections): 344 SQLHANDLE ORealObdcDriver::EnvironmentHandle(::rtl::OUString &_rPath) 345 { 346 // Ist (fuer diese Instanz) bereits ein Environment erzeugt worden? 347 if (!m_pDriverHandle) 348 { 349 SQLHANDLE h = SQL_NULL_HANDLE; 350 // Environment allozieren 351 352 // ODBC-DLL jetzt laden: 353 if (!LoadLibrary_ODBC3(_rPath) || N3SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&h) != SQL_SUCCESS) 354 return SQL_NULL_HANDLE; 355 356 // In globaler Struktur merken ... 357 m_pDriverHandle = h; 358 SQLRETURN nError = N3SQLSetEnvAttr(h, SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); 359 OSL_UNUSED( nError ); 360 //N3SQLSetEnvAttr(h, SQL_ATTR_CONNECTION_POOLING,(SQLPOINTER) SQL_CP_ONE_PER_HENV, SQL_IS_INTEGER); 361 } 362 363 return m_pDriverHandle; 364 } 365 // ----------------------------------------------------------------------------- 366 367 } 368 } 369 370