Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/ucbhelper/resultsetmetadata.hxx
Line
Count
Source
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_UCBHELPER_RESULTSETMETADATA_HXX
21
#define INCLUDED_UCBHELPER_RESULTSETMETADATA_HXX
22
23
#include <vector>
24
#include <memory>
25
#include <com/sun/star/uno/Reference.h>
26
#include <com/sun/star/uno/Sequence.h>
27
#include <com/sun/star/sdbc/XResultSetMetaData.hpp>
28
#include <cppuhelper/implbase.hxx>
29
#include <ucbhelper/ucbhelperdllapi.h>
30
31
namespace com::sun::star {
32
    namespace beans { struct Property; }
33
    namespace uno { class XComponentContext; }
34
}
35
36
namespace ucbhelper_impl {
37
    struct ResultSetMetaData_Impl;
38
}
39
40
namespace ucbhelper
41
{
42
43
44
/**
45
 * This is a structure that holds additional meta data for one column
46
 * of a resultset. The default values set in the constructor should be a
47
 * good guess for many UCB use cases.
48
 */
49
struct ResultSetColumnData
50
{
51
    /** @see ResultSetMetaData::isCaseSensitive */
52
    bool        isCaseSensitive;
53
54
    inline ResultSetColumnData();
55
};
56
57
// Note: Never change the initial values! Implementations using this struct
58
//       may heavily depend on the behaviour of the default constructor.
59
60
ResultSetColumnData::ResultSetColumnData()
61
69.9k
: isCaseSensitive( true )
62
69.9k
{
63
69.9k
}
64
65
66
/**
67
 * This is an implementation of the interface XResultSetMetaData. It can be
68
 * used to implement the interface
69
 * css::sdbc::XResultSetMetaDataSupplier, which is required for
70
 * implementations of service com.sun.star.ucb.ContentResultSet.
71
 */
72
class ResultSetMetaData final :
73
                public cppu::WeakImplHelper<css::sdbc::XResultSetMetaData>
74
{
75
    std::unique_ptr<ucbhelper_impl::ResultSetMetaData_Impl> m_pImpl;
76
    css::uno::Reference< css::uno::XComponentContext >    m_xContext;
77
    css::uno::Sequence< css::beans::Property >            m_aProps;
78
79
public:
80
81
    /**
82
      * Constructor. ResultSet is readonly by default.
83
      *
84
      * @param rxSMgr is a Service Manager.
85
      * @param rProps is a sequence of properties (partially) describing the
86
      *        columns of a resultset.
87
      */
88
    UCBHELPER_DLLPUBLIC ResultSetMetaData(
89
            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
90
            const css::uno::Sequence< css::beans::Property >& rProps );
91
92
    /**
93
      * Constructor.
94
      *
95
      * @param rxSMgr is a Service Manager.
96
      * @param rProps is a sequence of properties (partially) describing the
97
      *        columns of a resultset.
98
      * @param rColumnData contains additional meta data for the columns of
99
      *        a resultset, which override the default values returned by the
100
      *        appropriate methods of this class. The length of rColumnData
101
      *        must be the same as length of rProps.
102
      *        rColumnData[ 0 ] corresponds to data in rProps[ 0 ],
103
      *        rColumnData[ 1 ] corresponds to data in rProps[ 1 ], ...
104
      */
105
    UCBHELPER_DLLPUBLIC ResultSetMetaData(
106
            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
107
            const css::uno::Sequence< css::beans::Property >& rProps,
108
            std::vector< ResultSetColumnData >&& rColumnData );
109
110
    /**
111
      * Destructor.
112
      */
113
    virtual ~ResultSetMetaData() override;
114
115
    // XResultSetMetaData
116
117
    /**
118
      * Returns the number of columns of the resultset.
119
      *
120
      * @return the length of the property sequence.
121
      */
122
    virtual sal_Int32 SAL_CALL
123
    getColumnCount() override;
124
    /**
125
      * Checks whether column is automatically numbered, which makes it
126
      * read-only.
127
      *
128
      * @param  column is the number of the column for that a value shall
129
      *         be returned. The first column is 1, the second is 2, ...
130
      * @return true, if column is automatically numbered.
131
      */
132
    virtual sal_Bool SAL_CALL
133
    isAutoIncrement( sal_Int32 column ) override;
134
    /**
135
      * Checks whether column is case sensitive.
136
      *
137
      * @param  column is the number of the column for that a value shall
138
      *         be returned. The first column is 1, the second is 2, ...
139
      * @return true, if column is case sensitive.
140
      */
141
    virtual sal_Bool SAL_CALL
142
    isCaseSensitive( sal_Int32 column ) override;
143
    /**
144
      * Checks whether the value stored in column can be used in a
145
      * WHERE clause.
146
      *
147
      * @param  column is the number of the column for that a value shall
148
      *         be returned. The first column is 1, the second is 2, ...
149
      * @return true, if the column is searchable.
150
      */
151
    virtual sal_Bool SAL_CALL
152
    isSearchable( sal_Int32 column ) override;
153
    /**
154
      * Checks whether column is a cash value.
155
      *
156
      * @param  column is the number of the column for that a value shall
157
      *         be returned. The first column is 1, the second is 2, ...
158
      * @return true, if the column is a cash value.
159
      */
160
    virtual sal_Bool SAL_CALL
161
    isCurrency( sal_Int32 column ) override;
162
    /**
163
      * Checks whether a NULL can be stored in column.
164
      *
165
      * @see css::sdbc::ColumnValue
166
      *
167
      * @param  column is the number of the column for that a value shall
168
      *         be returned. The first column is 1, the second is 2, ...
169
      * @return css::sdbc::ColumnValue::NULLABLE, if a NULL
170
      *         can be stored in the column.
171
      */
172
    virtual sal_Int32 SAL_CALL
173
    isNullable( sal_Int32 column ) override;
174
    /**
175
      * Checks whether the value stored in column is a signed number.
176
      *
177
      * @param  column is the number of the column for that a value shall
178
      *         be returned. The first column is 1, the second is 2, ...
179
      * @return true, if the value stored in column is a signed number.
180
      */
181
    virtual sal_Bool SAL_CALL
182
    isSigned( sal_Int32 column ) override;
183
    /**
184
      * Gets the normal maximum width in characters for column.
185
      *
186
      * @param  column is the number of the column for that a value shall
187
      *         be returned. The first column is 1, the second is 2, ...
188
      * @return the normal maximum width in characters for column.
189
      */
190
    virtual sal_Int32 SAL_CALL
191
    getColumnDisplaySize( sal_Int32 column ) override;
192
    /**
193
      * Gets the suggested column title for column, to be used in print-
194
      * outs and displays.
195
      *
196
      * @param  column is the number of the column for that a value shall
197
      *         be returned. The first column is 1, the second is 2, ...
198
      * @return the column label.
199
      */
200
    virtual OUString SAL_CALL
201
    getColumnLabel( sal_Int32 column ) override;
202
    /**
203
      * Gets the name of column.
204
      *
205
      * @param  column is the number of the column for that a value shall
206
      *         be returned. The first column is 1, the second is 2, ...
207
      * @return the name of the property that corresponds to column.
208
      */
209
    virtual OUString SAL_CALL
210
    getColumnName( sal_Int32 column ) override;
211
    /**
212
      * Gets the schema name for the table from which column of this
213
      * result set was derived.
214
      * Because this feature is not widely supported, the return value
215
      * for many DBMSs will be an empty string.
216
      *
217
      * @param  column is the number of the column for that a value shall
218
      *         be returned. The first column is 1, the second is 2, ...
219
      * @return the schema name of column or an empty string.
220
      */
221
    virtual OUString SAL_CALL
222
    getSchemaName( sal_Int32 column ) override;
223
    /**
224
      * For number types, getprecision gets the number of decimal digits
225
      * in column.
226
      * For character types, it gets the maximum length in characters for
227
      * column.
228
      * For binary types, it gets the maximum length in bytes for column.
229
      *
230
      * @param  column is the number of the column for that a value shall
231
      *         be returned. The first column is 1, the second is 2, ...
232
      * @return the precision for the column.
233
      */
234
    virtual sal_Int32 SAL_CALL
235
    getPrecision( sal_Int32 column ) override;
236
    /**
237
      * Gets the number of digits to the right of the decimal point for
238
      * values in column.
239
      *
240
      * @param  column is the number of the column for that a value shall
241
      *         be returned. The first column is 1, the second is 2, ...
242
      * @return the scale of the column.
243
      */
244
    virtual sal_Int32 SAL_CALL
245
    getScale( sal_Int32 column ) override;
246
    /**
247
      * Gets the name of the table from which column of this result set
248
      * was derived or "" if there is none (for example, for a join).
249
      * Because this feature is not widely supported, the return value
250
      * for many DBMSs will be an empty string.
251
      *
252
      * @param  column is the number of the column for that a value shall
253
      *         be returned. The first column is 1, the second is 2, ...
254
      * @return the table name for column or an empty string.
255
      */
256
    virtual OUString SAL_CALL
257
    getTableName( sal_Int32 column ) override;
258
    virtual OUString SAL_CALL
259
    /**
260
      * Gets the catalog name for the table from which column of this
261
      * result set was derived.
262
      * Because this feature is not widely supported, the return value
263
      * for many DBMSs will be an empty string.
264
      *
265
      * @param  column is the number of the column for that a value shall
266
      *         be returned. The first column is 1, the second is 2, ...
267
      * @return the catalog name for column or an empty string.
268
      */
269
    getCatalogName( sal_Int32 column ) override;
270
    /**
271
      * Gets the JDBC type for the value stored in column. ... The STRUCT
272
      * and DISTINCT type codes are always returned for structured and
273
      * distinct types, regardless of whether the value will be mapped
274
      * according to the standard mapping or be a custom mapping.
275
      *
276
      * @param  column is the number of the column for that a value shall
277
      *         be returned. The first column is 1, the second is 2, ...
278
      * @return the type of the property that corresponds to column - mapped
279
      *         from UNO-Type to SQL-Type.
280
      */
281
    virtual sal_Int32 SAL_CALL
282
    getColumnType( sal_Int32 column ) override;
283
    /**
284
      * Gets the type name used by this particular data source for the
285
      * values stored in column. If the type code for the type of value
286
      * stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method
287
      * returns a fully-qualified SQL type name.
288
      *
289
      * @param  column is the number of the column for that a value shall
290
      *         be returned. The first column is 1, the second is 2, ...
291
      * @return the column type name.
292
      */
293
    virtual OUString SAL_CALL
294
    getColumnTypeName( sal_Int32 column ) override;
295
    /**
296
      * Indicates whether a column is definitely not writable.
297
      *
298
      * @param  column is the number of the column for that a value shall
299
      *         be returned. The first column is 1, the second is 2, ...
300
      * @return true, if the column is definitely not writable.
301
      */
302
    virtual sal_Bool SAL_CALL
303
    isReadOnly( sal_Int32 column ) override;
304
    /**
305
      * Indicates whether it is possible for a write on the column to succeed.
306
      *
307
      * @param  column is the number of the column for that a value shall
308
      *         be returned. The first column is 1, the second is 2, ...
309
      * @return true, if it is possible for a write to succeed.
310
      */
311
    virtual sal_Bool SAL_CALL
312
    isWritable( sal_Int32 column ) override;
313
    /**
314
      * Indicates whether a write on the column will definitely succeed.
315
      *
316
      * @param  column is the number of the column for that a value shall
317
      *         be returned. The first column is 1, the second is 2, ...
318
      * @return true, if a write on the column will definitely succeed.
319
      */
320
    virtual sal_Bool SAL_CALL
321
    isDefinitelyWritable( sal_Int32 column ) override;
322
    /**
323
      * Returns the fully-qualified name of the service whose instances
324
      * are manufactured if the method
325
      * css::sdbc::ResultSet::getObject is called to retrieve a
326
      * value from the column.
327
      *
328
      * @param  column is the number of the column for that a value shall
329
      *         be returned. The first column is 1, the second is 2, ...
330
      * @return the service name for column or an empty string, if no service
331
      *         is applicable.
332
      */
333
    virtual OUString SAL_CALL
334
    getColumnServiceName( sal_Int32 column ) override;
335
};
336
337
} // namespace ucbhelper
338
339
#endif /* ! INCLUDED_UCBHELPER_RESULTSETMETADATA_HXX */
340
341
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */