Skip to content

Commit

Permalink
Fixed CORE-6517 - CREATE DATABASE fails with 'Token unknown' error wh…
Browse files Browse the repository at this point in the history
…en DB name

is enclosed in double quotes and 'DEFAULT CHARACTER SET' is specified after DB name.
  • Loading branch information
asfernandes committed Apr 2, 2021
1 parent 91f7d20 commit 005bc68
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/yvalve/prepa_proto.h
Expand Up @@ -25,12 +25,12 @@
#define DSQL_PREPA_PROTO_H

#include "firebird/Interface.h"
#include "../common/classes/fb_string.h"

namespace Why {
class YAttachment;
}

bool PREPARSE_execute(Firebird::CheckStatusWrapper*, Why::YAttachment**,
USHORT, const SCHAR*, bool*, USHORT);
bool PREPARSE_execute(Firebird::CheckStatusWrapper*, Why::YAttachment**, Firebird::string&, bool*, USHORT);

#endif // DSQL_PREPA_PROTO_H
38 changes: 35 additions & 3 deletions src/yvalve/preparse.cpp
Expand Up @@ -157,14 +157,14 @@ static NoCaseString getToken(unsigned& pos, const Tokens& toks, int symbol = SYM
**/
bool PREPARSE_execute(CheckStatusWrapper* status, Why::YAttachment** ptrAtt,
USHORT stmt_length, const SCHAR* stmt, bool* stmt_eaten, USHORT dialect)
string& stmt, bool* stmt_eaten, USHORT dialect)
{
// no use creating separate pool for a couple of strings
ContextPoolHolder context(getDefaultMemoryPool());

try
{
if (!stmt)
if (stmt.isEmpty())
{
Arg::Gds(isc_command_end_err).raise();
}
Expand All @@ -177,7 +177,39 @@ bool PREPARSE_execute(CheckStatusWrapper* status, Why::YAttachment** ptrAtt,

Tokens tks;
tks.quotes(quotes);
tks.parse(stmt_length, stmt);
tks.parse(stmt.length(), stmt.c_str());

for (int tokenPos = tks.getCount() - 1; tokenPos >= 0; --tokenPos)
{
const Tokens::Tok& token = tks[tokenPos];

if (token.length > 0 && token.text[0] == '"')
{
string newToken = "'";

for (unsigned i = 1; i < token.length - 1; ++i)
{
switch (token.text[i])
{
case '\'':
newToken += "''";
break;

case '"':
++i;
newToken += '"';
break;

default:
newToken += token.text[i];
}
}

newToken += "'";
stmt.replace(token.origin, token.length, newToken);
}
}

unsigned pos = 0;

if (getToken(pos, tks) != pp_symbols[PP_CREATE].symbol)
Expand Down
7 changes: 5 additions & 2 deletions src/yvalve/utl.cpp
Expand Up @@ -587,7 +587,10 @@ YAttachment* UtilInterface::executeCreateDatabase(
if (stmtIsCreateDb)
*stmtIsCreateDb = FB_FALSE;

if (!PREPARSE_execute(status, &att, stmtLength, creatDBstatement, &stmtEaten, dialect))
string statement(creatDBstatement,
(stmtLength == 0 && creatDBstatement ? strlen(creatDBstatement) : stmtLength));

if (!PREPARSE_execute(status, &att, statement, &stmtEaten, dialect))
return NULL;

if (stmtIsCreateDb)
Expand All @@ -611,7 +614,7 @@ YAttachment* UtilInterface::executeCreateDatabase(

if (!stmtEaten)
{
att->execute(status, crdbTrans, stmtLength, creatDBstatement, dialect, NULL, NULL, NULL, NULL);
att->execute(status, crdbTrans, statement.length(), statement.c_str(), dialect, NULL, NULL, NULL, NULL);
if (status->getState() & Firebird::IStatus::STATE_ERRORS)
{
crdbTrans->rollback(&tempCheckStatusWrapper);
Expand Down

0 comments on commit 005bc68

Please sign in to comment.