[Libreoffice-commits] core.git: dbaccess/source
Tamas Bunth
tamas.bunth at collabora.co.uk
Wed May 16 09:10:28 UTC 2018
dbaccess/source/filter/hsqldb/hsqlimport.cxx | 54 +++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 4 deletions(-)
New commits:
commit ea19b96b6beb0ce2f25705339d1d6342dc38b283
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date: Tue May 15 20:25:55 2018 +0200
tdf#117333, tdf#117325 dbahsql: exception handling
Add proper exception handling for importing HSQL database.
If there are errors during migration, the migration process should
continue anyway. The first error should be shown to the user. All the
others can be seen as a warning.
Popping up several error messages would be just annoying for the user.
Change-Id: Ia726ad777fd798f064a8fde1c0062c5b05fe59d0
Reviewed-on: https://gerrit.libreoffice.org/54396
Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
Tested-by: Tamás Bunth <btomi96 at gmail.com>
diff --git a/dbaccess/source/filter/hsqldb/hsqlimport.cxx b/dbaccess/source/filter/hsqldb/hsqlimport.cxx
index cff35e6c702d..c5e77eea195d 100644
--- a/dbaccess/source/filter/hsqldb/hsqlimport.cxx
+++ b/dbaccess/source/filter/hsqldb/hsqlimport.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/embed/XStorage.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/WrongFormatException.hpp>
@@ -27,8 +28,12 @@
#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/sdbc/XParameters.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
+#include <com/sun/star/sdbc/SQLException.hpp>
#include <rtl/ustrbuf.hxx>
+#include <connectivity/dbtools.hxx>
+#include <connectivity/dbexception.hxx>
+#include <comphelper/processfactory.hxx>
#include "hsqlimport.hxx"
#include "parseschema.hxx"
@@ -293,7 +298,16 @@ void HsqlImporter::importHsqlDatabase()
assert(m_xStorage);
SchemaParser parser(m_xStorage);
- parser.parseSchema();
+ std::unique_ptr<SQLException> pException;
+ try
+ {
+ parser.parseSchema();
+ }
+ catch (SQLException& ex)
+ {
+ if (!pException)
+ pException.reset(new SQLException{ ex });
+ }
auto statements = parser.getCreateStatements();
@@ -307,21 +321,53 @@ void HsqlImporter::importHsqlDatabase()
for (auto& sSql : statements)
{
Reference<XStatement> statement = m_rConnection->createStatement();
- statement->executeQuery(sSql);
+ try
+ {
+ statement->executeQuery(sSql);
+ }
+ catch (SQLException& ex)
+ {
+ if (!pException)
+ pException.reset(new SQLException{ ex });
+ }
}
// data
for (const auto& tableIndex : parser.getTableIndexes())
{
std::vector<ColumnDefinition> aColTypes = parser.getTableColumnTypes(tableIndex.first);
- parseTableRows(tableIndex.second, aColTypes, tableIndex.first);
+ try
+ {
+ parseTableRows(tableIndex.second, aColTypes, tableIndex.first);
+ }
+ catch (SQLException& ex)
+ {
+ if (!pException)
+ pException.reset(new SQLException{ ex });
+ }
}
// alter stmts
for (const auto& sSql : parser.getAlterStatements())
{
Reference<XStatement> statement = m_rConnection->createStatement();
- statement->executeQuery(sSql);
+ try
+ {
+ statement->executeQuery(sSql);
+ }
+ catch (SQLException& ex)
+ {
+ if (!pException)
+ pException.reset(new SQLException{ ex });
+ }
+ }
+
+ // show first error occured
+ if (pException)
+ {
+ SAL_WARN("dbaccess", "Error during migration");
+ dbtools::showError(dbtools::SQLExceptionInfo{ *pException }, nullptr,
+ ::comphelper::getProcessComponentContext());
}
}
}
More information about the Libreoffice-commits
mailing list