diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2018-05-15 21:33:17 +0200 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2018-05-16 11:09:39 +0200 |
commit | a1825b219a22be8b6cf0ca54bf0ee6c64f55dc6d (patch) | |
tree | 85fcbbdf0d9eb80f3acd2283a4129f628ba4da43 /dbaccess | |
parent | 07174b62c6ee23f7b44742ecfe44d4ff8653e57f (diff) |
tdf#116987 dbahsql: check for table names..
..longer than 30 characters. In that case throw SQLException which
indicates that the currently used Firebird version cannot handle table
names longer than 30 characters.
Change-Id: Ib2978feaeef22b70de9f2351042c25206a041105
Reviewed-on: https://gerrit.libreoffice.org/54398
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/filter/hsqldb/fbalterparser.hxx | 3 | ||||
-rw-r--r-- | dbaccess/source/filter/hsqldb/fbcreateparser.cxx | 12 | ||||
-rw-r--r-- | dbaccess/source/filter/hsqldb/fbcreateparser.hxx | 5 | ||||
-rw-r--r-- | dbaccess/source/filter/hsqldb/hsqlimport.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/filter/hsqldb/utils.cxx | 15 | ||||
-rw-r--r-- | dbaccess/source/filter/hsqldb/utils.hxx | 2 |
6 files changed, 37 insertions, 2 deletions
diff --git a/dbaccess/source/filter/hsqldb/fbalterparser.hxx b/dbaccess/source/filter/hsqldb/fbalterparser.hxx index 99bbe55ef08a..d8ede453c99c 100644 --- a/dbaccess/source/filter/hsqldb/fbalterparser.hxx +++ b/dbaccess/source/filter/hsqldb/fbalterparser.hxx @@ -16,6 +16,9 @@ namespace dbahsql { class SAL_DLLPUBLIC_EXPORT FbAlterStmtParser : public AlterStmtParser { +protected: + void ensureProperTableLengths() const; + public: /** * Compose the result of the parser to statements of Firebird dialect diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx index d4f57c83800e..59f41c887368 100644 --- a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx +++ b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx @@ -19,8 +19,12 @@ #include "fbcreateparser.hxx" #include "columndef.hxx" +#include "utils.hxx" #include <com/sun/star/sdbc/DataType.hpp> + +#include <connectivity/dbexception.hxx> +#include <comphelper/processfactory.hxx> #include <rtl/ustrbuf.hxx> using namespace css::sdbc; @@ -102,8 +106,16 @@ OUString lcl_getTypeModifier(sal_Int32 eType) namespace dbahsql { +void FbCreateStmtParser::ensureProperTableLengths() const +{ + const std::vector<ColumnDefinition>& rColumns = getColumnDef(); + for (const auto& col : rColumns) + utils::ensureFirebirdTableLength(col.getName()); +} + OUString FbCreateStmtParser::compose() const { + ensureProperTableLengths(); OUStringBuffer sSql("CREATE TABLE "); sSql.append(getTableName()); diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.hxx b/dbaccess/source/filter/hsqldb/fbcreateparser.hxx index fab6752b8b0d..6f9aa5898d04 100644 --- a/dbaccess/source/filter/hsqldb/fbcreateparser.hxx +++ b/dbaccess/source/filter/hsqldb/fbcreateparser.hxx @@ -16,12 +16,15 @@ namespace dbahsql { class SAL_DLLPUBLIC_EXPORT FbCreateStmtParser : public CreateStmtParser { +protected: + void ensureProperTableLengths() const; + public: /** * Create statement parser, which can compose the result to statements of * Firebird dialect. */ - FbCreateStmtParser() {} + FbCreateStmtParser() = default; /** * Compose the result of the parser to statements of Firebird dialect diff --git a/dbaccess/source/filter/hsqldb/hsqlimport.cxx b/dbaccess/source/filter/hsqldb/hsqlimport.cxx index 707e34eaaa6c..cff35e6c702d 100644 --- a/dbaccess/source/filter/hsqldb/hsqlimport.cxx +++ b/dbaccess/source/filter/hsqldb/hsqlimport.cxx @@ -297,7 +297,7 @@ void HsqlImporter::importHsqlDatabase() auto statements = parser.getCreateStatements(); - if (statements.size() < 1) + if (statements.size() < 1 && !pException) { SAL_WARN("dbaccess", "dbashql: there is nothing to import"); return; // there is nothing to import diff --git a/dbaccess/source/filter/hsqldb/utils.cxx b/dbaccess/source/filter/hsqldb/utils.cxx index b6c5396e0c8e..dfdbee40c37b 100644 --- a/dbaccess/source/filter/hsqldb/utils.cxx +++ b/dbaccess/source/filter/hsqldb/utils.cxx @@ -19,6 +19,9 @@ */ #include <comphelper/string.hxx> +#include <comphelper/processfactory.hxx> +#include <connectivity/dbexception.hxx> + #include "utils.hxx" using namespace dbahsql; @@ -45,4 +48,16 @@ OUString utils::getTableNameFromStmt(const OUString& sSql) return *wordIter; } +void utils::ensureFirebirdTableLength(const OUString& sName) +{ + if (sName.getLength() > 30) // Firebird limitation + { + constexpr char NAME_TOO_LONG[] = "Firebird 3 doesn't currently support table names of more " + "than 30 characters, please shorten your table names in " + "the original file and try again."; + dbtools::throwGenericSQLException(NAME_TOO_LONG, + ::comphelper::getProcessComponentContext()); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/filter/hsqldb/utils.hxx b/dbaccess/source/filter/hsqldb/utils.hxx index cf76a1cd8781..02ccc3d2426b 100644 --- a/dbaccess/source/filter/hsqldb/utils.hxx +++ b/dbaccess/source/filter/hsqldb/utils.hxx @@ -17,6 +17,8 @@ namespace dbahsql namespace utils { OUString getTableNameFromStmt(const OUString& sSql); + +void ensureFirebirdTableLength(const OUString& sName); } } |