[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - dbaccess/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Feb 5 19:25:18 UTC 2019


 dbaccess/source/filter/hsqldb/fbcreateparser.cxx |   38 +++++++++++++++--------
 dbaccess/source/filter/hsqldb/fbcreateparser.hxx |    1 
 2 files changed, 26 insertions(+), 13 deletions(-)

New commits:
commit 8d070171116eb9c57aae10d3dfbd913a097d2451
Author:     Tamas Bunth <tamas.bunth at collabora.co.uk>
AuthorDate: Mon Feb 4 22:06:47 2019 +0100
Commit:     Xisco Faulí <xiscofauli at libreoffice.org>
CommitDate: Tue Feb 5 20:24:56 2019 +0100

    tdf#119502: dbahsql: tables without primary key
    
    No "PRIMARY KEY" keyword is needed, when composing a parsed sql which
    did not contain any primary key definition.
    
    Change-Id: Ife8b898806edba41a52d47dc04b1170606ea8aae
    Reviewed-on: https://gerrit.libreoffice.org/67379
    Tested-by: Jenkins
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
    (cherry picked from commit aa974a1b3798e04424623ad331e9f5a0ae01a34b)
    Reviewed-on: https://gerrit.libreoffice.org/67419
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>

diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx
index ad5fa6e65aa4..7a2e642670ae 100644
--- a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx
+++ b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx
@@ -106,6 +106,26 @@ OUString lcl_getTypeModifier(sal_Int32 eType)
 
 namespace dbahsql
 {
+void FbCreateStmtParser::appendPrimaryKeyPart(OUStringBuffer& rSql) const
+{
+    const std::vector<OUString>& sPrimaryKeys = getPrimaryKeys();
+    if (sPrimaryKeys.empty())
+        return; // no primary key specified
+
+    rSql.append(",");
+    rSql.append("PRIMARY KEY(");
+    auto it = sPrimaryKeys.cbegin();
+    while (it != sPrimaryKeys.end())
+    {
+        rSql.append(*it);
+        ++it;
+        if (it != sPrimaryKeys.end())
+            rSql.append(",");
+    }
+
+    rSql.append(")"); // end of primary key declaration
+}
+
 void FbCreateStmtParser::ensureProperTableLengths() const
 {
     const std::vector<ColumnDefinition>& rColumns = getColumnDef();
@@ -119,7 +139,7 @@ OUString FbCreateStmtParser::compose() const
     OUStringBuffer sSql("CREATE TABLE ");
     sSql.append(getTableName());
 
-    lcl_appendWithSpace(sSql, "(");
+    lcl_appendWithSpace(sSql, "("); // column declaration
     auto& rColumns = getColumnDef();
     auto columnIter = rColumns.cbegin();
     while (columnIter != rColumns.end())
@@ -184,21 +204,13 @@ OUString FbCreateStmtParser::compose() const
         }
 
         ++columnIter;
-        sSql.append(",");
-    }
-
-    sSql.append("PRIMARY KEY(");
-    const std::vector<OUString>& sPrimaryKeys = getPrimaryKeys();
-    auto it = sPrimaryKeys.cbegin();
-    while (it != sPrimaryKeys.end())
-    {
-        sSql.append(*it);
-        ++it;
-        if (it != sPrimaryKeys.end())
+        if (columnIter != rColumns.end())
             sSql.append(",");
     }
 
-    sSql.append("))"); // end of column declaration and primary keys
+    appendPrimaryKeyPart(sSql);
+
+    sSql.append(")"); // end of column declaration
     return sSql.makeStringAndClear();
 }
 
diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.hxx b/dbaccess/source/filter/hsqldb/fbcreateparser.hxx
index 6f9aa5898d04..c90e05c3bdd8 100644
--- a/dbaccess/source/filter/hsqldb/fbcreateparser.hxx
+++ b/dbaccess/source/filter/hsqldb/fbcreateparser.hxx
@@ -18,6 +18,7 @@ class SAL_DLLPUBLIC_EXPORT FbCreateStmtParser : public CreateStmtParser
 {
 protected:
     void ensureProperTableLengths() const;
+    void appendPrimaryKeyPart(rtl::OUStringBuffer& rSql) const;
 
 public:
     /**


More information about the Libreoffice-commits mailing list