Kaydet (Commit) aa974a1b authored tarafından Tamas Bunth's avatar Tamas Bunth Kaydeden (comit) Tamás Bunth

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: 's avatarTamás Bunth <btomi96@gmail.com>
üst 70295970
...@@ -106,6 +106,26 @@ OUString lcl_getTypeModifier(sal_Int32 eType) ...@@ -106,6 +106,26 @@ OUString lcl_getTypeModifier(sal_Int32 eType)
namespace dbahsql 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 void FbCreateStmtParser::ensureProperTableLengths() const
{ {
const std::vector<ColumnDefinition>& rColumns = getColumnDef(); const std::vector<ColumnDefinition>& rColumns = getColumnDef();
...@@ -119,7 +139,7 @@ OUString FbCreateStmtParser::compose() const ...@@ -119,7 +139,7 @@ OUString FbCreateStmtParser::compose() const
OUStringBuffer sSql("CREATE TABLE "); OUStringBuffer sSql("CREATE TABLE ");
sSql.append(getTableName()); sSql.append(getTableName());
lcl_appendWithSpace(sSql, "("); lcl_appendWithSpace(sSql, "("); // column declaration
auto& rColumns = getColumnDef(); auto& rColumns = getColumnDef();
auto columnIter = rColumns.cbegin(); auto columnIter = rColumns.cbegin();
while (columnIter != rColumns.end()) while (columnIter != rColumns.end())
...@@ -184,21 +204,13 @@ OUString FbCreateStmtParser::compose() const ...@@ -184,21 +204,13 @@ OUString FbCreateStmtParser::compose() const
} }
++columnIter; ++columnIter;
sSql.append(","); if (columnIter != rColumns.end())
}
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())
sSql.append(","); sSql.append(",");
} }
sSql.append("))"); // end of column declaration and primary keys appendPrimaryKeyPart(sSql);
sSql.append(")"); // end of column declaration
return sSql.makeStringAndClear(); return sSql.makeStringAndClear();
} }
......
...@@ -18,6 +18,7 @@ class SAL_DLLPUBLIC_EXPORT FbCreateStmtParser : public CreateStmtParser ...@@ -18,6 +18,7 @@ class SAL_DLLPUBLIC_EXPORT FbCreateStmtParser : public CreateStmtParser
{ {
protected: protected:
void ensureProperTableLengths() const; void ensureProperTableLengths() const;
void appendPrimaryKeyPart(rtl::OUStringBuffer& rSql) const;
public: public:
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment