diff options
author | Ocke Janssen [oj] <Ocke.Janssen@sun.com> | 2010-01-08 14:12:39 +0100 |
---|---|---|
committer | Ocke Janssen [oj] <Ocke.Janssen@sun.com> | 2010-01-08 14:12:39 +0100 |
commit | 5ac40e5c94ddb395f7b06f84524a852a0488f17c (patch) | |
tree | 12a4ea316a19ca86360a3961805d861344525375 /connectivity/source/commontools | |
parent | b0c799c7fbaa93f707bf18a87eb9aef5d86be52c (diff) | |
parent | bc7afd018ae687b2a8ba9096dfe463097b54799a (diff) |
dba33f: merge from dba33e
Diffstat (limited to 'connectivity/source/commontools')
-rw-r--r-- | connectivity/source/commontools/BlobHelper.cxx | 72 | ||||
-rw-r--r-- | connectivity/source/commontools/FValue.cxx | 136 | ||||
-rw-r--r-- | connectivity/source/commontools/TIndexes.cxx | 154 | ||||
-rw-r--r-- | connectivity/source/commontools/TKeys.cxx | 154 | ||||
-rw-r--r-- | connectivity/source/commontools/TTableHelper.cxx | 109 | ||||
-rw-r--r-- | connectivity/source/commontools/dbmetadata.cxx | 21 | ||||
-rw-r--r-- | connectivity/source/commontools/dbtools.cxx | 155 | ||||
-rw-r--r-- | connectivity/source/commontools/dbtools2.cxx | 32 | ||||
-rw-r--r-- | connectivity/source/commontools/formattedcolumnvalue.cxx | 90 | ||||
-rw-r--r-- | connectivity/source/commontools/makefile.mk | 1 | ||||
-rw-r--r-- | connectivity/source/commontools/predicateinput.cxx | 5 |
11 files changed, 651 insertions, 278 deletions
diff --git a/connectivity/source/commontools/BlobHelper.cxx b/connectivity/source/commontools/BlobHelper.cxx new file mode 100644 index 000000000000..5859db9036ac --- /dev/null +++ b/connectivity/source/commontools/BlobHelper.cxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: FValue.cxx,v $ + * $Revision: 1.34 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/BlobHelper.hxx" +#include <comphelper/seqstream.hxx> +#include "connectivity/dbexception.hxx" + +using namespace connectivity; +using namespace dbtools; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +BlobHelper::BlobHelper(const ::com::sun::star::uno::Sequence< sal_Int8 >& _val) : m_aValue(_val) +{ +} +// ----------------------------------------------------------------------------- +::sal_Int64 SAL_CALL BlobHelper::length( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + return m_aValue.getLength(); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::sal_Int8 > SAL_CALL BlobHelper::getBytes( ::sal_Int64 pos, ::sal_Int32 _length ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + if ( sal_Int32(pos + _length) > m_aValue.getLength() ) + throw ::com::sun::star::sdbc::SQLException(); + return ::com::sun::star::uno::Sequence< ::sal_Int8 >(m_aValue.getConstArray() + sal_Int32(pos),_length); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL BlobHelper::getBinaryStream( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + return new ::comphelper::SequenceInputStream(m_aValue); +} +// ----------------------------------------------------------------------------- +::sal_Int64 SAL_CALL BlobHelper::position( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& /*pattern*/, ::sal_Int64 /*start*/ ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::dbtools::throwFeatureNotImplementedException( "XBlob::position", *this ); + return 0; +} +// ----------------------------------------------------------------------------- +::sal_Int64 SAL_CALL BlobHelper::positionOfBlob( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob >& /*pattern*/, ::sal_Int64 /*start*/ ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::dbtools::throwFeatureNotImplementedException( "XBlob::positionOfBlob", *this ); + return 0; +} diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index f7943fc4cf45..b3254a0165a8 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,7 +1986,10 @@ 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 sal_Bool wasNull() const { return m_xColumn->wasNull( ); }; + 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: const Reference< XColumn > m_xColumn; @@ -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"); diff --git a/connectivity/source/commontools/TIndexes.cxx b/connectivity/source/commontools/TIndexes.cxx index cf17b7a51411..c07e3e302f9a 100644 --- a/connectivity/source/commontools/TIndexes.cxx +++ b/connectivity/source/commontools/TIndexes.cxx @@ -143,73 +143,80 @@ sdbcx::ObjectType OIndexesHelper::appendObject( const ::rtl::OUString& _rForName if ( m_pTable->isNew() ) return cloneDescriptor( descriptor ); - ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); - ::rtl::OUStringBuffer aSql( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATE "))); - ::rtl::OUString aQuote = m_pTable->getMetaData()->getIdentifierQuoteString( ); - ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); + if ( m_pTable->getIndexService().is() ) + { + m_pTable->getIndexService()->addIndex(m_pTable,descriptor); + } + else + { + ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); + ::rtl::OUStringBuffer aSql( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATE "))); + ::rtl::OUString aQuote = m_pTable->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString::createFromAscii("."); - if(comphelper::getBOOL(descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISUNIQUE)))) - aSql.appendAscii("UNIQUE "); - aSql.appendAscii("INDEX "); + if(comphelper::getBOOL(descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISUNIQUE)))) + aSql.appendAscii("UNIQUE "); + aSql.appendAscii("INDEX "); - ::rtl::OUString aCatalog,aSchema,aTable; - dbtools::qualifiedNameComponents(m_pTable->getMetaData(),m_pTable->getName(),aCatalog,aSchema,aTable,::dbtools::eInDataManipulation); - ::rtl::OUString aComposedName; + ::rtl::OUString aCatalog,aSchema,aTable; + dbtools::qualifiedNameComponents(m_pTable->getMetaData(),m_pTable->getName(),aCatalog,aSchema,aTable,::dbtools::eInDataManipulation); + ::rtl::OUString aComposedName; - aComposedName = dbtools::composeTableName(m_pTable->getMetaData(),aCatalog,aSchema,aTable,sal_True,::dbtools::eInIndexDefinitions); - if ( _rForName.getLength() ) - { - aSql.append( ::dbtools::quoteName( aQuote, _rForName ) ); - aSql.appendAscii(" ON "); - aSql.append(aComposedName); - aSql.appendAscii(" ( "); - - Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); - Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); - Reference< XPropertySet > xColProp; - sal_Bool bAddIndexAppendix = ::dbtools::getBooleanDataSourceSetting( m_pTable->getConnection(), "AddIndexAppendix" ); - sal_Int32 nCount = xColumns->getCount(); - for(sal_Int32 i = 0 ; i < nCount; ++i) + aComposedName = dbtools::composeTableName(m_pTable->getMetaData(),aCatalog,aSchema,aTable,sal_True,::dbtools::eInIndexDefinitions); + if ( _rForName.getLength() ) { - xColProp.set(xColumns->getByIndex(i),UNO_QUERY); - aSql.append(::dbtools::quoteName( aQuote,comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); + aSql.append( ::dbtools::quoteName( aQuote, _rForName ) ); + aSql.appendAscii(" ON "); + aSql.append(aComposedName); + aSql.appendAscii(" ( "); - if ( bAddIndexAppendix ) + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + sal_Bool bAddIndexAppendix = ::dbtools::getBooleanDataSourceSetting( m_pTable->getConnection(), "AddIndexAppendix" ); + sal_Int32 nCount = xColumns->getCount(); + for(sal_Int32 i = 0 ; i < nCount; ++i) { + xColProp.set(xColumns->getByIndex(i),UNO_QUERY); + aSql.append(::dbtools::quoteName( aQuote,comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); + + if ( bAddIndexAppendix ) + { - aSql.appendAscii(any2bool(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISASCENDING))) - ? - " ASC" - : - " DESC"); + aSql.appendAscii(any2bool(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISASCENDING))) + ? + " ASC" + : + " DESC"); + } + aSql.appendAscii(","); } - aSql.appendAscii(","); + aSql.setCharAt(aSql.getLength()-1,')'); } - aSql.setCharAt(aSql.getLength()-1,')'); - } - else - { - aSql.append(aComposedName); + else + { + aSql.append(aComposedName); - Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); - Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); - Reference< XPropertySet > xColProp; - if(xColumns->getCount() != 1) - throw SQLException(); + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + if(xColumns->getCount() != 1) + throw SQLException(); - xColumns->getByIndex(0) >>= xColProp; + xColumns->getByIndex(0) >>= xColProp; - aSql.append(aDot); - aSql.append(::dbtools::quoteName( aQuote,comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); - } + aSql.append(aDot); + aSql.append(::dbtools::quoteName( aQuote,comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); + } - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - if ( xStmt.is() ) - { - ::rtl::OUString sSql = aSql.makeStringAndClear(); - xStmt->execute(sSql); - ::comphelper::disposeComponent(xStmt); + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + if ( xStmt.is() ) + { + ::rtl::OUString sSql = aSql.makeStringAndClear(); + xStmt->execute(sSql); + ::comphelper::disposeComponent(xStmt); + } } return createObject( _rForName ); @@ -221,27 +228,34 @@ void OIndexesHelper::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElem Reference< XConnection> xConnection = m_pTable->getConnection(); if( xConnection.is() && !m_pTable->isNew()) { - ::rtl::OUString aName,aSchema; - sal_Int32 nLen = _sElementName.indexOf('.'); - if(nLen != -1) - aSchema = _sElementName.copy(0,nLen); - aName = _sElementName.copy(nLen+1); + if ( m_pTable->getIndexService().is() ) + { + m_pTable->getIndexService()->dropIndex(m_pTable,_sElementName); + } + else + { + ::rtl::OUString aName,aSchema; + sal_Int32 nLen = _sElementName.indexOf('.'); + if(nLen != -1) + aSchema = _sElementName.copy(0,nLen); + aName = _sElementName.copy(nLen+1); - ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP INDEX "); + ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP INDEX "); - ::rtl::OUString aComposedName = dbtools::composeTableName( m_pTable->getMetaData(), m_pTable, ::dbtools::eInIndexDefinitions, false, false, true ); - ::rtl::OUString sIndexName,sTemp; - sIndexName = dbtools::composeTableName( m_pTable->getMetaData(), sTemp, aSchema, aName, sal_True, ::dbtools::eInIndexDefinitions ); + ::rtl::OUString aComposedName = dbtools::composeTableName( m_pTable->getMetaData(), m_pTable, ::dbtools::eInIndexDefinitions, false, false, true ); + ::rtl::OUString sIndexName,sTemp; + sIndexName = dbtools::composeTableName( m_pTable->getMetaData(), sTemp, aSchema, aName, sal_True, ::dbtools::eInIndexDefinitions ); - aSql += sIndexName - + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ON ")) - + aComposedName; + aSql += sIndexName + + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ON ")) + + aComposedName; - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } } } } diff --git a/connectivity/source/commontools/TKeys.cxx b/connectivity/source/commontools/TKeys.cxx index 3dbe711552d7..c4cfc27b741a 100644 --- a/connectivity/source/commontools/TKeys.cxx +++ b/connectivity/source/commontools/TKeys.cxx @@ -150,69 +150,80 @@ sdbcx::ObjectType OKeysHelper::appendObject( const ::rtl::OUString& _rForName, c return xNewDescriptor; } - // if we're here, we belong to a table which is not new, i.e. already exists in the database. - // In this case, really append the new index. - const ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); sal_Int32 nKeyType = getINT32(descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE))); + sal_Int32 nUpdateRule = 0, nDeleteRule = 0; + ::rtl::OUString sReferencedName; - ::rtl::OUString aSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ALTER TABLE ")); - ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); - ::rtl::OUString aDot = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")); - - aSql += composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable, ::dbtools::eInTableDefinitions, false, false, true ); - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ADD ")); - - if ( nKeyType == KeyType::PRIMARY ) + if ( nKeyType == KeyType::FOREIGN ) { - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PRIMARY KEY (")); + descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_REFERENCEDTABLE)) >>= sReferencedName; + descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_UPDATERULE)) >>= nUpdateRule; + descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_DELETERULE)) >>= nDeleteRule; } - else if ( nKeyType == KeyType::FOREIGN ) + + if ( m_pTable->getKeyService().is() ) { - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FOREIGN KEY (")); + m_pTable->getKeyService()->addKey(m_pTable,descriptor); } else - throw SQLException(); - - Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); - Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); - Reference< XPropertySet > xColProp; - for(sal_Int32 i=0;i<xColumns->getCount();++i) { - ::cppu::extractInterface(xColProp,xColumns->getByIndex(i)); - aSql += ::dbtools::quoteName( aQuote,getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))) - + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(",")); - } - aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"))); + // if we're here, we belong to a table which is not new, i.e. already exists in the database. + // In this case, really append the new index. + ::rtl::OUStringBuffer aSql; + aSql.appendAscii("ALTER TABLE "); + ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString( ); + ::rtl::OUString aDot = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")); - sal_Int32 nUpdateRule = 0, nDeleteRule = 0; - ::rtl::OUString sReferencedName; + aSql.append(composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable, ::dbtools::eInTableDefinitions, false, false, true )); + aSql.appendAscii(" ADD "); - if ( nKeyType == KeyType::FOREIGN ) - { - descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_REFERENCEDTABLE)) >>= sReferencedName; - - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" REFERENCES ")) - + ::dbtools::quoteTableName(m_pTable->getConnection()->getMetaData(),sReferencedName,::dbtools::eInTableDefinitions); - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" (")); + if ( nKeyType == KeyType::PRIMARY ) + { + aSql.appendAscii(" PRIMARY KEY ("); + } + else if ( nKeyType == KeyType::FOREIGN ) + { + aSql.appendAscii(" FOREIGN KEY ("); + } + else + throw SQLException(); - for(sal_Int32 i=0;i<xColumns->getCount();++i) + Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY); + Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); + Reference< XPropertySet > xColProp; + for(sal_Int32 i = 0 ; i < xColumns->getCount() ; ++i) { - xColumns->getByIndex(i) >>= xColProp; - aSql += ::dbtools::quoteName( aQuote,getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_RELATEDCOLUMN)))) - + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(",")); + if ( i > 0 ) + aSql.appendAscii(","); + ::cppu::extractInterface(xColProp,xColumns->getByIndex(i)); + aSql.append( ::dbtools::quoteName( aQuote,getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))) ); + } - aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"))); + aSql.appendAscii(")"); - descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_UPDATERULE)) >>= nUpdateRule; - descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_DELETERULE)) >>= nDeleteRule; + if ( nKeyType == KeyType::FOREIGN ) + { + aSql.appendAscii(" REFERENCES "); + aSql.append(::dbtools::quoteTableName(m_pTable->getConnection()->getMetaData(),sReferencedName,::dbtools::eInTableDefinitions)); + aSql.appendAscii(" ("); - aSql += getKeyRuleString(sal_True ,nUpdateRule); - aSql += getKeyRuleString(sal_False ,nDeleteRule); - } + for(sal_Int32 i=0;i<xColumns->getCount();++i) + { + if ( i > 0 ) + aSql.appendAscii(","); + xColumns->getByIndex(i) >>= xColProp; + aSql.append(::dbtools::quoteName( aQuote,getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_RELATEDCOLUMN))))); - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - xStmt->execute(aSql); + } + aSql.appendAscii(")"); + aSql.append(getKeyRuleString(sal_True ,nUpdateRule)); + aSql.append(getKeyRuleString(sal_False ,nDeleteRule)); + } + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + xStmt->execute(aSql.makeStringAndClear()); + } // find the name which the database gave the new key ::rtl::OUString sNewName( _rForName ); try @@ -269,34 +280,41 @@ void OKeysHelper::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName Reference< XConnection> xConnection = m_pTable->getConnection(); if ( xConnection.is() && !m_pTable->isNew() ) { - ::rtl::OUString aSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ALTER TABLE ")); - - aSql += composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable,::dbtools::eInTableDefinitions, false, false, true ); - Reference<XPropertySet> xKey(getObject(_nPos),UNO_QUERY); - - sal_Int32 nKeyType = KeyType::PRIMARY; - if ( xKey.is() ) - { - ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); - xKey->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE)) >>= nKeyType; - } - if ( KeyType::PRIMARY == nKeyType ) + if ( m_pTable->getKeyService().is() ) { - aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP PRIMARY KEY")); + m_pTable->getKeyService()->dropKey(m_pTable,xKey); } else { - aSql += getDropForeignKey(); - const ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString(); - aSql += ::dbtools::quoteName( aQuote,_sElementName); - } + ::rtl::OUStringBuffer aSql; + aSql.appendAscii("ALTER TABLE "); - Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); + aSql.append( composeTableName( m_pTable->getConnection()->getMetaData(), m_pTable,::dbtools::eInTableDefinitions, false, false, true )); + + sal_Int32 nKeyType = KeyType::PRIMARY; + if ( xKey.is() ) + { + ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); + xKey->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE)) >>= nKeyType; + } + if ( KeyType::PRIMARY == nKeyType ) + { + aSql.appendAscii(" DROP PRIMARY KEY"); + } + else + { + aSql.append(getDropForeignKey()); + const ::rtl::OUString aQuote = m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString(); + aSql.append( ::dbtools::quoteName( aQuote,_sElementName) ); + } + + Reference< XStatement > xStmt = m_pTable->getConnection()->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql.makeStringAndClear()); + ::comphelper::disposeComponent(xStmt); + } } } } diff --git a/connectivity/source/commontools/TTableHelper.cxx b/connectivity/source/commontools/TTableHelper.cxx index 477ec01c0499..38b5d7fc52f3 100644 --- a/connectivity/source/commontools/TTableHelper.cxx +++ b/connectivity/source/commontools/TTableHelper.cxx @@ -101,11 +101,40 @@ namespace connectivity struct OTableHelperImpl { TKeyMap m_aKeys; - Reference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData; + // helper services which can be provided by extensions + Reference< ::com::sun::star::sdb::tools::XTableRename> m_xRename; + Reference< ::com::sun::star::sdb::tools::XTableAlteration> m_xAlter; + Reference< ::com::sun::star::sdb::tools::XKeyAlteration> m_xKeyAlter; + Reference< ::com::sun::star::sdb::tools::XIndexAlteration> m_xIndexAlter; + + Reference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData; Reference< ::com::sun::star::sdbc::XConnection > m_xConnection; ::comphelper::ImplementationReference< OTableContainerListener,XContainerListener> m_xTablePropertyListener; ::std::vector< ColumnDesc > m_aColumnDesc; + OTableHelperImpl(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection) + : m_xConnection(_xConnection) + { + try + { + m_xMetaData = m_xConnection->getMetaData(); + Reference<XMultiServiceFactory> xFac(_xConnection,UNO_QUERY); + if ( xFac.is() ) + { + static const ::rtl::OUString s_sTableRename(RTL_CONSTASCII_USTRINGPARAM("TableRenameServiceName")); + m_xRename.set(xFac->createInstance(s_sTableRename),UNO_QUERY); + static const ::rtl::OUString s_sTableAlteration(RTL_CONSTASCII_USTRINGPARAM("TableAlterationServiceName")); + m_xAlter.set(xFac->createInstance(s_sTableAlteration),UNO_QUERY); + static const ::rtl::OUString s_sKeyAlteration(RTL_CONSTASCII_USTRINGPARAM("KeyAlterationServiceName")); + m_xKeyAlter.set(xFac->createInstance(s_sKeyAlteration),UNO_QUERY); + static const ::rtl::OUString s_sIndexAlteration(RTL_CONSTASCII_USTRINGPARAM("IndexAlterationServiceName")); + m_xIndexAlter.set(xFac->createInstance(s_sIndexAlteration),UNO_QUERY); + } + } + catch(const Exception&) + { + } + } }; } @@ -113,16 +142,8 @@ OTableHelper::OTableHelper( sdbcx::OCollection* _pTables, const Reference< XConnection >& _xConnection, sal_Bool _bCase) :OTable_TYPEDEF(_pTables,_bCase) - ,m_pImpl(new OTableHelperImpl) + ,m_pImpl(new OTableHelperImpl(_xConnection)) { - try - { - m_pImpl->m_xConnection = _xConnection; - m_pImpl->m_xMetaData = m_pImpl->m_xConnection->getMetaData(); - } - catch(const Exception&) - { - } } // ------------------------------------------------------------------------- OTableHelper::OTableHelper( sdbcx::OCollection* _pTables, @@ -140,16 +161,8 @@ OTableHelper::OTableHelper( sdbcx::OCollection* _pTables, _Description, _SchemaName, _CatalogName) - ,m_pImpl(new OTableHelperImpl) + ,m_pImpl(new OTableHelperImpl(_xConnection)) { - try - { - m_pImpl->m_xConnection = _xConnection; - m_pImpl->m_xMetaData = m_pImpl->m_xConnection->getMetaData(); - } - catch(const Exception&) - { - } } // ----------------------------------------------------------------------------- OTableHelper::~OTableHelper() @@ -483,24 +496,31 @@ void SAL_CALL OTableHelper::rename( const ::rtl::OUString& newName ) throw(SQLEx if(!isNew()) { - ::rtl::OUString sSql = getRenameStart(); - ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); + if ( m_pImpl->m_xRename.is() ) + { + m_pImpl->m_xRename->rename(this,newName); + } + else + { + ::rtl::OUString sSql = getRenameStart(); + ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); - ::rtl::OUString sCatalog,sSchema,sTable; - ::dbtools::qualifiedNameComponents(getMetaData(),newName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation); + ::rtl::OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(getMetaData(),newName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation); - ::rtl::OUString sComposedName; - sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,sal_True,::dbtools::eInDataManipulation); - sSql += sComposedName - + ::rtl::OUString::createFromAscii(" TO "); - sComposedName = ::dbtools::composeTableName(getMetaData(),sCatalog,sSchema,sTable,sal_True,::dbtools::eInDataManipulation); - sSql += sComposedName; + ::rtl::OUString sComposedName; + sComposedName = ::dbtools::composeTableName(getMetaData(),m_CatalogName,m_SchemaName,m_Name,sal_True,::dbtools::eInDataManipulation); + sSql += sComposedName + + ::rtl::OUString::createFromAscii(" TO "); + sComposedName = ::dbtools::composeTableName(getMetaData(),sCatalog,sSchema,sTable,sal_True,::dbtools::eInDataManipulation); + sSql += sComposedName; - Reference< XStatement > xStmt = m_pImpl->m_xConnection->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(sSql); - ::comphelper::disposeComponent(xStmt); + Reference< XStatement > xStmt = m_pImpl->m_xConnection->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(sSql); + ::comphelper::disposeComponent(xStmt); + } } OTable_TYPEDEF::rename(newName); @@ -579,3 +599,24 @@ Reference< XConnection> OTableHelper::getConnection() const { return m_pImpl->m_xConnection; } +// ----------------------------------------------------------------------------- +Reference< ::com::sun::star::sdb::tools::XTableRename> OTableHelper::getRenameService() const +{ + return m_pImpl->m_xRename; +} +// ----------------------------------------------------------------------------- +Reference< ::com::sun::star::sdb::tools::XTableAlteration> OTableHelper::getAlterService() const +{ + return m_pImpl->m_xAlter; +} +// ----------------------------------------------------------------------------- +Reference< ::com::sun::star::sdb::tools::XKeyAlteration> OTableHelper::getKeyService() const +{ + return m_pImpl->m_xKeyAlter; +} +// ----------------------------------------------------------------------------- +Reference< ::com::sun::star::sdb::tools::XIndexAlteration> OTableHelper::getIndexService() const +{ + return m_pImpl->m_xIndexAlter; +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/commontools/dbmetadata.cxx b/connectivity/source/commontools/dbmetadata.cxx index c5b65a9d113b..d30161da497c 100644 --- a/connectivity/source/commontools/dbmetadata.cxx +++ b/connectivity/source/commontools/dbmetadata.cxx @@ -257,6 +257,27 @@ namespace dbtools } //-------------------------------------------------------------------- + bool DatabaseMetaData::supportsPrimaryKeys() const + { + lcl_checkConnected( *m_pImpl ); + + bool doesSupportPrimaryKeys = false; + try + { + Any setting; + if ( !( lcl_getConnectionSetting( "PrimaryKeySupport", *m_pImpl, setting ) ) + || !( setting >>= doesSupportPrimaryKeys ) + ) + doesSupportPrimaryKeys = m_pImpl->xConnectionMetaData->supportsCoreSQLGrammar(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return doesSupportPrimaryKeys; + } + + //-------------------------------------------------------------------- const ::rtl::OUString& DatabaseMetaData::getIdentifierQuoteString() const { return lcl_getConnectionStringSetting( *m_pImpl, m_pImpl->sCachedIdentifierQuoteString, &XDatabaseMetaData::getIdentifierQuoteString ); diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index 02e6e420142f..79f9f9707c26 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -213,6 +213,7 @@ sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType, case DataType::CHAR: case DataType::VARCHAR: case DataType::LONGVARCHAR: + case DataType::CLOB: nFormat = _xTypes->getStandardFormat(NumberFormat::TEXT, _rLocale); break; case DataType::DATE: @@ -234,10 +235,10 @@ sal_Int32 getDefaultNumberFormat(sal_Int32 _nDataType, case DataType::STRUCT: case DataType::ARRAY: case DataType::BLOB: - case DataType::CLOB: case DataType::REF: default: - nFormat = NumberFormat::UNDEFINED; + nFormat = _xTypes->getStandardFormat(NumberFormat::UNDEFINED, _rLocale); + //nFormat = NumberFormat::UNDEFINED; } return nFormat; } @@ -1387,16 +1388,18 @@ namespace ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); Reference< XPropertySetInfo > xInfo = _xTable->getPropertySetInfo(); if ( xInfo.is() - && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) - && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) ) { ::rtl::OUString aCatalog; ::rtl::OUString aSchema; ::rtl::OUString aTable; - _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) >>= _out_rCatalog; - _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= _out_rSchema; + if ( xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) + && xInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) ) + { + _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)) >>= _out_rCatalog; + _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= _out_rSchema; + } _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= _out_rName; } else @@ -1778,15 +1781,31 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>(); Reference<XNameAccess> xParamsAsNames(xParamsAsIndicies, UNO_QUERY); sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0; - if ( (nParamCount && _aParametersSet.empty()) || ::std::count(_aParametersSet.begin(),_aParametersSet.end(),true) != nParamCount ) + ::std::bit_vector aNewParameterSet( _aParametersSet ); + if ( nParamCount || ::std::count(aNewParameterSet.begin(),aNewParameterSet.end(),true) != nParamCount ) { + static const ::rtl::OUString PROPERTY_NAME(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)); + aNewParameterSet.resize(nParamCount ,false); + typedef ::std::map< ::rtl::OUString, ::std::vector<sal_Int32> > TParameterPositions; + TParameterPositions aParameterNames; + for(sal_Int32 i = 0; i < nParamCount; ++i) + { + Reference<XPropertySet> xParam(xParamsAsIndicies->getByIndex(i),UNO_QUERY); + ::rtl::OUString sName; + xParam->getPropertyValue(PROPERTY_NAME) >>= sName; + + TParameterPositions::iterator aFind = aParameterNames.find(sName); + if ( aFind != aParameterNames.end() ) + aNewParameterSet[i] = true; + aParameterNames[sName].push_back(i+1); + } // build an interaction request // two continuations (Ok and Cancel) OInteractionAbort* pAbort = new OInteractionAbort; OParameterContinuation* pParams = new OParameterContinuation; // the request ParametersRequest aRequest; - Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(_aParametersSet,xParamsAsIndicies); + Reference<XIndexAccess> xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies); aRequest.Parameters = xWrappedParameters; aRequest.Connection = _xConnection; OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); @@ -1814,11 +1833,10 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, Reference< XPropertySet > xParamColumn(xWrappedParameters->getByIndex(i),UNO_QUERY); if (xParamColumn.is()) { -#ifdef DBG_UTIL ::rtl::OUString sName; - xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName; + xParamColumn->getPropertyValue(PROPERTY_NAME) >>= sName; OSL_ENSURE(sName.equals(pFinalValues->Name), "::dbaui::askForParameters: inconsistent parameter names!"); -#endif + // determine the field type and ... sal_Int32 nParamType = 0; xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nParamType; @@ -1826,21 +1844,17 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, sal_Int32 nScale = 0; if (hasProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), xParamColumn)) xParamColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)) >>= nScale; - // and set the value - ::std::bit_vector::const_iterator aIter = _aParametersSet.begin(); - ::std::bit_vector::const_iterator aEnd = _aParametersSet.end(); - sal_Int32 j = 0; - sal_Int32 nParamPos = -1; - for(; aIter != aEnd && j <= i; ++aIter) + // (the index of the parameters is one-based) + TParameterPositions::iterator aFind = aParameterNames.find(pFinalValues->Name); + ::std::vector<sal_Int32>::iterator aIterPos = aFind->second.begin(); + ::std::vector<sal_Int32>::iterator aEndPos = aFind->second.end(); + for(;aIterPos != aEndPos;++aIterPos) { - ++nParamPos; - if ( !*aIter ) + if ( _aParametersSet.empty() || !_aParametersSet[(*aIterPos)-1] ) { - ++j; + _xParameters->setObjectWithInfo(*aIterPos, pFinalValues->Value, nParamType, nScale); } } - _xParameters->setObjectWithInfo(nParamPos + 1, pFinalValues->Value, nParamType, nScale); - // (the index of the parameters is one-based) } } } @@ -1850,9 +1864,20 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, - sal_Int32 /*scale*/) throw(SQLException, RuntimeException) + sal_Int32 scale) throw(SQLException, RuntimeException) +{ + 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(!x.hasValue()) + if ( _rValue.isNull() ) _xParams->setNull(parameterIndex,sqlType); else { @@ -1860,65 +1885,62 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, { case DataType::DECIMAL: case DataType::NUMERIC: - _xParams->setObjectWithInfo(parameterIndex,x,sqlType,0); + _xParams->setObjectWithInfo(parameterIndex,_rValue.makeAny(),sqlType,scale); break; case DataType::CHAR: case DataType::VARCHAR: - //case DataType::DECIMAL: - //case DataType::NUMERIC: case DataType::LONGVARCHAR: - _xParams->setString(parameterIndex,::comphelper::getString(x)); + _xParams->setString(parameterIndex,_rValue); break; - case DataType::BIGINT: + case DataType::CLOB: { - sal_Int64 nValue = 0; - if(x >>= nValue) + Any x(_rValue.makeAny()); + ::rtl::OUString sValue; + if ( x >>= sValue ) + _xParams->setString(parameterIndex,sValue); + else { - _xParams->setLong(parameterIndex,nValue); - break; + Reference< XClob > xClob; + 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; + case DataType::BIGINT: + if ( _rValue.isSigned() ) + _xParams->setLong(parameterIndex,_rValue); + else + _xParams->setString(parameterIndex,_rValue); + break; case DataType::FLOAT: + _xParams->setFloat(parameterIndex,_rValue); + break; 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: - _xParams->setDouble(parameterIndex,::comphelper::getDouble(x)); + _xParams->setDouble(parameterIndex,_rValue); break; case DataType::DATE: - { - ::com::sun::star::util::Date aValue; - if(x >>= aValue) - _xParams->setDate(parameterIndex,aValue); - } + _xParams->setDate(parameterIndex,_rValue); break; case DataType::TIME: - { - ::com::sun::star::util::Time aValue; - if(x >>= aValue) - _xParams->setTime(parameterIndex,aValue); - } + _xParams->setTime(parameterIndex,_rValue); break; case DataType::TIMESTAMP: - { - ::com::sun::star::util::DateTime aValue; - if(x >>= aValue) - _xParams->setTimestamp(parameterIndex,aValue); - } + _xParams->setTimestamp(parameterIndex,_rValue); break; case DataType::BINARY: case DataType::VARBINARY: case DataType::LONGVARBINARY: + case DataType::BLOB: { + Any x(_rValue.makeAny()); Sequence< sal_Int8> aBytes; if(x >>= aBytes) _xParams->setBytes(parameterIndex,aBytes); @@ -1944,16 +1966,25 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams, break; case DataType::BIT: case DataType::BOOLEAN: - _xParams->setBoolean(parameterIndex,::cppu::any2bool(x)); + _xParams->setBoolean(parameterIndex,_rValue); break; case DataType::TINYINT: - _xParams->setByte(parameterIndex,(sal_Int8)::comphelper::getINT32(x)); + if ( _rValue.isSigned() ) + _xParams->setByte(parameterIndex,_rValue); + else + _xParams->setShort(parameterIndex,_rValue); break; case DataType::SMALLINT: - _xParams->setShort(parameterIndex,(sal_Int16)::comphelper::getINT32(x)); + if ( _rValue.isSigned() ) + _xParams->setShort(parameterIndex,_rValue); + else + _xParams->setInt(parameterIndex,_rValue); break; case DataType::INTEGER: - _xParams->setInt(parameterIndex,::comphelper::getINT32(x)); + if ( _rValue.isSigned() ) + _xParams->setInt(parameterIndex,_rValue); + else + _xParams->setLong(parameterIndex,_rValue); break; default: { diff --git a/connectivity/source/commontools/dbtools2.cxx b/connectivity/source/commontools/dbtools2.cxx index e08c3a33076d..8e7c3bdb5dca 100644 --- a/connectivity/source/commontools/dbtools2.cxx +++ b/connectivity/source/commontools/dbtools2.cxx @@ -596,7 +596,39 @@ bool getBooleanDataSourceSetting( const Reference< XConnection >& _rxConnection, } return bValue; } +// ------------------------------------------------------------------------- +bool getDataSourceSetting( const Reference< XInterface >& _xChild, const ::rtl::OUString& _sAsciiSettingsName, + Any& /* [out] */ _rSettingsValue ) +{ + bool bIsPresent = false; + try + { + const Reference< XPropertySet> xDataSourceProperties( findDataSource( _xChild ), UNO_QUERY ); + OSL_ENSURE( xDataSourceProperties.is(), "getDataSourceSetting: invalid data source object!" ); + if ( !xDataSourceProperties.is() ) + return false; + + const Reference< XPropertySet > xSettings( + xDataSourceProperties->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Settings") ) ), + UNO_QUERY_THROW + ); + _rSettingsValue = xSettings->getPropertyValue( _sAsciiSettingsName ); + bIsPresent = true; + } + catch( const Exception& ) + { + bIsPresent = false; + } + return bIsPresent; +} +// ------------------------------------------------------------------------- +bool getDataSourceSetting( const Reference< XInterface >& _rxDataSource, const sal_Char* _pAsciiSettingsName, + Any& /* [out] */ _rSettingsValue ) +{ + ::rtl::OUString sAsciiSettingsName = ::rtl::OUString::createFromAscii(_pAsciiSettingsName); + return getDataSourceSetting( _rxDataSource, sAsciiSettingsName,_rSettingsValue ); +} // ----------------------------------------------------------------------------- sal_Bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp,const ::rtl::OUString& _sProperty,sal_Bool _bDefault) { diff --git a/connectivity/source/commontools/formattedcolumnvalue.cxx b/connectivity/source/commontools/formattedcolumnvalue.cxx index e1b49c878ba9..50189dac8a8e 100644 --- a/connectivity/source/commontools/formattedcolumnvalue.cxx +++ b/connectivity/source/commontools/formattedcolumnvalue.cxx @@ -45,13 +45,11 @@ /** === end UNO includes === **/ //#include <unotools/syslocale.hxx> - #include <tools/diagnose_ex.h> - #include <i18npool/mslangid.hxx> - #include <comphelper/numbers.hxx> #include <comphelper/componentcontext.hxx> +#include <unotools/sharedunocomponent.hxx> //........................................................................ namespace dbtools @@ -62,6 +60,7 @@ namespace dbtools using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::RuntimeException; using ::com::sun::star::uno::Any; @@ -116,21 +115,7 @@ namespace dbtools //................................................................ void lcl_clear_nothrow( FormattedColumnValue_Data& _rData ) { - if ( _rData.m_xFormatter.is() ) - { - try - { - Reference< XComponent > xFormatterComp( _rData.m_xFormatter, UNO_QUERY ); - if ( xFormatterComp.is() ) - xFormatterComp->dispose(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - _rData.m_xFormatter.clear(); - } - + _rData.m_xFormatter.clear(); _rData.m_nFormatKey = 0; _rData.m_nFieldType = DataType::OTHER; _rData.m_nKeyType = NumberFormat::UNDEFINED; @@ -141,21 +126,24 @@ namespace dbtools } //................................................................ - void lcl_initColumnDataValue_nothrow( const ::comphelper::ComponentContext& _rContext, FormattedColumnValue_Data& _rData, - const Reference< XRowSet >& _rxRowSet, const Reference< XPropertySet >& _rxColumn ) + void lcl_initColumnDataValue_nothrow( FormattedColumnValue_Data& _rData, + const Reference< XNumberFormatter >& i_rNumberFormatter, const Reference< XPropertySet >& _rxColumn ) { lcl_clear_nothrow( _rData ); - OSL_PRECOND( _rxRowSet.is(), "lcl_initColumnDataValue_nothrow: no row set!" ); - OSL_PRECOND( _rxColumn.is(), "lcl_initColumnDataValue_nothrow: no column!" ); - if ( !_rxRowSet.is() || !_rxColumn.is() ) + OSL_PRECOND( i_rNumberFormatter.is(), "lcl_initColumnDataValue_nothrow: no number formats -> no formatted values!" ); + if ( !i_rNumberFormatter.is() ) return; try { + Reference< XNumberFormatsSupplier > xNumberFormatsSupp( i_rNumberFormatter->getNumberFormatsSupplier(), UNO_SET_THROW ); + + // remember the column _rData.m_xColumn.set( _rxColumn, UNO_QUERY_THROW ); _rData.m_xColumnUpdate.set( _rxColumn, UNO_QUERY ); + // determine the field type, and whether it's a numeric field OSL_VERIFY( _rxColumn->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" ) ) ) >>= _rData.m_nFieldType ); switch ( _rData.m_nFieldType ) @@ -180,10 +168,6 @@ namespace dbtools break; } - // get the number formats supplier of the connection of the form - Reference< XConnection > xConnection( getConnection( _rxRowSet ), UNO_QUERY_THROW ); - Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( xConnection, sal_False, _rContext.getLegacyServiceFactory() ), UNO_QUERY_THROW ); - // get the format key of our bound field Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_QUERY_THROW ); bool bHaveFieldFormat = false; @@ -197,23 +181,49 @@ namespace dbtools // fall back to a format key as indicated by the field type Locale aSystemLocale; MsLangId::convertLanguageToLocale( MsLangId::getSystemLanguage(), aSystemLocale ); - Reference< XNumberFormatTypes > xNumTypes( xSupplier->getNumberFormats(), UNO_QUERY_THROW ); + Reference< XNumberFormatTypes > xNumTypes( xNumberFormatsSupp->getNumberFormats(), UNO_QUERY_THROW ); _rData.m_nFormatKey = getDefaultNumberFormat( _rxColumn, xNumTypes, aSystemLocale ); } // some more formatter settings - _rData.m_nKeyType = ::comphelper::getNumberFormatType( xSupplier->getNumberFormats(), _rData.m_nFormatKey ); - Reference< XPropertySet > xFormatSettings( xSupplier->getNumberFormatSettings(), UNO_QUERY_THROW ); + _rData.m_nKeyType = ::comphelper::getNumberFormatType( xNumberFormatsSupp->getNumberFormats(), _rData.m_nFormatKey ); + Reference< XPropertySet > xFormatSettings( xNumberFormatsSupp->getNumberFormatSettings(), UNO_QUERY_THROW ); OSL_VERIFY( xFormatSettings->getPropertyValue( ::rtl::OUString::createFromAscii( "NullDate" ) ) >>= _rData.m_aNullDate ); - // create a formatter working with the connection's number format supplier - _rData.m_xFormatter.set( _rContext.createComponent( "com.sun.star.util.NumberFormatter" ), UNO_QUERY_THROW ); - _rData.m_xFormatter->attachNumberFormatsSupplier( xSupplier ); + // remember the formatter + _rData.m_xFormatter = i_rNumberFormatter; + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + //................................................................ + void lcl_initColumnDataValue_nothrow( const ::comphelper::ComponentContext& i_rContext, FormattedColumnValue_Data& i_rData, + const Reference< XRowSet >& i_rRowSet, const Reference< XPropertySet >& i_rColumn ) + { + OSL_PRECOND( i_rRowSet.is(), "lcl_initColumnDataValue_nothrow: no row set!" ); + if ( !i_rRowSet.is() ) + return; + + Reference< XNumberFormatter > xNumberFormatter; + try + { + // get the number formats supplier of the connection of the form + Reference< XConnection > xConnection( getConnection( i_rRowSet ), UNO_QUERY_THROW ); + Reference< XNumberFormatsSupplier > xSupplier( getNumberFormats( xConnection, sal_True, i_rContext.getLegacyServiceFactory() ), UNO_SET_THROW ); + + // create a number formatter for it + xNumberFormatter.set( i_rContext.createComponent( "com.sun.star.util.NumberFormatter" ), UNO_QUERY_THROW ); + xNumberFormatter->attachNumberFormatsSupplier( xSupplier ); } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } + + lcl_initColumnDataValue_nothrow( i_rData, xNumberFormatter, i_rColumn ); } } @@ -221,11 +231,19 @@ namespace dbtools //= FormattedColumnValue //==================================================================== //-------------------------------------------------------------------- - FormattedColumnValue::FormattedColumnValue( const ::comphelper::ComponentContext& _rContext, - const Reference< XRowSet >& _rxRowSet, const Reference< XPropertySet >& _rxColumn ) + FormattedColumnValue::FormattedColumnValue( const ::comphelper::ComponentContext& i_rContext, + const Reference< XRowSet >& _rxRowSet, const Reference< XPropertySet >& i_rColumn ) + :m_pData( new FormattedColumnValue_Data ) + { + lcl_initColumnDataValue_nothrow( i_rContext, *m_pData, _rxRowSet, i_rColumn ); + } + + //-------------------------------------------------------------------- + FormattedColumnValue::FormattedColumnValue( const Reference< XNumberFormatter >& i_rNumberFormatter, + const Reference< XPropertySet >& _rxColumn ) :m_pData( new FormattedColumnValue_Data ) { - lcl_initColumnDataValue_nothrow( _rContext, *m_pData, _rxRowSet, _rxColumn ); + lcl_initColumnDataValue_nothrow( *m_pData, i_rNumberFormatter, _rxColumn ); } //-------------------------------------------------------------------- diff --git a/connectivity/source/commontools/makefile.mk b/connectivity/source/commontools/makefile.mk index cb5a4ad3f7aa..1cc6cf494919 100644 --- a/connectivity/source/commontools/makefile.mk +++ b/connectivity/source/commontools/makefile.mk @@ -89,6 +89,7 @@ EXCEPTIONSFILES=\ $(SLO)$/ParamterSubstitution.obj \ $(SLO)$/DriversConfig.obj \ $(SLO)$/formattedcolumnvalue.obj \ + $(SLO)$/BlobHelper.obj \ $(SLO)$/warningscontainer.obj SLOFILES=\ diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx index 45e937235dd1..f5d22e2937aa 100644 --- a/connectivity/source/commontools/predicateinput.cxx +++ b/connectivity/source/commontools/predicateinput.cxx @@ -148,9 +148,10 @@ namespace dbtools sal_Int32 nType = DataType::OTHER; _rxField->getPropertyValue( ::rtl::OUString::createFromAscii( "Type" ) ) >>= nType; - if ( ( DataType::CHAR == nType ) - || ( DataType::VARCHAR == nType ) + if ( ( DataType::CHAR == nType ) + || ( DataType::VARCHAR == nType ) || ( DataType::LONGVARCHAR == nType ) + || ( DataType::CLOB == nType ) ) { // yes -> force a quoted text and try again ::rtl::OUString sQuoted( _rStatement ); |