diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2022-07-27 13:34:22 +0200 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2022-07-27 14:42:15 +0200 |
commit | 4d855bb916bd41221e2b23d6d782e19b4b2740f9 (patch) | |
tree | 73556a24dc683360c06216cfe47175211a6a404c /dbaccess | |
parent | 772f7a2dc3508bdebb53b6de4a43685d517cf1ef (diff) |
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 <serval2412@yahoo.fr>
Tested-by: Jenkins
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/ui/uno/copytablewizard.cxx | 58 |
1 files changed, 31 insertions, 27 deletions
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); + } } } } |