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