dbaccess/source/ui/uno/copytablewizard.cxx | 58 +++++++++++++++-------------- 1 file changed, 31 insertions(+), 27 deletions(-)
New commits: commit 8c54c132cac96bb13ff70d3920c81d126fd7c17d Author: Julien Nabet <serval2...@yahoo.fr> AuthorDate: Wed Jul 27 13:34:22 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jul 27 17:48:43 2022 +0200 tdf#150089: not all databases know "RESTART WITH" Regression from: https://cgit.freedesktop.org/libreoffice/core/commit tdf#119962 Fix autoincrement for copied table in 2021 so use the block added in the patch only when detecting "hsql" or "firebird" in the string returned by getDatabaseProductName put in lowercase Change-Id: Ic35a03039e6d06846892d93d5b30186c53f24052 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137499 Reviewed-by: Julien Nabet <serval2...@yahoo.fr> (cherry picked from commit e9d046442c500c82b353d1e2e27b9adc22bf396b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137515 Reviewed-by: Lionel Mamane <lio...@mamane.lu> Tested-by: Jenkins diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 6196cba6678c..f7cf836be721 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -1346,42 +1346,46 @@ void CopyTableWizard::impl_doCopy_nothrow() // tdf#119962 const Reference< XDatabaseMetaData > xDestMetaData( m_xDestConnection->getMetaData(), UNO_SET_THROW ); - const OUString sComposedTableName = ::dbtools::composeTableName( xDestMetaData, xTable, ::dbtools::EComposeRule::InDataManipulation, true ); + OUString sDatabaseDest = xDestMetaData->getDatabaseProductName().toAsciiLowerCase(); + if ( (sDatabaseDest.indexOf("hsql") != -1) || (sDatabaseDest.indexOf("firebird") != -1) ) + { + const OUString sComposedTableName = ::dbtools::composeTableName( xDestMetaData, xTable, ::dbtools::EComposeRule::InDataManipulation, true ); - OUString aSchema,aTable; - xTable->getPropertyValue("SchemaName") >>= aSchema; - xTable->getPropertyValue("Name") >>= aTable; - Any aCatalog = xTable->getPropertyValue("CatalogName"); + OUString aSchema,aTable; + xTable->getPropertyValue("SchemaName") >>= aSchema; + xTable->getPropertyValue("Name") >>= aTable; + Any aCatalog = xTable->getPropertyValue("CatalogName"); - const Reference< XResultSet > xResultPKCL(xDestMetaData->getPrimaryKeys(aCatalog,aSchema,aTable)); - Reference< XRow > xRowPKCL(xResultPKCL, UNO_QUERY_THROW); - OUString sPKCL; - if ( xRowPKCL.is() ) - { - if (xResultPKCL->next()) + const Reference< XResultSet > xResultPKCL(xDestMetaData->getPrimaryKeys(aCatalog,aSchema,aTable)); + Reference< XRow > xRowPKCL(xResultPKCL, UNO_QUERY_THROW); + OUString sPKCL; + if ( xRowPKCL.is() ) { - sPKCL = xRowPKCL->getString(4); + if (xResultPKCL->next()) + { + sPKCL = xRowPKCL->getString(4); + } } - } - if (!sPKCL.isEmpty()) - { - OUString strSql = "SELECT MAX(\"" + sPKCL + "\") FROM " + sComposedTableName; + if (!sPKCL.isEmpty()) + { + OUString strSql = "SELECT MAX(\"" + sPKCL + "\") FROM " + sComposedTableName; - Reference< XResultSet > xResultMAXNUM(m_xDestConnection->createStatement()->executeQuery(strSql)); - Reference< XRow > xRow(xResultMAXNUM, UNO_QUERY_THROW); + Reference< XResultSet > xResultMAXNUM(m_xDestConnection->createStatement()->executeQuery(strSql)); + Reference< XRow > xRow(xResultMAXNUM, UNO_QUERY_THROW); - sal_Int64 maxVal = -1L; - if (xResultMAXNUM->next()) - { - maxVal = xRow->getLong(1); - } + sal_Int64 maxVal = -1L; + if (xResultMAXNUM->next()) + { + maxVal = xRow->getLong(1); + } - if (maxVal > 0L) - { - strSql = "ALTER TABLE " + sComposedTableName + " ALTER \"" + sPKCL + "\" RESTART WITH " + OUString::number(maxVal + 1); + if (maxVal > 0L) + { + strSql = "ALTER TABLE " + sComposedTableName + " ALTER \"" + sPKCL + "\" RESTART WITH " + OUString::number(maxVal + 1); - m_xDestConnection->createStatement()->execute(strSql); + m_xDestConnection->createStatement()->execute(strSql); + } } } }