From eb0f90d33200e26d128672bbb6a105e815144cfc Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 26 Nov 2009 09:07:47 +0100 Subject: dba33d: #i106526# askParameter now compress duplicate parameter names --- connectivity/source/commontools/dbtools.cxx | 53 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'connectivity/source/commontools') diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index bb088937c313..d5502fc0272c 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -1388,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 @@ -1779,15 +1781,31 @@ void askForParameters(const Reference< XSingleSelectQueryComposer >& _xComposer, Reference xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference(); Reference 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 > TParameterPositions; + TParameterPositions aParameterNames; + for(sal_Int32 i = 0; i < nParamCount; ++i) + { + Reference 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 xWrappedParameters = new OParameterWrapper(_aParametersSet,xParamsAsIndicies); + Reference xWrappedParameters = new OParameterWrapper(aNewParameterSet,xParamsAsIndicies); aRequest.Parameters = xWrappedParameters; aRequest.Connection = _xConnection; OInteractionRequest* pRequest = new OInteractionRequest(makeAny(aRequest)); @@ -1815,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; @@ -1827,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::iterator aIterPos = aFind->second.begin(); + ::std::vector::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) } } } -- cgit From e469ee0ef7a27b7fe74de6961bb2fca7836bf9b9 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Thu, 10 Dec 2009 11:45:59 +0100 Subject: dba33d: merge --- connectivity/source/commontools/FValue.cxx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'connectivity/source/commontools') diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index 36d5bd2db16c..7ea68e099dc3 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -1921,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< XClob > getClob() const = 0; + virtual Reference< XBlob > getBlob() const = 0; + virtual Any getObject() const = 0; virtual sal_Bool wasNull() const = 0; virtual ~IValueSource() { } @@ -1950,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< XClob > getClob() const { return m_xRow->getClob( m_nPos ); }; + virtual Reference< XBlob > getBlob() const { return m_xRow->getBlob( m_nPos ); }; + virtual Any getObject() const { return m_xRow->getObject( m_nPos ,NULL); }; virtual sal_Bool wasNull() const { return m_xRow->wasNull( ); }; private: @@ -1980,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< XClob > getClob() const { return m_xColumn->getClob(); }; + virtual Reference< XBlob > getBlob() const { return m_xColumn->getBlob(); }; + virtual Any getObject() const { return m_xColumn->getObject(NULL); }; virtual sal_Bool wasNull() const { return m_xColumn->wasNull( ); }; private: @@ -2075,23 +2084,15 @@ void ORowSetValue::impl_fill( const sal_Int32 _nType, sal_Bool _bNullable, const (*this) = _rValueSource.getLong(); break; case DataType::CLOB: -<<<<<<< local - (*this) = ::com::sun::star::uno::makeAny(_xRow->getClob(_nPos)); -======= - (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getCharacterStream()); ->>>>>>> other + (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getClob()); setTypeKind(DataType::CLOB); break; case DataType::BLOB: -<<<<<<< local - (*this) = ::com::sun::star::uno::makeAny(_xRow->getBlob(_nPos)); -======= - (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBinaryStream()); ->>>>>>> other + (*this) = ::com::sun::star::uno::makeAny(_rValueSource.getBlob()); setTypeKind(DataType::BLOB); break; case DataType::OTHER: - (*this) = _xRow->getObject(_nPos,NULL); + (*this) = _rValueSource.getObject(); setTypeKind(DataType::OTHER); break; default: -- cgit From 55988d12e9edbdabd2a6b9b83c995e787d07b940 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 16 Dec 2009 12:46:33 +0100 Subject: dba33e: #i107717# impl first entry points for db extensions --- connectivity/source/commontools/TIndexes.cxx | 154 ++++++++++++----------- connectivity/source/commontools/TKeys.cxx | 154 +++++++++++++---------- connectivity/source/commontools/TTableHelper.cxx | 109 +++++++++++----- connectivity/source/commontools/dbtools2.cxx | 32 +++++ 4 files changed, 277 insertions(+), 172 deletions(-) (limited to 'connectivity/source/commontools') 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 xColumnSup(descriptor,UNO_QUERY); - Reference 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 xColumnSup(descriptor,UNO_QUERY); + Reference 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 xColumnSup(descriptor,UNO_QUERY); - Reference xColumns(xColumnSup->getColumns(),UNO_QUERY); - Reference< XPropertySet > xColProp; - if(xColumns->getCount() != 1) - throw SQLException(); + Reference xColumnSup(descriptor,UNO_QUERY); + Reference 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 xColumnSup(descriptor,UNO_QUERY); - Reference xColumns(xColumnSup->getColumns(),UNO_QUERY); - Reference< XPropertySet > xColProp; - for(sal_Int32 i=0;igetCount();++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;igetCount();++i) + Reference xColumnSup(descriptor,UNO_QUERY); + Reference 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;igetCount();++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 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 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/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& _xProp,const ::rtl::OUString& _sProperty,sal_Bool _bDefault) { -- cgit From d7bee45fb0d3178bcf4bfe52fddd9e2b73735ee8 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Thu, 17 Dec 2009 10:48:18 +0100 Subject: dba33e: #i107251#: allow to work with an external number formatter --- .../source/commontools/formattedcolumnvalue.cxx | 90 +++++++++++++--------- 1 file changed, 54 insertions(+), 36 deletions(-) (limited to 'connectivity/source/commontools') diff --git a/connectivity/source/commontools/formattedcolumnvalue.cxx b/connectivity/source/commontools/formattedcolumnvalue.cxx index 76519aa6a551..b2481d0c1020 100644 --- a/connectivity/source/commontools/formattedcolumnvalue.cxx +++ b/connectivity/source/commontools/formattedcolumnvalue.cxx @@ -45,13 +45,11 @@ /** === end UNO includes === **/ #include - #include - #include - #include #include +#include //........................................................................ 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 ); } //-------------------------------------------------------------------- -- cgit