diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2019-02-04 22:06:47 +0100 |
---|---|---|
committer | Xisco Faulí <xiscofauli@libreoffice.org> | 2019-02-05 20:24:56 +0100 |
commit | 8d070171116eb9c57aae10d3dfbd913a097d2451 (patch) | |
tree | f012accfeb15f768ab53a595679ebe2d775ff621 /dbaccess | |
parent | 226df6f5835316f6a6322c33f59be18474a70f81 (diff) |
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@gmail.com>
(cherry picked from commit aa974a1b3798e04424623ad331e9f5a0ae01a34b)
Reviewed-on: https://gerrit.libreoffice.org/67419
Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/source/filter/hsqldb/fbcreateparser.cxx | 38 | ||||
-rw-r--r-- | dbaccess/source/filter/hsqldb/fbcreateparser.hxx | 1 |
2 files changed, 26 insertions, 13 deletions
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: /** |