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 
21 #include <string.h>
22 #include <connectivity/FValue.hxx>
23 #include <connectivity/dbconversion.hxx>
24 #include <comphelper/extract.hxx>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/sdbc/XClob.hpp>
27 #include <com/sun/star/sdbc/XBlob.hpp>
28 #include <com/sun/star/sdb/XColumn.hpp>
29 #include <com/sun/star/sdbc/XRow.hpp>
30 #include <rtl/ustrbuf.hxx>
31 #include <sal/log.hxx>
32 #include <osl/diagnose.h>
33 
34 using namespace ::dbtools;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::sdb;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::io;
40 
41 namespace connectivity
42 {
43 
44 namespace {
isStorageCompatible(sal_Int32 _eType1,sal_Int32 _eType2)45     bool isStorageCompatible(sal_Int32 _eType1, sal_Int32 _eType2)
46     {
47         bool bIsCompatible = true;
48 
49         if (_eType1 != _eType2)
50         {
51             SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
52             switch (_eType1)
53             {
54                 case DataType::CHAR:
55                 case DataType::VARCHAR:
56                 case DataType::DECIMAL:
57                 case DataType::NUMERIC:
58                 case DataType::LONGVARCHAR:
59                     bIsCompatible = (DataType::CHAR         == _eType2)
60                                 ||  (DataType::VARCHAR      == _eType2)
61                                 ||  (DataType::DECIMAL      == _eType2)
62                                 ||  (DataType::NUMERIC      == _eType2)
63                                 ||  (DataType::LONGVARCHAR  == _eType2);
64                     break;
65 
66                 case DataType::DOUBLE:
67                 case DataType::REAL:
68                     bIsCompatible = (DataType::DOUBLE   == _eType2)
69                                 ||  (DataType::REAL     == _eType2);
70                     break;
71 
72                 case DataType::BINARY:
73                 case DataType::VARBINARY:
74                 case DataType::LONGVARBINARY:
75                     bIsCompatible = (DataType::BINARY           == _eType2)
76                                 ||  (DataType::VARBINARY        == _eType2)
77                                 ||  (DataType::LONGVARBINARY    == _eType2);
78                     break;
79 
80                 case DataType::INTEGER:
81                     bIsCompatible = (DataType::SMALLINT == _eType2)
82                                 ||  (DataType::TINYINT  == _eType2)
83                                 ||  (DataType::BIT      == _eType2)
84                                 ||  (DataType::BOOLEAN  == _eType2);
85                     break;
86                 case DataType::SMALLINT:
87                     bIsCompatible = (DataType::TINYINT  == _eType2)
88                                 ||  (DataType::BIT      == _eType2)
89                                 ||  (DataType::BOOLEAN  == _eType2);
90                     break;
91                 case DataType::TINYINT:
92                     bIsCompatible = (DataType::BIT      == _eType2)
93                                 ||  (DataType::BOOLEAN  == _eType2);
94                     break;
95 
96                 case DataType::BLOB:
97                 case DataType::CLOB:
98                 case DataType::OBJECT:
99                     bIsCompatible = (DataType::BLOB     == _eType2)
100                                 ||  (DataType::CLOB     == _eType2)
101                                 ||  (DataType::OBJECT   == _eType2);
102                     break;
103 
104                 default:
105                     bIsCompatible = false;
106             }
107         }
108         return bIsCompatible;
109     }
110 
isStorageComparable(sal_Int32 _eType1,sal_Int32 _eType2)111     bool isStorageComparable(sal_Int32 _eType1, sal_Int32 _eType2)
112     {
113         bool bIsComparable = true;
114 
115         if (_eType1 != _eType2)
116         {
117             SAL_INFO( "connectivity.commontools", "ORowSetValue::isStorageCompatible _eType1 != _eType2" );
118             switch (_eType1)
119             {
120                 case DataType::CHAR:
121                 case DataType::VARCHAR:
122                 case DataType::LONGVARCHAR:
123                     bIsComparable = (DataType::CHAR         == _eType2)
124                                 ||  (DataType::VARCHAR      == _eType2)
125                                 ||  (DataType::LONGVARCHAR  == _eType2);
126                     break;
127 
128                 case DataType::DECIMAL:
129                 case DataType::NUMERIC:
130                     bIsComparable = (DataType::DECIMAL      == _eType2)
131                                 ||  (DataType::NUMERIC      == _eType2);
132                     break;
133 
134             case DataType::DOUBLE:
135                 case DataType::REAL:
136                     bIsComparable = (DataType::DOUBLE   == _eType2)
137                                 ||  (DataType::REAL     == _eType2);
138                     break;
139 
140                 case DataType::BINARY:
141                 case DataType::VARBINARY:
142                 case DataType::LONGVARBINARY:
143                     bIsComparable = (DataType::BINARY           == _eType2)
144                                 ||  (DataType::VARBINARY        == _eType2)
145                                 ||  (DataType::LONGVARBINARY    == _eType2);
146                     break;
147 
148                 case DataType::INTEGER:
149                     bIsComparable = (DataType::SMALLINT == _eType2)
150                                 ||  (DataType::TINYINT  == _eType2)
151                                 ||  (DataType::BIT      == _eType2)
152                                 ||  (DataType::BOOLEAN  == _eType2);
153                     break;
154                 case DataType::SMALLINT:
155                     bIsComparable = (DataType::TINYINT  == _eType2)
156                                 ||  (DataType::BIT      == _eType2)
157                                 ||  (DataType::BOOLEAN  == _eType2);
158                     break;
159                 case DataType::TINYINT:
160                     bIsComparable = (DataType::BIT      == _eType2)
161                                 ||  (DataType::BOOLEAN  == _eType2);
162                     break;
163 
164                 case DataType::BLOB:
165                 case DataType::CLOB:
166                 case DataType::OBJECT:
167                     bIsComparable = (DataType::BLOB     == _eType2)
168                                 ||  (DataType::CLOB     == _eType2)
169                                 ||  (DataType::OBJECT   == _eType2);
170                     break;
171 
172                 default:
173                     bIsComparable = false;
174             }
175         }
176         return bIsComparable;
177     }
178 }
179 
setTypeKind(sal_Int32 _eType)180 void ORowSetValue::setTypeKind(sal_Int32 _eType)
181 {
182     if ( !m_bNull && !isStorageCompatible(_eType, m_eTypeKind) )
183     {
184         switch(_eType)
185         {
186             case DataType::VARCHAR:
187             case DataType::CHAR:
188             case DataType::DECIMAL:
189             case DataType::NUMERIC:
190             case DataType::LONGVARCHAR:
191                 (*this) = getString();
192                 break;
193             case DataType::BIGINT:
194             {
195                 sal_Int64 nVal(getLong());
196                 sal_uInt64 nuVal(getULong());
197                 if (nVal == 0 && nuVal != 0)
198                     (*this) = nuVal;
199                 else
200                     (*this) = nVal;
201                 break;
202             }
203 
204             case DataType::FLOAT:
205                 (*this) = getFloat();
206                 break;
207             case DataType::DOUBLE:
208             case DataType::REAL:
209                 (*this) = getDouble();
210                 break;
211             case DataType::TINYINT:
212                 (*this) = getInt8();
213                 break;
214             case DataType::SMALLINT:
215                 (*this) = getInt16();
216                 break;
217             case DataType::INTEGER:
218             {
219                 sal_Int32 nVal(getInt32());
220                 sal_uInt32 nuVal(getUInt32());
221                 if (nVal == 0 && nuVal != 0)
222                     (*this) = nuVal;
223                 else
224                     (*this) = nVal;
225                 break;
226             }
227             case DataType::BIT:
228             case DataType::BOOLEAN:
229                 (*this) = getBool();
230                 break;
231             case DataType::DATE:
232                 (*this) = getDate();
233                 break;
234             case DataType::TIME:
235                 (*this) = getTime();
236                 break;
237             case DataType::TIMESTAMP:
238                 (*this) = getDateTime();
239                 break;
240             case DataType::BINARY:
241             case DataType::VARBINARY:
242             case DataType::LONGVARBINARY:
243                 (*this) = getSequence();
244                 break;
245             case DataType::BLOB:
246             case DataType::CLOB:
247             case DataType::OBJECT:
248             case DataType::OTHER:
249                 (*this) = makeAny();
250                 break;
251             default:
252                 (*this) = makeAny();
253                 SAL_WARN( "connectivity.commontools","ORowSetValue::setTypeKind(): UNSUPPORTED TYPE!");
254         }
255     }
256 
257     m_eTypeKind = _eType;
258 }
259 
260 
free()261 void ORowSetValue::free() noexcept
262 {
263     if(m_bNull)
264         return;
265 
266     switch(m_eTypeKind)
267     {
268         case DataType::CHAR:
269         case DataType::VARCHAR:
270         case DataType::DECIMAL:
271         case DataType::NUMERIC:
272         case DataType::LONGVARCHAR:
273             OSL_ENSURE(m_aValue.m_pString,"String pointer is null!");
274             rtl_uString_release(m_aValue.m_pString);
275             m_aValue.m_pString = nullptr;
276             break;
277         case DataType::DATE:
278             delete static_cast<css::util::Date*>(m_aValue.m_pValue);
279             m_aValue.m_pValue = nullptr;
280             break;
281         case DataType::TIME:
282             delete static_cast<css::util::Time*>(m_aValue.m_pValue);
283             m_aValue.m_pValue = nullptr;
284             break;
285         case DataType::TIMESTAMP:
286             delete static_cast<css::util::DateTime*>(m_aValue.m_pValue);
287             m_aValue.m_pValue = nullptr;
288             break;
289         case DataType::BINARY:
290         case DataType::VARBINARY:
291         case DataType::LONGVARBINARY:
292             delete static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
293             m_aValue.m_pValue = nullptr;
294             break;
295         case DataType::BLOB:
296         case DataType::CLOB:
297         case DataType::OBJECT:
298             delete static_cast<Any*>(m_aValue.m_pValue);
299             m_aValue.m_pValue = nullptr;
300             break;
301         case DataType::BIT:
302         case DataType::TINYINT:
303         case DataType::SMALLINT:
304         case DataType::INTEGER:
305         case DataType::BIGINT:
306         case DataType::BOOLEAN:
307         case DataType::FLOAT:
308         case DataType::DOUBLE:
309         case DataType::REAL:
310             break;
311         default:
312             if ( m_aValue.m_pValue )
313             {
314                 delete static_cast<Any*>(m_aValue.m_pValue);
315                 m_aValue.m_pValue = nullptr;
316             }
317             break;
318 
319     }
320     m_bNull = true;
321 }
322 
operator =(const ORowSetValue & _rRH)323 ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
324 {
325     if(&_rRH == this)
326         return *this;
327 
328     if ( m_eTypeKind != _rRH.m_eTypeKind || (_rRH.m_bNull && !m_bNull) || m_bSigned != _rRH.m_bSigned)
329         free();
330 
331     m_bBound    = _rRH.m_bBound;
332     m_eTypeKind = _rRH.m_eTypeKind;
333     m_bSigned   = _rRH.m_bSigned;
334 
335     if(m_bNull && !_rRH.m_bNull)
336     {
337         switch(_rRH.m_eTypeKind)
338         {
339             case DataType::CHAR:
340             case DataType::VARCHAR:
341             case DataType::DECIMAL:
342             case DataType::NUMERIC:
343             case DataType::LONGVARCHAR:
344                 rtl_uString_acquire(_rRH.m_aValue.m_pString);
345                 m_aValue.m_pString = _rRH.m_aValue.m_pString;
346                 break;
347             case DataType::DATE:
348                 m_aValue.m_pValue   = new Date(*static_cast<Date*>(_rRH.m_aValue.m_pValue));
349                 break;
350             case DataType::TIME:
351                 m_aValue.m_pValue   = new Time(*static_cast<Time*>(_rRH.m_aValue.m_pValue));
352                 break;
353             case DataType::TIMESTAMP:
354                 m_aValue.m_pValue   = new DateTime(*static_cast<DateTime*>(_rRH.m_aValue.m_pValue));
355                 break;
356             case DataType::BINARY:
357             case DataType::VARBINARY:
358             case DataType::LONGVARBINARY:
359                 m_aValue.m_pValue   = new Sequence<sal_Int8>(*static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue));
360                 break;
361             case DataType::BIT:
362             case DataType::BOOLEAN:
363                 m_aValue.m_bBool    = _rRH.m_aValue.m_bBool;
364                 break;
365             case DataType::TINYINT:
366                 if ( _rRH.m_bSigned )
367                     m_aValue.m_nInt8    = _rRH.m_aValue.m_nInt8;
368                 else
369                     m_aValue.m_uInt8    = _rRH.m_aValue.m_uInt8;
370                 break;
371             case DataType::SMALLINT:
372                 if ( _rRH.m_bSigned )
373                     m_aValue.m_nInt16   = _rRH.m_aValue.m_nInt16;
374                 else
375                     m_aValue.m_uInt16   = _rRH.m_aValue.m_uInt16;
376                 break;
377             case DataType::INTEGER:
378                 if ( _rRH.m_bSigned )
379                     m_aValue.m_nInt32   = _rRH.m_aValue.m_nInt32;
380                 else
381                     m_aValue.m_uInt32   = _rRH.m_aValue.m_uInt32;
382                 break;
383             case DataType::BIGINT:
384                 if ( _rRH.m_bSigned )
385                     m_aValue.m_nInt64   = _rRH.m_aValue.m_nInt64;
386                 else
387                     m_aValue.m_uInt64   = _rRH.m_aValue.m_uInt64;
388                 break;
389             case DataType::FLOAT:
390                 m_aValue.m_nFloat  = _rRH.m_aValue.m_nFloat;
391                 break;
392             case DataType::DOUBLE:
393             case DataType::REAL:
394                 m_aValue.m_nDouble  = _rRH.m_aValue.m_nDouble;
395                 break;
396             default:
397                 m_aValue.m_pValue   = new Any(*static_cast<Any*>(_rRH.m_aValue.m_pValue));
398         }
399     }
400     else if(!_rRH.m_bNull)
401     {
402         switch(_rRH.m_eTypeKind)
403         {
404             case DataType::CHAR:
405             case DataType::VARCHAR:
406             case DataType::DECIMAL:
407             case DataType::NUMERIC:
408             case DataType::LONGVARCHAR:
409                 (*this) = OUString(_rRH.m_aValue.m_pString);
410                 break;
411             case DataType::DATE:
412                 (*this) = *static_cast<Date*>(_rRH.m_aValue.m_pValue);
413                 break;
414             case DataType::TIME:
415                 (*this) = *static_cast<Time*>(_rRH.m_aValue.m_pValue);
416                 break;
417             case DataType::TIMESTAMP:
418                 (*this) = *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
419                 break;
420             case DataType::BINARY:
421             case DataType::VARBINARY:
422             case DataType::LONGVARBINARY:
423                 (*this) = *static_cast<Sequence<sal_Int8>*>(_rRH.m_aValue.m_pValue);
424                 break;
425             case DataType::BIT:
426             case DataType::BOOLEAN:
427                 m_aValue.m_bBool    = _rRH.m_aValue.m_bBool;
428                 break;
429             case DataType::TINYINT:
430                 if ( _rRH.m_bSigned )
431                     m_aValue.m_nInt8    = _rRH.m_aValue.m_nInt8;
432                 else
433                     m_aValue.m_uInt8    = _rRH.m_aValue.m_uInt8;
434                 break;
435             case DataType::SMALLINT:
436                 if ( _rRH.m_bSigned )
437                     m_aValue.m_nInt16   = _rRH.m_aValue.m_nInt16;
438                 else
439                     m_aValue.m_uInt16   = _rRH.m_aValue.m_uInt16;
440                 break;
441             case DataType::INTEGER:
442                 if ( _rRH.m_bSigned )
443                     m_aValue.m_nInt32   = _rRH.m_aValue.m_nInt32;
444                 else
445                     m_aValue.m_uInt32   = _rRH.m_aValue.m_uInt32;
446                 break;
447             case DataType::BIGINT:
448                 if ( _rRH.m_bSigned )
449                     m_aValue.m_nInt64   = _rRH.m_aValue.m_nInt64;
450                 else
451                     m_aValue.m_uInt64   = _rRH.m_aValue.m_uInt64;
452                 break;
453             case DataType::FLOAT:
454                 m_aValue.m_nFloat  = _rRH.m_aValue.m_nFloat;
455                 break;
456             case DataType::DOUBLE:
457             case DataType::REAL:
458                 m_aValue.m_nDouble  = _rRH.m_aValue.m_nDouble;
459                 break;
460             default:
461                 *static_cast<Any*>(m_aValue.m_pValue) = *static_cast<Any*>(_rRH.m_aValue.m_pValue);
462         }
463     }
464 
465     m_bNull     = _rRH.m_bNull;
466     // OJ: BUGID: 96277
467     m_eTypeKind = _rRH.m_eTypeKind;
468 
469     return *this;
470 }
471 
operator =(ORowSetValue && _rRH)472 ORowSetValue& ORowSetValue::operator=(ORowSetValue&& _rRH) noexcept
473 {
474     if ( m_eTypeKind != _rRH.m_eTypeKind || !m_bNull)
475         free();
476     if(!_rRH.m_bNull)
477     {
478         m_aValue    = _rRH.m_aValue;
479         memset(&_rRH.m_aValue, 0, sizeof(_rRH.m_aValue));
480     }
481     m_bBound    = _rRH.m_bBound;
482     m_eTypeKind = _rRH.m_eTypeKind;
483     m_bSigned   = _rRH.m_bSigned;
484     m_bNull     = _rRH.m_bNull;
485     _rRH.m_bNull = true;
486     return *this;
487 }
488 
489 
operator =(const Date & _rRH)490 ORowSetValue& ORowSetValue::operator=(const Date& _rRH)
491 {
492     if(m_eTypeKind != DataType::DATE)
493         free();
494 
495     if(m_bNull)
496     {
497         m_aValue.m_pValue = new Date(_rRH);
498         m_eTypeKind = DataType::DATE;
499         m_bNull = false;
500     }
501     else
502         *static_cast<Date*>(m_aValue.m_pValue) = _rRH;
503 
504     return *this;
505 }
506 
operator =(const css::util::Time & _rRH)507 ORowSetValue& ORowSetValue::operator=(const css::util::Time& _rRH)
508 {
509     if(m_eTypeKind != DataType::TIME)
510         free();
511 
512     if(m_bNull)
513     {
514         m_aValue.m_pValue = new Time(_rRH);
515         m_eTypeKind = DataType::TIME;
516         m_bNull = false;
517     }
518     else
519         *static_cast<Time*>(m_aValue.m_pValue) = _rRH;
520 
521     return *this;
522 }
523 
operator =(const DateTime & _rRH)524 ORowSetValue& ORowSetValue::operator=(const DateTime& _rRH)
525 {
526     if(m_eTypeKind != DataType::TIMESTAMP)
527         free();
528     if(m_bNull)
529     {
530         m_aValue.m_pValue = new DateTime(_rRH);
531         m_eTypeKind = DataType::TIMESTAMP;
532         m_bNull = false;
533     }
534     else
535         *static_cast<DateTime*>(m_aValue.m_pValue) = _rRH;
536 
537     return *this;
538 }
539 
540 
operator =(const OUString & _rRH)541 ORowSetValue& ORowSetValue::operator=(const OUString& _rRH)
542 {
543     if(m_eTypeKind != DataType::VARCHAR || m_aValue.m_pString != _rRH.pData)
544     {
545         free();
546         m_bNull = false;
547 
548         m_aValue.m_pString = _rRH.pData;
549         rtl_uString_acquire(m_aValue.m_pString);
550         m_eTypeKind = DataType::VARCHAR;
551     }
552 
553     return *this;
554 }
555 
556 
operator =(double _rRH)557 ORowSetValue& ORowSetValue::operator=(double _rRH)
558 {
559     if(m_eTypeKind != DataType::DOUBLE)
560         free();
561 
562     m_aValue.m_nDouble = _rRH;
563     m_eTypeKind = DataType::DOUBLE;
564     m_bNull = false;
565 
566     return *this;
567 }
568 
operator =(float _rRH)569 ORowSetValue& ORowSetValue::operator=(float _rRH)
570 {
571     if(m_eTypeKind != DataType::FLOAT)
572         free();
573 
574     m_aValue.m_nFloat = _rRH;
575     m_eTypeKind = DataType::FLOAT;
576     m_bNull = false;
577 
578     return *this;
579 }
580 
581 
operator =(sal_Int8 _rRH)582 ORowSetValue& ORowSetValue::operator=(sal_Int8 _rRH)
583 {
584     if(m_eTypeKind != DataType::TINYINT )
585         free();
586 
587     m_aValue.m_nInt8 = _rRH;
588     m_eTypeKind = DataType::TINYINT;
589     m_bNull = false;
590     m_bSigned = true;
591     return *this;
592 }
593 
operator =(sal_Int16 _rRH)594 ORowSetValue& ORowSetValue::operator=(sal_Int16 _rRH)
595 {
596     if(m_eTypeKind != DataType::SMALLINT )
597         free();
598 
599     m_aValue.m_nInt16 = _rRH;
600     m_eTypeKind = DataType::SMALLINT;
601     m_bNull = false;
602     m_bSigned = true;
603 
604     return *this;
605 }
606 
607 
operator =(sal_uInt16 _rRH)608 ORowSetValue& ORowSetValue::operator=(sal_uInt16 _rRH)
609 {
610     if(m_eTypeKind != DataType::SMALLINT )
611         free();
612 
613     m_aValue.m_uInt16 = _rRH;
614     m_eTypeKind = DataType::SMALLINT;
615     m_bNull = false;
616     m_bSigned = false;
617 
618     return *this;
619 }
620 
621 
operator =(sal_Int32 _rRH)622 ORowSetValue& ORowSetValue::operator=(sal_Int32 _rRH)
623 {
624     if(m_eTypeKind != DataType::INTEGER )
625         free();
626 
627     m_aValue.m_nInt32 = _rRH;
628 
629     m_eTypeKind = DataType::INTEGER;
630     m_bNull = false;
631     m_bSigned = true;
632 
633     return *this;
634 }
635 
636 
operator =(sal_uInt32 _rRH)637 ORowSetValue& ORowSetValue::operator=(sal_uInt32 _rRH)
638 {
639     if(m_eTypeKind != DataType::INTEGER )
640         free();
641 
642     m_aValue.m_uInt32 = _rRH;
643 
644     m_eTypeKind = DataType::INTEGER;
645     m_bNull = false;
646     m_bSigned = false;
647 
648     return *this;
649 }
650 
651 
operator =(const bool _rRH)652 ORowSetValue& ORowSetValue::operator=(const bool _rRH)
653 {
654     if(m_eTypeKind != DataType::BIT && DataType::BOOLEAN != m_eTypeKind )
655         free();
656 
657     m_aValue.m_bBool = _rRH;
658     m_eTypeKind = DataType::BOOLEAN;
659     m_bNull = false;
660 
661     return *this;
662 }
663 
operator =(sal_Int64 _rRH)664 ORowSetValue& ORowSetValue::operator=(sal_Int64 _rRH)
665 {
666     if ( DataType::BIGINT != m_eTypeKind)
667         free();
668 
669     m_aValue.m_nInt64 = _rRH;
670     m_eTypeKind = DataType::BIGINT;
671     m_bNull = false;
672     m_bSigned = true;
673 
674     return *this;
675 }
676 
operator =(sal_uInt64 _rRH)677 ORowSetValue& ORowSetValue::operator=(sal_uInt64 _rRH)
678 {
679     if ( DataType::BIGINT != m_eTypeKind)
680         free();
681 
682     m_aValue.m_uInt64 = _rRH;
683     m_eTypeKind = DataType::BIGINT;
684     m_bNull = false;
685     m_bSigned = false;
686 
687     return *this;
688 }
689 
operator =(const Sequence<sal_Int8> & _rRH)690 ORowSetValue& ORowSetValue::operator=(const Sequence<sal_Int8>& _rRH)
691 {
692     if (!isStorageCompatible(DataType::LONGVARBINARY,m_eTypeKind))
693         free();
694 
695     if (m_bNull)
696     {
697         m_aValue.m_pValue = new Sequence<sal_Int8>(_rRH);
698     }
699     else
700         *static_cast< Sequence< sal_Int8 >* >(m_aValue.m_pValue) = _rRH;
701 
702     m_eTypeKind = DataType::LONGVARBINARY;
703     m_bNull = false;
704 
705     return *this;
706 }
707 
operator =(const Any & _rAny)708 ORowSetValue& ORowSetValue::operator=(const Any& _rAny)
709 {
710     if (!isStorageCompatible(DataType::OBJECT,m_eTypeKind))
711         free();
712 
713     if ( m_bNull )
714     {
715         m_aValue.m_pValue = new Any(_rAny);
716     }
717     else
718         *static_cast<Any*>(m_aValue.m_pValue) = _rAny;
719 
720     m_eTypeKind = DataType::OBJECT;
721     m_bNull = false;
722 
723     return *this;
724 }
725 
726 
operator ==(const ORowSetValue & _rRH) const727 bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
728 {
729     if ( m_bNull != _rRH.isNull() )
730         return false;
731 
732     if(m_bNull && _rRH.isNull())
733         return true;
734 
735     if ( !isStorageComparable(m_eTypeKind, _rRH.m_eTypeKind ))
736     {
737         switch(m_eTypeKind)
738         {
739             case DataType::FLOAT:
740             case DataType::DOUBLE:
741             case DataType::REAL:
742                 return getDouble() == _rRH.getDouble();
743             default:
744                 switch(_rRH.m_eTypeKind)
745                 {
746                     case DataType::FLOAT:
747                     case DataType::DOUBLE:
748                     case DataType::REAL:
749                             return getDouble() == _rRH.getDouble();
750                     default:
751                             break;
752                 }
753                 break;
754         }
755         return false;
756     }
757 
758     bool bRet = false;
759     OSL_ENSURE(!m_bNull,"Should not be null!");
760     switch(m_eTypeKind)
761     {
762         case DataType::VARCHAR:
763         case DataType::CHAR:
764         case DataType::LONGVARCHAR:
765         {
766             OUString aVal1(m_aValue.m_pString);
767             OUString aVal2(_rRH.m_aValue.m_pString);
768             return aVal1 == aVal2;
769         }
770         default:
771             if ( m_bSigned != _rRH.m_bSigned )
772                 return false;
773             break;
774     }
775 
776     switch(m_eTypeKind)
777     {
778         case DataType::DECIMAL:
779         case DataType::NUMERIC:
780             {
781                 OUString aVal1(m_aValue.m_pString);
782                 OUString aVal2(_rRH.m_aValue.m_pString);
783                 bRet = aVal1 == aVal2;
784             }
785             break;
786         case DataType::FLOAT:
787             bRet = m_aValue.m_nFloat == _rRH.m_aValue.m_nFloat;
788             break;
789         case DataType::DOUBLE:
790         case DataType::REAL:
791             bRet = m_aValue.m_nDouble == _rRH.m_aValue.m_nDouble;
792             break;
793         case DataType::TINYINT:
794             bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_uInt8 == _rRH.m_aValue.m_uInt8);
795             break;
796         case DataType::SMALLINT:
797             bRet = m_bSigned ? ( m_aValue.m_nInt16 == _rRH.m_aValue.m_nInt16 ) : (m_aValue.m_uInt16 == _rRH.m_aValue.m_uInt16);
798             break;
799         case DataType::INTEGER:
800             bRet = m_bSigned ? ( m_aValue.m_nInt32 == _rRH.m_aValue.m_nInt32 ) : (m_aValue.m_uInt32 == _rRH.m_aValue.m_uInt32);
801             break;
802         case DataType::BIGINT:
803             bRet = m_bSigned ? ( m_aValue.m_nInt64 == _rRH.m_aValue.m_nInt64 ) : (m_aValue.m_uInt64 == _rRH.m_aValue.m_uInt64);
804             break;
805         case DataType::BIT:
806         case DataType::BOOLEAN:
807             bRet = m_aValue.m_bBool == _rRH.m_aValue.m_bBool;
808             break;
809         case DataType::DATE:
810             bRet = *static_cast<Date*>(m_aValue.m_pValue) == *static_cast<Date*>(_rRH.m_aValue.m_pValue);
811             break;
812         case DataType::TIME:
813             bRet = *static_cast<Time*>(m_aValue.m_pValue) == *static_cast<Time*>(_rRH.m_aValue.m_pValue);
814             break;
815         case DataType::TIMESTAMP:
816             bRet = *static_cast<DateTime*>(m_aValue.m_pValue) == *static_cast<DateTime*>(_rRH.m_aValue.m_pValue);
817             break;
818         case DataType::BINARY:
819         case DataType::VARBINARY:
820         case DataType::LONGVARBINARY:
821             bRet = false;
822             break;
823         case DataType::BLOB:
824         case DataType::CLOB:
825         case DataType::OBJECT:
826         case DataType::OTHER:
827             bRet = false;
828             break;
829         default:
830             bRet = false;
831             SAL_WARN( "connectivity.commontools","ORowSetValue::operator==(): UNSUPPORTED TYPE!");
832             break;
833     }
834     return bRet;
835 }
836 
makeAny() const837 Any ORowSetValue::makeAny() const
838 {
839     Any rValue;
840     if(isBound() && !isNull())
841     {
842         switch(getTypeKind())
843         {
844             case DataType::SQLNULL:
845                 assert(rValue == Any());
846                 break;
847             case DataType::CHAR:
848             case DataType::VARCHAR:
849             case DataType::DECIMAL:
850             case DataType::NUMERIC:
851             case DataType::LONGVARCHAR:
852                 OSL_ENSURE(m_aValue.m_pString,"Value is null!");
853                 rValue <<= OUString(m_aValue.m_pString);
854                 break;
855             case DataType::FLOAT:
856                 rValue <<= m_aValue.m_nFloat;
857                 break;
858             case DataType::DOUBLE:
859             case DataType::REAL:
860                 rValue <<= m_aValue.m_nDouble;
861                 break;
862             case DataType::DATE:
863                 assert(m_aValue.m_pValue && "Value is null!");
864                 rValue <<= *static_cast<Date*>(m_aValue.m_pValue);
865                 break;
866             case DataType::TIME:
867                 assert(m_aValue.m_pValue && "Value is null!");
868                 rValue <<= *static_cast<Time*>(m_aValue.m_pValue);
869                 break;
870             case DataType::TIMESTAMP:
871                 assert(m_aValue.m_pValue && "Value is null!");
872                 rValue <<= *static_cast<DateTime*>(m_aValue.m_pValue);
873                 break;
874             case DataType::BINARY:
875             case DataType::VARBINARY:
876             case DataType::LONGVARBINARY:
877                 assert(m_aValue.m_pValue && "Value is null!");
878                 rValue <<= *static_cast<Sequence<sal_Int8>*>(m_aValue.m_pValue);
879                 break;
880             case DataType::BLOB:
881             case DataType::CLOB:
882             case DataType::OBJECT:
883             case DataType::OTHER:
884                 rValue = getAny();
885                 break;
886             case DataType::BIT:
887             case DataType::BOOLEAN:
888                 rValue <<= m_aValue.m_bBool;
889                 break;
890             case DataType::TINYINT:
891                 if ( m_bSigned )
892                     // TypeClass_BYTE
893                     rValue <<= m_aValue.m_nInt8;
894                 else
895                     // There is no TypeClass_UNSIGNED_BYTE,
896                     // so silently promote it to a 16-bit integer,
897                     // that is TypeClass_UNSIGNED_SHORT
898                     rValue <<= static_cast<sal_uInt16>(m_aValue.m_uInt8);
899                 break;
900             case DataType::SMALLINT:
901                 if ( m_bSigned )
902                     // TypeClass_SHORT
903                     rValue <<= m_aValue.m_nInt16;
904                 else
905                     // TypeClass_UNSIGNED_SHORT
906                     rValue <<= m_aValue.m_uInt16;
907                 break;
908             case DataType::INTEGER:
909                 if ( m_bSigned )
910                     // TypeClass_LONG
911                     rValue <<= m_aValue.m_nInt32;
912                 else
913                     // TypeClass_UNSIGNED_LONG
914                     rValue <<= m_aValue.m_uInt32;
915                 break;
916             case DataType::BIGINT:
917                 if ( m_bSigned )
918                     // TypeClass_HYPER
919                     rValue <<= m_aValue.m_nInt64;
920                 else
921                     // TypeClass_UNSIGNED_HYPER
922                     rValue <<= m_aValue.m_uInt64;
923                 break;
924             default:
925                 SAL_WARN( "connectivity.commontools","ORowSetValue::makeAny(): UNSUPPORTED TYPE!");
926                 rValue = getAny();
927                 break;
928         }
929     }
930     return rValue;
931 }
932 
getString() const933 OUString ORowSetValue::getString( ) const
934 {
935     OUString aRet;
936     if(!m_bNull)
937     {
938         switch(getTypeKind())
939         {
940             case DataType::CHAR:
941             case DataType::VARCHAR:
942             case DataType::DECIMAL:
943             case DataType::NUMERIC:
944             case DataType::LONGVARCHAR:
945                 aRet = m_aValue.m_pString;
946                 break;
947             case DataType::FLOAT:
948                 aRet = OUString::number(getFloat());
949                 break;
950             case DataType::DOUBLE:
951             case DataType::REAL:
952                 aRet = OUString::number(getDouble());
953                 break;
954             case DataType::DATE:
955                 aRet = DBTypeConversion::toDateString(getDate());
956                 break;
957             case DataType::TIME:
958                 aRet = DBTypeConversion::toTimeString(getTime());
959                 break;
960             case DataType::TIMESTAMP:
961                 aRet = DBTypeConversion::toDateTimeString(getDateTime());
962                 break;
963             case DataType::BINARY:
964             case DataType::VARBINARY:
965             case DataType::LONGVARBINARY:
966                 {
967                     OUStringBuffer sVal("0x");
968                     for (sal_Int32 byte : getSequence())
969                         sVal.append(byte, 16);
970                     aRet = sVal.makeStringAndClear();
971                 }
972                 break;
973             case DataType::BIT:
974                 aRet = OUString::number(int(getBool()));
975                 break;
976             case DataType::BOOLEAN:
977                 aRet = OUString::boolean(getBool());
978                 break;
979             case DataType::TINYINT:
980             case DataType::SMALLINT:
981             case DataType::INTEGER:
982                 if ( m_bSigned )
983                     aRet = OUString::number(getInt32());
984                 else
985                     aRet = OUString::number(getUInt32());
986                 break;
987             case DataType::BIGINT:
988                 if ( m_bSigned )
989                     aRet = OUString::number(getLong());
990                 else
991                     aRet = OUString::number(getULong());
992                 break;
993             case DataType::CLOB:
994                 {
995                     Any aValue( getAny() );
996                     Reference< XClob > xClob;
997                     if ( (aValue >>= xClob) && xClob.is() )
998                     {
999                         aRet = xClob->getSubString(1,static_cast<sal_Int32>(xClob->length()) );
1000                     }
1001                 }
1002                 break;
1003             default:
1004                 {
1005                     Any aValue = makeAny();
1006                     aValue >>= aRet;
1007                     break;
1008                 }
1009         }
1010     }
1011     return aRet;
1012 }
1013 
getBool() const1014 bool ORowSetValue::getBool()    const
1015 {
1016     bool bRet = false;
1017     if(!m_bNull)
1018     {
1019         switch(getTypeKind())
1020         {
1021             case DataType::CHAR:
1022             case DataType::VARCHAR:
1023             case DataType::LONGVARCHAR:
1024                 {
1025                     const OUString sValue(m_aValue.m_pString);
1026                     if ( sValue.equalsIgnoreAsciiCase("true") || (sValue == "1") )
1027                     {
1028                         bRet = true;
1029                         break;
1030                     }
1031                     else if ( sValue.equalsIgnoreAsciiCase("false") || (sValue == "0") )
1032                     {
1033                         bRet = false;
1034                         break;
1035                     }
1036                 }
1037                 [[fallthrough]];
1038             case DataType::DECIMAL:
1039             case DataType::NUMERIC:
1040 
1041                 bRet = OUString::unacquired(&m_aValue.m_pString).toInt32() != 0;
1042                 break;
1043             case DataType::FLOAT:
1044                 bRet = m_aValue.m_nFloat != 0.0;
1045                 break;
1046             case DataType::DOUBLE:
1047             case DataType::REAL:
1048                 bRet = m_aValue.m_nDouble != 0.0;
1049                 break;
1050             case DataType::DATE:
1051             case DataType::TIME:
1052             case DataType::TIMESTAMP:
1053             case DataType::BINARY:
1054             case DataType::VARBINARY:
1055             case DataType::LONGVARBINARY:
1056                 OSL_FAIL("getBool() for this type is not allowed!");
1057                 break;
1058             case DataType::BIT:
1059             case DataType::BOOLEAN:
1060                 bRet = m_aValue.m_bBool;
1061                 break;
1062             case DataType::TINYINT:
1063                 bRet = m_bSigned ? (m_aValue.m_nInt8  != 0) : (m_aValue.m_uInt8 != 0);
1064                 break;
1065             case DataType::SMALLINT:
1066                 bRet = m_bSigned ? (m_aValue.m_nInt16  != 0) : (m_aValue.m_uInt16 != 0);
1067                 break;
1068             case DataType::INTEGER:
1069                 bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (m_aValue.m_uInt32 != 0);
1070                 break;
1071             case DataType::BIGINT:
1072                 bRet = m_bSigned ? (m_aValue.m_nInt64 != 0) : (m_aValue.m_uInt64 != 0);
1073                 break;
1074             default:
1075                 {
1076                     Any aValue = makeAny();
1077                     aValue >>= bRet;
1078                     break;
1079                 }
1080         }
1081     }
1082     return bRet;
1083 }
1084 
1085 
getInt8() const1086 sal_Int8 ORowSetValue::getInt8()    const
1087 {
1088     sal_Int8 nRet = 0;
1089     if(!m_bNull)
1090     {
1091         switch(getTypeKind())
1092         {
1093             case DataType::CHAR:
1094             case DataType::VARCHAR:
1095             case DataType::DECIMAL:
1096             case DataType::NUMERIC:
1097             case DataType::LONGVARCHAR:
1098                 nRet = sal_Int8(OUString::unacquired(&m_aValue.m_pString).toInt32());
1099                 break;
1100             case DataType::FLOAT:
1101                 nRet = sal_Int8(m_aValue.m_nFloat);
1102                 break;
1103             case DataType::DOUBLE:
1104             case DataType::REAL:
1105                 nRet = sal_Int8(m_aValue.m_nDouble);
1106                 break;
1107             case DataType::DATE:
1108             case DataType::TIME:
1109             case DataType::TIMESTAMP:
1110             case DataType::BINARY:
1111             case DataType::VARBINARY:
1112             case DataType::LONGVARBINARY:
1113             case DataType::BLOB:
1114             case DataType::CLOB:
1115                 OSL_FAIL("getInt8() for this type is not allowed!");
1116                 break;
1117             case DataType::BIT:
1118             case DataType::BOOLEAN:
1119                 nRet = sal_Int8(m_aValue.m_bBool);
1120                 break;
1121             case DataType::TINYINT:
1122                 if ( m_bSigned )
1123                     nRet = m_aValue.m_nInt8;
1124                 else
1125                     nRet = static_cast<sal_Int8>(m_aValue.m_uInt8);
1126                 break;
1127             case DataType::SMALLINT:
1128                 if ( m_bSigned )
1129                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt16);
1130                 else
1131                     nRet = static_cast<sal_Int8>(m_aValue.m_uInt16);
1132                 break;
1133             case DataType::INTEGER:
1134                 if ( m_bSigned )
1135                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt32);
1136                 else
1137                     nRet = static_cast<sal_Int8>(m_aValue.m_uInt32);
1138                 break;
1139             case DataType::BIGINT:
1140                 if ( m_bSigned )
1141                     nRet = static_cast<sal_Int8>(m_aValue.m_nInt64);
1142                 else
1143                     nRet = static_cast<sal_Int8>(m_aValue.m_uInt64);
1144                 break;
1145             default:
1146                 {
1147                     Any aValue = makeAny();
1148                     aValue >>= nRet;
1149                     break;
1150                 }
1151         }
1152     }
1153     return nRet;
1154 }
1155 
1156 
getUInt8() const1157 sal_uInt8 ORowSetValue::getUInt8()    const
1158 {
1159     sal_uInt8 nRet = 0;
1160     if(!m_bNull)
1161     {
1162         switch(getTypeKind())
1163         {
1164             case DataType::CHAR:
1165             case DataType::VARCHAR:
1166             case DataType::DECIMAL:
1167             case DataType::NUMERIC:
1168             case DataType::LONGVARCHAR:
1169                 nRet = sal_uInt8(OUString::unacquired(&m_aValue.m_pString).toInt32());
1170                 break;
1171             case DataType::FLOAT:
1172                 nRet = sal_uInt8(m_aValue.m_nFloat);
1173                 break;
1174             case DataType::DOUBLE:
1175             case DataType::REAL:
1176                 nRet = sal_uInt8(m_aValue.m_nDouble);
1177                 break;
1178             case DataType::DATE:
1179             case DataType::TIME:
1180             case DataType::TIMESTAMP:
1181             case DataType::BINARY:
1182             case DataType::VARBINARY:
1183             case DataType::LONGVARBINARY:
1184             case DataType::BLOB:
1185             case DataType::CLOB:
1186                 OSL_FAIL("getuInt8() for this type is not allowed!");
1187                 break;
1188             case DataType::BIT:
1189             case DataType::BOOLEAN:
1190                 nRet = int(m_aValue.m_bBool);
1191                 break;
1192             case DataType::TINYINT:
1193                 if ( m_bSigned )
1194                     nRet = m_aValue.m_nInt8;
1195                 else
1196                     nRet = m_aValue.m_uInt8;
1197                 break;
1198             case DataType::SMALLINT:
1199                 if ( m_bSigned )
1200                     nRet = static_cast<sal_uInt8>(m_aValue.m_nInt16);
1201                 else
1202                     nRet = static_cast<sal_uInt8>(m_aValue.m_uInt16);
1203                 break;
1204             case DataType::INTEGER:
1205                 if ( m_bSigned )
1206                     nRet = static_cast<sal_uInt8>(m_aValue.m_nInt32);
1207                 else
1208                     nRet = static_cast<sal_uInt8>(m_aValue.m_uInt32);
1209                 break;
1210             case DataType::BIGINT:
1211                 if ( m_bSigned )
1212                     nRet = static_cast<sal_uInt8>(m_aValue.m_nInt64);
1213                 else
1214                     nRet = static_cast<sal_uInt8>(m_aValue.m_uInt64);
1215                 break;
1216             default:
1217                 {
1218                     Any aValue = makeAny();
1219                     // Cf. "There is no TypeClass_UNSIGNED_BYTE" in makeAny:
1220                     sal_uInt16 n;
1221                     if (aValue >>= n) {
1222                         nRet = static_cast<sal_uInt8>(n);
1223                     }
1224                     break;
1225                 }
1226         }
1227     }
1228     return nRet;
1229 }
1230 
1231 
getInt16() const1232 sal_Int16 ORowSetValue::getInt16()  const
1233 {
1234     sal_Int16 nRet = 0;
1235     if(!m_bNull)
1236     {
1237         switch(getTypeKind())
1238         {
1239             case DataType::CHAR:
1240             case DataType::VARCHAR:
1241             case DataType::DECIMAL:
1242             case DataType::NUMERIC:
1243             case DataType::LONGVARCHAR:
1244                 nRet = sal_Int16(OUString::unacquired(&m_aValue.m_pString).toInt32());
1245                 break;
1246             case DataType::FLOAT:
1247                 nRet = sal_Int16(m_aValue.m_nFloat);
1248                 break;
1249             case DataType::DOUBLE:
1250             case DataType::REAL:
1251                 nRet = sal_Int16(m_aValue.m_nDouble);
1252                 break;
1253             case DataType::DATE:
1254             case DataType::TIME:
1255             case DataType::TIMESTAMP:
1256             case DataType::BINARY:
1257             case DataType::VARBINARY:
1258             case DataType::LONGVARBINARY:
1259             case DataType::BLOB:
1260             case DataType::CLOB:
1261                 OSL_FAIL("getInt16() for this type is not allowed!");
1262                 break;
1263             case DataType::BIT:
1264             case DataType::BOOLEAN:
1265                 nRet = sal_Int16(m_aValue.m_bBool);
1266                 break;
1267             case DataType::TINYINT:
1268                 if ( m_bSigned )
1269                     nRet = m_aValue.m_nInt8;
1270                 else
1271                     nRet = m_aValue.m_uInt8;
1272                 break;
1273             case DataType::SMALLINT:
1274                 if ( m_bSigned )
1275                     nRet = m_aValue.m_nInt16;
1276                 else
1277                     nRet = static_cast<sal_Int16>(m_aValue.m_uInt16);
1278                 break;
1279             case DataType::INTEGER:
1280                 if ( m_bSigned )
1281                     nRet = static_cast<sal_Int16>(m_aValue.m_nInt32);
1282                 else
1283                     nRet = static_cast<sal_Int16>(m_aValue.m_uInt32);
1284                 break;
1285             case DataType::BIGINT:
1286                 if ( m_bSigned )
1287                     nRet = static_cast<sal_Int16>(m_aValue.m_nInt64);
1288                 else
1289                     nRet = static_cast<sal_Int16>(m_aValue.m_uInt64);
1290                 break;
1291             default:
1292                 {
1293                     Any aValue = makeAny();
1294                     aValue >>= nRet;
1295                     break;
1296                 }
1297         }
1298     }
1299     return nRet;
1300 }
1301 
1302 
getUInt16() const1303 sal_uInt16 ORowSetValue::getUInt16()  const
1304 {
1305     sal_uInt16 nRet = 0;
1306     if(!m_bNull)
1307     {
1308         switch(getTypeKind())
1309         {
1310             case DataType::CHAR:
1311             case DataType::VARCHAR:
1312             case DataType::DECIMAL:
1313             case DataType::NUMERIC:
1314             case DataType::LONGVARCHAR:
1315                 nRet = sal_uInt16(OUString::unacquired(&m_aValue.m_pString).toInt32());
1316                 break;
1317             case DataType::FLOAT:
1318                 nRet = sal_uInt16(m_aValue.m_nFloat);
1319                 break;
1320             case DataType::DOUBLE:
1321             case DataType::REAL:
1322                 nRet = sal_uInt16(m_aValue.m_nDouble);
1323                 break;
1324             case DataType::DATE:
1325             case DataType::TIME:
1326             case DataType::TIMESTAMP:
1327             case DataType::BINARY:
1328             case DataType::VARBINARY:
1329             case DataType::LONGVARBINARY:
1330             case DataType::BLOB:
1331             case DataType::CLOB:
1332                 OSL_FAIL("getuInt16() for this type is not allowed!");
1333                 break;
1334             case DataType::BIT:
1335             case DataType::BOOLEAN:
1336                 nRet = sal_uInt16(m_aValue.m_bBool);
1337                 break;
1338             case DataType::TINYINT:
1339                 if ( m_bSigned )
1340                     nRet = m_aValue.m_nInt8;
1341                 else
1342                     nRet = m_aValue.m_uInt8;
1343                 break;
1344             case DataType::SMALLINT:
1345                 if ( m_bSigned )
1346                     nRet = m_aValue.m_nInt16;
1347                 else
1348                     nRet = m_aValue.m_uInt16;
1349                 break;
1350             case DataType::INTEGER:
1351                 if ( m_bSigned )
1352                     nRet = static_cast<sal_uInt16>(m_aValue.m_nInt32);
1353                 else
1354                     nRet = static_cast<sal_uInt16>(m_aValue.m_uInt32);
1355                 break;
1356             case DataType::BIGINT:
1357                 if ( m_bSigned )
1358                     nRet = static_cast<sal_uInt16>(m_aValue.m_nInt64);
1359                 else
1360                     nRet = static_cast<sal_uInt16>(m_aValue.m_uInt64);
1361                 break;
1362             default:
1363                 {
1364                     Any aValue = makeAny();
1365                     aValue >>= nRet;
1366                     break;
1367                 }
1368         }
1369     }
1370     return nRet;
1371 }
1372 
1373 
getInt32() const1374 sal_Int32 ORowSetValue::getInt32()  const
1375 {
1376     sal_Int32 nRet = 0;
1377     if(!m_bNull)
1378     {
1379         switch(getTypeKind())
1380         {
1381             case DataType::CHAR:
1382             case DataType::VARCHAR:
1383             case DataType::DECIMAL:
1384             case DataType::NUMERIC:
1385             case DataType::LONGVARCHAR:
1386                 nRet = OUString::unacquired(&m_aValue.m_pString).toInt32();
1387                 break;
1388             case DataType::FLOAT:
1389                 nRet = sal_Int32(m_aValue.m_nFloat);
1390                 break;
1391             case DataType::DOUBLE:
1392             case DataType::REAL:
1393                 nRet = sal_Int32(m_aValue.m_nDouble);
1394                 break;
1395             case DataType::DATE:
1396                 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1397                 break;
1398             case DataType::TIME:
1399             case DataType::TIMESTAMP:
1400             case DataType::BINARY:
1401             case DataType::VARBINARY:
1402             case DataType::LONGVARBINARY:
1403             case DataType::BLOB:
1404             case DataType::CLOB:
1405                 OSL_FAIL("getInt32() for this type is not allowed!");
1406                 break;
1407             case DataType::BIT:
1408             case DataType::BOOLEAN:
1409                 nRet = sal_Int32(m_aValue.m_bBool);
1410                 break;
1411             case DataType::TINYINT:
1412                 if ( m_bSigned )
1413                     nRet = m_aValue.m_nInt8;
1414                 else
1415                     nRet = m_aValue.m_uInt8;
1416                 break;
1417             case DataType::SMALLINT:
1418                 if ( m_bSigned )
1419                     nRet = m_aValue.m_nInt16;
1420                 else
1421                     nRet = m_aValue.m_uInt16;
1422                 break;
1423             case DataType::INTEGER:
1424                 if ( m_bSigned )
1425                     nRet = m_aValue.m_nInt32;
1426                 else
1427                     nRet = static_cast<sal_Int32>(m_aValue.m_uInt32);
1428                 break;
1429             case DataType::BIGINT:
1430                 if ( m_bSigned )
1431                     nRet = static_cast<sal_Int32>(m_aValue.m_nInt64);
1432                 else
1433                     nRet = static_cast<sal_Int32>(m_aValue.m_uInt64);
1434                 break;
1435             default:
1436                 {
1437                     Any aValue = makeAny();
1438                     aValue >>= nRet;
1439                     break;
1440                 }
1441         }
1442     }
1443     return nRet;
1444 }
1445 
1446 
getUInt32() const1447 sal_uInt32 ORowSetValue::getUInt32()  const
1448 {
1449     sal_uInt32 nRet = 0;
1450     if(!m_bNull)
1451     {
1452         switch(getTypeKind())
1453         {
1454             case DataType::CHAR:
1455             case DataType::VARCHAR:
1456             case DataType::DECIMAL:
1457             case DataType::NUMERIC:
1458             case DataType::LONGVARCHAR:
1459                 nRet = OUString::unacquired(&m_aValue.m_pString).toUInt32();
1460                 break;
1461             case DataType::FLOAT:
1462                 nRet = sal_uInt32(m_aValue.m_nFloat);
1463                 break;
1464             case DataType::DOUBLE:
1465             case DataType::REAL:
1466                 nRet = sal_uInt32(m_aValue.m_nDouble);
1467                 break;
1468             case DataType::DATE:
1469                 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1470                 break;
1471             case DataType::TIME:
1472             case DataType::TIMESTAMP:
1473             case DataType::BINARY:
1474             case DataType::VARBINARY:
1475             case DataType::LONGVARBINARY:
1476             case DataType::BLOB:
1477             case DataType::CLOB:
1478                 OSL_FAIL("getuInt32() for this type is not allowed!");
1479                 break;
1480             case DataType::BIT:
1481             case DataType::BOOLEAN:
1482                 nRet = sal_uInt32(m_aValue.m_bBool);
1483                 break;
1484             case DataType::TINYINT:
1485                 if ( m_bSigned )
1486                     nRet = m_aValue.m_nInt8;
1487                 else
1488                     nRet = m_aValue.m_uInt8;
1489                 break;
1490             case DataType::SMALLINT:
1491                 if ( m_bSigned )
1492                     nRet = m_aValue.m_nInt16;
1493                 else
1494                     nRet = m_aValue.m_uInt16;
1495                 break;
1496             case DataType::INTEGER:
1497                 if ( m_bSigned )
1498                     nRet = m_aValue.m_nInt32;
1499                 else
1500                     nRet = m_aValue.m_uInt32;
1501                 break;
1502             case DataType::BIGINT:
1503                 if ( m_bSigned )
1504                     nRet = static_cast<sal_uInt32>(m_aValue.m_nInt64);
1505                 else
1506                     nRet = static_cast<sal_uInt32>(m_aValue.m_uInt64);
1507                 break;
1508             default:
1509                 {
1510                     Any aValue = makeAny();
1511                     aValue >>= nRet;
1512                     break;
1513                 }
1514         }
1515     }
1516     return nRet;
1517 }
1518 
1519 
getLong() const1520 sal_Int64 ORowSetValue::getLong()   const
1521 {
1522     sal_Int64 nRet = 0;
1523     if(!m_bNull)
1524     {
1525         switch(getTypeKind())
1526         {
1527             case DataType::CHAR:
1528             case DataType::VARCHAR:
1529             case DataType::DECIMAL:
1530             case DataType::NUMERIC:
1531             case DataType::LONGVARCHAR:
1532                 nRet = OUString::unacquired(&m_aValue.m_pString).toInt64();
1533                 break;
1534             case DataType::FLOAT:
1535                 nRet = sal_Int64(m_aValue.m_nFloat);
1536                 break;
1537             case DataType::DOUBLE:
1538             case DataType::REAL:
1539                 nRet = sal_Int64(m_aValue.m_nDouble);
1540                 break;
1541             case DataType::DATE:
1542                 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1543                 break;
1544             case DataType::TIME:
1545             case DataType::TIMESTAMP:
1546             case DataType::BINARY:
1547             case DataType::VARBINARY:
1548             case DataType::LONGVARBINARY:
1549             case DataType::BLOB:
1550             case DataType::CLOB:
1551                 OSL_FAIL("getLong() for this type is not allowed!");
1552                 break;
1553             case DataType::BIT:
1554             case DataType::BOOLEAN:
1555                 nRet = sal_Int64(m_aValue.m_bBool);
1556                 break;
1557             case DataType::TINYINT:
1558                 if ( m_bSigned )
1559                     nRet = m_aValue.m_nInt8;
1560                 else
1561                     nRet = m_aValue.m_uInt8;
1562                 break;
1563             case DataType::SMALLINT:
1564                 if ( m_bSigned )
1565                     nRet = m_aValue.m_nInt16;
1566                 else
1567                     nRet = m_aValue.m_uInt16;
1568                 break;
1569             case DataType::INTEGER:
1570                 if ( m_bSigned )
1571                     nRet = m_aValue.m_nInt32;
1572                 else
1573                     nRet = m_aValue.m_uInt32;
1574                 break;
1575             case DataType::BIGINT:
1576                 if ( m_bSigned )
1577                     nRet = m_aValue.m_nInt64;
1578                 else
1579                     nRet = static_cast<sal_Int64>(m_aValue.m_uInt64);
1580                 break;
1581             default:
1582                 {
1583                     Any aValue = makeAny();
1584                     aValue >>= nRet;
1585                     break;
1586                 }
1587         }
1588     }
1589     return nRet;
1590 }
1591 
1592 
getULong() const1593 sal_uInt64 ORowSetValue::getULong()   const
1594 {
1595     sal_uInt64 nRet = 0;
1596     if(!m_bNull)
1597     {
1598         switch(getTypeKind())
1599         {
1600             case DataType::CHAR:
1601             case DataType::VARCHAR:
1602             case DataType::DECIMAL:
1603             case DataType::NUMERIC:
1604             case DataType::LONGVARCHAR:
1605                 nRet = OUString::unacquired(&m_aValue.m_pString).toUInt64();
1606                 break;
1607             case DataType::FLOAT:
1608                 nRet = sal_uInt64(m_aValue.m_nFloat);
1609                 break;
1610             case DataType::DOUBLE:
1611             case DataType::REAL:
1612                 nRet = sal_uInt64(m_aValue.m_nDouble);
1613                 break;
1614             case DataType::DATE:
1615                 nRet = dbtools::DBTypeConversion::toDays(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1616                 break;
1617             case DataType::TIME:
1618             case DataType::TIMESTAMP:
1619             case DataType::BINARY:
1620             case DataType::VARBINARY:
1621             case DataType::LONGVARBINARY:
1622             case DataType::BLOB:
1623             case DataType::CLOB:
1624                 OSL_FAIL("getULong() for this type is not allowed!");
1625                 break;
1626             case DataType::BIT:
1627             case DataType::BOOLEAN:
1628                 nRet = sal_uInt64(m_aValue.m_bBool);
1629                 break;
1630             case DataType::TINYINT:
1631                 if ( m_bSigned )
1632                     nRet = m_aValue.m_nInt8;
1633                 else
1634                     nRet = m_aValue.m_uInt8;
1635                 break;
1636             case DataType::SMALLINT:
1637                 if ( m_bSigned )
1638                     nRet = m_aValue.m_nInt16;
1639                 else
1640                     nRet = m_aValue.m_uInt16;
1641                 break;
1642             case DataType::INTEGER:
1643                 if ( m_bSigned )
1644                     nRet = m_aValue.m_nInt32;
1645                 else
1646                     nRet = m_aValue.m_uInt32;
1647                 break;
1648             case DataType::BIGINT:
1649                 if ( m_bSigned )
1650                     nRet = m_aValue.m_nInt64;
1651                 else
1652                     nRet = m_aValue.m_uInt64;
1653                 break;
1654             default:
1655                 {
1656                     Any aValue = makeAny();
1657                     aValue >>= nRet;
1658                     break;
1659                 }
1660         }
1661     }
1662     return nRet;
1663 }
1664 
1665 
getFloat() const1666 float ORowSetValue::getFloat()  const
1667 {
1668     float nRet = 0;
1669     if(!m_bNull)
1670     {
1671         switch(getTypeKind())
1672         {
1673             case DataType::CHAR:
1674             case DataType::VARCHAR:
1675             case DataType::DECIMAL:
1676             case DataType::NUMERIC:
1677             case DataType::LONGVARCHAR:
1678                 nRet = OUString::unacquired(&m_aValue.m_pString).toFloat();
1679                 break;
1680             case DataType::FLOAT:
1681                 nRet = m_aValue.m_nFloat;
1682                 break;
1683             case DataType::DOUBLE:
1684             case DataType::REAL:
1685                 nRet = static_cast<float>(m_aValue.m_nDouble);
1686                 break;
1687             case DataType::DATE:
1688                 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue)));
1689                 break;
1690             case DataType::TIME:
1691                 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue)));
1692                 break;
1693             case DataType::TIMESTAMP:
1694                 nRet = static_cast<float>(dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue)));
1695                 break;
1696             case DataType::BINARY:
1697             case DataType::VARBINARY:
1698             case DataType::LONGVARBINARY:
1699             case DataType::BLOB:
1700             case DataType::CLOB:
1701                 OSL_FAIL("getDouble() for this type is not allowed!");
1702                 break;
1703             case DataType::BIT:
1704             case DataType::BOOLEAN:
1705                 nRet = float(m_aValue.m_bBool);
1706                 break;
1707             case DataType::TINYINT:
1708                 if ( m_bSigned )
1709                     nRet = m_aValue.m_nInt8;
1710                 else
1711                     nRet = m_aValue.m_uInt8;
1712                 break;
1713             case DataType::SMALLINT:
1714                 if ( m_bSigned )
1715                     nRet = m_aValue.m_nInt16;
1716                 else
1717                     nRet = static_cast<float>(m_aValue.m_uInt16);
1718                 break;
1719             case DataType::INTEGER:
1720                 if ( m_bSigned )
1721                     nRet = static_cast<float>(m_aValue.m_nInt32);
1722                 else
1723                     nRet = static_cast<float>(m_aValue.m_uInt32);
1724                 break;
1725             case DataType::BIGINT:
1726                 if ( m_bSigned )
1727                     nRet = static_cast<float>(m_aValue.m_nInt64);
1728                 else
1729                     nRet = static_cast<float>(m_aValue.m_uInt64);
1730                 break;
1731             default:
1732                 {
1733                     Any aValue = makeAny();
1734                     aValue >>= nRet;
1735                     break;
1736                 }
1737         }
1738     }
1739     return nRet;
1740 }
1741 
getDouble() const1742 double ORowSetValue::getDouble()    const
1743 {
1744     double nRet = 0;
1745     if(!m_bNull)
1746     {
1747         switch(getTypeKind())
1748         {
1749             case DataType::CHAR:
1750             case DataType::VARCHAR:
1751             case DataType::DECIMAL:
1752             case DataType::NUMERIC:
1753             case DataType::LONGVARCHAR:
1754                 nRet = OUString::unacquired(&m_aValue.m_pString).toDouble();
1755                 break;
1756             case DataType::FLOAT:
1757                 nRet = m_aValue.m_nFloat;
1758                 break;
1759             case DataType::DOUBLE:
1760             case DataType::REAL:
1761                 nRet = m_aValue.m_nDouble;
1762                 break;
1763             case DataType::DATE:
1764                 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Date*>(m_aValue.m_pValue));
1765                 break;
1766             case DataType::TIME:
1767                 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::Time*>(m_aValue.m_pValue));
1768                 break;
1769             case DataType::TIMESTAMP:
1770                 nRet = dbtools::DBTypeConversion::toDouble(*static_cast<css::util::DateTime*>(m_aValue.m_pValue));
1771                 break;
1772             case DataType::BINARY:
1773             case DataType::VARBINARY:
1774             case DataType::LONGVARBINARY:
1775             case DataType::BLOB:
1776             case DataType::CLOB:
1777                 OSL_FAIL("getDouble() for this type is not allowed!");
1778                 break;
1779             case DataType::BIT:
1780             case DataType::BOOLEAN:
1781                 nRet = double(m_aValue.m_bBool);
1782                 break;
1783             case DataType::TINYINT:
1784                 if ( m_bSigned )
1785                     nRet = m_aValue.m_nInt8;
1786                 else
1787                     nRet = m_aValue.m_uInt8;
1788                 break;
1789             case DataType::SMALLINT:
1790                 if ( m_bSigned )
1791                     nRet = m_aValue.m_nInt16;
1792                 else
1793                     nRet = m_aValue.m_uInt16;
1794                 break;
1795             case DataType::INTEGER:
1796                 if ( m_bSigned )
1797                     nRet = m_aValue.m_nInt32;
1798                 else
1799                     nRet = m_aValue.m_uInt32;
1800                 break;
1801             case DataType::BIGINT:
1802                 if ( m_bSigned )
1803                     nRet = m_aValue.m_nInt64;
1804                 else
1805                     nRet = m_aValue.m_uInt64;
1806                 break;
1807             default:
1808                 {
1809                     Any aValue = makeAny();
1810                     aValue >>= nRet;
1811                     break;
1812                 }
1813         }
1814     }
1815     return nRet;
1816 }
1817 
getSequence() const1818 Sequence<sal_Int8>  ORowSetValue::getSequence() const
1819 {
1820     Sequence<sal_Int8> aSeq;
1821     if (!m_bNull)
1822     {
1823         switch(m_eTypeKind)
1824         {
1825             case DataType::OBJECT:
1826             case DataType::CLOB:
1827             case DataType::BLOB:
1828             {
1829                 Reference<XInputStream> xStream;
1830                 const Any aValue = makeAny();
1831                 if(aValue.hasValue())
1832                 {
1833                     Reference<XBlob> xBlob(aValue,UNO_QUERY);
1834                     if ( xBlob.is() )
1835                         xStream = xBlob->getBinaryStream();
1836                     else
1837                     {
1838                         Reference<XClob> xClob(aValue,UNO_QUERY);
1839                         if ( xClob.is() )
1840                             xStream = xClob->getCharacterStream();
1841                     }
1842                     if(xStream.is())
1843                     {
1844                         const sal_uInt32    nBytesToRead = 65535;
1845                         sal_uInt32          nRead;
1846 
1847                         do
1848                         {
1849                             css::uno::Sequence< sal_Int8 > aReadSeq;
1850 
1851                             nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead );
1852 
1853                             if( nRead )
1854                             {
1855                                 const sal_uInt32 nOldLength = aSeq.getLength();
1856                                 aSeq.realloc( nOldLength + nRead );
1857                                 memcpy( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() );
1858                             }
1859                         }
1860                         while( nBytesToRead == nRead );
1861                         xStream->closeInput();
1862                     }
1863                 }
1864             }
1865             break;
1866             case DataType::VARCHAR:
1867             case DataType::LONGVARCHAR:
1868                 {
1869                     aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(m_aValue.m_pString->buffer),
1870                                               sizeof(sal_Unicode) * m_aValue.m_pString->length);
1871                 }
1872                 break;
1873             case DataType::BINARY:
1874             case DataType::VARBINARY:
1875             case DataType::LONGVARBINARY:
1876                 aSeq = *static_cast< Sequence<sal_Int8>*>(m_aValue.m_pValue);
1877                 break;
1878             default:
1879                 {
1880                     Any aValue = makeAny();
1881                     aValue >>= aSeq;
1882                     break;
1883                 }
1884         }
1885     }
1886     return aSeq;
1887 
1888 }
1889 
getDate() const1890 css::util::Date ORowSetValue::getDate() const
1891 {
1892     css::util::Date aValue;
1893     if(!m_bNull)
1894     {
1895         switch(m_eTypeKind)
1896         {
1897             case DataType::CHAR:
1898             case DataType::VARCHAR:
1899             case DataType::LONGVARCHAR:
1900                 aValue = DBTypeConversion::toDate(getString());
1901                 break;
1902             case DataType::DECIMAL:
1903             case DataType::NUMERIC:
1904             case DataType::FLOAT:
1905             case DataType::DOUBLE:
1906             case DataType::REAL:
1907                 aValue = DBTypeConversion::toDate(getDouble());
1908                 break;
1909 
1910             case DataType::DATE:
1911                 aValue = *static_cast< css::util::Date*>(m_aValue.m_pValue);
1912                 break;
1913             case DataType::TIMESTAMP:
1914                 {
1915                     css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1916                     aValue.Day      = pDateTime->Day;
1917                     aValue.Month    = pDateTime->Month;
1918                     aValue.Year     = pDateTime->Year;
1919                 }
1920                 break;
1921             case DataType::BIT:
1922             case DataType::BOOLEAN:
1923             case DataType::TINYINT:
1924             case DataType::SMALLINT:
1925             case DataType::INTEGER:
1926             case DataType::BIGINT:
1927                 aValue = DBTypeConversion::toDate( double( getLong() ) );
1928                 break;
1929 
1930             case DataType::BLOB:
1931             case DataType::CLOB:
1932             case DataType::OBJECT:
1933             default:
1934                 OSL_ENSURE( false, "ORowSetValue::getDate: cannot retrieve the data!" );
1935                 [[fallthrough]];
1936 
1937             case DataType::BINARY:
1938             case DataType::VARBINARY:
1939             case DataType::LONGVARBINARY:
1940             case DataType::TIME:
1941                 aValue = DBTypeConversion::toDate( double(0) );
1942                 break;
1943         }
1944     }
1945     return aValue;
1946 }
1947 
getTime() const1948 css::util::Time ORowSetValue::getTime()        const
1949 {
1950     css::util::Time aValue;
1951     if(!m_bNull)
1952     {
1953         switch(m_eTypeKind)
1954         {
1955             case DataType::CHAR:
1956             case DataType::VARCHAR:
1957             case DataType::LONGVARCHAR:
1958                 aValue = DBTypeConversion::toTime(getString());
1959                 break;
1960             case DataType::DECIMAL:
1961             case DataType::NUMERIC:
1962                 aValue = DBTypeConversion::toTime(getDouble());
1963                 break;
1964             case DataType::FLOAT:
1965             case DataType::DOUBLE:
1966             case DataType::REAL:
1967                 aValue = DBTypeConversion::toTime(getDouble());
1968                 break;
1969             case DataType::TIMESTAMP:
1970                 {
1971                     css::util::DateTime* pDateTime = static_cast< css::util::DateTime*>(m_aValue.m_pValue);
1972                     aValue.NanoSeconds      = pDateTime->NanoSeconds;
1973                     aValue.Seconds          = pDateTime->Seconds;
1974                     aValue.Minutes          = pDateTime->Minutes;
1975                     aValue.Hours            = pDateTime->Hours;
1976                 }
1977                 break;
1978             case DataType::TIME:
1979                 aValue = *static_cast< css::util::Time*>(m_aValue.m_pValue);
1980                 break;
1981             default:
1982                 {
1983                     Any aAnyValue = makeAny();
1984                     aAnyValue >>= aValue;
1985                     break;
1986                 }
1987         }
1988     }
1989     return aValue;
1990 }
1991 
getDateTime() const1992 css::util::DateTime ORowSetValue::getDateTime()    const
1993 {
1994     css::util::DateTime aValue;
1995     if(!m_bNull)
1996     {
1997         switch(m_eTypeKind)
1998         {
1999             case DataType::CHAR:
2000             case DataType::VARCHAR:
2001             case DataType::LONGVARCHAR:
2002                 aValue = DBTypeConversion::toDateTime(getString());
2003                 break;
2004             case DataType::DECIMAL:
2005             case DataType::NUMERIC:
2006                 aValue = DBTypeConversion::toDateTime(getDouble());
2007                 break;
2008             case DataType::FLOAT:
2009             case DataType::DOUBLE:
2010             case DataType::REAL:
2011                 aValue = DBTypeConversion::toDateTime(getDouble());
2012                 break;
2013             case DataType::DATE:
2014                 {
2015                     css::util::Date* pDate = static_cast< css::util::Date*>(m_aValue.m_pValue);
2016                     aValue.Day      = pDate->Day;
2017                     aValue.Month    = pDate->Month;
2018                     aValue.Year     = pDate->Year;
2019                 }
2020                 break;
2021             case DataType::TIME:
2022                 {
2023                     css::util::Time* pTime = static_cast< css::util::Time*>(m_aValue.m_pValue);
2024                     aValue.NanoSeconds      = pTime->NanoSeconds;
2025                     aValue.Seconds          = pTime->Seconds;
2026                     aValue.Minutes          = pTime->Minutes;
2027                     aValue.Hours            = pTime->Hours;
2028                 }
2029                 break;
2030             case DataType::TIMESTAMP:
2031                 aValue = *static_cast< css::util::DateTime*>(m_aValue.m_pValue);
2032                 break;
2033             default:
2034                 {
2035                     Any aAnyValue = makeAny();
2036                     aAnyValue >>= aValue;
2037                     break;
2038                 }
2039         }
2040     }
2041     return aValue;
2042 }
2043 
setSigned(bool _bMod)2044 void ORowSetValue::setSigned(bool _bMod)
2045 {
2046     if ( m_bSigned == _bMod )
2047         return;
2048 
2049     m_bSigned = _bMod;
2050     if ( m_bNull )
2051         return;
2052 
2053     sal_Int32 nType = m_eTypeKind;
2054     switch(m_eTypeKind)
2055     {
2056         case DataType::TINYINT:
2057             if ( m_bSigned )
2058                 (*this) = getInt8();
2059             else
2060             {
2061                 m_bSigned = !m_bSigned;
2062                 (*this) = getInt16();
2063                 m_bSigned = !m_bSigned;
2064             }
2065             break;
2066         case DataType::SMALLINT:
2067             if ( m_bSigned )
2068                 (*this) = getInt16();
2069             else
2070             {
2071                 m_bSigned = !m_bSigned;
2072                 (*this) = getInt32();
2073                 m_bSigned = !m_bSigned;
2074             }
2075             break;
2076         case DataType::INTEGER:
2077             if ( m_bSigned )
2078                 (*this) = getInt32();
2079             else
2080             {
2081                 m_bSigned = !m_bSigned;
2082                 (*this) = getLong();
2083                 m_bSigned = !m_bSigned;
2084             }
2085             break;
2086         case DataType::BIGINT:
2087         {
2088             if ( m_bSigned )
2089             {
2090                 auto nTmp = static_cast<sal_Int64>(m_aValue.m_uInt64);
2091                 m_aValue.m_nInt64 = nTmp;
2092             }
2093             else
2094             {
2095                 auto nTmp = static_cast<sal_uInt64>(m_aValue.m_nInt64);
2096                 m_aValue.m_uInt64 = nTmp;
2097             }
2098             break;
2099         }
2100     }
2101     m_eTypeKind = nType;
2102 }
2103 
2104 
2105 namespace detail
2106 {
2107     class SAL_NO_VTABLE IValueSource
2108     {
2109     public:
2110         virtual OUString             getString() const = 0;
2111         virtual bool                        getBoolean() const = 0;
2112         virtual sal_Int8                    getByte() const = 0;
2113         virtual sal_Int16                   getShort() const = 0;
2114         virtual sal_Int32                   getInt() const = 0;
2115         virtual sal_Int64                   getLong() const = 0;
2116         virtual float                       getFloat() const = 0;
2117         virtual double                      getDouble() const = 0;
2118         virtual Date                        getDate() const = 0;
2119         virtual css::util::Time             getTime() const = 0;
2120         virtual DateTime                    getTimestamp() const = 0;
2121         virtual Sequence< sal_Int8 >        getBytes() const = 0;
2122         virtual Reference< XBlob >          getBlob() const = 0;
2123         virtual Reference< XClob >          getClob() const = 0;
2124         virtual Any                         getObject() const = 0;
2125         virtual bool                        wasNull() const = 0;
2126 
~IValueSource()2127         virtual ~IValueSource() { }
2128     };
2129 
2130     namespace {
2131 
2132     class RowValue : public IValueSource
2133     {
2134     public:
RowValue(const Reference<XRow> & _xRow,const sal_Int32 _nPos)2135         RowValue( const Reference< XRow >& _xRow, const sal_Int32 _nPos )
2136             :m_xRow( _xRow )
2137             ,m_nPos( _nPos )
2138         {
2139         }
2140 
2141         // IValueSource
getString() const2142         virtual OUString             getString() const override           { return m_xRow->getString( m_nPos ); };
getBoolean() const2143         virtual bool                        getBoolean() const override          { return m_xRow->getBoolean( m_nPos ); };
getByte() const2144         virtual sal_Int8                    getByte() const override             { return m_xRow->getByte( m_nPos ); };
getShort() const2145         virtual sal_Int16                   getShort() const override            { return m_xRow->getShort( m_nPos ); }
getInt() const2146         virtual sal_Int32                   getInt() const override              { return m_xRow->getInt( m_nPos ); }
getLong() const2147         virtual sal_Int64                   getLong() const override             { return m_xRow->getLong( m_nPos ); }
getFloat() const2148         virtual float                       getFloat() const override            { return m_xRow->getFloat( m_nPos ); };
getDouble() const2149         virtual double                      getDouble() const override           { return m_xRow->getDouble( m_nPos ); };
getDate() const2150         virtual Date                        getDate() const override             { return m_xRow->getDate( m_nPos ); };
getTime() const2151         virtual css::util::Time             getTime() const override             { return m_xRow->getTime( m_nPos ); };
getTimestamp() const2152         virtual DateTime                    getTimestamp() const override        { return m_xRow->getTimestamp( m_nPos ); };
getBytes() const2153         virtual Sequence< sal_Int8 >        getBytes() const override            { return m_xRow->getBytes( m_nPos ); };
getBlob() const2154         virtual Reference< XBlob >          getBlob() const override             { return m_xRow->getBlob( m_nPos ); };
getClob() const2155         virtual Reference< XClob >          getClob() const override             { return m_xRow->getClob( m_nPos ); };
getObject() const2156         virtual Any                         getObject() const override           { return m_xRow->getObject( m_nPos ,nullptr); };
wasNull() const2157         virtual bool                        wasNull() const override             { return m_xRow->wasNull( ); };
2158 
2159     private:
2160         const Reference< XRow > m_xRow;
2161         const sal_Int32         m_nPos;
2162     };
2163 
2164     class ColumnValue : public IValueSource
2165     {
2166     public:
ColumnValue(const Reference<XColumn> & _rxColumn)2167         explicit ColumnValue( const Reference< XColumn >& _rxColumn )
2168             :m_xColumn( _rxColumn )
2169         {
2170         }
2171 
2172         // IValueSource
getString() const2173         virtual OUString             getString() const override           { return m_xColumn->getString(); };
getBoolean() const2174         virtual bool                        getBoolean() const override          { return m_xColumn->getBoolean(); };
getByte() const2175         virtual sal_Int8                    getByte() const override             { return m_xColumn->getByte(); };
getShort() const2176         virtual sal_Int16                   getShort() const override            { return m_xColumn->getShort(); }
getInt() const2177         virtual sal_Int32                   getInt() const override              { return m_xColumn->getInt(); }
getLong() const2178         virtual sal_Int64                   getLong() const override             { return m_xColumn->getLong(); }
getFloat() const2179         virtual float                       getFloat() const override            { return m_xColumn->getFloat(); };
getDouble() const2180         virtual double                      getDouble() const override           { return m_xColumn->getDouble(); };
getDate() const2181         virtual Date                        getDate() const override             { return m_xColumn->getDate(); };
getTime() const2182         virtual css::util::Time             getTime() const override             { return m_xColumn->getTime(); };
getTimestamp() const2183         virtual DateTime                    getTimestamp() const override        { return m_xColumn->getTimestamp(); };
getBytes() const2184         virtual Sequence< sal_Int8 >        getBytes() const override            { return m_xColumn->getBytes(); };
getBlob() const2185         virtual Reference< XBlob >          getBlob() const override             { return m_xColumn->getBlob(); };
getClob() const2186         virtual Reference< XClob >          getClob() const override             { return m_xColumn->getClob(); };
getObject() const2187         virtual Any                         getObject() const override           { return m_xColumn->getObject( nullptr ); };
wasNull() const2188         virtual bool                        wasNull() const override             { return m_xColumn->wasNull( ); };
2189 
2190     private:
2191         const Reference< XColumn >  m_xColumn;
2192     };
2193 
2194     }
2195 }
2196 
2197 
fill(const sal_Int32 _nType,const Reference<XColumn> & _rxColumn)2198 void ORowSetValue::fill( const sal_Int32 _nType, const Reference< XColumn >& _rxColumn )
2199 {
2200     detail::ColumnValue aColumnValue( _rxColumn );
2201     impl_fill( _nType, true, aColumnValue );
2202 }
2203 
2204 
fill(sal_Int32 _nPos,sal_Int32 _nType,bool _bNullable,const Reference<XRow> & _xRow)2205 void ORowSetValue::fill( sal_Int32 _nPos, sal_Int32 _nType, bool  _bNullable, const Reference< XRow>& _xRow )
2206 {
2207     detail::RowValue aRowValue( _xRow, _nPos );
2208     impl_fill( _nType, _bNullable, aRowValue );
2209 }
2210 
2211 
fill(sal_Int32 _nPos,sal_Int32 _nType,const css::uno::Reference<css::sdbc::XRow> & _xRow)2212 void ORowSetValue::fill(sal_Int32 _nPos,
2213                      sal_Int32 _nType,
2214                      const css::uno::Reference< css::sdbc::XRow>& _xRow)
2215 {
2216     fill(_nPos,_nType,true,_xRow);
2217 }
2218 
2219 
impl_fill(const sal_Int32 _nType,bool _bNullable,const detail::IValueSource & _rValueSource)2220 void ORowSetValue::impl_fill( const sal_Int32 _nType, bool _bNullable, const detail::IValueSource& _rValueSource )
2221 {
2222     switch(_nType)
2223     {
2224     case DataType::CHAR:
2225     case DataType::VARCHAR:
2226     case DataType::DECIMAL:
2227     case DataType::NUMERIC:
2228     case DataType::LONGVARCHAR:
2229         (*this) = _rValueSource.getString();
2230         break;
2231     case DataType::BIGINT:
2232         if ( isSigned() )
2233             (*this) = _rValueSource.getLong();
2234         else
2235             // TODO: this is rather horrible performance-wise
2236             //       but fixing it needs extending the css::sdbc::XRow API
2237             //       to have a getULong(), and needs updating all drivers :-|
2238             //       When doing that, add getUByte, getUShort, getUInt for symmetry/completeness
2239             (*this) = _rValueSource.getString().toUInt64();
2240         break;
2241     case DataType::FLOAT:
2242         (*this) = _rValueSource.getFloat();
2243         break;
2244     case DataType::DOUBLE:
2245     case DataType::REAL:
2246         (*this) = _rValueSource.getDouble();
2247         break;
2248     case DataType::DATE:
2249         (*this) = _rValueSource.getDate();
2250         break;
2251     case DataType::TIME:
2252         (*this) = _rValueSource.getTime();
2253         break;
2254     case DataType::TIMESTAMP:
2255         (*this) = _rValueSource.getTimestamp();
2256         break;
2257     case DataType::BINARY:
2258     case DataType::VARBINARY:
2259     case DataType::LONGVARBINARY:
2260         (*this) = _rValueSource.getBytes();
2261         break;
2262     case DataType::BIT:
2263     case DataType::BOOLEAN:
2264         (*this) = _rValueSource.getBoolean();
2265         break;
2266     case DataType::TINYINT:
2267         if ( isSigned() )
2268             (*this) = _rValueSource.getByte();
2269         else
2270             (*this) = _rValueSource.getShort();
2271         break;
2272     case DataType::SMALLINT:
2273         if ( isSigned() )
2274             (*this) = _rValueSource.getShort();
2275         else
2276             (*this) = _rValueSource.getInt();
2277         break;
2278     case DataType::INTEGER:
2279         if ( isSigned() )
2280             (*this) = _rValueSource.getInt();
2281         else
2282             (*this) = _rValueSource.getLong();
2283         break;
2284     case DataType::CLOB:
2285         (*this) = css::uno::Any(_rValueSource.getClob());
2286         setTypeKind(DataType::CLOB);
2287         break;
2288     case DataType::BLOB:
2289         (*this) = css::uno::Any(_rValueSource.getBlob());
2290         setTypeKind(DataType::BLOB);
2291         break;
2292     case DataType::OTHER:
2293         (*this) = _rValueSource.getObject();
2294         setTypeKind(DataType::OTHER);
2295         break;
2296     default:
2297         SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported type!" );
2298         (*this) = _rValueSource.getObject();
2299         break;
2300     }
2301     if ( _bNullable && _rValueSource.wasNull() )
2302         setNull();
2303     setTypeKind(_nType);
2304 }
2305 
fill(const Any & _rValue)2306 void ORowSetValue::fill(const Any& _rValue)
2307 {
2308     switch (_rValue.getValueType().getTypeClass())
2309     {
2310         case TypeClass_VOID:
2311             setNull();            break;
2312         case TypeClass_BOOLEAN:
2313         {
2314             bool bValue( false );
2315             _rValue >>= bValue;
2316             (*this) = bValue;
2317             break;
2318         }
2319         case TypeClass_CHAR:
2320         {
2321             sal_Unicode aDummy(0);
2322             _rValue >>= aDummy;
2323             (*this) = OUString(aDummy);
2324             break;
2325         }
2326         case TypeClass_STRING:
2327         {
2328             OUString sDummy;
2329             _rValue >>= sDummy;
2330             (*this) = sDummy;
2331             break;
2332         }
2333         case TypeClass_FLOAT:
2334         {
2335             float aDummy(0.0);
2336             _rValue >>= aDummy;
2337             (*this) = aDummy;
2338             break;
2339         }
2340         case TypeClass_DOUBLE:
2341         {
2342             double aDummy(0.0);
2343             _rValue >>= aDummy;
2344             (*this) = aDummy;
2345             break;
2346         }
2347         case TypeClass_BYTE:
2348         {
2349             sal_Int8 aDummy(0);
2350             _rValue >>= aDummy;
2351             (*this) = aDummy;
2352             break;
2353         }
2354         case TypeClass_SHORT:
2355         {
2356             sal_Int16 aDummy(0);
2357             _rValue >>= aDummy;
2358             (*this) = aDummy;
2359             break;
2360         }
2361         case TypeClass_UNSIGNED_SHORT:
2362         {
2363             sal_uInt16 nValue(0);
2364             _rValue >>= nValue;
2365             (*this) = nValue;
2366             break;
2367         }
2368         case TypeClass_LONG:
2369         {
2370             sal_Int32 aDummy(0);
2371             _rValue >>= aDummy;
2372             (*this) = aDummy;
2373             break;
2374         }
2375         case TypeClass_UNSIGNED_LONG:
2376         {
2377             sal_uInt32 nValue(0);
2378             _rValue >>= nValue;
2379             (*this) = static_cast<sal_Int64>(nValue);
2380             setSigned(false);
2381             break;
2382         }
2383         case TypeClass_HYPER:
2384         {
2385             sal_Int64 nValue(0);
2386             _rValue >>= nValue;
2387             (*this) = nValue;
2388             break;
2389         }
2390         case TypeClass_UNSIGNED_HYPER:
2391         {
2392             sal_uInt64 nValue(0);
2393             _rValue >>= nValue;
2394             (*this) = nValue;
2395             setSigned(false);
2396             break;
2397         }
2398         case TypeClass_ENUM:
2399         {
2400             sal_Int32 enumValue( 0 );
2401             ::cppu::enum2int( enumValue, _rValue );
2402             (*this) = enumValue;
2403         }
2404         break;
2405 
2406         case TypeClass_SEQUENCE:
2407         {
2408             Sequence<sal_Int8> aDummy;
2409             if ( _rValue >>= aDummy )
2410                 (*this) = aDummy;
2411             else
2412                 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported sequence type!" );
2413             break;
2414         }
2415 
2416         case TypeClass_STRUCT:
2417         {
2418             css::util::Date aDate;
2419             css::util::Time aTime;
2420             css::util::DateTime aDateTime;
2421             if ( _rValue >>= aDate )
2422             {
2423                 (*this) = aDate;
2424             }
2425             else if ( _rValue >>= aTime )
2426             {
2427                 (*this) = aTime;
2428             }
2429             else if ( _rValue >>= aDateTime )
2430             {
2431                 (*this) = aDateTime;
2432             }
2433             else
2434                 SAL_WARN( "connectivity.commontools", "ORowSetValue::fill: unsupported structure!" );
2435 
2436             break;
2437         }
2438         case TypeClass_INTERFACE:
2439             {
2440                 Reference< XClob > xClob;
2441                 if ( _rValue >>= xClob )
2442                 {
2443                     (*this) = _rValue;
2444                     setTypeKind(DataType::CLOB);
2445                 }
2446                 else
2447                 {
2448                     Reference< XBlob > xBlob;
2449                     if ( _rValue >>= xBlob )
2450                     {
2451                         (*this) = _rValue;
2452                         setTypeKind(DataType::BLOB);
2453                     }
2454                     else
2455                     {
2456                         (*this) = _rValue;
2457                     }
2458                 }
2459             }
2460             break;
2461 
2462         default:
2463             SAL_WARN( "connectivity.commontools","Unknown type");
2464             break;
2465     }
2466 }
2467 
2468 }   // namespace connectivity
2469 
2470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2471