#i105086# fix for clob and blob

This commit is contained in:
Ocke Janssen 2009-11-11 13:30:02 +01:00
parent e5f5288c13
commit a5a48d4f88
3 changed files with 148 additions and 47 deletions

View file

@ -254,6 +254,7 @@ void ORowSetValue::setTypeKind(sal_Int32 _eType)
case DataType::BLOB: case DataType::BLOB:
case DataType::CLOB: case DataType::CLOB:
case DataType::OBJECT: case DataType::OBJECT:
case DataType::OTHER:
(*this) = getAny(); (*this) = getAny();
break; break;
default: default:
@ -844,6 +845,7 @@ bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
case DataType::BLOB: case DataType::BLOB:
case DataType::CLOB: case DataType::CLOB:
case DataType::OBJECT: case DataType::OBJECT:
case DataType::OTHER:
bRet = false; bRet = false;
break; break;
default: default:
@ -910,6 +912,7 @@ Any ORowSetValue::makeAny() const
case DataType::BLOB: case DataType::BLOB:
case DataType::CLOB: case DataType::CLOB:
case DataType::OBJECT: case DataType::OBJECT:
case DataType::OTHER:
rValue = getAny(); rValue = getAny();
break; break;
case DataType::BIT: case DataType::BIT:
@ -1016,6 +1019,19 @@ Any ORowSetValue::makeAny() const
else else
aRet = ::rtl::OUString::valueOf((sal_Int64)*this); aRet = ::rtl::OUString::valueOf((sal_Int64)*this);
break; 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; return aRet;
@ -1087,6 +1103,9 @@ sal_Bool ORowSetValue::getBool() const
case DataType::INTEGER: case DataType::INTEGER:
bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (*static_cast<sal_Int64*>(m_aValue.m_pValue) != sal_Int64(0)); bRet = m_bSigned ? (m_aValue.m_nInt32 != 0) : (*static_cast<sal_Int64*>(m_aValue.m_pValue) != sal_Int64(0));
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return bRet; return bRet;
@ -1128,6 +1147,8 @@ sal_Int8 ORowSetValue::getInt8() const
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"getInt8() for this type is not allowed!"); OSL_ASSERT(!"getInt8() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1152,6 +1173,9 @@ sal_Int8 ORowSetValue::getInt8() const
else else
nRet = static_cast<sal_Int8>(*static_cast<sal_Int64*>(m_aValue.m_pValue)); nRet = static_cast<sal_Int8>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return nRet; return nRet;
@ -1193,6 +1217,8 @@ sal_Int16 ORowSetValue::getInt16() const
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"getInt16() for this type is not allowed!"); OSL_ASSERT(!"getInt16() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1217,6 +1243,9 @@ sal_Int16 ORowSetValue::getInt16() const
else else
nRet = static_cast<sal_Int16>(*static_cast<sal_Int64*>(m_aValue.m_pValue)); nRet = static_cast<sal_Int16>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return nRet; return nRet;
@ -1258,6 +1287,8 @@ sal_Int32 ORowSetValue::getInt32() const
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"getInt32() for this type is not allowed!"); OSL_ASSERT(!"getInt32() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1282,6 +1313,9 @@ sal_Int32 ORowSetValue::getInt32() const
else else
nRet = static_cast<sal_Int32>(*static_cast<sal_Int64*>(m_aValue.m_pValue)); nRet = static_cast<sal_Int32>(*static_cast<sal_Int64*>(m_aValue.m_pValue));
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return nRet; return nRet;
@ -1323,6 +1357,8 @@ sal_Int64 ORowSetValue::getLong() const
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"getInt32() for this type is not allowed!"); OSL_ASSERT(!"getInt32() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1347,6 +1383,9 @@ sal_Int64 ORowSetValue::getLong() const
else else
nRet = *(sal_Int64*)m_aValue.m_pValue; nRet = *(sal_Int64*)m_aValue.m_pValue;
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return nRet; return nRet;
@ -1392,6 +1431,8 @@ float ORowSetValue::getFloat() const
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"getDouble() for this type is not allowed!"); OSL_ASSERT(!"getDouble() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1416,6 +1457,9 @@ float ORowSetValue::getFloat() const
else else
nRet = float(*(sal_Int64*)m_aValue.m_pValue); nRet = float(*(sal_Int64*)m_aValue.m_pValue);
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return nRet; return nRet;
@ -1463,6 +1507,8 @@ double ORowSetValue::getDouble() const
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"getDouble() for this type is not allowed!"); OSL_ASSERT(!"getDouble() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1487,6 +1533,9 @@ double ORowSetValue::getDouble() const
else else
nRet = double(*(sal_Int64*)m_aValue.m_pValue); nRet = double(*(sal_Int64*)m_aValue.m_pValue);
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return nRet; return nRet;
@ -1548,6 +1597,8 @@ void ORowSetValue::setFromDouble(const double& _rVal,sal_Int32 _nDatatype)
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
case DataType::CLOB:
OSL_ASSERT(!"setFromDouble() for this type is not allowed!"); OSL_ASSERT(!"setFromDouble() for this type is not allowed!");
break; break;
case DataType::BIT: case DataType::BIT:
@ -1655,6 +1706,9 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const
aValue.Year = pDateTime->Year; aValue.Year = pDateTime->Year;
} }
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return aValue; return aValue;
@ -1693,6 +1747,9 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const
break; break;
case DataType::TIME: case DataType::TIME:
aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue); aValue = *static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue);
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return aValue; return aValue;
@ -1740,6 +1797,9 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const
case DataType::TIMESTAMP: case DataType::TIMESTAMP:
aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue); aValue = *static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue);
break; break;
default:
OSL_ENSURE(0,"Illegal conversion!");
break;
} }
} }
return aValue; return aValue;
@ -1885,13 +1945,17 @@ void ORowSetValue::fill(sal_Int32 _nPos,
(*this) = _xRow->getLong(_nPos); (*this) = _xRow->getLong(_nPos);
break; break;
case DataType::CLOB: case DataType::CLOB:
(*this) = ::com::sun::star::uno::makeAny(_xRow->getCharacterStream(_nPos)); (*this) = ::com::sun::star::uno::makeAny(_xRow->getClob(_nPos));
setTypeKind(DataType::CLOB); setTypeKind(DataType::CLOB);
break; break;
case DataType::BLOB: case DataType::BLOB:
(*this) = ::com::sun::star::uno::makeAny(_xRow->getBinaryStream(_nPos)); (*this) = ::com::sun::star::uno::makeAny(_xRow->getBlob(_nPos));
setTypeKind(DataType::BLOB); setTypeKind(DataType::BLOB);
break; break;
case DataType::OTHER:
(*this) = _xRow->getObject(_nPos,NULL);
setTypeKind(DataType::OTHER);
break;
default: default:
OSL_ENSURE( false, "ORowSetValue::fill: unsupported type!" ); OSL_ENSURE( false, "ORowSetValue::fill: unsupported type!" );
bReadData = false; bReadData = false;
@ -2037,6 +2101,25 @@ void ORowSetValue::fill(const Any& _rValue)
break; 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);
}
}
}
break;
default: default:
OSL_ENSURE(0,"Unknown type"); OSL_ENSURE(0,"Unknown type");

View file

@ -213,6 +213,7 @@ sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType,
case DataType::CHAR: case DataType::CHAR:
case DataType::VARCHAR: case DataType::VARCHAR:
case DataType::LONGVARCHAR: case DataType::LONGVARCHAR:
case DataType::CLOB:
nFormat = _xTypes->getStandardFormat(NumberFormat::TEXT, _rLocale); nFormat = _xTypes->getStandardFormat(NumberFormat::TEXT, _rLocale);
break; break;
case DataType::DATE: case DataType::DATE:
@ -234,10 +235,10 @@ sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType,
case DataType::STRUCT: case DataType::STRUCT:
case DataType::ARRAY: case DataType::ARRAY:
case DataType::BLOB: case DataType::BLOB:
case DataType::CLOB:
case DataType::REF: case DataType::REF:
default: default:
nFormat = NumberFormat::UNDEFINED; nFormat = _xTypes->getStandardFormat(NumberFormat::UNDEFINED, _rLocale);
//nFormat = NumberFormat::UNDEFINED;
} }
return nFormat; return nFormat;
} }
@ -1850,9 +1851,20 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams,
sal_Int32 parameterIndex, sal_Int32 parameterIndex,
const Any& x, const Any& x,
sal_Int32 sqlType, sal_Int32 sqlType,
sal_Int32 /*scale*/) throw(SQLException, RuntimeException) sal_Int32 scale) throw(SQLException, RuntimeException)
{ {
if(!x.hasValue()) ORowSetValue aVal;
aVal.fill(x);
setObjectWithInfo(_xParams,parameterIndex,aVal,sqlType,scale);
}
// -----------------------------------------------------------------------------
void setObjectWithInfo(const Reference<XParameters>& _xParams,
sal_Int32 parameterIndex,
const ::connectivity::ORowSetValue& _rValue,
sal_Int32 sqlType,
sal_Int32 scale) throw(SQLException, RuntimeException)
{
if ( _rValue.isNull() )
_xParams->setNull(parameterIndex,sqlType); _xParams->setNull(parameterIndex,sqlType);
else else
{ {
@ -1860,65 +1872,62 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams,
{ {
case DataType::DECIMAL: case DataType::DECIMAL:
case DataType::NUMERIC: case DataType::NUMERIC:
_xParams->setObjectWithInfo(parameterIndex,x,sqlType,0); _xParams->setObjectWithInfo(parameterIndex,_rValue.makeAny(),sqlType,scale);
break; break;
case DataType::CHAR: case DataType::CHAR:
case DataType::VARCHAR: case DataType::VARCHAR:
//case DataType::DECIMAL:
//case DataType::NUMERIC:
case DataType::LONGVARCHAR: case DataType::LONGVARCHAR:
_xParams->setString(parameterIndex,::comphelper::getString(x)); _xParams->setString(parameterIndex,_rValue);
break; break;
case DataType::BIGINT: case DataType::CLOB:
{ {
sal_Int64 nValue = 0; Any x(_rValue.makeAny());
if(x >>= nValue) ::rtl::OUString sValue;
if ( x >>= sValue )
_xParams->setString(parameterIndex,sValue);
else
{ {
_xParams->setLong(parameterIndex,nValue); Reference< XClob > xClob;
break; if(x >>= xClob)
_xParams->setClob(parameterIndex,xClob);
else
{
Reference< ::com::sun::star::io::XInputStream > xStream;
if(x >>= xStream)
_xParams->setCharacterStream(parameterIndex,xStream,xStream->available());
}
} }
} }
break; break;
case DataType::BIGINT:
if ( _rValue.isSigned() )
_xParams->setLong(parameterIndex,_rValue);
else
_xParams->setString(parameterIndex,_rValue);
break;
case DataType::FLOAT: case DataType::FLOAT:
_xParams->setFloat(parameterIndex,_rValue);
break;
case DataType::REAL: case DataType::REAL:
{
float nValue = 0;
if(x >>= nValue)
{
_xParams->setFloat(parameterIndex,nValue);
break;
}
}
// run through if we couldn't set a float value
case DataType::DOUBLE: case DataType::DOUBLE:
_xParams->setDouble(parameterIndex,::comphelper::getDouble(x)); _xParams->setDouble(parameterIndex,_rValue);
break; break;
case DataType::DATE: case DataType::DATE:
{ _xParams->setDate(parameterIndex,_rValue);
::com::sun::star::util::Date aValue;
if(x >>= aValue)
_xParams->setDate(parameterIndex,aValue);
}
break; break;
case DataType::TIME: case DataType::TIME:
{ _xParams->setTime(parameterIndex,_rValue);
::com::sun::star::util::Time aValue;
if(x >>= aValue)
_xParams->setTime(parameterIndex,aValue);
}
break; break;
case DataType::TIMESTAMP: case DataType::TIMESTAMP:
{ _xParams->setTimestamp(parameterIndex,_rValue);
::com::sun::star::util::DateTime aValue;
if(x >>= aValue)
_xParams->setTimestamp(parameterIndex,aValue);
}
break; break;
case DataType::BINARY: case DataType::BINARY:
case DataType::VARBINARY: case DataType::VARBINARY:
case DataType::LONGVARBINARY: case DataType::LONGVARBINARY:
case DataType::BLOB:
{ {
Any x(_rValue.makeAny());
Sequence< sal_Int8> aBytes; Sequence< sal_Int8> aBytes;
if(x >>= aBytes) if(x >>= aBytes)
_xParams->setBytes(parameterIndex,aBytes); _xParams->setBytes(parameterIndex,aBytes);
@ -1944,16 +1953,24 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams,
break; break;
case DataType::BIT: case DataType::BIT:
case DataType::BOOLEAN: case DataType::BOOLEAN:
_xParams->setBoolean(parameterIndex,::cppu::any2bool(x)); _xParams->setBoolean(parameterIndex,_rValue);
break; break;
case DataType::TINYINT: if ( _rValue.isSigned() )
_xParams->setByte(parameterIndex,(sal_Int8)::comphelper::getINT32(x)); _xParams->setByte(parameterIndex,_rValue);
else
_xParams->setShort(parameterIndex,_rValue);
break; break;
case DataType::SMALLINT: case DataType::SMALLINT:
_xParams->setShort(parameterIndex,(sal_Int16)::comphelper::getINT32(x)); if ( _rValue.isSigned() )
_xParams->setShort(parameterIndex,_rValue);
else
_xParams->setInt(parameterIndex,_rValue);
break; break;
case DataType::INTEGER: case DataType::INTEGER:
_xParams->setInt(parameterIndex,::comphelper::getINT32(x)); if ( _rValue.isSigned() )
_xParams->setInt(parameterIndex,_rValue);
else
_xParams->setLong(parameterIndex,_rValue);
break; break;
default: default:
{ {

View file

@ -148,9 +148,10 @@ namespace dbtools
sal_Int32 nType = DataType::OTHER; sal_Int32 nType = DataType::OTHER;
_rxField->getPropertyValue( ::rtl::OUString::createFromAscii( "Type" ) ) >>= nType; _rxField->getPropertyValue( ::rtl::OUString::createFromAscii( "Type" ) ) >>= nType;
if ( ( DataType::CHAR == nType ) if ( ( DataType::CHAR == nType )
|| ( DataType::VARCHAR == nType ) || ( DataType::VARCHAR == nType )
|| ( DataType::LONGVARCHAR == nType ) || ( DataType::LONGVARCHAR == nType )
|| ( DataType::CLOB == nType )
) )
{ // yes -> force a quoted text and try again { // yes -> force a quoted text and try again
::rtl::OUString sQuoted( _rStatement ); ::rtl::OUString sQuoted( _rStatement );