1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir #ifndef _CONNECTIVITY_OTOOLS_HXX_ 24cdf0e10cSrcweir #define _CONNECTIVITY_OTOOLS_HXX_ 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "odbc/OFunctiondefs.hxx" 27cdf0e10cSrcweir #include "odbc/odbcbasedllapi.hxx" 28cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLException.hpp> 29cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp> 30cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp> 31cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp> 32cdf0e10cSrcweir #include <osl/thread.h> 33cdf0e10cSrcweir #include <rtl/ustring.hxx> 34cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 35cdf0e10cSrcweir #include <rtl/textenc.h> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #define ODBC3SQLAllocHandle 1 38cdf0e10cSrcweir #define ODBC3SQLConnect 2 39cdf0e10cSrcweir #define ODBC3SQLDriverConnect 3 40cdf0e10cSrcweir #define ODBC3SQLBrowseConnect 4 41cdf0e10cSrcweir #define ODBC3SQLDataSources 5 42cdf0e10cSrcweir #define ODBC3SQLDrivers 6 43cdf0e10cSrcweir #define ODBC3SQLGetInfo 7 44cdf0e10cSrcweir #define ODBC3SQLGetFunctions 8 45cdf0e10cSrcweir #define ODBC3SQLGetTypeInfo 9 46cdf0e10cSrcweir #define ODBC3SQLSetConnectAttr 10 47cdf0e10cSrcweir #define ODBC3SQLGetConnectAttr 11 48cdf0e10cSrcweir #define ODBC3SQLSetEnvAttr 12 49cdf0e10cSrcweir #define ODBC3SQLGetEnvAttr 13 50cdf0e10cSrcweir #define ODBC3SQLSetStmtAttr 14 51cdf0e10cSrcweir #define ODBC3SQLGetStmtAttr 15 52cdf0e10cSrcweir #define ODBC3SQLPrepare 16 53cdf0e10cSrcweir #define ODBC3SQLBindParameter 17 54cdf0e10cSrcweir #define ODBC3SQLSetCursorName 18 55cdf0e10cSrcweir #define ODBC3SQLExecute 19 56cdf0e10cSrcweir #define ODBC3SQLExecDirect 20 57cdf0e10cSrcweir #define ODBC3SQLDescribeParam 21 58cdf0e10cSrcweir #define ODBC3SQLNumParams 22 59cdf0e10cSrcweir #define ODBC3SQLParamData 23 60cdf0e10cSrcweir #define ODBC3SQLPutData 24 61cdf0e10cSrcweir #define ODBC3SQLRowCount 25 62cdf0e10cSrcweir #define ODBC3SQLNumResultCols 26 63cdf0e10cSrcweir #define ODBC3SQLDescribeCol 27 64cdf0e10cSrcweir #define ODBC3SQLColAttribute 28 65cdf0e10cSrcweir #define ODBC3SQLBindCol 29 66cdf0e10cSrcweir #define ODBC3SQLFetch 30 67cdf0e10cSrcweir #define ODBC3SQLFetchScroll 31 68cdf0e10cSrcweir #define ODBC3SQLGetData 32 69cdf0e10cSrcweir #define ODBC3SQLSetPos 33 70cdf0e10cSrcweir #define ODBC3SQLBulkOperations 34 71cdf0e10cSrcweir #define ODBC3SQLMoreResults 35 72cdf0e10cSrcweir #define ODBC3SQLGetDiagRec 36 73cdf0e10cSrcweir #define ODBC3SQLColumnPrivileges 37 74cdf0e10cSrcweir #define ODBC3SQLColumns 38 75cdf0e10cSrcweir #define ODBC3SQLForeignKeys 39 76cdf0e10cSrcweir #define ODBC3SQLPrimaryKeys 40 77cdf0e10cSrcweir #define ODBC3SQLProcedureColumns 41 78cdf0e10cSrcweir #define ODBC3SQLProcedures 42 79cdf0e10cSrcweir #define ODBC3SQLSpecialColumns 43 80cdf0e10cSrcweir #define ODBC3SQLStatistics 44 81cdf0e10cSrcweir #define ODBC3SQLTablePrivileges 45 82cdf0e10cSrcweir #define ODBC3SQLTables 46 83cdf0e10cSrcweir #define ODBC3SQLFreeStmt 47 84cdf0e10cSrcweir #define ODBC3SQLCloseCursor 48 85cdf0e10cSrcweir #define ODBC3SQLCancel 49 86cdf0e10cSrcweir #define ODBC3SQLEndTran 50 87cdf0e10cSrcweir #define ODBC3SQLDisconnect 51 88cdf0e10cSrcweir #define ODBC3SQLFreeHandle 52 89cdf0e10cSrcweir #define ODBC3SQLGetCursorName 53 90cdf0e10cSrcweir #define ODBC3SQLNativeSql 54 91cdf0e10cSrcweir 92cdf0e10cSrcweir namespace connectivity 93cdf0e10cSrcweir { 94cdf0e10cSrcweir namespace odbc 95cdf0e10cSrcweir { 96cdf0e10cSrcweir class OConnection; 97cdf0e10cSrcweir 98cdf0e10cSrcweir const sal_uInt32 ODBC_FRACTION_UNITS_PER_HSECOND = 10000000L; 99cdf0e10cSrcweir const sal_Int32 MAX_PUT_DATA_LENGTH = 2000; 100cdf0e10cSrcweir 101cdf0e10cSrcweir class OOO_DLLPUBLIC_ODBCBASE OTools 102cdf0e10cSrcweir { 103cdf0e10cSrcweir public: 104cdf0e10cSrcweir static void ThrowException( OConnection* _pConnection, 105cdf0e10cSrcweir SQLRETURN _rRetCode, 106cdf0e10cSrcweir SQLHANDLE _pContext, 107cdf0e10cSrcweir SQLSMALLINT _nHandleType, 108cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 109cdf0e10cSrcweir sal_Bool _bNoFound=sal_True, 110cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding = RTL_TEXTENCODING_MS_1252) 111cdf0e10cSrcweir throw(::com::sun::star::sdbc::SQLException); 112cdf0e10cSrcweir 113cdf0e10cSrcweir static void GetInfo(OConnection* _pConnection, 114cdf0e10cSrcweir SQLHANDLE _aConnectionHandle, 115cdf0e10cSrcweir SQLUSMALLINT _nInfo, 116cdf0e10cSrcweir ::rtl::OUString &_rValue, 117cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 118cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding) 119cdf0e10cSrcweir throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 120cdf0e10cSrcweir 121cdf0e10cSrcweir static void GetInfo(OConnection* _pConnection, 122cdf0e10cSrcweir SQLHANDLE _aConnectionHandle, 123cdf0e10cSrcweir SQLUSMALLINT _nInfo, 124cdf0e10cSrcweir sal_Int32 &_rValue, 125cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 126cdf0e10cSrcweir 127cdf0e10cSrcweir static void GetInfo(OConnection* _pConnection, 128cdf0e10cSrcweir SQLHANDLE _aConnectionHandle, 129cdf0e10cSrcweir SQLUSMALLINT _nInfo, 130cdf0e10cSrcweir SQLUSMALLINT &_rValue, 131cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 132cdf0e10cSrcweir 133cdf0e10cSrcweir static void GetInfo(OConnection* _pConnection, 134cdf0e10cSrcweir SQLHANDLE _aConnectionHandle, 135cdf0e10cSrcweir SQLUSMALLINT _nInfo, 136cdf0e10cSrcweir SQLUINTEGER &_rValue, 137cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 138cdf0e10cSrcweir 139cdf0e10cSrcweir static void GetInfo(OConnection* _pConnection, 140cdf0e10cSrcweir SQLHANDLE _aConnectionHandle, 141cdf0e10cSrcweir SQLUSMALLINT _nInfo, 142cdf0e10cSrcweir sal_Bool &_rValue, 143cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 144cdf0e10cSrcweir 145cdf0e10cSrcweir static sal_Int32 MapOdbcType2Jdbc(sal_Int32 _nType); 146cdf0e10cSrcweir static sal_Int32 jdbcTypeToOdbc(sal_Int32 jdbcType); 147cdf0e10cSrcweir DateToOdbcDate(const::com::sun::star::util::Date & x)148cdf0e10cSrcweir static DATE_STRUCT DateToOdbcDate(const ::com::sun::star::util::Date& x) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir DATE_STRUCT aVal; 151cdf0e10cSrcweir aVal.year = x.Year; 152cdf0e10cSrcweir aVal.month = x.Month; 153cdf0e10cSrcweir aVal.day = x.Day; 154cdf0e10cSrcweir return aVal; 155cdf0e10cSrcweir } TimeToOdbcTime(const::com::sun::star::util::Time & x)156cdf0e10cSrcweir static TIME_STRUCT TimeToOdbcTime(const ::com::sun::star::util::Time& x) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir TIME_STRUCT aVal; 159cdf0e10cSrcweir aVal.hour = x.Hours; 160cdf0e10cSrcweir aVal.minute = x.Minutes; 161cdf0e10cSrcweir aVal.second = x.Seconds; 162cdf0e10cSrcweir return aVal; 163cdf0e10cSrcweir } DateTimeToTimestamp(const::com::sun::star::util::DateTime & x)164cdf0e10cSrcweir static TIMESTAMP_STRUCT DateTimeToTimestamp(const ::com::sun::star::util::DateTime& x) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir TIMESTAMP_STRUCT aVal; 167cdf0e10cSrcweir aVal.year = x.Year; 168cdf0e10cSrcweir aVal.month = x.Month; 169cdf0e10cSrcweir aVal.day = x.Day; 170cdf0e10cSrcweir aVal.hour = x.Hours; 171cdf0e10cSrcweir aVal.minute = x.Minutes; 172cdf0e10cSrcweir aVal.second = x.Seconds; 173cdf0e10cSrcweir aVal.fraction = x.HundredthSeconds * ODBC_FRACTION_UNITS_PER_HSECOND; 174cdf0e10cSrcweir return aVal; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir /** 177cdf0e10cSrcweir getBindTypes set the ODBC type for C 178cdf0e10cSrcweir @param _bUseWChar true when Unicode should be used 179cdf0e10cSrcweir @param _bUseOldTimeDate true when the old datetime format should be used 180cdf0e10cSrcweir @param _nOdbcType the ODBC sql type 181cdf0e10cSrcweir @param fCType the C type for the ODBC type 182cdf0e10cSrcweir @param fSqlType the SQL type for the ODBC type 183cdf0e10cSrcweir */ 184cdf0e10cSrcweir static void getBindTypes(sal_Bool _bUseWChar, 185cdf0e10cSrcweir sal_Bool _bUseOldTimeDate, 186cdf0e10cSrcweir SQLSMALLINT _nOdbcType, 187cdf0e10cSrcweir SQLSMALLINT& fCType, 188cdf0e10cSrcweir SQLSMALLINT& fSqlType); 189cdf0e10cSrcweir 190cdf0e10cSrcweir static ::rtl::OUString getStringValue( OConnection* _pConnection, 191cdf0e10cSrcweir SQLHANDLE _aStatementHandle, 192cdf0e10cSrcweir sal_Int32 columnIndex, 193cdf0e10cSrcweir SQLSMALLINT _fSqlType, 194cdf0e10cSrcweir sal_Bool &_bWasNull, 195cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 196cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 197cdf0e10cSrcweir 198cdf0e10cSrcweir static ::com::sun::star::uno::Sequence<sal_Int8> getBytesValue(OConnection* _pConnection, 199cdf0e10cSrcweir SQLHANDLE _aStatementHandle, 200cdf0e10cSrcweir sal_Int32 columnIndex, 201cdf0e10cSrcweir SQLSMALLINT _fSqlType, 202cdf0e10cSrcweir sal_Bool &_bWasNull, 203cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 204cdf0e10cSrcweir static void getValue( OConnection* _pConnection, 205cdf0e10cSrcweir SQLHANDLE _aStatementHandle, 206cdf0e10cSrcweir sal_Int32 columnIndex, 207cdf0e10cSrcweir SQLSMALLINT _nType, 208cdf0e10cSrcweir sal_Bool &_bWasNull, 209cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 210cdf0e10cSrcweir void* _pValue, 211cdf0e10cSrcweir SQLLEN _nSize) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 212cdf0e10cSrcweir 213cdf0e10cSrcweir /** 214cdf0e10cSrcweir bindData copies the from pValue to pData 215cdf0e10cSrcweir @param _nOdbcType the ODBC sql type 216cdf0e10cSrcweir @param _bUseWChar true when Unicode should be used 217cdf0e10cSrcweir @param _pData contains a copy of the data to be set 218cdf0e10cSrcweir @param _pValue contains the data to be copied 219cdf0e10cSrcweir @param _nTextEncoding the text encoding 220cdf0e10cSrcweir @param _nColumnSize the columnsize which is a out param 221cdf0e10cSrcweir */ 222cdf0e10cSrcweir static void bindData( SQLSMALLINT _nOdbcType, 223cdf0e10cSrcweir sal_Bool _bUseWChar, 224cdf0e10cSrcweir sal_Int8 *&_pData, 225cdf0e10cSrcweir SQLLEN*& pLen, 226cdf0e10cSrcweir const void* _pValue, 227cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding, 228cdf0e10cSrcweir SQLULEN& _nColumnSize); 229cdf0e10cSrcweir 230cdf0e10cSrcweir static void bindParameter( OConnection* _pConnection, 231cdf0e10cSrcweir SQLHANDLE _hStmt, 232cdf0e10cSrcweir sal_Int32 nPos, 233cdf0e10cSrcweir sal_Int8*& pDataBuffer, 234cdf0e10cSrcweir sal_Int8* pLenBuffer, 235cdf0e10cSrcweir SQLSMALLINT _nJDBCtype, 236cdf0e10cSrcweir sal_Bool _bUseWChar, 237cdf0e10cSrcweir sal_Bool _bUseOldTimeDate, 238cdf0e10cSrcweir const void* _pValue, 239cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 240cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding) 241cdf0e10cSrcweir throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 242cdf0e10cSrcweir 243cdf0e10cSrcweir static void bindValue( OConnection* _pConnection, 244cdf0e10cSrcweir SQLHANDLE _aStatementHandle, 245cdf0e10cSrcweir sal_Int32 columnIndex, 246cdf0e10cSrcweir SQLSMALLINT _nType, 247cdf0e10cSrcweir SQLSMALLINT _nMaxLen, 248cdf0e10cSrcweir const void* _pValue, 249cdf0e10cSrcweir void* _pData, 250cdf0e10cSrcweir SQLLEN *pLen, 251cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 252cdf0e10cSrcweir rtl_TextEncoding _nTextEncoding, 253cdf0e10cSrcweir sal_Bool _bUseOldTimeDate) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); 254cdf0e10cSrcweir }; 255cdf0e10cSrcweir getValue(OConnection * _pConnection,SQLHANDLE _aStatementHandle,sal_Int32 columnIndex,SQLSMALLINT _nType,sal_Bool & _bWasNull,const::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface> & _xInterface,T & _rValue)256cdf0e10cSrcweir template <class T> void getValue( OConnection* _pConnection, 257cdf0e10cSrcweir SQLHANDLE _aStatementHandle, 258cdf0e10cSrcweir sal_Int32 columnIndex, 259cdf0e10cSrcweir SQLSMALLINT _nType, 260cdf0e10cSrcweir sal_Bool &_bWasNull, 261cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface, 262cdf0e10cSrcweir T& _rValue) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir OTools::getValue(_pConnection,_aStatementHandle,columnIndex,_nType,_bWasNull,_xInterface,&_rValue,sizeof _rValue); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir //----------------------------------------------------------------------------- 267cdf0e10cSrcweir 268cdf0e10cSrcweir 269cdf0e10cSrcweir } 270cdf0e10cSrcweir } 271cdf0e10cSrcweir #endif // _CONNECTIVITY_OTOOLS_HXX_ 272cdf0e10cSrcweir 273