summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-10-28 12:26:00 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-11-02 06:53:41 +0100
commit33a83d378f3feaafb4befc7f493df36f67f55cae (patch)
tree82bbd83a53b4684916be552267bd4fb655e98b69 /dbaccess
parent421e82eef7b60a5ebbba1d57c3c95228cb7fa7ee (diff)
Fix bug in copying table where we need to create a primary key
The problem seems to be that commit fa177231cd20bf3c3f4bb9b50f6646da139c6766 Author: Tamas Bunth <tamas.bunth@collabora.co.uk> Date: Fri Aug 30 14:57:31 2019 +0200 tdf#127093, tdf#127092 Fix pasting autoincremented was reverted in commit d783017c1ccb4e62e99f26b42250ac4e15780cff. But the follow-on commit commit 376cc3ea0fc2e0f209763a2a27c5852136332c86 Author: Tamas Bunth <tamas.bunth@collabora.co.uk> Date: Sat Aug 31 18:27:44 2019 +0200 dbaccess: delete old paste autoincrement logic was not reverted. This is not a straight revert of the second commit, because autoincrement has since been improved with commit 2a8e120db1c3175ff937cdbe6d0ade23dc380c01 Author: Oleksii Makhotin <alex@bitprox.com> Date: Tue Apr 6 16:03:41 2021 +0300 tdf#119962 Fix autoincrement for copied table Change-Id: Ia9657d88b3e77ba72399ad9afeece3bda3f57038 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141967 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> (cherry picked from commit 0325be6f3de622be6af9b2f686e3c7afae0405b1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141933 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/source/ui/uno/copytablewizard.cxx11
1 files changed, 11 insertions, 0 deletions
diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx
index 9ebd7d6df288..dfc179ff367c 100644
--- a/dbaccess/source/ui/uno/copytablewizard.cxx
+++ b/dbaccess/source/ui/uno/copytablewizard.cxx
@@ -1068,6 +1068,7 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou
const OCopyTableWizard& rWizard = impl_getDialog_throw();
ODatabaseExport::TPositions aColumnPositions = rWizard.GetColumnPositions();
+ const bool bShouldCreatePrimaryKey = rWizard.shouldCreatePrimaryKey();
Reference< XRow > xRow ( _rxSourceResultSet, UNO_QUERY_THROW );
Reference< XRowLocate > xRowLocate ( _rxSourceResultSet, UNO_QUERY_THROW );
@@ -1139,6 +1140,7 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou
aCopyEvent.Error.clear();
try
{
+ bool bInsertedPrimaryKey = false;
// notify listeners
m_aCopyTableListeners.notifyEach( &XCopyTableListener::copyingRow, aCopyEvent );
@@ -1156,6 +1158,14 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou
continue;
}
+ if ( bShouldCreatePrimaryKey && !bInsertedPrimaryKey )
+ {
+ xStatementParams->setInt( 1, nRowCount );
+ ++nSourceColumn;
+ bInsertedPrimaryKey = true;
+ continue;
+ }
+
if ( ( nSourceColumn < 1 ) || ( nSourceColumn >= static_cast<sal_Int32>(aSourceColTypes.size()) ) )
{ // ( we have to check here against 1 because the parameters are 1 based)
::dbtools::throwSQLException("Internal error: invalid column type index.",
@@ -1257,6 +1267,7 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou
}
catch( const Exception& )
{
+ TOOLS_WARN_EXCEPTION("dbaccess", "");
aCopyEvent.Error = ::cppu::getCaughtException();
}