Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATARESULTSET_HXX
21 : #define INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATARESULTSET_HXX
22 :
23 : #include <com/sun/star/sdbc/ResultSetType.hpp>
24 : #include <com/sun/star/sdbc/FetchDirection.hpp>
25 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
26 : #include <com/sun/star/sdbc/XResultSet.hpp>
27 : #include <com/sun/star/sdbc/XRow.hpp>
28 : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
29 : #include <com/sun/star/sdbc/XCloseable.hpp>
30 : #include <com/sun/star/sdbc/XColumnLocate.hpp>
31 : #include <com/sun/star/util/XCancellable.hpp>
32 : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
33 : #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
34 : #include <com/sun/star/sdbc/XRowUpdate.hpp>
35 : #include <cppuhelper/compbase7.hxx>
36 : #include <comphelper/proparrhlp.hxx>
37 : #include "odbc/OStatement.hxx"
38 : #include "odbc/ODatabaseMetaData.hxx"
39 : #include "odbc/odbcbasedllapi.hxx"
40 : #include <comphelper/broadcasthelper.hxx>
41 : #include <connectivity/StdTypeDefs.hxx>
42 :
43 : namespace connectivity
44 : {
45 : namespace odbc
46 : {
47 : /*
48 : ** java_sql_ResultSet
49 : */
50 : typedef ::cppu::WeakComponentImplHelper7< ::com::sun::star::sdbc::XResultSet,
51 : ::com::sun::star::sdbc::XRow,
52 : ::com::sun::star::sdbc::XResultSetMetaDataSupplier,
53 : ::com::sun::star::util::XCancellable,
54 : ::com::sun::star::sdbc::XWarningsSupplier,
55 : ::com::sun::star::sdbc::XCloseable,
56 : ::com::sun::star::sdbc::XColumnLocate> ODatabaseMetaDataResultSet_BASE;
57 :
58 : class OOO_DLLPUBLIC_ODBCBASE ODatabaseMetaDataResultSet :
59 : public comphelper::OBaseMutex,
60 : public ODatabaseMetaDataResultSet_BASE,
61 : public ::cppu::OPropertySetHelper,
62 : public ::comphelper::OPropertyArrayUsageHelper<ODatabaseMetaDataResultSet>
63 : {
64 : ::connectivity::TIntVector m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time
65 :
66 : ::std::map<sal_Int32, ::connectivity::TInt2IntMap > m_aValueRange;
67 : ::std::map<sal_Int32, ::connectivity::TString2IntMap > m_aStrValueRange;
68 :
69 : ::std::map<sal_Int32, ::connectivity::TInt2StringMap > m_aIntValueRange;
70 : ::std::map<sal_Int32,SWORD> m_aODBCColumnTypes;
71 :
72 : SQLHANDLE m_aStatementHandle; // ... until freed
73 : ::com::sun::star::uno::WeakReferenceHelper m_aStatement;
74 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData;
75 : SQLUSMALLINT* m_pRowStatusArray;
76 : OConnection* m_pConnection;
77 : rtl_TextEncoding m_nTextEncoding;
78 : sal_Int32 m_nRowPos;
79 : sal_Int32 m_nDriverColumnCount; // column count of the driver which can sometimes be less than the metadata count
80 : SQLRETURN m_nCurrentFetchState;
81 : bool m_bWasNull;
82 : bool m_bEOF; // after last record
83 :
84 : // set the columncount of the driver
85 : void checkColumnCount();
86 0 : static sal_Int32 getResultSetConcurrency() { return css::sdbc::ResultSetConcurrency::READ_ONLY; }
87 0 : static sal_Int32 getResultSetType() { return css::sdbc::ResultSetType::FORWARD_ONLY; }
88 0 : static sal_Int32 getFetchDirection() { return css::sdbc::FetchDirection::FORWARD; }
89 : static sal_Int32 getFetchSize() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
90 : static OUString getCursorName() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
91 : SWORD impl_getColumnType_nothrow(sal_Int32 columnIndex);
92 :
93 : sal_Int32 mapColumn (sal_Int32 column);
94 :
95 : protected:
96 :
97 : // OPropertyArrayUsageHelper
98 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE;
99 : // OPropertySetHelper
100 : virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() SAL_OVERRIDE;
101 :
102 : virtual sal_Bool SAL_CALL convertFastPropertyValue(
103 : ::com::sun::star::uno::Any & rConvertedValue,
104 : ::com::sun::star::uno::Any & rOldValue,
105 : sal_Int32 nHandle,
106 : const ::com::sun::star::uno::Any& rValue )
107 : throw (::com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE;
108 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
109 : sal_Int32 nHandle,
110 : const ::com::sun::star::uno::Any& rValue
111 : )
112 : throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
113 : virtual void SAL_CALL getFastPropertyValue(
114 : ::com::sun::star::uno::Any& rValue,
115 : sal_Int32 nHandle
116 : ) const SAL_OVERRIDE;
117 : virtual ~ODatabaseMetaDataResultSet();
118 : template < typename T, SQLSMALLINT sqlTypeId > T getInteger ( sal_Int32 columnIndex );
119 :
120 : public:
121 : // A ctor needed for returning the object
122 : ODatabaseMetaDataResultSet(OConnection* _pConnection);
123 :
124 :
125 0 : inline oslGenericFunction getOdbcFunction(ODBC3SQLFunctionId _nIndex) const
126 : {
127 0 : return m_pConnection->getOdbcFunction(_nIndex);
128 : }
129 : // ::cppu::OComponentHelper
130 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
131 : // XInterface
132 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
133 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
134 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
135 : //XTypeProvider
136 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
137 : // XPropertySet
138 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 0 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > operator *()
140 : {
141 0 : return ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(*static_cast<ODatabaseMetaDataResultSet_BASE*>(this));
142 : }
143 : // XResultSet
144 : virtual sal_Bool SAL_CALL next( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 : virtual sal_Bool SAL_CALL isBeforeFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 : virtual sal_Bool SAL_CALL isAfterLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 : virtual sal_Bool SAL_CALL isFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 : virtual sal_Bool SAL_CALL isLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 : virtual void SAL_CALL beforeFirst( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
150 : virtual void SAL_CALL afterLast( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 : virtual sal_Bool SAL_CALL first( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 : virtual sal_Bool SAL_CALL last( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 : virtual sal_Int32 SAL_CALL getRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 : virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 : virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 : virtual sal_Bool SAL_CALL previous( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
157 : virtual void SAL_CALL refreshRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 : virtual sal_Bool SAL_CALL rowUpdated( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 : virtual sal_Bool SAL_CALL rowInserted( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 : virtual sal_Bool SAL_CALL rowDeleted( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getStatement( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
162 : // XRow
163 : virtual sal_Bool SAL_CALL wasNull( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 : virtual OUString SAL_CALL getString( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 : virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
166 : virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
167 : virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
168 : virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 : virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
171 : virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 : virtual ::com::sun::star::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
174 : virtual ::com::sun::star::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 : virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
178 : virtual ::com::sun::star::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
179 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
181 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
182 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
183 : // XResultSetMetaDataSupplier
184 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > SAL_CALL getMetaData( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
185 : // XCancellable
186 : virtual void SAL_CALL cancel( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
187 : // XCloseable
188 : virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
189 : // XWarningsSupplier
190 : virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
191 : virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
192 : // XColumnLocate
193 : virtual sal_Int32 SAL_CALL findColumn( const OUString& columnName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
194 :
195 : const ::connectivity::TIntVector& getColumnMapping() { return m_aColMapping; }
196 :
197 : void openTablesTypes( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
198 : void openTypeInfo() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
199 : void openCatalogs() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
200 : void openSchemas() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
201 : void openTables(const ::com::sun::star::uno::Any& catalog, const OUString& schemaPattern,
202 : const OUString& tableNamePattern, const ::com::sun::star::uno::Sequence< OUString >& types )
203 : throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
204 : void openColumnPrivileges( const ::com::sun::star::uno::Any& catalog, const OUString& schema,
205 : const OUString& table, const OUString& columnNamePattern )throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
206 : void openColumns( const ::com::sun::star::uno::Any& catalog, const OUString& schemaPattern,
207 : const OUString& tableNamePattern, const OUString& columnNamePattern )throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
208 : void openProcedureColumns( const ::com::sun::star::uno::Any& catalog, const OUString& schemaPattern,
209 : const OUString& procedureNamePattern,const OUString& columnNamePattern )throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
210 : void openProcedures( const ::com::sun::star::uno::Any& catalog, const OUString& schemaPattern,
211 : const OUString& procedureNamePattern)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
212 : void openVersionColumns(const ::com::sun::star::uno::Any& catalog, const OUString& schema,
213 : const OUString& table)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
214 : void openBestRowIdentifier( const ::com::sun::star::uno::Any& catalog, const OUString& schema,
215 : const OUString& table,sal_Int32 scope, bool nullable )throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
216 : void openForeignKeys( const ::com::sun::star::uno::Any& catalog, const OUString* schema,const OUString* table,
217 : const ::com::sun::star::uno::Any& catalog2, const OUString* schema2,const OUString* table2)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
218 : void openExportedKeys(const ::com::sun::star::uno::Any& catalog, const OUString& schema,const OUString& table)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
219 : void openImportedKeys(const ::com::sun::star::uno::Any& catalog, const OUString& schema,const OUString& table)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
220 : void openPrimaryKeys(const ::com::sun::star::uno::Any& catalog, const OUString& schema,const OUString& table)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
221 : void openTablePrivileges(const ::com::sun::star::uno::Any& catalog, const OUString& schemaPattern,
222 : const OUString& tableNamePattern)throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
223 : void openSpecialColumns(bool _bRowVer,const ::com::sun::star::uno::Any& catalog, const OUString& schema,
224 : const OUString& table,sal_Int32 scope, bool nullable )throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
225 : void openIndexInfo( const ::com::sun::star::uno::Any& catalog, const OUString& schema,
226 : const OUString& table,bool unique,bool approximate )throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
227 :
228 : protected:
229 : using OPropertySetHelper::getFastPropertyValue;
230 : };
231 : }
232 :
233 : }
234 : #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_ODBC_ODATABASEMETADATARESULTSET_HXX
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|