diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-10-28 12:26:00 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-10-28 14:46:24 +0200 |
commit | 0325be6f3de622be6af9b2f686e3c7afae0405b1 (patch) | |
tree | 00ec431017081cfd91aca276cb8e158daffa6aa6 /dbaccess | |
parent | f27bf3e888c6e98c4a723eb0a00c57f0197f1ed2 (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>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/ui/uno/copytablewizard.cxx | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 49cbb81d5c9f..995ca99ed022 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -1065,6 +1065,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 ); @@ -1096,6 +1097,7 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou const Any* pSelectedRow = m_aSourceSelection.getConstArray(); const Any* pSelEnd = pSelectedRow + m_aSourceSelection.getLength(); + sal_Int32 nRowCount = 0; bool bContinue = false; CopyTableRowEvent aCopyEvent; @@ -1130,9 +1132,12 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou break; } + ++nRowCount; + aCopyEvent.Error.clear(); try { + bool bInsertedPrimaryKey = false; // notify listeners m_aCopyTableListeners.notifyEach( &XCopyTableListener::copyingRow, aCopyEvent ); @@ -1149,6 +1154,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 ) || ( o3tl::make_unsigned(nSourceColumn) >= aSourceColTypes.size() ) ) { // ( we have to check here against 1 because the parameters are 1 based) ::dbtools::throwSQLException("Internal error: invalid column type index.", @@ -1250,6 +1263,7 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou } catch( const Exception& ) { + TOOLS_WARN_EXCEPTION("dbaccess", ""); aCopyEvent.Error = ::cppu::getCaughtException(); } |