diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2018-05-15 20:25:55 +0200 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2018-05-16 11:10:04 +0200 |
commit | ea19b96b6beb0ce2f25705339d1d6342dc38b283 (patch) | |
tree | fcf16f0d367914eba12551b9f6a4a992f9d43c9b /dbaccess | |
parent | a1825b219a22be8b6cf0ca54bf0ee6c64f55dc6d (diff) |
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@gmail.com>
Tested-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/filter/hsqldb/hsqlimport.cxx | 54 |
1 files changed, 50 insertions, 4 deletions
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()); } } } |