diff options
Diffstat (limited to 'connectivity/source/commontools/FValue.cxx')
-rw-r--r-- | connectivity/source/commontools/FValue.cxx | 134 |
1 files changed, 129 insertions, 5 deletions
diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index f7943fc4cf45..f171af5ec530 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -257,6 +257,7 @@ void ORowSetValue::setTypeKind(sal_Int32 _eType) case DataType::BLOB: case DataType::CLOB: case DataType::OBJECT: + case DataType::OTHER: (*this) = getAny(); break; default: @@ -847,6 +848,7 @@ bool ORowSetValue::operator==(const ORowSetValue& _rRH) const case DataType::BLOB: case DataType::CLOB: case DataType::OBJECT: + case DataType::OTHER: bRet = false; break; default: @@ -913,6 +915,7 @@ Any ORowSetValue::makeAny() const case DataType::BLOB: case DataType::CLOB: case DataType::OBJECT: + case DataType::OTHER: rValue = getAny(); break; case DataType::BIT: @@ -1019,6 +1022,19 @@ Any ORowSetValue::makeAny() const else aRet = ::rtl::OUString::valueOf((sal_Int64)*this); break; + case DataType::CLOB: + { + Any aValue( getAny() ); + Reference< XClob > xClob; + if ( aValue >>= xClob ) + { + if ( xClob.is() ) + { + aRet = xClob->getSubString(1,(sal_Int32)xClob->length() ); + } + } + } + break; } } return aRet; @@ -1090,6 +1106,9 @@ sal_Bool ORowSetValue::getBool() const case DataType::INTEGER: bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (*static_cast<sal_Int64*>(m_aValue.m_pValue) != sal_Int64(0)); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return bRet; @@ -1131,6 +1150,8 @@ sal_Int8 ORowSetValue::getInt8() const case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"getInt8() for this type is not allowed!"); break; case DataType::BIT: @@ -1155,6 +1176,9 @@ sal_Int8 ORowSetValue::getInt8() const else nRet = static_cast<sal_Int8>(*static_cast<sal_Int64*>(m_aValue.m_pValue)); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return nRet; @@ -1196,6 +1220,8 @@ sal_Int16 ORowSetValue::getInt16() const case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"getInt16() for this type is not allowed!"); break; case DataType::BIT: @@ -1220,6 +1246,9 @@ sal_Int16 ORowSetValue::getInt16() const else nRet = static_cast<sal_Int16>(*static_cast<sal_Int64*>(m_aValue.m_pValue)); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return nRet; @@ -1261,6 +1290,8 @@ sal_Int32 ORowSetValue::getInt32() const case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"getInt32() for this type is not allowed!"); break; case DataType::BIT: @@ -1285,6 +1316,9 @@ sal_Int32 ORowSetValue::getInt32() const else nRet = static_cast<sal_Int32>(*static_cast<sal_Int64*>(m_aValue.m_pValue)); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return nRet; @@ -1326,6 +1360,8 @@ sal_Int64 ORowSetValue::getLong() const case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"getInt32() for this type is not allowed!"); break; case DataType::BIT: @@ -1350,6 +1386,9 @@ sal_Int64 ORowSetValue::getLong() const else nRet = *(sal_Int64*)m_aValue.m_pValue; break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return nRet; @@ -1395,6 +1434,8 @@ float ORowSetValue::getFloat() const case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"getDouble() for this type is not allowed!"); break; case DataType::BIT: @@ -1419,6 +1460,9 @@ float ORowSetValue::getFloat() const else nRet = float(*(sal_Int64*)m_aValue.m_pValue); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return nRet; @@ -1466,6 +1510,8 @@ double ORowSetValue::getDouble() const case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"getDouble() for this type is not allowed!"); break; case DataType::BIT: @@ -1490,6 +1536,9 @@ double ORowSetValue::getDouble() const else nRet = double(*(sal_Int64*)m_aValue.m_pValue); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return nRet; @@ -1551,6 +1600,8 @@ void ORowSetValue::setFromDouble(const double& _rVal,sal_Int32 _nDatatype) case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: + case DataType::CLOB: OSL_ASSERT(!"setFromDouble() for this type is not allowed!"); break; case DataType::BIT: @@ -1595,12 +1646,39 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const case DataType::BLOB: { Reference<XInputStream> xStream; - Any aValue = getAny(); + const Any aValue = makeAny(); if(aValue.hasValue()) { - aValue >>= xStream; + Reference<XBlob> xBlob(aValue,UNO_QUERY); + if ( xBlob.is() ) + xStream = xBlob->getBinaryStream(); + else + { + Reference<XClob> xClob(aValue,UNO_QUERY); + if ( xClob.is() ) + xStream = xClob->getCharacterStream(); + } if(xStream.is()) - xStream->readBytes(aSeq,xStream->available()); + { + const sal_uInt32 nBytesToRead = 65535; + sal_uInt32 nRead; + + do + { + ::com::sun::star::uno::Sequence< sal_Int8 > aReadSeq; + + nRead = xStream->readSomeBytes( aReadSeq, nBytesToRead ); + + if( nRead ) + { + const sal_uInt32 nOldLength = aSeq.getLength(); + aSeq.realloc( nOldLength + nRead ); + rtl_copyMemory( aSeq.getArray() + nOldLength, aReadSeq.getConstArray(), aReadSeq.getLength() ); + } + } + while( nBytesToRead == nRead ); + xStream->closeInput(); + } } } break; @@ -1658,6 +1736,9 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const aValue.Year = pDateTime->Year; } break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return aValue; @@ -1696,6 +1777,10 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const break; case DataType::TIME: aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue); + break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return aValue; @@ -1743,6 +1828,9 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const case DataType::TIMESTAMP: aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue); break; + default: + OSL_ENSURE(0,"Illegal conversion!"); + break; } } return aValue; @@ -1833,6 +1921,9 @@ namespace detail virtual Sequence< sal_Int8 > getBytes() const = 0; virtual Reference< XInputStream > getBinaryStream() const = 0; virtual Reference< XInputStream > getCharacterStream() const = 0; + virtual Reference< XBlob > getBlob() const = 0; + virtual Reference< XClob > getClob() const = 0; + virtual Any getObject() const = 0; virtual sal_Bool wasNull() const = 0; virtual ~IValueSource() { } @@ -1862,6 +1953,9 @@ namespace detail virtual Sequence< sal_Int8 > getBytes() const { return m_xRow->getBytes( m_nPos ); }; virtual Reference< XInputStream > getBinaryStream() const { return m_xRow->getBinaryStream( m_nPos ); }; virtual Reference< XInputStream > getCharacterStream() const { return m_xRow->getCharacterStream( m_nPos ); }; + virtual Reference< XBlob > getBlob() const { return m_xRow->getBlob( m_nPos ); }; + virtual Reference< XClob > getClob() const { return m_xRow->getClob( m_nPos ); }; + virtual Any getObject() const { return m_xRow->getObject( m_nPos, NULL ); }; virtual sal_Bool wasNull() const { return m_xRow->wasNull( ); }; private: @@ -1892,6 +1986,9 @@ namespace detail virtual Sequence< sal_Int8 > getBytes() const { return m_xColumn->getBytes(); }; virtual Reference< XInputStream > getBinaryStream() const { return m_xColumn->getBinaryStream(); }; virtual Reference< XInputStream > getCharacterStream() const { return m_xColumn->getCharacterStream(); }; + virtual Reference< XBlob > getBlob() const { return m_xColumn->getBlob(); }; + virtual Reference< XClob > getClob() const { return m_xColumn->getClob(); }; + virtual Any getObject() const { return m_xColumn->getObject( NULL ); }; virtual sal_Bool wasNull() const { return m_xColumn->wasNull( ); }; private: @@ -1987,13 +2084,17 @@ void ORowSetValue::impl_fill( const sal_Int32 _nType, sal_Bool _bNullable, const (*this) = _rValueSource.getLong(); break; case DataType::CLOB: - (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getCharacterStream()); + (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getClob()); setTypeKind(DataType::CLOB); break; case DataType::BLOB: - (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBinaryStream()); + (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBlob()); setTypeKind(DataType::BLOB); break; + case DataType::OTHER: + (*this) = _rValueSource.getObject(); + setTypeKind(DataType::OTHER); + break; default: OSL_ENSURE( false, "ORowSetValue::fill: unsupported type!" ); bReadData = false; @@ -2139,6 +2240,29 @@ void ORowSetValue::fill(const Any& _rValue) break; } + case TypeClass_INTERFACE: + { + Reference< XClob > xClob; + if ( _rValue >>= xClob ) + { + (*this) = _rValue; + setTypeKind(DataType::CLOB); + } + else + { + Reference< XBlob > xBlob; + if ( _rValue >>= xBlob ) + { + (*this) = _rValue; + setTypeKind(DataType::BLOB); + } + else + { + (*this) = _rValue; + } + } + } + break; default: OSL_ENSURE(0,"Unknown type"); |