1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-01 06:21:41 +03:00
Files
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

155 lines
3.6 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.h 9210 2013-01-21 14:10:42Z rdempsey $
*
*
***********************************************************************/
/** @file
*
* This contains a class wrapper for the Bison parsing machinery.
*/
#include <stdexcept>
#include "collation.h" // CHARSET_INFO
#include "ddlpkg.h"
#include "mariadb_my_sys.h" // myf, MYF()
#define EXPORT
namespace ddlpackage
{
typedef SqlStatementList ParseTree;
/** @brief SqlParser is a class interface around the Bison parser
* machinery for DDL.
*
* Example:
*
* @verbatim
SqlParser parser;
parser.Parse(sqlbuf);
or
SqlFileParser parser;
parser.setDefaultSchema("tpch");
parser.Parse(sqlFileName);
if (parser.Good()) {
const ParseTree &ptree = parser.GetParseTree();
cout << ptree.fList.size() << " " << "SQL statements" << endl;
cout << ptree << endl;
}
else {
cout << "Parser failed." << endl;
}
@endverbatim
*/
/*
Instance specific data for use by the scanner.
*/
typedef std::vector<char*> valbuf_t;
struct scan_data
{
/* Handles to the buffer that the lexer uses internally */
char* scanbuf;
void* scanbufhandle; // This is a YY_BUFFER_STATE defined in ddl-scan.cpp
valbuf_t valbuf;
};
struct pass_to_bison
{
ParseTree* fParseTree;
std::string fDBSchema;
void* scanner;
const CHARSET_INFO* default_table_charset;
myf utf8_flag;
pass_to_bison(ParseTree* pt) :
fParseTree(pt)
, scanner(NULL)
, default_table_charset(NULL)
, utf8_flag(MYF(0))
{};
};
class SqlParser
{
public:
EXPORT SqlParser(void);
EXPORT virtual ~SqlParser();
EXPORT int Parse(const char* sqltext, myf utf8_flag);
/** @brief Return the ParseTree if state is Good. Otherwise
* throw a logic_error.
*/
EXPORT const ParseTree& GetParseTree(void);
/** @brief Tells whether current state resulted from a good
* parse.
*/
EXPORT bool Good(void);
/** @brief Control bison debugging
*/
EXPORT void SetDebug(bool debug);
/** @brief Set the default schema to use if it is not
* supplied in the DDL statement
*
* @param schema the default schema
*/
EXPORT void setDefaultSchema(std::string schema);
/** @brief Set the default table charset. Can be overriden by column
* or table options
*
* @param default_charset the default CHARSET_INFO pointer
*/
EXPORT void setDefaultCharset(const CHARSET_INFO* default_charset);
protected:
ParseTree fParseTree;
std::string fDBSchema;
int fStatus; ///< return from yyparse() stored here.
bool fDebug; ///< Turn on bison debugging.
scan_data scanData;
pass_to_bison x;
};
/** SqlFileParser is a testing device.
*/
class SqlFileParser : public SqlParser
{
public:
SqlFileParser();
int Parse(const std::string& fileName);
};
} // namespace ddlpackage
#undef EXPORT