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

tdf#116987 dbahsql: check for table names..

..longer than 30 characters. In that case throw SQLException which
indicates that the currently used Firebird version cannot handle table
names longer than 30 characters.

Change-Id: Ib2978feaeef22b70de9f2351042c25206a041105
Reviewed-on: https://gerrit.libreoffice.org/54398Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTamás Bunth <btomi96@gmail.com>
üst 07174b62
......@@ -16,6 +16,9 @@ namespace dbahsql
{
class SAL_DLLPUBLIC_EXPORT FbAlterStmtParser : public AlterStmtParser
{
protected:
void ensureProperTableLengths() const;
public:
/**
* Compose the result of the parser to statements of Firebird dialect
......
......@@ -19,8 +19,12 @@
#include "fbcreateparser.hxx"
#include "columndef.hxx"
#include "utils.hxx"
#include <com/sun/star/sdbc/DataType.hpp>
#include <connectivity/dbexception.hxx>
#include <comphelper/processfactory.hxx>
#include <rtl/ustrbuf.hxx>
using namespace css::sdbc;
......@@ -102,8 +106,16 @@ OUString lcl_getTypeModifier(sal_Int32 eType)
namespace dbahsql
{
void FbCreateStmtParser::ensureProperTableLengths() const
{
const std::vector<ColumnDefinition>& rColumns = getColumnDef();
for (const auto& col : rColumns)
utils::ensureFirebirdTableLength(col.getName());
}
OUString FbCreateStmtParser::compose() const
{
ensureProperTableLengths();
OUStringBuffer sSql("CREATE TABLE ");
sSql.append(getTableName());
......
......@@ -16,12 +16,15 @@ namespace dbahsql
{
class SAL_DLLPUBLIC_EXPORT FbCreateStmtParser : public CreateStmtParser
{
protected:
void ensureProperTableLengths() const;
public:
/**
* Create statement parser, which can compose the result to statements of
* Firebird dialect.
*/
FbCreateStmtParser() {}
FbCreateStmtParser() = default;
/**
* Compose the result of the parser to statements of Firebird dialect
......
......@@ -297,7 +297,7 @@ void HsqlImporter::importHsqlDatabase()
auto statements = parser.getCreateStatements();
if (statements.size() < 1)
if (statements.size() < 1 && !pException)
{
SAL_WARN("dbaccess", "dbashql: there is nothing to import");
return; // there is nothing to import
......
......@@ -19,6 +19,9 @@
*/
#include <comphelper/string.hxx>
#include <comphelper/processfactory.hxx>
#include <connectivity/dbexception.hxx>
#include "utils.hxx"
using namespace dbahsql;
......@@ -45,4 +48,16 @@ OUString utils::getTableNameFromStmt(const OUString& sSql)
return *wordIter;
}
void utils::ensureFirebirdTableLength(const OUString& sName)
{
if (sName.getLength() > 30) // Firebird limitation
{
constexpr char NAME_TOO_LONG[] = "Firebird 3 doesn't currently support table names of more "
"than 30 characters, please shorten your table names in "
"the original file and try again.";
dbtools::throwGenericSQLException(NAME_TOO_LONG,
::comphelper::getProcessComponentContext());
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -17,6 +17,8 @@ namespace dbahsql
namespace utils
{
OUString getTableNameFromStmt(const OUString& sSql);
void ensureFirebirdTableLength(const OUString& sName);
}
}
......
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