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 .
20 #ifndef INCLUDED_CONNECTIVITY_FVALUE_HXX
21 #define INCLUDED_CONNECTIVITY_FVALUE_HXX
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <rtl/ustring.hxx>
26 #include <salhelper/simplereferenceobject.hxx>
27 #include <rtl/ref.hxx>
28 #include <connectivity/dbtoolsdllapi.hxx>
29 #include <connectivity/CommonTools.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>
36 namespace com::sun::star::sdb
{ class XColumn
; }
37 namespace com::sun::star::sdbc
{ class XRow
; }
39 namespace connectivity
46 class OOO_DLLPUBLIC_DBTOOLS ORowSetValue
67 rtl_uString
* m_pString
;
69 void* m_pValue
; // date/time/timestamp/sequence
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
82 :m_eTypeKind(css::sdbc::DataType::VARCHAR
)
88 m_aValue
.m_pString
= nullptr;
91 ORowSetValue(const ORowSetValue
& _rRH
)
92 :m_eTypeKind(css::sdbc::DataType::VARCHAR
)
98 m_aValue
.m_pString
= nullptr;
102 ORowSetValue(ORowSetValue
&& _rRH
) noexcept
103 :m_eTypeKind(css::sdbc::DataType::VARCHAR
)
109 m_aValue
.m_pString
= nullptr;
110 operator=(std::move(_rRH
));
113 ORowSetValue(const OUString
& _rRH
)
114 :m_eTypeKind(css::sdbc::DataType::VARCHAR
)
120 m_aValue
.m_pString
= nullptr;
124 ORowSetValue(const double& _rRH
)
125 :m_eTypeKind(css::sdbc::DataType::DOUBLE
)
131 m_aValue
.m_pString
= nullptr;
135 ORowSetValue(float _rRH
)
136 :m_eTypeKind(css::sdbc::DataType::FLOAT
)
142 m_aValue
.m_pString
= nullptr;
146 ORowSetValue(sal_Int8 _rRH
)
147 :m_eTypeKind(css::sdbc::DataType::TINYINT
)
153 m_aValue
.m_pString
= nullptr;
157 ORowSetValue(sal_Int16 _rRH
)
158 :m_eTypeKind(css::sdbc::DataType::SMALLINT
)
164 m_aValue
.m_pString
= nullptr;
167 ORowSetValue(sal_uInt16 _rRH
)
168 :m_eTypeKind(css::sdbc::DataType::SMALLINT
)
174 m_aValue
.m_pString
= nullptr;
177 ORowSetValue(sal_Int32 _rRH
)
178 :m_eTypeKind(css::sdbc::DataType::INTEGER
)
184 m_aValue
.m_pString
= nullptr;
187 ORowSetValue(sal_uInt32 _rRH
)
188 :m_eTypeKind(css::sdbc::DataType::INTEGER
)
194 m_aValue
.m_pString
= nullptr;
197 ORowSetValue(sal_Int64 _rRH
)
198 :m_eTypeKind(css::sdbc::DataType::BIGINT
)
204 m_aValue
.m_pString
= nullptr;
207 ORowSetValue(sal_uInt64 _rRH
)
208 :m_eTypeKind(css::sdbc::DataType::BIGINT
)
214 m_aValue
.m_pString
= nullptr;
218 ORowSetValue(bool _rRH
)
219 :m_eTypeKind(css::sdbc::DataType::BIT
)
225 m_aValue
.m_pString
= nullptr;
228 ORowSetValue(sal_Bool
) = delete; // aka sal_uInt8
230 ORowSetValue(const css::util::Date
& _rRH
)
231 :m_eTypeKind(css::sdbc::DataType::DATE
)
237 m_aValue
.m_pString
= nullptr;
241 ORowSetValue(const css::util::Time
& _rRH
)
242 :m_eTypeKind(css::sdbc::DataType::TIME
)
248 m_aValue
.m_pString
= nullptr;
252 ORowSetValue(const css::util::DateTime
& _rRH
)
253 :m_eTypeKind(css::sdbc::DataType::TIMESTAMP
)
259 m_aValue
.m_pString
= nullptr;
263 ORowSetValue(const css::uno::Sequence
<sal_Int8
>& _rRH
)
264 :m_eTypeKind(css::sdbc::DataType::LONGVARBINARY
)
270 m_aValue
.m_pString
= nullptr;
274 // Avoid accidental uses of ORowSetValue(bool const &):
275 template<typename T
> ORowSetValue(T
const *) = delete;
282 ORowSetValue
& operator=(const ORowSetValue
& _rRH
);
283 ORowSetValue
& operator=(ORowSetValue
&& _rRH
) noexcept
;
286 ORowSetValue
& operator=(bool _rRH
);
287 void operator =(sal_Bool
) = delete; // aka sal_uInt8
289 ORowSetValue
& operator=(sal_Int8 _rRH
);
291 ORowSetValue
& operator=(sal_Int16 _rRH
);
292 ORowSetValue
& operator=(sal_uInt16 _rRH
);
294 ORowSetValue
& operator=(sal_Int32 _rRH
);
295 ORowSetValue
& operator=(sal_uInt32 _rRH
);
297 ORowSetValue
& operator=(sal_Int64 _rRH
);
298 ORowSetValue
& operator=(sal_uInt64 _rRH
);
300 ORowSetValue
& operator=(double _rRH
);
301 ORowSetValue
& operator=(float _rRH
);
304 ORowSetValue
& operator=(const css::util::Date
& _rRH
);
305 ORowSetValue
& operator=(const css::util::Time
& _rRH
);
306 ORowSetValue
& operator=(const css::util::DateTime
& _rRH
);
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
);
314 bool operator==(const ORowSetValue
& _rRH
) const;
315 bool operator!=(const ORowSetValue
& _rRH
) const
317 return !( *this == _rRH
);
328 m_aValue
.m_pString
= nullptr;
331 bool isBound() const { return m_bBound
; }
332 void setBound(bool _bBound
) { m_bBound
= _bBound
; }
334 bool isModified() const { return m_bModified
; }
335 void setModified(bool _bMod
) { m_bModified
= _bMod
; }
337 bool isSigned() const { return m_bSigned
; }
338 void setSigned(bool _bSig
);
340 sal_Int32
getTypeKind() const { return m_eTypeKind
; }
341 void setTypeKind(sal_Int32 _eType
);
343 bool getBool() const;
345 sal_Int8
getInt8() const;
346 sal_uInt8
getUInt8() const;
348 sal_Int16
getInt16() const;
349 sal_uInt16
getUInt16() const;
351 sal_Int32
getInt32() const;
352 sal_uInt32
getUInt32() const;
354 sal_Int64
getLong() const;
355 sal_uInt64
getULong() const;
357 double getDouble() const;
358 float getFloat() const;
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;
366 const css::uno::Any
& getAny() const { return *static_cast<css::uno::Any
*>(m_aValue
.m_pValue
); }
367 css::uno::Any
makeAny() const;
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
375 void fill(sal_Int32 _nPos
,
377 const css::uno::Reference
< css::sdbc::XRow
>& _xRow
);
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
386 void fill(sal_Int32 _nPos
,
389 const css::uno::Reference
< css::sdbc::XRow
>& _xRow
);
391 void fill(const css::uno::Any
& _rValue
);
393 void fill( const sal_Int32 _nType
,
394 const css::uno::Reference
< css::sdb::XColumn
>& _rxColumn
);
397 void impl_fill( const sal_Int32 _nType
, bool _bNullable
, const detail::IValueSource
& _rValueSource
);
400 /// ORowSetValueDecorator decorates an ORowSetValue so the value is "refcounted"
401 class OOO_DLLPUBLIC_DBTOOLS ORowSetValueDecorator final
: public ::salhelper::SimpleReferenceObject
403 ORowSetValue m_aValue
; // my own value
405 ORowSetValueDecorator(){m_aValue
.setBound(true);}
406 ORowSetValueDecorator(ORowSetValue _aValue
) : m_aValue(std::move(_aValue
)){m_aValue
.setBound(true);}
407 ORowSetValueDecorator
& operator=(const ORowSetValue
& _aValue
);
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
); }
421 typedef ::rtl::Reference
<ORowSetValueDecorator
> ORowSetValueDecoratorRef
;
424 /// TSetBound is a functor to set the bound value with e.q. for_each call
425 struct OOO_DLLPUBLIC_DBTOOLS TSetBound
428 TSetBound(bool _bBound
) : m_bBound(_bBound
){}
429 void operator()(ORowSetValue
& _rValue
) const { _rValue
.setBound(m_bBound
); }
434 /// TSetBound is a functor to set the bound value with e.q. for_each call
435 struct OOO_DLLPUBLIC_DBTOOLS TSetRefBound
438 TSetRefBound(bool _bBound
) : m_bBound(_bBound
){}
439 void operator()(ORowSetValueDecoratorRef
const & _rValue
) const { _rValue
->setBound(m_bBound
); }
444 // Vector for file based rows
446 template< class VectorVal
> class ODeleteVector
: public connectivity::ORowVector
< VectorVal
>
450 ODeleteVector() : connectivity::ORowVector
< VectorVal
>() ,m_bDeleted(false) {}
451 ODeleteVector(size_t _st
) : connectivity::ORowVector
< VectorVal
>(_st
) ,m_bDeleted(false) {}
453 bool isDeleted() const { return m_bDeleted
; }
454 void setDeleted(bool _bDeleted
) { m_bDeleted
= _bDeleted
; }
457 typedef ODeleteVector
< ORowSetValue
> OValueVector
;
459 class OOO_DLLPUBLIC_DBTOOLS OValueRefVector
: public ODeleteVector
< ORowSetValueDecoratorRef
>
463 OValueRefVector(size_t _st
) : ODeleteVector
< ORowSetValueDecoratorRef
>(_st
)
465 for (auto & elem
: *this)
466 elem
= new ORowSetValueDecorator
;
470 #define SQL_NO_PARAMETER (SAL_MAX_UINT32)
471 class OAssignValues final
: public OValueRefVector
473 ::std::vector
<sal_Int32
> m_nParameterIndexes
;
475 OAssignValues(size_type n
) : OValueRefVector(n
),m_nParameterIndexes(n
+1,SQL_NO_PARAMETER
){}
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
]; }
481 typedef ::rtl::Reference
< OAssignValues
> ORefAssignValues
;
484 typedef ::rtl::Reference
< OValueVector
> OValueRow
;
485 typedef ::rtl::Reference
< OValueRefVector
> OValueRefRow
;
488 #endif // INCLUDED_CONNECTIVITY_FVALUE_HXX
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */