From b6dc6712aef820c2d296101961b163d665633d9a Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 26 Mar 2023 10:02:26 +0300 Subject: Simplify FbCreateStmtParser::compose Change-Id: I7b593cdfc4ee32897314d95d71c9dcecc8bb9a8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149614 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- dbaccess/source/filter/hsqldb/fbcreateparser.cxx | 33 +++++++++--------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx index 1740998c62d2..5d4244f8085b 100644 --- a/dbaccess/source/filter/hsqldb/fbcreateparser.cxx +++ b/dbaccess/source/filter/hsqldb/fbcreateparser.cxx @@ -29,12 +29,6 @@ using namespace css::sdbc; namespace { -void lcl_appendWithSpace(OUStringBuffer& sBuff, std::u16string_view sStr) -{ - sBuff.append(" "); - sBuff.append(sStr); -} - OUString lcl_DataTypetoFbTypeName(sal_Int32 eType) { switch (eType) @@ -110,8 +104,7 @@ void FbCreateStmtParser::appendPrimaryKeyPart(OUStringBuffer& rSql) const if (sPrimaryKeys.empty()) return; // no primary key specified - rSql.append(","); - rSql.append("PRIMARY KEY("); + rSql.append(",PRIMARY KEY("); auto it = sPrimaryKeys.cbegin(); while (it != sPrimaryKeys.end()) { @@ -135,15 +128,14 @@ OUString FbCreateStmtParser::compose() const { ensureProperTableLengths(); OUStringBuffer sSql(128); - sSql.append("CREATE TABLE " + getTableName()); + sSql.append("CREATE TABLE " + getTableName() + " ("); // column declaration - lcl_appendWithSpace(sSql, u"("); // column declaration auto& rColumns = getColumnDef(); auto columnIter = rColumns.cbegin(); while (columnIter != rColumns.end()) { - lcl_appendWithSpace(sSql, columnIter->getName()); - lcl_appendWithSpace(sSql, lcl_DataTypetoFbTypeName(columnIter->getDataType())); + sSql.append(" " + columnIter->getName() + " " + + lcl_DataTypetoFbTypeName(columnIter->getDataType())); std::vector params{ columnIter->getParams() }; @@ -173,31 +165,30 @@ OUString FbCreateStmtParser::compose() const // special modifiers here, based on type (e.g. charset, subtype) OUString sModifier = lcl_getTypeModifier(columnIter->getDataType()); if (!sModifier.isEmpty()) - lcl_appendWithSpace(sSql, sModifier); + sSql.append(" " + sModifier); if (columnIter->isAutoIncremental()) { - lcl_appendWithSpace(sSql, u"GENERATED BY DEFAULT AS IDENTITY (START WITH "); - // start with 0: // HSQLDB: first value will be 0. // Firebird: first value will be 1. - sSql.append(OUString::number(columnIter->getStartValue() - 1) + ")"); + sSql.append(" GENERATED BY DEFAULT AS IDENTITY (START WITH " + + OUString::number(columnIter->getStartValue() - 1) + ")"); } else if (!columnIter->isNullable()) - lcl_appendWithSpace(sSql, u"NOT NULL"); + sSql.append(" NOT NULL"); if (columnIter->isCaseInsensitive()) - lcl_appendWithSpace(sSql, u"COLLATE UNICODE_CI"); + sSql.append(" COLLATE UNICODE_CI"); const OUString& sDefaultVal = columnIter->getDefault(); if (!sDefaultVal.isEmpty()) { - lcl_appendWithSpace(sSql, u"DEFAULT"); + sSql.append(" DEFAULT "); if (sDefaultVal.equalsIgnoreAsciiCase("NOW")) - lcl_appendWithSpace(sSql, u"\'NOW\'"); // Fb likes it single quoted + sSql.append("'NOW'"); // Fb likes it single quoted else - lcl_appendWithSpace(sSql, sDefaultVal); + sSql.append(sDefaultVal); } ++columnIter; -- cgit