1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-04-18 21:44:02 +03:00
Sergey Zefirov 5b9ddd902e
feat(ddl): MCOL-5744: better handling of utf8 charset aliases (#3174)
Server expands ut8_XXX aliases to utf8mb3_XXX or utf8mb4_XXX depending
on the UTF8_IS_UTF8MB3 setting in the OLD_MODE environment variable.

Server already has the necessary code implemented in the get_utf8_flag()
method of class THD. There are several uses of this flag and all we have
to do to be in line with server is to use it.

This patch does that for DDL as work on MCOL-5705 uncovered some
problems in that area.
2024-05-10 17:17:57 +01:00

136 lines
3.1 KiB
C++

/* Copyright (C) 2014 InfiniDB, Inc.
Copyright (C) 2016 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
/***********************************************************************
* $Id: sqlparser.cpp 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
#include <fstream>
#include <errno.h>
#define DDLPKGSQLPARSER_DLLEXPORT
#include "sqlparser.h"
#undef DDLPKGSQLPARSER_DLLEXPORT
#include "ddl-gram.h"
void scanner_finish(void* yyscanner);
void scanner_init(const char* str, void* yyscanner);
int ddllex_init_extra(void* user_defined, void** yyscanner);
int ddllex_destroy(void* yyscanner);
int ddlparse(ddlpackage::pass_to_bison* x);
void set_schema(std::string schema);
namespace ddlpackage
{
using namespace std;
SqlParser::SqlParser() : fStatus(-1), fDebug(false), x(&fParseTree)
{
}
void SqlParser::SetDebug(bool debug)
{
fDebug = debug;
}
void SqlParser::setDefaultSchema(std::string schema)
{
x.fDBSchema = schema;
}
void SqlParser::setDefaultCharset(const CHARSET_INFO* default_charset)
{
x.default_table_charset = default_charset;
}
int SqlParser::Parse(const char* sqltext, myf utf8_flag)
{
x.utf8_flag = utf8_flag;
ddllex_init_extra(&scanData, &x.scanner);
scanner_init(sqltext, x.scanner);
fStatus = ddlparse(&x);
return fStatus;
}
const ParseTree& SqlParser::GetParseTree(void)
{
if (!Good())
{
throw logic_error("The ParseTree is invalid");
}
return fParseTree;
}
bool SqlParser::Good()
{
return fStatus == 0;
}
SqlParser::~SqlParser()
{
scanner_finish(x.scanner); // free scanner allocated memory
ddllex_destroy(x.scanner);
}
SqlFileParser::SqlFileParser() : SqlParser()
{
}
int SqlFileParser::Parse(const string& sqlfile)
{
fStatus = -1;
ifstream ifsql;
ifsql.open(sqlfile.c_str());
if (!ifsql.is_open())
{
perror(sqlfile.c_str());
return fStatus;
}
char sqlbuf[1024 * 1024];
unsigned length;
ifsql.seekg(0, ios::end);
length = ifsql.tellg();
ifsql.seekg(0, ios::beg);
if (length > sizeof(sqlbuf) - 1)
{
throw length_error("SqlFileParser has file size hard limit of 16K.");
}
std::streamsize rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
if (rcount < 0)
return fStatus;
sqlbuf[rcount] = 0;
// cout << endl << sqlfile << "(" << rcount << ")" << endl;
// cout << "----------------------" << endl;
// cout << sqlbuf << endl;
return SqlParser::Parse(sqlbuf, MYF(0));
}
} // namespace ddlpackage