diff options
Diffstat (limited to 'connectivity/source/drivers/firebird/Tables.cxx')
-rw-r--r-- | connectivity/source/drivers/firebird/Tables.cxx | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 5acb391caeb5..3675882446f4 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * @@ -9,8 +9,8 @@ #include "Table.hxx" #include "Tables.hxx" +#include "Views.hxx" #include "Catalog.hxx" -#include "Util.hxx" #include <TConnection.hxx> @@ -30,7 +30,6 @@ using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::uno; @@ -42,7 +41,7 @@ void Tables::impl_refresh() static_cast<Catalog&>(m_rParent).refreshTables(); } -ObjectType Tables::createObject(const OUString& rName) +css::uno::Reference< css::beans::XPropertySet > Tables::createObject(const OUString& rName) { // Only retrieving a single table, so table type is irrelevant (param 4) uno::Reference< XResultSet > xTables = m_xMetaData->getTables(Any(), @@ -51,14 +50,14 @@ ObjectType Tables::createObject(const OUString& rName) uno::Sequence< OUString >()); if (!xTables.is()) - throw RuntimeException("Could not acquire table."); + throw RuntimeException(u"Could not acquire table."_ustr); uno::Reference< XRow > xRow(xTables,UNO_QUERY_THROW); if (!xTables->next()) throw RuntimeException(); - ObjectType xRet(new Table(this, + css::uno::Reference< css::beans::XPropertySet > xRet(new Table(this, m_rMutex, m_xMetaData->getConnection(), xRow->getString(3), // Name @@ -66,7 +65,7 @@ ObjectType Tables::createObject(const OUString& rName) xRow->getString(5))); // Description / Remarks / Comments if (xTables->next()) - throw RuntimeException("Found more tables than expected."); + throw RuntimeException(u"Found more tables than expected."_ustr); return xRet; } @@ -81,7 +80,7 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bIsAutoIncrement; const OUString sQuoteString = xMetaData->getIdentifierQuoteString(); - OUStringBuffer aSql = ::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)))); + OUStringBuffer aSql(::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))); // check if the user enter a specific string to create autoincrement values OUString sAutoIncrementValue; @@ -90,9 +89,8 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP if ( xPropInfo.is() && xPropInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) ) xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) >>= sAutoIncrementValue; - aSql.append(" "); - - aSql.append(dbtools::createStandardTypePart(xColProp, _xConnection)); + aSql.append(" " + + dbtools::createStandardTypePart(xColProp, _xConnection)); // Add character set for (VAR)BINARY (fix) types: // (VAR) BINARY is distinguished from other CHAR types by its character set. // Octets is a special character set for binary data. @@ -104,15 +102,13 @@ OUString Tables::createStandardColumnPart(const Reference< XPropertySet >& xColP >>= aType; if(aType == DataType::BINARY || aType == DataType::VARBINARY) { - aSql.append(" "); - aSql.append("CHARACTER SET OCTETS"); + aSql.append(" CHARACTER SET OCTETS"); } } if ( bIsAutoIncrement && !sAutoIncrementValue.isEmpty()) { - aSql.append(" "); - aSql.append(sAutoIncrementValue); + aSql.append(" " + sAutoIncrementValue); } // AutoIncrement "IDENTITY" is implicitly "NOT NULL" else if(::comphelper::getINT32(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISNULLABLE))) == ColumnValue::NO_NULLS) @@ -130,14 +126,14 @@ uno::Reference< XPropertySet > Tables::createDescriptor() } //----- XAppend --------------------------------------------------------------- -ObjectType Tables::appendObject(const OUString& rName, +css::uno::Reference< css::beans::XPropertySet > Tables::appendObject(const OUString& rName, const uno::Reference< XPropertySet >& rDescriptor) { /* OUString sSql(::dbtools::createSqlCreateTableStatement(rDescriptor, m_xMetaData->getConnection())); */ OUStringBuffer aSqlBuffer("CREATE TABLE "); OUString sCatalog, sSchema, sComposedName, sTable; - const Reference< XConnection>& xConnection = m_xMetaData->getConnection(); + const Reference< XConnection> xConnection = m_xMetaData->getConnection(); ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap(); @@ -149,11 +145,11 @@ ObjectType Tables::appendObject(const OUString& rName, if ( sComposedName.isEmpty() ) ::dbtools::throwFunctionSequenceException(xConnection); - aSqlBuffer.append(sComposedName); - aSqlBuffer.append(" ("); + aSqlBuffer.append(sComposedName + + " ("); // columns - Reference<XColumnsSupplier> xColumnSup(rDescriptor,UNO_QUERY); + Reference<XColumnsSupplier> xColumnSup(rDescriptor, UNO_QUERY_THROW); Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY); // check if there are columns if(!xColumns.is() || !xColumns->getCount()) @@ -166,24 +162,23 @@ ObjectType Tables::appendObject(const OUString& rName, { if ( (xColumns->getByIndex(i) >>= xColProp) && xColProp.is() ) { - aSqlBuffer.append(createStandardColumnPart(xColProp,xConnection)); - aSqlBuffer.append(","); + aSqlBuffer.append(createStandardColumnPart(xColProp,xConnection) + + ","); } } - OUString sSql = aSqlBuffer.makeStringAndClear(); const OUString sKeyStmt = ::dbtools::createStandardKeyStatement(rDescriptor,xConnection); if ( !sKeyStmt.isEmpty() ) - sSql += sKeyStmt; + aSqlBuffer.append(sKeyStmt); else { - if ( sSql.endsWith(",") ) - sSql = sSql.replaceAt(sSql.getLength()-1, 1, ")"); + if (aSqlBuffer[aSqlBuffer.getLength() - 1] == ',') + aSqlBuffer[aSqlBuffer.getLength() - 1] = ')'; else - sSql += ")"; + aSqlBuffer.append(")"); } - m_xMetaData->getConnection()->createStatement()->execute(sSql); + m_xMetaData->getConnection()->createStatement()->execute(OUString::unacquired(aSqlBuffer)); return createObject(rName); } @@ -196,16 +191,34 @@ void Tables::dropObject(sal_Int32 nPosition, const OUString& sName) if (ODescriptor::isNew(xTable)) return; - OUStringBuffer sSql("DROP "); - OUString sType; - xTable->getPropertyValue("Type") >>= sType; - sSql.append(sType); + xTable->getPropertyValue(u"Type"_ustr) >>= sType; const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); - sSql.append(::dbtools::quoteName(sQuoteString,sName)); - m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); + m_xMetaData->getConnection()->createStatement()->execute( + "DROP " + sType + " " + ::dbtools::quoteName(sQuoteString,sName)); + + if (sType == "VIEW") + { + Views* pViews = static_cast<Views*>(static_cast<Catalog&>(m_rParent).getPrivateViews()); + if ( pViews && pViews->hasByName(sName) ) + pViews->dropByNameImpl(sName); + } } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +void connectivity::firebird::Tables::appendNew(const OUString& _rsNewTable) +{ + insertElement(_rsNewTable, nullptr); + + // notify our container listeners + css::container::ContainerEvent aEvent(static_cast<XContainer*>(this), + css::uno::Any(_rsNewTable), css::uno::Any(), + css::uno::Any()); + comphelper::OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + aListenerLoop.next()->elementInserted(aEvent); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |