[Libreoffice-commits] core.git: dbaccess/source

Tamas Bunth tamas.bunth at collabora.co.uk
Wed May 16 09:10:02 UTC 2018


 dbaccess/source/filter/hsqldb/fbalterparser.hxx  |    3 +++
 dbaccess/source/filter/hsqldb/fbcreateparser.cxx |   12 ++++++++++++
 dbaccess/source/filter/hsqldb/fbcreateparser.hxx |    5 ++++-
 dbaccess/source/filter/hsqldb/hsqlimport.cxx     |    2 +-
 dbaccess/source/filter/hsqldb/utils.cxx          |   15 +++++++++++++++
 dbaccess/source/filter/hsqldb/utils.hxx          |    2 ++
 6 files changed, 37 insertions(+), 2 deletions(-)

New commits:
commit a1825b219a22be8b6cf0ca54bf0ee6c64f55dc6d
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Tue May 15 21:33:17 2018 +0200

    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 at libreoffice.org>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

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);
 }
 }
 


More information about the Libreoffice-commits mailing list