1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX
20 #define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX
22 #include <connectivity/odbc.hxx>
23 #include "odbc/odbcbasedllapi.hxx"
24 #include <com/sun/star/sdbc/SQLException.hpp>
25 #include <com/sun/star/util/Date.hpp>
26 #include <com/sun/star/util/Time.hpp>
27 #include <com/sun/star/util/DateTime.hpp>
28 #include <osl/thread.h>
29 #include <rtl/ustring.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <rtl/textenc.h>
33 #define ODBC3SQLAllocHandle 1
34 #define ODBC3SQLConnect 2
35 #define ODBC3SQLDriverConnect 3
36 #define ODBC3SQLBrowseConnect 4
37 #define ODBC3SQLDataSources 5
38 #define ODBC3SQLDrivers 6
39 #define ODBC3SQLGetInfo 7
40 #define ODBC3SQLGetFunctions 8
41 #define ODBC3SQLGetTypeInfo 9
42 #define ODBC3SQLSetConnectAttr 10
43 #define ODBC3SQLGetConnectAttr 11
44 #define ODBC3SQLSetEnvAttr 12
45 #define ODBC3SQLGetEnvAttr 13
46 #define ODBC3SQLSetStmtAttr 14
47 #define ODBC3SQLGetStmtAttr 15
48 #define ODBC3SQLPrepare 16
49 #define ODBC3SQLBindParameter 17
50 #define ODBC3SQLSetCursorName 18
51 #define ODBC3SQLExecute 19
52 #define ODBC3SQLExecDirect 20
53 #define ODBC3SQLDescribeParam 21
54 #define ODBC3SQLNumParams 22
55 #define ODBC3SQLParamData 23
56 #define ODBC3SQLPutData 24
57 #define ODBC3SQLRowCount 25
58 #define ODBC3SQLNumResultCols 26
59 #define ODBC3SQLDescribeCol 27
60 #define ODBC3SQLColAttribute 28
61 #define ODBC3SQLBindCol 29
62 #define ODBC3SQLFetch 30
63 #define ODBC3SQLFetchScroll 31
64 #define ODBC3SQLGetData 32
65 #define ODBC3SQLSetPos 33
66 #define ODBC3SQLBulkOperations 34
67 #define ODBC3SQLMoreResults 35
68 #define ODBC3SQLGetDiagRec 36
69 #define ODBC3SQLColumnPrivileges 37
70 #define ODBC3SQLColumns 38
71 #define ODBC3SQLForeignKeys 39
72 #define ODBC3SQLPrimaryKeys 40
73 #define ODBC3SQLProcedureColumns 41
74 #define ODBC3SQLProcedures 42
75 #define ODBC3SQLSpecialColumns 43
76 #define ODBC3SQLStatistics 44
77 #define ODBC3SQLTablePrivileges 45
78 #define ODBC3SQLTables 46
79 #define ODBC3SQLFreeStmt 47
80 #define ODBC3SQLCloseCursor 48
81 #define ODBC3SQLCancel 49
82 #define ODBC3SQLEndTran 50
83 #define ODBC3SQLDisconnect 51
84 #define ODBC3SQLFreeHandle 52
85 #define ODBC3SQLGetCursorName 53
86 #define ODBC3SQLNativeSql 54
88 namespace connectivity
94 const sal_Int32 MAX_PUT_DATA_LENGTH
= 2000;
96 class OOO_DLLPUBLIC_ODBCBASE OTools
99 static void ThrowException( const OConnection
* _pConnection
,
102 SQLSMALLINT _nHandleType
,
103 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
105 rtl_TextEncoding _nTextEncoding
= RTL_TEXTENCODING_MS_1252
)
106 throw(::com::sun::star::sdbc::SQLException
);
108 static void GetInfo(OConnection
* _pConnection
,
109 SQLHANDLE _aConnectionHandle
,
112 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
113 rtl_TextEncoding _nTextEncoding
)
114 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
116 static void GetInfo(OConnection
* _pConnection
,
117 SQLHANDLE _aConnectionHandle
,
120 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
122 static void GetInfo(OConnection
* _pConnection
,
123 SQLHANDLE _aConnectionHandle
,
125 SQLUSMALLINT
&_rValue
,
126 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
128 static void GetInfo(OConnection
* _pConnection
,
129 SQLHANDLE _aConnectionHandle
,
131 SQLUINTEGER
&_rValue
,
132 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
134 static void GetInfo(OConnection
* _pConnection
,
135 SQLHANDLE _aConnectionHandle
,
138 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
140 static sal_Int32
MapOdbcType2Jdbc(SQLSMALLINT _nType
);
141 static SQLSMALLINT
jdbcTypeToOdbc(sal_Int32 jdbcType
);
143 static DATE_STRUCT
DateToOdbcDate(const ::com::sun::star::util::Date
& x
)
147 aVal
.month
= x
.Month
;
151 static TIME_STRUCT
TimeToOdbcTime(const ::com::sun::star::util::Time
& x
)
155 aVal
.minute
= x
.Minutes
;
156 aVal
.second
= x
.Seconds
;
159 static TIMESTAMP_STRUCT
DateTimeToTimestamp(const ::com::sun::star::util::DateTime
& x
)
161 TIMESTAMP_STRUCT aVal
;
163 aVal
.month
= x
.Month
;
166 aVal
.minute
= x
.Minutes
;
167 aVal
.second
= x
.Seconds
;
168 aVal
.fraction
= x
.NanoSeconds
;
172 getBindTypes set the ODBC type for C
173 @param _bUseWChar true when Unicode should be used
174 @param _bUseOldTimeDate true when the old datetime format should be used
175 @param _nOdbcType the ODBC sql type
176 @param fCType the C type for the ODBC type
177 @param fSqlType the SQL type for the ODBC type
179 static void getBindTypes(bool _bUseWChar
,
180 bool _bUseOldTimeDate
,
181 SQLSMALLINT _nOdbcType
,
183 SQLSMALLINT
& fSqlType
);
185 static OUString
getStringValue( OConnection
* _pConnection
,
186 SQLHANDLE _aStatementHandle
,
187 sal_Int32 columnIndex
,
188 SQLSMALLINT _fSqlType
,
190 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
191 rtl_TextEncoding _nTextEncoding
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
193 static ::com::sun::star::uno::Sequence
<sal_Int8
> getBytesValue(const OConnection
* _pConnection
,
194 SQLHANDLE _aStatementHandle
,
195 sal_Int32 columnIndex
,
196 SQLSMALLINT _fSqlType
,
198 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
199 static void getValue( OConnection
* _pConnection
,
200 SQLHANDLE _aStatementHandle
,
201 sal_Int32 columnIndex
,
204 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
206 SQLLEN _nSize
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
208 static void bindValue( OConnection
* _pConnection
,
209 SQLHANDLE _aStatementHandle
,
210 sal_Int32 columnIndex
,
212 SQLSMALLINT _nMaxLen
,
216 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
217 rtl_TextEncoding _nTextEncoding
,
218 bool _bUseOldTimeDate
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
221 template <class T
> void getValue( OConnection
* _pConnection
,
222 SQLHANDLE _aStatementHandle
,
223 sal_Int32 columnIndex
,
226 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xInterface
,
227 T
& _rValue
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
229 OTools::getValue(_pConnection
,_aStatementHandle
,columnIndex
,_nType
,_bWasNull
,_xInterface
,&_rValue
,sizeof _rValue
);
236 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_OTOOLS_HXX
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */