LibreOffice Module connectivity (master) 1
FValue.hxx
Go to the documentation of this file.
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 <com/sun/star/uno/Any.hxx>
25#include <rtl/ustring.hxx>
27#include <rtl/ref.hxx>
30#include <com/sun/star/util/DateTime.hpp>
31#include <com/sun/star/util/Date.hpp>
32#include <com/sun/star/util/Time.hpp>
33#include <com/sun/star/uno/Sequence.hxx>
34#include <utility>
35
36namespace com::sun::star::sdb { class XColumn; }
37namespace com::sun::star::sdbc { class XRow; }
38
39namespace connectivity
40{
41 namespace detail
42 {
43 class IValueSource;
44 }
45
47 {
48 union
49 {
50 bool m_bBool;
51
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:
82 :m_eTypeKind(css::sdbc::DataType::VARCHAR)
83 ,m_bNull(true)
84 ,m_bBound(true)
85 ,m_bModified(false)
86 ,m_bSigned(true)
87 {
88 m_aValue.m_pString = nullptr;
89 }
90
92 :m_eTypeKind(css::sdbc::DataType::VARCHAR)
93 ,m_bNull(true)
94 ,m_bBound(true)
95 ,m_bModified(false)
96 ,m_bSigned(true)
97 {
98 m_aValue.m_pString = nullptr;
99 operator=(_rRH);
100 }
101
102 ORowSetValue(ORowSetValue&& _rRH) noexcept
103 :m_eTypeKind(css::sdbc::DataType::VARCHAR)
104 ,m_bNull(true)
105 ,m_bBound(true)
106 ,m_bModified(false)
107 ,m_bSigned(true)
108 {
109 m_aValue.m_pString = nullptr;
110 operator=(std::move(_rRH));
111 }
112
113 ORowSetValue(const OUString& _rRH)
114 :m_eTypeKind(css::sdbc::DataType::VARCHAR)
115 ,m_bNull(true)
116 ,m_bBound(true)
117 ,m_bModified(false)
118 ,m_bSigned(true)
119 {
120 m_aValue.m_pString = nullptr;
121 operator=(_rRH);
122 }
123
124 ORowSetValue(const double& _rRH)
125 :m_eTypeKind(css::sdbc::DataType::DOUBLE)
126 ,m_bNull(true)
127 ,m_bBound(true)
128 ,m_bModified(false)
129 ,m_bSigned(true)
130 {
131 m_aValue.m_pString = nullptr;
132 operator=(_rRH);
133 }
134
135 ORowSetValue(float _rRH)
136 :m_eTypeKind(css::sdbc::DataType::FLOAT)
137 ,m_bNull(true)
138 ,m_bBound(true)
139 ,m_bModified(false)
140 ,m_bSigned(true)
141 {
142 m_aValue.m_pString = nullptr;
143 operator=(_rRH);
144 }
145
147 :m_eTypeKind(css::sdbc::DataType::TINYINT)
148 ,m_bNull(true)
149 ,m_bBound(true)
150 ,m_bModified(false)
151 ,m_bSigned(true)
152 {
153 m_aValue.m_pString = nullptr;
154 operator=(_rRH);
155 }
156
157 ORowSetValue(sal_Int16 _rRH)
158 :m_eTypeKind(css::sdbc::DataType::SMALLINT)
159 ,m_bNull(true)
160 ,m_bBound(true)
161 ,m_bModified(false)
162 ,m_bSigned(true)
163 {
164 m_aValue.m_pString = nullptr;
165 operator=(_rRH);
166 }
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 {
174 m_aValue.m_pString = nullptr;
175 operator=(_rRH);
176 }
177 ORowSetValue(sal_Int32 _rRH)
178 :m_eTypeKind(css::sdbc::DataType::INTEGER)
179 ,m_bNull(true)
180 ,m_bBound(true)
181 ,m_bModified(false)
182 ,m_bSigned(true)
183 {
184 m_aValue.m_pString = nullptr;
185 operator=(_rRH);
186 }
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 {
194 m_aValue.m_pString = nullptr;
195 operator=(_rRH);
196 }
197 ORowSetValue(sal_Int64 _rRH)
198 :m_eTypeKind(css::sdbc::DataType::BIGINT)
199 ,m_bNull(true)
200 ,m_bBound(true)
201 ,m_bModified(false)
202 ,m_bSigned(true)
203 {
204 m_aValue.m_pString = nullptr;
205 operator=(_rRH);
206 }
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 {
214 m_aValue.m_pString = nullptr;
215 operator=(_rRH);
216 }
217
218 ORowSetValue(bool _rRH)
219 :m_eTypeKind(css::sdbc::DataType::BIT)
220 ,m_bNull(true)
221 ,m_bBound(true)
222 ,m_bModified(false)
223 ,m_bSigned(true)
224 {
225 m_aValue.m_pString = nullptr;
226 operator=(_rRH);
227 }
228 ORowSetValue(sal_Bool) = delete; // aka sal_uInt8
229
230 ORowSetValue(const css::util::Date& _rRH)
231 :m_eTypeKind(css::sdbc::DataType::DATE)
232 ,m_bNull(true)
233 ,m_bBound(true)
234 ,m_bModified(false)
235 ,m_bSigned(true)
236 {
237 m_aValue.m_pString = nullptr;
238 operator=(_rRH);
239 }
240
241 ORowSetValue(const css::util::Time& _rRH)
242 :m_eTypeKind(css::sdbc::DataType::TIME)
243 ,m_bNull(true)
244 ,m_bBound(true)
245 ,m_bModified(false)
246 ,m_bSigned(true)
247 {
248 m_aValue.m_pString = nullptr;
249 operator=(_rRH);
250 }
251
252 ORowSetValue(const css::util::DateTime& _rRH)
253 :m_eTypeKind(css::sdbc::DataType::TIMESTAMP)
254 ,m_bNull(true)
255 ,m_bBound(true)
256 ,m_bModified(false)
257 ,m_bSigned(true)
258 {
259 m_aValue.m_pString = nullptr;
260 operator=(_rRH);
261 }
262
263 ORowSetValue(const css::uno::Sequence<sal_Int8>& _rRH)
264 :m_eTypeKind(css::sdbc::DataType::LONGVARBINARY)
265 ,m_bNull(true)
266 ,m_bBound(true)
267 ,m_bModified(false)
268 ,m_bSigned(true)
269 {
270 m_aValue.m_pString = nullptr;
271 operator=(_rRH);
272 }
273
274 // Avoid accidental uses of ORowSetValue(bool const &):
275 template<typename T> ORowSetValue(T const *) = delete;
276
278 {
279 free();
280 }
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 {
317 return !( *this == _rRH );
318 }
319
320 bool isNull() const
321 {
322 return m_bNull;
323 }
324 void setNull()
325 {
326 free();
327 m_bNull = true;
328 m_aValue.m_pString = nullptr;
329 }
330
331 bool isBound() const { return m_bBound; }
332 void setBound(bool _bBound) { m_bBound = _bBound; }
333
334 bool isModified() const { return m_bModified; }
335 void setModified(bool _bMod) { m_bModified = _bMod; }
336
337 bool isSigned() const { return m_bSigned; }
338 void setSigned(bool _bSig);
339
340 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 const css::uno::Any& getAny() const { return *static_cast<css::uno::Any*>(m_aValue.m_pValue); }
367 css::uno::Any makeAny() const;
368
375 void fill(sal_Int32 _nPos,
376 sal_Int32 _nType,
377 const css::uno::Reference< css::sdbc::XRow>& _xRow);
378
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
402 {
403 ORowSetValue m_aValue; // my own value
404 public:
406 ORowSetValueDecorator(ORowSetValue _aValue) : m_aValue(std::move(_aValue)){m_aValue.setBound(true);}
407 ORowSetValueDecorator& operator=(const ORowSetValue& _aValue);
408
409 operator const ORowSetValue&() const { return m_aValue; }
410 bool operator ==( const ORowSetValue & _rRH ) { return m_aValue == _rRH; }
411 const ORowSetValue& getValue() const { return m_aValue; }
412 ORowSetValue& get() { return m_aValue; }
413 void setValue(const ORowSetValue& _aValue) { m_aValue = _aValue; }
414 void setNull() { m_aValue.setNull(); }
415 void setBound(bool _bBound ) { m_aValue.setBound(_bBound);}
416 bool isBound( ) const { return m_aValue.isBound();}
417 void setTypeKind(sal_Int32 _nType) { m_aValue.setTypeKind(_nType); }
418 void setModified(bool _bModified) { m_aValue.setModified(_bModified); }
419
420 };
421 typedef ::rtl::Reference<ORowSetValueDecorator> ORowSetValueDecoratorRef;
422
423
426 {
428 TSetBound(bool _bBound) : m_bBound(_bBound){}
429 void operator()(ORowSetValue& _rValue) const { _rValue.setBound(m_bBound); }
430
431 };
432
433
436 {
438 TSetRefBound(bool _bBound) : m_bBound(_bBound){}
439 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 {
449 public:
450 ODeleteVector() : connectivity::ORowVector< VectorVal >() ,m_bDeleted(false) {}
451 ODeleteVector(size_t _st) : connectivity::ORowVector< VectorVal >(_st) ,m_bDeleted(false) {}
452
453 bool isDeleted() const { return m_bDeleted; }
454 void setDeleted(bool _bDeleted) { m_bDeleted = _bDeleted; }
455 };
456
458
459 class OOO_DLLPUBLIC_DBTOOLS OValueRefVector : public ODeleteVector< ORowSetValueDecoratorRef >
460 {
461 public:
464 {
465 for (auto & elem : *this)
466 elem = new ORowSetValueDecorator;
467 }
468 };
469
470#define SQL_NO_PARAMETER (SAL_MAX_UINT32)
471 class OAssignValues final : public OValueRefVector
472 {
473 ::std::vector<sal_Int32> m_nParameterIndexes;
474 public:
476
477 void setParameterIndex(sal_Int32 _nId,sal_Int32 _nParameterIndex) { m_nParameterIndexes[_nId] = _nParameterIndex;}
478 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: */
#define SQL_NO_PARAMETER
Definition: FValue.hxx:470
#define DOUBLE
OAssignValues(size_type n)
Definition: FValue.hxx:475
sal_Int32 getParameterIndex(sal_Int32 _nId) const
Definition: FValue.hxx:478
void setParameterIndex(sal_Int32 _nId, sal_Int32 _nParameterIndex)
Definition: FValue.hxx:477
::std::vector< sal_Int32 > m_nParameterIndexes
Definition: FValue.hxx:473
void setDeleted(bool _bDeleted)
Definition: FValue.hxx:454
ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted".
Definition: FValue.hxx:402
void setModified(bool _bModified)
Definition: FValue.hxx:418
ORowSetValueDecorator(ORowSetValue _aValue)
Definition: FValue.hxx:406
void setValue(const ORowSetValue &_aValue)
Definition: FValue.hxx:413
const ORowSetValue & getValue() const
Definition: FValue.hxx:411
void setTypeKind(sal_Int32 _nType)
Definition: FValue.hxx:417
ORowSetValue(T const *)=delete
rtl_uString * m_pString
Definition: FValue.hxx:67
bool isModified() const
Definition: FValue.hxx:334
ORowSetValue(sal_Bool)=delete
ORowSetValue(sal_uInt16 _rRH)
Definition: FValue.hxx:167
ORowSetValue(sal_uInt32 _rRH)
Definition: FValue.hxx:187
ORowSetValue & operator=(const css::uno::Sequence< sal_Int8 > &_rRH)
ORowSetValue(const double &_rRH)
Definition: FValue.hxx:124
ORowSetValue & operator=(const css::util::Date &_rRH)
ORowSetValue(sal_Int32 _rRH)
Definition: FValue.hxx:177
ORowSetValue(sal_Int8 _rRH)
Definition: FValue.hxx:146
void fill(const sal_Int32 _nType, const css::uno::Reference< css::sdb::XColumn > &_rxColumn)
ORowSetValue(sal_uInt64 _rRH)
Definition: FValue.hxx:207
ORowSetValue(const OUString &_rRH)
Definition: FValue.hxx:113
sal_Int32 getTypeKind() const
Definition: FValue.hxx:340
void setBound(bool _bBound)
Definition: FValue.hxx:332
void fill(const css::uno::Any &_rValue)
ORowSetValue(const css::uno::Sequence< sal_Int8 > &_rRH)
Definition: FValue.hxx:263
ORowSetValue(sal_Int64 _rRH)
Definition: FValue.hxx:197
ORowSetValue & operator=(const css::util::DateTime &_rRH)
void setTypeKind(sal_Int32 _eType)
Definition: FValue.cxx:180
ORowSetValue & operator=(const css::uno::Any &_rAny)
ORowSetValue(sal_Int16 _rRH)
Definition: FValue.hxx:157
void setModified(bool _bMod)
Definition: FValue.hxx:335
ORowSetValue(const css::util::Date &_rRH)
Definition: FValue.hxx:230
ORowSetValue(const css::util::Time &_rRH)
Definition: FValue.hxx:241
void fill(sal_Int32 _nPos, sal_Int32 _nType, bool _bNullable, const css::uno::Reference< css::sdbc::XRow > &_xRow)
fetches a single value out of the row
bool operator!=(const ORowSetValue &_rRH) const
Definition: FValue.hxx:315
ORowSetValue(const ORowSetValue &_rRH)
Definition: FValue.hxx:91
const css::uno::Any & getAny() const
Definition: FValue.hxx:366
ORowSetValue(float _rRH)
Definition: FValue.hxx:135
ORowSetValue(ORowSetValue &&_rRH) noexcept
Definition: FValue.hxx:102
ORowSetValue(const css::util::DateTime &_rRH)
Definition: FValue.hxx:252
#define OOO_DLLPUBLIC_DBTOOLS
sal_Int64 n
double getDouble(const Any &_rAny)
float getFloat(const Any &_rAny)
OUString getString(const Any &_rAny)
DATE
::rtl::Reference< OValueVector > OValueRow
Definition: FValue.hxx:484
::rtl::Reference< OValueRefVector > OValueRefRow
Definition: FValue.hxx:485
::rtl::Reference< OAssignValues > ORefAssignValues
Definition: FValue.hxx:481
::rtl::Reference< ORowSetValueDecorator > ORowSetValueDecoratorRef
Definition: FValue.hxx:421
ODeleteVector< ORowSetValue > OValueVector
Definition: FValue.hxx:457
bool operator==(const OCharsetMap::CharsetIterator &lhs, const OCharsetMap::CharsetIterator &rhs)
Definition: dbcharset.cxx:182
DataType
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)
TSetBound is a functor to set the bound value with e.q. for_each call.
Definition: FValue.hxx:426
void operator()(ORowSetValue &_rValue) const
Definition: FValue.hxx:429
TSetBound(bool _bBound)
Definition: FValue.hxx:428
TSetBound is a functor to set the bound value with e.q. for_each call.
Definition: FValue.hxx:436
void operator()(ORowSetValueDecoratorRef const &_rValue) const
Definition: FValue.hxx:439
TSetRefBound(bool _bBound)
Definition: FValue.hxx:438
unsigned char sal_uInt8
unsigned char sal_Bool
signed char sal_Int8