Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/connectivity/FValue.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_CONNECTIVITY_FVALUE_HXX
21
#define INCLUDED_CONNECTIVITY_FVALUE_HXX
22
23
#include <com/sun/star/sdbc/DataType.hpp>
24
#include <rtl/ustring.hxx>
25
#include <salhelper/simplereferenceobject.hxx>
26
#include <rtl/ref.hxx>
27
#include <connectivity/dbtoolsdllapi.hxx>
28
#include <connectivity/CommonTools.hxx>
29
#include <utility>
30
31
namespace com::sun::star::sdb { class XColumn; }
32
namespace com::sun::star::sdbc { class XRow; }
33
namespace com::sun::star::uno { class Any; }
34
namespace com::sun::star::uno { template <class E> class Sequence; }
35
namespace com::sun::star::util { struct Date; }
36
namespace com::sun::star::util { struct DateTime; }
37
namespace com::sun::star::util { struct Time; }
38
39
namespace connectivity
40
{
41
    namespace detail
42
    {
43
        class IValueSource;
44
    }
45
46
    class OOO_DLLPUBLIC_DBTOOLS ORowSetValue
47
    {
48
        union
49
        {
50
            bool            m_bBool;
51
52
            sal_Int8        m_nInt8;
53
            sal_uInt8       m_uInt8;
54
55
            sal_Int16       m_nInt16;
56
            sal_uInt16      m_uInt16;
57
58
            sal_Int32       m_nInt32;
59
            sal_uInt32      m_uInt32;
60
61
            sal_Int64       m_nInt64;
62
            sal_uInt64      m_uInt64;
63
64
            float           m_nFloat;
65
            double          m_nDouble;
66
67
            rtl_uString*    m_pString;
68
69
            void*           m_pValue;           // date/time/timestamp/sequence
70
        } m_aValue;
71
72
        sal_Int32           m_eTypeKind;        // the database type
73
        bool                m_bNull     : 1;    // value is null
74
        bool                m_bBound    : 1;    // is bound
75
        bool                m_bModified : 1;    // value was changed
76
        bool                m_bSigned   : 1;    // value is signed
77
78
        void free() noexcept;
79
80
    public:
81
        ORowSetValue()
82
4.82M
            :m_eTypeKind(css::sdbc::DataType::VARCHAR)
83
4.82M
            ,m_bNull(true)
84
4.82M
            ,m_bBound(true)
85
4.82M
            ,m_bModified(false)
86
4.82M
            ,m_bSigned(true)
87
4.82M
        {
88
4.82M
            m_aValue.m_pString = nullptr;
89
4.82M
        }
90
91
        ORowSetValue(const ORowSetValue& _rRH)
92
22.1M
            :m_eTypeKind(css::sdbc::DataType::VARCHAR)
93
22.1M
            ,m_bNull(true)
94
22.1M
            ,m_bBound(true)
95
22.1M
            ,m_bModified(false)
96
22.1M
            ,m_bSigned(true)
97
22.1M
        {
98
22.1M
            m_aValue.m_pString = nullptr;
99
22.1M
            operator=(_rRH);
100
22.1M
        }
101
102
        ORowSetValue(ORowSetValue&& _rRH) noexcept
103
2.97M
            :m_eTypeKind(css::sdbc::DataType::VARCHAR)
104
2.97M
            ,m_bNull(true)
105
2.97M
            ,m_bBound(true)
106
2.97M
            ,m_bModified(false)
107
2.97M
            ,m_bSigned(true)
108
2.97M
        {
109
2.97M
            m_aValue.m_pString = nullptr;
110
2.97M
            operator=(std::move(_rRH));
111
2.97M
        }
112
113
        ORowSetValue(const OUString& _rRH)
114
2.15M
            :m_eTypeKind(css::sdbc::DataType::VARCHAR)
115
2.15M
            ,m_bNull(true)
116
2.15M
            ,m_bBound(true)
117
2.15M
            ,m_bModified(false)
118
2.15M
            ,m_bSigned(true)
119
2.15M
        {
120
2.15M
            m_aValue.m_pString = nullptr;
121
2.15M
            operator=(_rRH);
122
2.15M
        }
123
124
        ORowSetValue(const double& _rRH)
125
378k
            :m_eTypeKind(css::sdbc::DataType::DOUBLE)
126
378k
            ,m_bNull(true)
127
378k
            ,m_bBound(true)
128
378k
            ,m_bModified(false)
129
378k
            ,m_bSigned(true)
130
378k
        {
131
378k
            m_aValue.m_pString = nullptr;
132
378k
            operator=(_rRH);
133
378k
        }
134
135
        ORowSetValue(float _rRH)
136
0
            :m_eTypeKind(css::sdbc::DataType::FLOAT)
137
0
            ,m_bNull(true)
138
0
            ,m_bBound(true)
139
0
            ,m_bModified(false)
140
0
            ,m_bSigned(true)
141
0
        {
142
0
            m_aValue.m_pString = nullptr;
143
0
            operator=(_rRH);
144
0
        }
145
146
        ORowSetValue(sal_Int8 _rRH)
147
0
            :m_eTypeKind(css::sdbc::DataType::TINYINT)
148
0
            ,m_bNull(true)
149
0
            ,m_bBound(true)
150
0
            ,m_bModified(false)
151
0
            ,m_bSigned(true)
152
0
        {
153
0
            m_aValue.m_pString = nullptr;
154
0
            operator=(_rRH);
155
0
        }
156
157
        ORowSetValue(sal_Int16 _rRH)
158
0
            :m_eTypeKind(css::sdbc::DataType::SMALLINT)
159
0
            ,m_bNull(true)
160
0
            ,m_bBound(true)
161
0
            ,m_bModified(false)
162
0
            ,m_bSigned(true)
163
0
        {
164
0
            m_aValue.m_pString = nullptr;
165
0
            operator=(_rRH);
166
0
        }
167
        ORowSetValue(sal_uInt16 _rRH)
168
            :m_eTypeKind(css::sdbc::DataType::SMALLINT)
169
            ,m_bNull(true)
170
            ,m_bBound(true)
171
            ,m_bModified(false)
172
            ,m_bSigned(false)
173
0
        {
174
0
            m_aValue.m_pString = nullptr;
175
0
            operator=(_rRH);
176
0
        }
177
        ORowSetValue(sal_Int32 _rRH)
178
5.65M
            :m_eTypeKind(css::sdbc::DataType::INTEGER)
179
5.65M
            ,m_bNull(true)
180
5.65M
            ,m_bBound(true)
181
5.65M
            ,m_bModified(false)
182
5.65M
            ,m_bSigned(true)
183
5.65M
        {
184
5.65M
            m_aValue.m_pString = nullptr;
185
5.65M
            operator=(_rRH);
186
5.65M
        }
187
        ORowSetValue(sal_uInt32 _rRH)
188
            :m_eTypeKind(css::sdbc::DataType::INTEGER)
189
            ,m_bNull(true)
190
            ,m_bBound(true)
191
            ,m_bModified(false)
192
            ,m_bSigned(false)
193
0
        {
194
0
            m_aValue.m_pString = nullptr;
195
0
            operator=(_rRH);
196
0
        }
197
        ORowSetValue(sal_Int64 _rRH)
198
0
            :m_eTypeKind(css::sdbc::DataType::BIGINT)
199
0
            ,m_bNull(true)
200
0
            ,m_bBound(true)
201
0
            ,m_bModified(false)
202
0
            ,m_bSigned(true)
203
0
        {
204
0
            m_aValue.m_pString = nullptr;
205
0
            operator=(_rRH);
206
0
        }
207
        ORowSetValue(sal_uInt64 _rRH)
208
            :m_eTypeKind(css::sdbc::DataType::BIGINT)
209
            ,m_bNull(true)
210
            ,m_bBound(true)
211
            ,m_bModified(false)
212
            ,m_bSigned(false)
213
0
        {
214
0
            m_aValue.m_pString = nullptr;
215
0
            operator=(_rRH);
216
0
        }
217
218
        ORowSetValue(bool _rRH)
219
28.3k
            :m_eTypeKind(css::sdbc::DataType::BIT)
220
28.3k
            ,m_bNull(true)
221
28.3k
            ,m_bBound(true)
222
28.3k
            ,m_bModified(false)
223
28.3k
            ,m_bSigned(true)
224
28.3k
        {
225
28.3k
            m_aValue.m_pString = nullptr;
226
28.3k
            operator=(_rRH);
227
28.3k
        }
228
        ORowSetValue(sal_Bool) = delete; // aka sal_uInt8
229
230
        ORowSetValue(const css::util::Date& _rRH)
231
28.4k
            :m_eTypeKind(css::sdbc::DataType::DATE)
232
28.4k
            ,m_bNull(true)
233
28.4k
            ,m_bBound(true)
234
28.4k
            ,m_bModified(false)
235
28.4k
            ,m_bSigned(true)
236
28.4k
        {
237
28.4k
            m_aValue.m_pString = nullptr;
238
28.4k
            operator=(_rRH);
239
28.4k
        }
240
241
        ORowSetValue(const css::util::Time& _rRH)
242
0
            :m_eTypeKind(css::sdbc::DataType::TIME)
243
0
            ,m_bNull(true)
244
0
            ,m_bBound(true)
245
0
            ,m_bModified(false)
246
0
            ,m_bSigned(true)
247
0
        {
248
0
            m_aValue.m_pString = nullptr;
249
0
            operator=(_rRH);
250
0
        }
251
252
        ORowSetValue(const css::util::DateTime& _rRH)
253
60.8k
            :m_eTypeKind(css::sdbc::DataType::TIMESTAMP)
254
60.8k
            ,m_bNull(true)
255
60.8k
            ,m_bBound(true)
256
60.8k
            ,m_bModified(false)
257
60.8k
            ,m_bSigned(true)
258
60.8k
        {
259
60.8k
            m_aValue.m_pString = nullptr;
260
60.8k
            operator=(_rRH);
261
60.8k
        }
262
263
        ORowSetValue(const css::uno::Sequence<sal_Int8>& _rRH)
264
0
            :m_eTypeKind(css::sdbc::DataType::LONGVARBINARY)
265
0
            ,m_bNull(true)
266
0
            ,m_bBound(true)
267
0
            ,m_bModified(false)
268
0
            ,m_bSigned(true)
269
0
        {
270
0
            m_aValue.m_pString = nullptr;
271
0
            operator=(_rRH);
272
0
        }
273
274
        // Avoid accidental uses of ORowSetValue(bool const &):
275
        template<typename T> ORowSetValue(T const *) = delete;
276
277
        ~ORowSetValue()
278
38.2M
        {
279
38.2M
            free();
280
38.2M
        }
281
282
        ORowSetValue& operator=(const ORowSetValue& _rRH);
283
        ORowSetValue& operator=(ORowSetValue&& _rRH) noexcept;
284
285
        // simple types
286
        ORowSetValue& operator=(bool _rRH);
287
        void operator =(sal_Bool) = delete; // aka sal_uInt8
288
289
        ORowSetValue& operator=(sal_Int8 _rRH);
290
291
        ORowSetValue& operator=(sal_Int16 _rRH);
292
        ORowSetValue& operator=(sal_uInt16 _rRH);
293
294
        ORowSetValue& operator=(sal_Int32 _rRH);
295
        ORowSetValue& operator=(sal_uInt32 _rRH);
296
297
        ORowSetValue& operator=(sal_Int64 _rRH);
298
        ORowSetValue& operator=(sal_uInt64 _rRH);
299
300
        ORowSetValue& operator=(double _rRH);
301
        ORowSetValue& operator=(float _rRH);
302
303
        // ADT's
304
        ORowSetValue& operator=(const css::util::Date& _rRH);
305
        ORowSetValue& operator=(const css::util::Time& _rRH);
306
        ORowSetValue& operator=(const css::util::DateTime& _rRH);
307
308
        ORowSetValue& operator=(const OUString& _rRH);
309
        // the type isn't set it will be set to VARCHAR if the type is different change it
310
        ORowSetValue& operator=(const css::uno::Sequence<sal_Int8>& _rRH);
311
        // with the possibility to save an any for bookmarks
312
        ORowSetValue& operator=(const css::uno::Any& _rAny);
313
314
        bool operator==(const ORowSetValue& _rRH) const;
315
        bool operator!=(const ORowSetValue& _rRH) const
316
0
        {
317
0
            return !( *this == _rRH );
318
0
        }
319
320
        bool isNull() const
321
27.3M
        {
322
27.3M
            return m_bNull;
323
27.3M
        }
324
        void        setNull()
325
8.86M
        {
326
8.86M
            free();
327
8.86M
            m_bNull = true;
328
8.86M
            m_aValue.m_pString = nullptr;
329
8.86M
        }
330
331
26.1M
        bool        isBound() const                     { return m_bBound;      }
332
11.9M
        void        setBound(bool _bBound)              { m_bBound = _bBound; }
333
334
0
        bool        isModified() const                  { return m_bModified;   }
335
0
        void        setModified(bool _bMod)             { m_bModified = _bMod;  }
336
337
85.7k
        bool        isSigned() const                    { return m_bSigned; }
338
        void        setSigned(bool _bSig);
339
340
18.3M
        sal_Int32   getTypeKind() const                 { return m_eTypeKind;   }
341
        void        setTypeKind(sal_Int32 _eType);
342
343
        bool            getBool()   const;
344
345
        sal_Int8        getInt8()   const;
346
        sal_uInt8       getUInt8()  const;
347
348
        sal_Int16       getInt16()  const;
349
        sal_uInt16      getUInt16() const;
350
351
        sal_Int32       getInt32()  const;
352
        sal_uInt32      getUInt32() const;
353
354
        sal_Int64       getLong()   const;
355
        sal_uInt64      getULong()  const;
356
357
        double          getDouble() const;
358
        float           getFloat()  const;
359
360
        OUString getString() const;      // makes an automatic conversion if type isn't a string
361
        css::util::Date                getDate()       const;
362
        css::util::Time                getTime()       const;
363
        css::util::DateTime            getDateTime()   const;
364
        css::uno::Sequence<sal_Int8>   getSequence()   const;
365
        // only use for anys
366
9.58M
        const css::uno::Any&           getAny()        const { return *static_cast<css::uno::Any*>(m_aValue.m_pValue); }
367
        css::uno::Any                  makeAny()       const;
368
369
        /**
370
            fetches a single value out of the row
371
            @param _nPos    the current column position
372
            @param _nType   the type of the current column
373
            @param _xRow    the row where to fetch the data from
374
        */
375
        void fill(sal_Int32 _nPos,
376
                  sal_Int32 _nType,
377
                  const css::uno::Reference< css::sdbc::XRow>& _xRow);
378
379
        /**
380
            fetches a single value out of the row
381
            @param _nPos    the current column position
382
            @param _nType   the type of the current column
383
            @param _bNullable   if true then it will be checked if the result could be NULL, otherwise not.
384
            @param _xRow    the row where to fetch the data from
385
        */
386
        void fill(sal_Int32 _nPos,
387
                  sal_Int32 _nType,
388
                  bool      _bNullable,
389
                  const css::uno::Reference< css::sdbc::XRow>& _xRow);
390
391
        void fill(const css::uno::Any& _rValue);
392
393
        void fill( const sal_Int32 _nType,
394
                   const css::uno::Reference< css::sdb::XColumn >& _rxColumn );
395
396
    private:
397
        void impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource );
398
    };
399
400
    /// ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted"
401
    class OOO_DLLPUBLIC_DBTOOLS ORowSetValueDecorator final : public ::salhelper::SimpleReferenceObject
402
    {
403
        ORowSetValue    m_aValue;   // my own value
404
    public:
405
3.20M
        ORowSetValueDecorator(){m_aValue.setBound(true);}
406
2.97M
        ORowSetValueDecorator(ORowSetValue _aValue) : m_aValue(std::move(_aValue)){m_aValue.setBound(true);}
407
        ORowSetValueDecorator& operator=(const ORowSetValue& _aValue);
408
409
11.8M
        operator const ORowSetValue&()   const               { return m_aValue; }
410
0
        bool operator ==( const ORowSetValue & _rRH )        { return m_aValue == _rRH; }
411
13.2M
        const ORowSetValue& getValue()   const               { return m_aValue; }
412
0
        ORowSetValue& get()                                  { return m_aValue; }
413
0
        void setValue(const ORowSetValue& _aValue)           { m_aValue = _aValue; }
414
632k
        void setNull()                                       { m_aValue.setNull(); }
415
5.75M
        void setBound(bool _bBound )                         { m_aValue.setBound(_bBound);}
416
13.1M
        bool isBound( ) const                                { return m_aValue.isBound();}
417
1.06M
        void setTypeKind(sal_Int32 _nType)                   { m_aValue.setTypeKind(_nType); }
418
0
        void setModified(bool _bModified)                    { m_aValue.setModified(_bModified); }
419
420
    };
421
    typedef ::rtl::Reference<ORowSetValueDecorator> ORowSetValueDecoratorRef;
422
423
424
    /// TSetBound is a functor to set the bound value with e.q. for_each call
425
    struct OOO_DLLPUBLIC_DBTOOLS TSetBound
426
    {
427
        bool m_bBound;
428
0
        TSetBound(bool _bBound) : m_bBound(_bBound){}
429
0
        void operator()(ORowSetValue& _rValue) const { _rValue.setBound(m_bBound); }
430
431
    };
432
433
434
    /// TSetBound is a functor to set the bound value with e.q. for_each call
435
    struct OOO_DLLPUBLIC_DBTOOLS TSetRefBound
436
    {
437
        bool m_bBound;
438
98.0k
        TSetRefBound(bool _bBound) : m_bBound(_bBound){}
439
3.13M
        void operator()(ORowSetValueDecoratorRef const & _rValue) const { _rValue->setBound(m_bBound); }
440
441
    };
442
443
444
    // Vector for file based rows
445
446
    template< class VectorVal > class  ODeleteVector : public connectivity::ORowVector< VectorVal >
447
    {
448
        bool    m_bDeleted;
449
    public:
450
17.8k
        ODeleteVector()             : connectivity::ORowVector< VectorVal >()       ,m_bDeleted(false)  {}
451
98.0k
        ODeleteVector(size_t _st)   : connectivity::ORowVector< VectorVal >(_st)    ,m_bDeleted(false)  {}
connectivity::ODeleteVector<rtl::Reference<connectivity::ORowSetValueDecorator> >::ODeleteVector(unsigned long)
Line
Count
Source
451
98.0k
        ODeleteVector(size_t _st)   : connectivity::ORowVector< VectorVal >(_st)    ,m_bDeleted(false)  {}
Unexecuted instantiation: connectivity::ODeleteVector<connectivity::ORowSetValue>::ODeleteVector(unsigned long)
452
453
1.80M
        bool isDeleted() const           { return m_bDeleted;        }
454
1.86M
        void setDeleted(bool _bDeleted)  { m_bDeleted = _bDeleted;   }
455
    };
456
457
    typedef ODeleteVector< ORowSetValue >               OValueVector;
458
459
    class OOO_DLLPUBLIC_DBTOOLS OValueRefVector : public ODeleteVector< ORowSetValueDecoratorRef >
460
    {
461
    public:
462
17.8k
        OValueRefVector(){}
463
98.0k
        OValueRefVector(size_t _st) : ODeleteVector< ORowSetValueDecoratorRef >(_st)
464
98.0k
        {
465
98.0k
            for (auto & elem : *this)
466
3.20M
                elem = new ORowSetValueDecorator;
467
98.0k
        }
468
    };
469
470
0
#define SQL_NO_PARAMETER (SAL_MAX_UINT32)
471
    class OAssignValues final : public OValueRefVector
472
    {
473
        ::std::vector<sal_Int32> m_nParameterIndexes;
474
    public:
475
0
        OAssignValues(size_type n) : OValueRefVector(n),m_nParameterIndexes(n+1,SQL_NO_PARAMETER){}
476
477
0
        void setParameterIndex(sal_Int32 _nId,sal_Int32 _nParameterIndex) { m_nParameterIndexes[_nId] = _nParameterIndex;}
478
0
        sal_Int32 getParameterIndex(sal_Int32 _nId) const { return m_nParameterIndexes[_nId]; }
479
    };
480
481
    typedef ::rtl::Reference< OAssignValues > ORefAssignValues;
482
483
484
    typedef ::rtl::Reference< OValueVector >                    OValueRow;
485
    typedef ::rtl::Reference< OValueRefVector >             OValueRefRow;
486
}
487
488
#endif // INCLUDED_CONNECTIVITY_FVALUE_HXX
489
490
491
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */