diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2019-02-04 22:06:47 +0100 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2019-02-05 11:25:07 +0100 |
commit | aa974a1b3798e04424623ad331e9f5a0ae01a34b (patch) | |
tree | b0fc260f220a73791bb41e3e5cda6ea625cb700e /dbaccess | |
parent | 7029597034363c301727a3d16bd394c27a379796 (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>
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: /** |