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 .
22 #include <com/sun/star/sdbc/ResultSetType.hpp>
23 #include <com/sun/star/sdbc/FetchDirection.hpp>
24 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
25 #include <com/sun/star/sdbc/XResultSet.hpp>
26 #include <com/sun/star/sdbc/XRow.hpp>
27 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
28 #include <com/sun/star/sdbc/XCloseable.hpp>
29 #include <com/sun/star/sdbc/XColumnLocate.hpp>
30 #include <com/sun/star/util/XCancellable.hpp>
31 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
32 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
33 #include <com/sun/star/sdbc/XRowUpdate.hpp>
34 #include <cppuhelper/compbase.hxx>
35 #include <cppuhelper/basemutex.hxx>
36 #include <comphelper/proparrhlp.hxx>
37 #include <odbc/OStatement.hxx>
38 #include <odbc/ODatabaseMetaData.hxx>
39 #include <odbc/odbcbasedllapi.hxx>
41 #include <string_view>
43 namespace connectivity::odbc
45 class OResultSetMetaData
;
49 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XResultSet
,
51 css::sdbc::XResultSetMetaDataSupplier
,
52 css::util::XCancellable
,
53 css::sdbc::XWarningsSupplier
,
54 css::sdbc::XCloseable
,
55 css::sdbc::XColumnLocate
> ODatabaseMetaDataResultSet_BASE
;
57 class ODatabaseMetaDataResultSet
:
58 public cppu::BaseMutex
,
59 public ODatabaseMetaDataResultSet_BASE
,
60 public ::cppu::OPropertySetHelper
,
61 public ::comphelper::OPropertyArrayUsageHelper
<ODatabaseMetaDataResultSet
>
63 std::vector
< sal_Int32
> m_aColMapping
; // pos 0 is unused so we don't have to decrement 1 every time
65 std::map
<sal_Int32
, ::std::map
<sal_Int32
,sal_Int32
> >
68 std::map
<sal_Int32
,SWORD
> m_aODBCColumnTypes
;
70 SQLHANDLE m_aStatementHandle
; // ... until freed
71 css::uno::WeakReferenceHelper m_aStatement
;
72 rtl::Reference
<OResultSetMetaData
> m_xMetaData
;
73 std::unique_ptr
<SQLUSMALLINT
[]> m_pRowStatusArray
;
74 rtl::Reference
<OConnection
> m_pConnection
;
75 rtl_TextEncoding m_nTextEncoding
;
77 sal_Int32 m_nDriverColumnCount
; // column count of the driver which can sometimes be less than the metadata count
78 SQLRETURN m_nCurrentFetchState
;
80 bool m_bEOF
; // after last record
82 // set the columncount of the driver
83 void checkColumnCount();
84 static sal_Int32
getFetchDirection() { return css::sdbc::FetchDirection::FORWARD
; }
85 /// @throws css::sdbc::SQLException
86 /// @throws css::uno::RuntimeException
87 static sal_Int32
getFetchSize();
88 /// @throws css::sdbc::SQLException
89 /// @throws css::uno::RuntimeException
90 static const OUString
& getCursorName();
91 SWORD
impl_getColumnType_nothrow(sal_Int32 columnIndex
);
93 sal_Int32
mapColumn (sal_Int32 column
);
97 // OPropertyArrayUsageHelper
98 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const override
;
100 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
102 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
103 css::uno::Any
& rConvertedValue
,
104 css::uno::Any
& rOldValue
,
106 const css::uno::Any
& rValue
) override
;
107 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
108 virtual void SAL_CALL
getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nHandle
) const override
;
109 virtual ~ODatabaseMetaDataResultSet() override
;
110 template < typename T
, SQLSMALLINT sqlTypeId
> T
getInteger ( sal_Int32 columnIndex
);
113 // A ctor needed for returning the object
114 ODatabaseMetaDataResultSet(OConnection
* _pConnection
);
117 const Functions
& functions() const { return m_pConnection
->functions(); }
118 // ::cppu::OComponentHelper
119 virtual void SAL_CALL
disposing() override
;
121 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
122 virtual void SAL_CALL
acquire() noexcept override
;
123 virtual void SAL_CALL
release() noexcept override
;
125 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
127 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
128 css::uno::Reference
< css::uno::XInterface
> operator *()
130 return css::uno::Reference
< css::uno::XInterface
>(*static_cast<ODatabaseMetaDataResultSet_BASE
*>(this));
133 virtual sal_Bool SAL_CALL
next( ) override
;
134 virtual sal_Bool SAL_CALL
isBeforeFirst( ) override
;
135 virtual sal_Bool SAL_CALL
isAfterLast( ) override
;
136 virtual sal_Bool SAL_CALL
isFirst( ) override
;
137 virtual sal_Bool SAL_CALL
isLast( ) override
;
138 virtual void SAL_CALL
beforeFirst( ) override
;
139 virtual void SAL_CALL
afterLast( ) override
;
140 virtual sal_Bool SAL_CALL
first( ) override
;
141 virtual sal_Bool SAL_CALL
last( ) override
;
142 virtual sal_Int32 SAL_CALL
getRow( ) override
;
143 virtual sal_Bool SAL_CALL
absolute( sal_Int32 row
) override
;
144 virtual sal_Bool SAL_CALL
relative( sal_Int32 rows
) override
;
145 virtual sal_Bool SAL_CALL
previous( ) override
;
146 virtual void SAL_CALL
refreshRow( ) override
;
147 virtual sal_Bool SAL_CALL
rowUpdated( ) override
;
148 virtual sal_Bool SAL_CALL
rowInserted( ) override
;
149 virtual sal_Bool SAL_CALL
rowDeleted( ) override
;
150 virtual css::uno::Reference
< css::uno::XInterface
> SAL_CALL
getStatement( ) override
;
152 virtual sal_Bool SAL_CALL
wasNull( ) override
;
153 virtual OUString SAL_CALL
getString( sal_Int32 columnIndex
) override
;
154 virtual sal_Bool SAL_CALL
getBoolean( sal_Int32 columnIndex
) override
;
155 virtual sal_Int8 SAL_CALL
getByte( sal_Int32 columnIndex
) override
;
156 virtual sal_Int16 SAL_CALL
getShort( sal_Int32 columnIndex
) override
;
157 virtual sal_Int32 SAL_CALL
getInt( sal_Int32 columnIndex
) override
;
158 virtual sal_Int64 SAL_CALL
getLong( sal_Int32 columnIndex
) override
;
159 virtual float SAL_CALL
getFloat( sal_Int32 columnIndex
) override
;
160 virtual double SAL_CALL
getDouble( sal_Int32 columnIndex
) override
;
161 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getBytes( sal_Int32 columnIndex
) override
;
162 virtual css::util::Date SAL_CALL
getDate( sal_Int32 columnIndex
) override
;
163 virtual css::util::Time SAL_CALL
getTime( sal_Int32 columnIndex
) override
;
164 virtual css::util::DateTime SAL_CALL
getTimestamp( sal_Int32 columnIndex
) override
;
165 virtual css::uno::Reference
< css::io::XInputStream
> SAL_CALL
getBinaryStream( sal_Int32 columnIndex
) override
;
166 virtual css::uno::Reference
< css::io::XInputStream
> SAL_CALL
getCharacterStream( sal_Int32 columnIndex
) override
;
167 virtual css::uno::Any SAL_CALL
getObject( sal_Int32 columnIndex
, const css::uno::Reference
< css::container::XNameAccess
>& typeMap
) override
;
168 virtual css::uno::Reference
< css::sdbc::XRef
> SAL_CALL
getRef( sal_Int32 columnIndex
) override
;
169 virtual css::uno::Reference
< css::sdbc::XBlob
> SAL_CALL
getBlob( sal_Int32 columnIndex
) override
;
170 virtual css::uno::Reference
< css::sdbc::XClob
> SAL_CALL
getClob( sal_Int32 columnIndex
) override
;
171 virtual css::uno::Reference
< css::sdbc::XArray
> SAL_CALL
getArray( sal_Int32 columnIndex
) override
;
172 // XResultSetMetaDataSupplier
173 virtual css::uno::Reference
< css::sdbc::XResultSetMetaData
> SAL_CALL
getMetaData( ) override
;
175 virtual void SAL_CALL
cancel( ) override
;
177 virtual void SAL_CALL
close( ) override
;
179 virtual css::uno::Any SAL_CALL
getWarnings( ) override
;
180 virtual void SAL_CALL
clearWarnings( ) override
;
182 virtual sal_Int32 SAL_CALL
findColumn( const OUString
& columnName
) override
;
184 /// @throws css::sdbc::SQLException
185 /// @throws css::uno::RuntimeException
186 void openTablesTypes( );
187 /// @throws css::sdbc::SQLException
188 /// @throws css::uno::RuntimeException
190 /// @throws css::sdbc::SQLException
191 /// @throws css::uno::RuntimeException
193 /// @throws css::sdbc::SQLException
194 /// @throws css::uno::RuntimeException
196 /// @throws css::sdbc::SQLException
197 /// @throws css::uno::RuntimeException
198 void openTables(const css::uno::Any
& catalog
, const OUString
& schemaPattern
,
199 const OUString
& tableNamePattern
, const css::uno::Sequence
< OUString
>& types
);
200 /// @throws css::sdbc::SQLException
201 /// @throws css::uno::RuntimeException
202 void openColumnPrivileges( const css::uno::Any
& catalog
, const OUString
& schema
,
203 const OUString
& table
, const OUString
& columnNamePattern
);
204 /// @throws css::sdbc::SQLException
205 /// @throws css::uno::RuntimeException
206 void openColumns( const css::uno::Any
& catalog
, const OUString
& schemaPattern
,
207 const OUString
& tableNamePattern
, const OUString
& columnNamePattern
);
208 /// @throws css::sdbc::SQLException
209 /// @throws css::uno::RuntimeException
210 void openProcedureColumns( const css::uno::Any
& catalog
, const OUString
& schemaPattern
,
211 const OUString
& procedureNamePattern
,const OUString
& columnNamePattern
);
212 /// @throws css::sdbc::SQLException
213 /// @throws css::uno::RuntimeException
214 void openProcedures( const css::uno::Any
& catalog
, const OUString
& schemaPattern
,
215 const OUString
& procedureNamePattern
);
216 /// @throws css::sdbc::SQLException
217 /// @throws css::uno::RuntimeException
218 void openVersionColumns(const css::uno::Any
& catalog
, const OUString
& schema
,
219 const OUString
& table
);
220 /// @throws css::sdbc::SQLException
221 /// @throws css::uno::RuntimeException
222 void openBestRowIdentifier( const css::uno::Any
& catalog
, const OUString
& schema
,
223 const OUString
& table
,sal_Int32 scope
, bool nullable
);
224 /// @throws css::sdbc::SQLException
225 /// @throws css::uno::RuntimeException
226 void openForeignKeys( const css::uno::Any
& catalog
, const OUString
* schema
,const OUString
* table
,
227 const css::uno::Any
& catalog2
, const OUString
* schema2
,const OUString
* table2
);
228 /// @throws css::sdbc::SQLException
229 /// @throws css::uno::RuntimeException
230 void openExportedKeys(const css::uno::Any
& catalog
, const OUString
& schema
,const OUString
& table
);
231 /// @throws css::sdbc::SQLException
232 /// @throws css::uno::RuntimeException
233 void openImportedKeys(const css::uno::Any
& catalog
, const OUString
& schema
,const OUString
& table
);
234 /// @throws css::sdbc::SQLException
235 /// @throws css::uno::RuntimeException
236 void openPrimaryKeys(const css::uno::Any
& catalog
, const OUString
& schema
,const OUString
& table
);
237 /// @throws css::sdbc::SQLException
238 /// @throws css::uno::RuntimeException
239 void openTablePrivileges(const css::uno::Any
& catalog
, const OUString
& schemaPattern
,
240 const OUString
& tableNamePattern
);
241 /// @throws css::sdbc::SQLException
242 /// @throws css::uno::RuntimeException
243 void openSpecialColumns(bool _bRowVer
,const css::uno::Any
& catalog
, const OUString
& schema
,
244 const OUString
& table
,sal_Int32 scope
, bool nullable
);
245 /// @throws css::sdbc::SQLException
246 /// @throws css::uno::RuntimeException
247 void openIndexInfo( const css::uno::Any
& catalog
, const OUString
& schema
,
248 const OUString
& table
,bool unique
,bool approximate
);
251 using OPropertySetHelper::getFastPropertyValue
;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */