mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
A 11.3->10.4 backport for MDEV-31991 Split class Database_qualified_name
This is a requirement step to fix and merge easier MDEV-33019 The database part is not case sensitive in SP names The original MDEV-31991 commit commend: - Moving some of Database_qualified_name methods into a new class Identifier_chain2. - Changing the data type of the following variables from Database_qualified_name to Identifier_chain2: * q_pkg_proc in LEX::call_statement_start() * q_pkg_func in LEX::make_item_func_call_generic() Rationale: The data type of Database_qualified_name::m_db will be changed to Lex_ident_db soon. So Database_qualified_name won't be able to store the `pkg.routine` part of `db.pkg.routine` any more, because `pkg` must not depend on lower-case-table-names.
This commit is contained in:
parent
1b747ffd05
commit
371bf4abc6
3 changed files with 64 additions and 36 deletions
|
@ -2710,11 +2710,11 @@ Item_sp::func_name(THD *thd, bool is_package_function) const
|
|||
quoted `pkg` and `func` separately, so the entire result looks like:
|
||||
`db`.`pkg`.`func`
|
||||
*/
|
||||
Database_qualified_name tmp= Database_qualified_name::split(m_name->m_name);
|
||||
DBUG_ASSERT(tmp.m_db.length);
|
||||
append_identifier(thd, &qname, &tmp.m_db);
|
||||
Identifier_chain2 tmp= Identifier_chain2::split(m_name->m_name);
|
||||
DBUG_ASSERT(tmp[0].length);
|
||||
append_identifier(thd, &qname, &tmp[0]);
|
||||
qname.append('.');
|
||||
append_identifier(thd, &qname, &tmp.m_name);
|
||||
append_identifier(thd, &qname, &tmp[1]);
|
||||
}
|
||||
else
|
||||
append_identifier(thd, &qname, &m_name->m_name);
|
||||
|
|
|
@ -7051,6 +7051,61 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class Identifier_chain2
|
||||
{
|
||||
LEX_CSTRING m_name[2];
|
||||
public:
|
||||
Identifier_chain2()
|
||||
:m_name{Lex_cstring(), Lex_cstring()}
|
||||
{ }
|
||||
Identifier_chain2(const LEX_CSTRING &a, const LEX_CSTRING &b)
|
||||
:m_name{a, b}
|
||||
{ }
|
||||
|
||||
const LEX_CSTRING& operator [] (size_t i) const
|
||||
{
|
||||
return m_name[i];
|
||||
}
|
||||
|
||||
static Identifier_chain2 split(const LEX_CSTRING &txt)
|
||||
{
|
||||
DBUG_ASSERT(txt.str[txt.length] == '\0'); // Expect 0-terminated input
|
||||
const char *dot= strchr(txt.str, '.');
|
||||
if (!dot)
|
||||
return Identifier_chain2(Lex_cstring(), txt);
|
||||
size_t length0= dot - txt.str;
|
||||
Lex_cstring name0(txt.str, length0);
|
||||
Lex_cstring name1(txt.str + length0 + 1, txt.length - length0 - 1);
|
||||
return Identifier_chain2(name0, name1);
|
||||
}
|
||||
|
||||
// Export as a qualified name string: 'db.name'
|
||||
size_t make_qname(char *dst, size_t dstlen) const
|
||||
{
|
||||
return my_snprintf(dst, dstlen, "%.*s.%.*s",
|
||||
(int) m_name[0].length, m_name[0].str,
|
||||
(int) m_name[1].length, m_name[1].str);
|
||||
}
|
||||
|
||||
// Export as a qualified name string, allocate on mem_root.
|
||||
bool make_qname(MEM_ROOT *mem_root, LEX_CSTRING *dst) const
|
||||
{
|
||||
const uint dot= !!m_name[0].length;
|
||||
char *tmp;
|
||||
/* format: [pkg + dot] + name + '\0' */
|
||||
dst->length= m_name[0].length + dot + m_name[1].length;
|
||||
if (unlikely(!(dst->str= tmp= (char*) alloc_root(mem_root,
|
||||
dst->length + 1))))
|
||||
return true;
|
||||
snprintf(tmp, dst->length + 1, "%.*s%.*s%.*s",
|
||||
(int) m_name[0].length, (m_name[0].length ? m_name[0].str : ""),
|
||||
dot, ".",
|
||||
(int) m_name[1].length, m_name[1].str);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This class resembles the SQL Standard schema qualified object name:
|
||||
<schema qualified name> ::= [ <schema name> <period> ] <qualified identifier>
|
||||
|
@ -7093,41 +7148,16 @@ public:
|
|||
void copy(MEM_ROOT *mem_root, const LEX_CSTRING &db,
|
||||
const LEX_CSTRING &name);
|
||||
|
||||
static Database_qualified_name split(const LEX_CSTRING &txt)
|
||||
{
|
||||
DBUG_ASSERT(txt.str[txt.length] == '\0'); // Expect 0-terminated input
|
||||
const char *dot= strchr(txt.str, '.');
|
||||
if (!dot)
|
||||
return Database_qualified_name(NULL, 0, txt.str, txt.length);
|
||||
size_t dblen= dot - txt.str;
|
||||
Lex_cstring db(txt.str, dblen);
|
||||
Lex_cstring name(txt.str + dblen + 1, txt.length - dblen - 1);
|
||||
return Database_qualified_name(db, name);
|
||||
}
|
||||
|
||||
// Export db and name as a qualified name string: 'db.name'
|
||||
size_t make_qname(char *dst, size_t dstlen) const
|
||||
{
|
||||
return my_snprintf(dst, dstlen, "%.*s.%.*s",
|
||||
(int) m_db.length, m_db.str,
|
||||
(int) m_name.length, m_name.str);
|
||||
return Identifier_chain2(m_db, m_name).make_qname(dst, dstlen);
|
||||
}
|
||||
// Export db and name as a qualified name string, allocate on mem_root.
|
||||
bool make_qname(MEM_ROOT *mem_root, LEX_CSTRING *dst) const
|
||||
{
|
||||
const uint dot= !!m_db.length;
|
||||
char *tmp;
|
||||
/* format: [database + dot] + name + '\0' */
|
||||
dst->length= m_db.length + dot + m_name.length;
|
||||
if (unlikely(!(dst->str= tmp= (char*) alloc_root(mem_root,
|
||||
dst->length + 1))))
|
||||
return true;
|
||||
snprintf(tmp, dst->length + 1, "%.*s%.*s%.*s",
|
||||
(int) m_db.length, (m_db.length ? m_db.str : ""),
|
||||
dot, ".",
|
||||
(int) m_name.length, m_name.str);
|
||||
DBUG_SLOW_ASSERT(ok_for_lower_case_names(m_db.str));
|
||||
return false;
|
||||
return Identifier_chain2(m_db, m_name).make_qname(mem_root, dst);
|
||||
}
|
||||
|
||||
bool make_package_routine_name(MEM_ROOT *mem_root,
|
||||
|
@ -7138,9 +7168,7 @@ public:
|
|||
size_t length= package.length + 1 + routine.length + 1;
|
||||
if (unlikely(!(tmp= (char *) alloc_root(mem_root, length))))
|
||||
return true;
|
||||
m_name.length= my_snprintf(tmp, length, "%.*s.%.*s",
|
||||
(int) package.length, package.str,
|
||||
(int) routine.length, routine.str);
|
||||
m_name.length= Identifier_chain2(package, routine).make_qname(tmp, length);
|
||||
m_name.str= tmp;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -8616,7 +8616,7 @@ bool LEX::call_statement_start(THD *thd, const LEX_CSTRING &db,
|
|||
const LEX_CSTRING &proc)
|
||||
{
|
||||
Database_qualified_name q_db_pkg(db, pkg);
|
||||
Database_qualified_name q_pkg_proc(pkg, proc);
|
||||
Identifier_chain2 q_pkg_proc(pkg, proc);
|
||||
sp_name *spname;
|
||||
|
||||
sql_command= SQLCOM_CALL;
|
||||
|
@ -9026,7 +9026,7 @@ Item *LEX::make_item_func_call_generic(THD *thd,
|
|||
static Lex_cstring dot(".", 1);
|
||||
Lex_ident_sys db(thd, cdb), pkg(thd, cpkg), func(thd, cfunc);
|
||||
Database_qualified_name q_db_pkg(db, pkg);
|
||||
Database_qualified_name q_pkg_func(pkg, func);
|
||||
Identifier_chain2 q_pkg_func(pkg, func);
|
||||
sp_name *qname;
|
||||
|
||||
if (db.is_null() || pkg.is_null() || func.is_null())
|
||||
|
|
Loading…
Reference in a new issue