mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
SQL: start_end_t members as LEX_CSTRING
This commit is contained in:
@ -6584,13 +6584,12 @@ int del_global_index_stat(THD *thd, TABLE* table, KEY* key_info)
|
|||||||
bool Vers_parse_info::is_trx_start(const char *name) const
|
bool Vers_parse_info::is_trx_start(const char *name) const
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(name);
|
DBUG_ASSERT(name);
|
||||||
return generated_as_row.start &&
|
return generated_as_row.start && generated_as_row.start == LString_i(name);
|
||||||
!strcmp(generated_as_row.start->c_ptr(), name);
|
|
||||||
}
|
}
|
||||||
bool Vers_parse_info::is_trx_end(const char *name) const
|
bool Vers_parse_info::is_trx_end(const char *name) const
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(name);
|
DBUG_ASSERT(name);
|
||||||
return generated_as_row.end && !strcmp(generated_as_row.end->c_ptr(), name);
|
return generated_as_row.end && generated_as_row.end == LString_i(name);
|
||||||
}
|
}
|
||||||
bool Vers_parse_info::is_trx_start(const Create_field &f) const
|
bool Vers_parse_info::is_trx_start(const Create_field &f) const
|
||||||
{
|
{
|
||||||
@ -6601,14 +6600,9 @@ bool Vers_parse_info::is_trx_end(const Create_field &f) const
|
|||||||
return f.flags & VERS_SYS_END_FLAG;
|
return f.flags & VERS_SYS_END_FLAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool create_string(MEM_ROOT *mem_root, String **s, const char *value)
|
|
||||||
{
|
|
||||||
*s= new (mem_root) String(value, system_charset_info);
|
|
||||||
return *s == NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool vers_create_sys_field(THD *thd, const char *field_name,
|
static bool vers_create_sys_field(THD *thd, const char *field_name,
|
||||||
Alter_info *alter_info, String **s,
|
Alter_info *alter_info,
|
||||||
int flags,
|
int flags,
|
||||||
bool integer_fields)
|
bool integer_fields)
|
||||||
{
|
{
|
||||||
@ -6635,9 +6629,6 @@ static bool vers_create_sys_field(THD *thd, const char *field_name,
|
|||||||
if (f->check(thd))
|
if (f->check(thd))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (create_string(thd->mem_root, s, field_name))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
alter_info->create_list.push_back(f);
|
alter_info->create_list.push_back(f);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -6652,19 +6643,18 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info,
|
|||||||
|
|
||||||
alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;
|
alter_info->flags|= Alter_info::ALTER_ADD_COLUMN;
|
||||||
|
|
||||||
static const char * sys_trx_start= "sys_trx_start";
|
static const LString sys_trx_start= "sys_trx_start";
|
||||||
static const char * sys_trx_end= "sys_trx_end";
|
static const LString sys_trx_end= "sys_trx_end";
|
||||||
|
|
||||||
|
period_for_system_time= start_end_t(sys_trx_start, sys_trx_end);
|
||||||
|
generated_as_row= period_for_system_time;
|
||||||
|
|
||||||
return vers_create_sys_field(thd, sys_trx_start, alter_info,
|
return vers_create_sys_field(thd, sys_trx_start, alter_info,
|
||||||
&generated_as_row.start, VERS_SYS_START_FLAG,
|
VERS_SYS_START_FLAG,
|
||||||
integer_fields) ||
|
integer_fields) ||
|
||||||
vers_create_sys_field(thd, sys_trx_end, alter_info,
|
vers_create_sys_field(thd, sys_trx_end, alter_info,
|
||||||
&generated_as_row.end, VERS_SYS_END_FLAG,
|
VERS_SYS_END_FLAG,
|
||||||
integer_fields) ||
|
integer_fields);
|
||||||
create_string(thd->mem_root, &period_for_system_time.start,
|
|
||||||
sys_trx_start) ||
|
|
||||||
create_string(thd->mem_root, &period_for_system_time.end,
|
|
||||||
sys_trx_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vers_parse_info::check_and_fix_implicit(
|
bool Vers_parse_info::check_and_fix_implicit(
|
||||||
@ -6731,7 +6721,7 @@ bool Vers_parse_info::check_and_fix_implicit(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
orig_table= f->field->orig_table;
|
orig_table= f->field->orig_table;
|
||||||
generated_as_row.start= new (thd->mem_root) String(f->field_name, system_charset_info);
|
generated_as_row.start= f->field_name;
|
||||||
period_for_system_time.start= generated_as_row.start;
|
period_for_system_time.start= generated_as_row.start;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -6746,7 +6736,7 @@ bool Vers_parse_info::check_and_fix_implicit(
|
|||||||
goto err_different_tables;
|
goto err_different_tables;
|
||||||
}
|
}
|
||||||
orig_table= f->field->orig_table;
|
orig_table= f->field->orig_table;
|
||||||
generated_as_row.end= new (thd->mem_root) String(f->field_name, system_charset_info);
|
generated_as_row.end= f->field_name;
|
||||||
period_for_system_time.end= generated_as_row.end;
|
period_for_system_time.end= generated_as_row.end;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -6866,11 +6856,8 @@ bool Vers_parse_info::check_and_fix_alter(THD *thd, Alter_info *alter_info,
|
|||||||
const char *end= share->vers_end_field()->field_name;
|
const char *end= share->vers_end_field()->field_name;
|
||||||
DBUG_ASSERT(start && end);
|
DBUG_ASSERT(start && end);
|
||||||
|
|
||||||
if (create_string(thd->mem_root, &generated_as_row.start, start) ||
|
generated_as_row= start_end_t(start, end);
|
||||||
create_string(thd->mem_root, &generated_as_row.end, end) ||
|
period_for_system_time= generated_as_row;
|
||||||
create_string(thd->mem_root, &period_for_system_time.start, start) ||
|
|
||||||
create_string(thd->mem_root, &period_for_system_time.end, end))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (alter_info->create_list.elements)
|
if (alter_info->create_list.elements)
|
||||||
{
|
{
|
||||||
@ -6935,14 +6922,8 @@ bool Vers_parse_info::fix_create_like(THD *thd, Alter_info *alter_info,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (create_string(thd->mem_root, &generated_as_row.start, f_start->field_name) ||
|
generated_as_row= start_end_t(f_start->field_name, f_end->field_name);
|
||||||
create_string(thd->mem_root, &period_for_system_time.start, f_start->field_name) ||
|
period_for_system_time= generated_as_row;
|
||||||
create_string(thd->mem_root, &generated_as_row.end, f_end->field_name) ||
|
|
||||||
create_string(thd->mem_root, &period_for_system_time.end, f_end->field_name))
|
|
||||||
{
|
|
||||||
sql_print_error("Failed to allocate memory for Vers_parse_info::fix_create_like()");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
create_info->options|= HA_VERSIONED_TABLE;
|
create_info->options|= HA_VERSIONED_TABLE;
|
||||||
return false;
|
return false;
|
||||||
@ -6972,16 +6953,14 @@ bool Vers_parse_info::check_with_conditions(const char *table_name) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my_strcasecmp(system_charset_info, generated_as_row.start->c_ptr(),
|
if (generated_as_row.start != period_for_system_time.start)
|
||||||
period_for_system_time.start->c_ptr()))
|
|
||||||
{
|
{
|
||||||
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
|
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
|
||||||
"'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW START' mismatch");
|
"'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW START' mismatch");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my_strcasecmp(system_charset_info, generated_as_row.end->c_ptr(),
|
if (generated_as_row.end != period_for_system_time.end)
|
||||||
period_for_system_time.end->c_ptr()))
|
|
||||||
{
|
{
|
||||||
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
|
my_error(ER_VERS_WRONG_PARAMS, MYF(0), table_name,
|
||||||
"'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW END' mismatch");
|
"'PERIOD FOR SYSTEM_TIME' and 'GENERATED AS ROW END' mismatch");
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "sql_array.h" /* Dynamic_array<> */
|
#include "sql_array.h" /* Dynamic_array<> */
|
||||||
#include "mdl.h"
|
#include "mdl.h"
|
||||||
#include "vtq.h"
|
#include "vtq.h"
|
||||||
|
#include "vers_string.h"
|
||||||
|
|
||||||
#include "sql_analyze_stmt.h" // for Exec_time_tracker
|
#include "sql_analyze_stmt.h" // for Exec_time_tracker
|
||||||
|
|
||||||
@ -1684,17 +1685,19 @@ struct Vers_parse_info
|
|||||||
|
|
||||||
struct start_end_t
|
struct start_end_t
|
||||||
{
|
{
|
||||||
start_end_t() :
|
start_end_t()
|
||||||
start(NULL),
|
{}
|
||||||
end(NULL) {}
|
start_end_t(const char* _start, const char* _end) :
|
||||||
String *start;
|
start(_start),
|
||||||
String *end;
|
end(_end) {}
|
||||||
|
LString_i start;
|
||||||
|
LString_i end;
|
||||||
};
|
};
|
||||||
|
|
||||||
start_end_t period_for_system_time;
|
start_end_t period_for_system_time;
|
||||||
start_end_t generated_as_row;
|
start_end_t generated_as_row;
|
||||||
|
|
||||||
void set_period_for_system_time(String *start, String *end)
|
void set_period_for_system_time(LString start, LString end)
|
||||||
{
|
{
|
||||||
period_for_system_time.start = start;
|
period_for_system_time.start = start;
|
||||||
period_for_system_time.end = end;
|
period_for_system_time.end = end;
|
||||||
@ -1713,10 +1716,10 @@ private:
|
|||||||
has_unversioned_fields ||
|
has_unversioned_fields ||
|
||||||
declared_with_system_versioning ||
|
declared_with_system_versioning ||
|
||||||
declared_without_system_versioning ||
|
declared_without_system_versioning ||
|
||||||
period_for_system_time.start ||
|
period_for_system_time.start.str ||
|
||||||
period_for_system_time.end ||
|
period_for_system_time.end.str ||
|
||||||
generated_as_row.start ||
|
generated_as_row.start.str ||
|
||||||
generated_as_row.end;
|
generated_as_row.end.str;
|
||||||
}
|
}
|
||||||
bool check_with_conditions(const char *table_name) const;
|
bool check_with_conditions(const char *table_name) const;
|
||||||
bool check_generated_type(const char *table_name, Alter_info *alter_info,
|
bool check_generated_type(const char *table_name, Alter_info *alter_info,
|
||||||
|
@ -4326,9 +4326,9 @@ vers_prepare_keys(THD *thd,
|
|||||||
{
|
{
|
||||||
DBUG_ASSERT(create_info->versioned());
|
DBUG_ASSERT(create_info->versioned());
|
||||||
|
|
||||||
const char *row_start_field= create_info->vers_info.generated_as_row.start->c_ptr();
|
const char *row_start_field= create_info->vers_info.generated_as_row.start;
|
||||||
DBUG_ASSERT(row_start_field);
|
DBUG_ASSERT(row_start_field);
|
||||||
const char *row_end_field= create_info->vers_info.generated_as_row.end->c_ptr();
|
const char *row_end_field= create_info->vers_info.generated_as_row.end;
|
||||||
DBUG_ASSERT(row_end_field);
|
DBUG_ASSERT(row_end_field);
|
||||||
|
|
||||||
List_iterator<Key> key_it(alter_info->key_list);
|
List_iterator<Key> key_it(alter_info->key_list);
|
||||||
@ -4354,10 +4354,8 @@ vers_prepare_keys(THD *thd,
|
|||||||
if (key_part)
|
if (key_part)
|
||||||
continue; // Key already contains Sys_start or Sys_end
|
continue; // Key already contains Sys_start or Sys_end
|
||||||
|
|
||||||
const LEX_STRING &lex_sys_end=
|
|
||||||
create_info->vers_info.generated_as_row.end->lex_string();
|
|
||||||
Key_part_spec *key_part_sys_end_col=
|
Key_part_spec *key_part_sys_end_col=
|
||||||
new(thd->mem_root) Key_part_spec(lex_sys_end, 0);
|
new(thd->mem_root) Key_part_spec(create_info->vers_info.generated_as_row.end, 0);
|
||||||
key->columns.push_back(key_part_sys_end_col);
|
key->columns.push_back(key_part_sys_end_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1622,6 +1622,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
|||||||
opt_constraint constraint opt_ident
|
opt_constraint constraint opt_ident
|
||||||
sp_decl_ident
|
sp_decl_ident
|
||||||
sp_block_label
|
sp_block_label
|
||||||
|
period_for_system_time_column_id
|
||||||
|
|
||||||
%type <lex_string_with_metadata>
|
%type <lex_string_with_metadata>
|
||||||
TEXT_STRING
|
TEXT_STRING
|
||||||
@ -1651,7 +1652,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
|
|||||||
|
|
||||||
%type <string>
|
%type <string>
|
||||||
text_string hex_or_bin_String opt_gconcat_separator
|
text_string hex_or_bin_String opt_gconcat_separator
|
||||||
period_for_system_time_column_id
|
|
||||||
|
|
||||||
%type <field_type> int_type real_type
|
%type <field_type> int_type real_type
|
||||||
|
|
||||||
@ -6167,7 +6167,7 @@ period_for_system_time:
|
|||||||
PERIOD_SYM FOR_SYSTEM_TIME_SYM '(' period_for_system_time_column_id ',' period_for_system_time_column_id ')'
|
PERIOD_SYM FOR_SYSTEM_TIME_SYM '(' period_for_system_time_column_id ',' period_for_system_time_column_id ')'
|
||||||
{
|
{
|
||||||
Vers_parse_info &info= Lex->vers_get_info();
|
Vers_parse_info &info= Lex->vers_get_info();
|
||||||
if (!my_strcasecmp(system_charset_info, $4->c_ptr(), $6->c_ptr()))
|
if (!my_strcasecmp(system_charset_info, $4.str, $6.str))
|
||||||
{
|
{
|
||||||
my_yyabort_error((ER_VERS_WRONG_PARAMS, MYF(0),
|
my_yyabort_error((ER_VERS_WRONG_PARAMS, MYF(0),
|
||||||
Lex->create_last_non_select_table->table_name,
|
Lex->create_last_non_select_table->table_name,
|
||||||
@ -6284,14 +6284,10 @@ field_def:
|
|||||||
{
|
{
|
||||||
LEX *lex= Lex;
|
LEX *lex= Lex;
|
||||||
Vers_parse_info &info= lex->vers_get_info();
|
Vers_parse_info &info= lex->vers_get_info();
|
||||||
String *field_name= new (thd->mem_root)
|
const char *field_name= lex->last_field->field_name;
|
||||||
String((const char*)lex->last_field->field_name, system_charset_info);
|
|
||||||
if (!field_name)
|
|
||||||
MYSQL_YYABORT;
|
|
||||||
|
|
||||||
const char *table_name= lex->create_last_non_select_table->table_name;
|
const char *table_name= lex->create_last_non_select_table->table_name;
|
||||||
|
|
||||||
String **p= NULL;
|
LString_i *p;
|
||||||
const char* err;
|
const char* err;
|
||||||
switch ($4)
|
switch ($4)
|
||||||
{
|
{
|
||||||
@ -6310,6 +6306,7 @@ field_def:
|
|||||||
MYSQL_YYABORT;
|
MYSQL_YYABORT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
DBUG_ASSERT(p);
|
||||||
if (*p)
|
if (*p)
|
||||||
{
|
{
|
||||||
my_yyabort_error((ER_VERS_WRONG_PARAMS, MYF(0), table_name, err));
|
my_yyabort_error((ER_VERS_WRONG_PARAMS, MYF(0), table_name, err));
|
||||||
@ -16237,10 +16234,7 @@ column_list:
|
|||||||
period_for_system_time_column_id:
|
period_for_system_time_column_id:
|
||||||
ident
|
ident
|
||||||
{
|
{
|
||||||
String *new_str= new (thd->mem_root) String((const char*) $1.str,$1.length,system_charset_info);
|
$$= $1;
|
||||||
if (new_str == NULL)
|
|
||||||
MYSQL_YYABORT;
|
|
||||||
$$= new_str;
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ vers_get_field(HA_CREATE_INFO *create_info, List<Create_field> &create_fields, b
|
|||||||
|
|
||||||
const char *row_field =
|
const char *row_field =
|
||||||
row_start ?
|
row_start ?
|
||||||
create_info->vers_info.generated_as_row.start->c_ptr() :
|
create_info->vers_info.generated_as_row.start :
|
||||||
create_info->vers_info.generated_as_row.end->c_ptr();
|
create_info->vers_info.generated_as_row.end;
|
||||||
DBUG_ASSERT(row_field);
|
DBUG_ASSERT(row_field);
|
||||||
|
|
||||||
for (unsigned field_no = 0; (sql_field = it++); ++field_no)
|
for (unsigned field_no = 0; (sql_field = it++); ++field_no)
|
||||||
|
131
sql/vers_string.h
Normal file
131
sql/vers_string.h
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#ifndef VERS_STRING_INCLUDED
|
||||||
|
#define VERS_STRING_INCLUDED
|
||||||
|
|
||||||
|
struct Compare_strncmp
|
||||||
|
{
|
||||||
|
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
|
||||||
|
{
|
||||||
|
return strncmp(a.str, b.str, a.length);
|
||||||
|
}
|
||||||
|
static CHARSET_INFO* charset()
|
||||||
|
{
|
||||||
|
return system_charset_info;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <CHARSET_INFO* &CS= system_charset_info>
|
||||||
|
struct Compare_my_strcasecmp
|
||||||
|
{
|
||||||
|
int operator()(const LEX_CSTRING& a, const LEX_CSTRING& b) const
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(a.str[a.length] == 0 && b.str[b.length] == 0);
|
||||||
|
return my_strcasecmp(CS, a.str, b.str);
|
||||||
|
}
|
||||||
|
static CHARSET_INFO* charset()
|
||||||
|
{
|
||||||
|
return CS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Compare_my_strcasecmp<files_charset_info> Compare_fs;
|
||||||
|
typedef Compare_my_strcasecmp<table_alias_charset> Compare_t;
|
||||||
|
|
||||||
|
template <class Storage= LEX_CSTRING>
|
||||||
|
struct LEX_STRING_u : public Storage
|
||||||
|
{
|
||||||
|
LEX_STRING_u()
|
||||||
|
{
|
||||||
|
Storage::str= NULL;
|
||||||
|
Storage::length= 0;
|
||||||
|
}
|
||||||
|
LEX_STRING_u(const char *_str, uint32 _len, CHARSET_INFO *)
|
||||||
|
{
|
||||||
|
Storage::str= _str;
|
||||||
|
Storage::length= _len;
|
||||||
|
}
|
||||||
|
uint32 length() const
|
||||||
|
{
|
||||||
|
return Storage::length;
|
||||||
|
}
|
||||||
|
const char *ptr() const
|
||||||
|
{
|
||||||
|
return Storage::str;
|
||||||
|
}
|
||||||
|
void set(const char *_str, uint32 _len, CHARSET_INFO *)
|
||||||
|
{
|
||||||
|
Storage::str= _str;
|
||||||
|
Storage::length= _len;
|
||||||
|
}
|
||||||
|
const LEX_CSTRING& lex_cstring() const
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Compare= Compare_strncmp, class Storage= LEX_STRING_u<> >
|
||||||
|
struct XString : public Storage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
XString() {}
|
||||||
|
XString(const char *_str, size_t _len) :
|
||||||
|
Storage(_str, _len, Compare::charset())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
XString(LEX_STRING& src) :
|
||||||
|
Storage(src.str, src.length, Compare::charset())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
XString(const char *_str) :
|
||||||
|
Storage(_str, strlen(_str), Compare::charset())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
XString& operator= (const char *_str)
|
||||||
|
{
|
||||||
|
DBUG_ASSERT(_str);
|
||||||
|
Storage::set(_str, strlen(_str), Compare::charset());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
bool operator== (const XString& b) const
|
||||||
|
{
|
||||||
|
return Storage::length() == b.length() && 0 == Compare()(this->lex_cstring(), b.lex_cstring());
|
||||||
|
}
|
||||||
|
bool operator!= (const XString& b) const
|
||||||
|
{
|
||||||
|
return !(*this == b);
|
||||||
|
}
|
||||||
|
operator const char* () const
|
||||||
|
{
|
||||||
|
return Storage::ptr();
|
||||||
|
}
|
||||||
|
operator LEX_CSTRING& () const
|
||||||
|
{
|
||||||
|
return this->lex_cstring();
|
||||||
|
}
|
||||||
|
operator LEX_STRING () const
|
||||||
|
{
|
||||||
|
LEX_STRING res;
|
||||||
|
res.str= const_cast<char *>(this->ptr());
|
||||||
|
res.length= this->length();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
operator bool () const
|
||||||
|
{
|
||||||
|
return Storage::ptr() != NULL;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef XString<> LString;
|
||||||
|
typedef XString<Compare_fs> LString_fs;
|
||||||
|
typedef XString<Compare_my_strcasecmp<> > LString_i;
|
||||||
|
|
||||||
|
typedef XString<Compare_strncmp, String> SString;
|
||||||
|
typedef XString<Compare_fs, String> SString_fs;
|
||||||
|
typedef XString<Compare_t, String> SString_t;
|
||||||
|
|
||||||
|
|
||||||
|
#define XSTRING_WITH_LEN(X) (X).ptr(), (X).length()
|
||||||
|
#define DB_WITH_LEN(X) (X).db, (X).db_length
|
||||||
|
#define TABLE_NAME_WITH_LEN(X) (X).table_name, (X).table_name_length
|
||||||
|
|
||||||
|
|
||||||
|
#endif // VERS_STRING_INCLUDED
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "sql_class.h"
|
#include "sql_class.h"
|
||||||
|
#include "vers_string.h"
|
||||||
|
|
||||||
class MDL_auto_lock
|
class MDL_auto_lock
|
||||||
{
|
{
|
||||||
@ -30,104 +31,6 @@ public:
|
|||||||
bool acquire_error() const { return error; }
|
bool acquire_error() const { return error; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Compare_strncmp
|
|
||||||
{
|
|
||||||
int operator()(const LEX_STRING& a, const LEX_STRING& b) const
|
|
||||||
{
|
|
||||||
return strncmp(a.str, b.str, a.length);
|
|
||||||
}
|
|
||||||
static CHARSET_INFO* charset()
|
|
||||||
{
|
|
||||||
return system_charset_info;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <CHARSET_INFO* &CS= system_charset_info>
|
|
||||||
struct Compare_my_strcasecmp
|
|
||||||
{
|
|
||||||
int operator()(const LEX_STRING& a, const LEX_STRING& b) const
|
|
||||||
{
|
|
||||||
DBUG_ASSERT(a.str[a.length] == 0 && b.str[b.length] == 0);
|
|
||||||
return my_strcasecmp(CS, a.str, b.str);
|
|
||||||
}
|
|
||||||
static CHARSET_INFO* charset()
|
|
||||||
{
|
|
||||||
return CS;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef Compare_my_strcasecmp<files_charset_info> Compare_fs;
|
|
||||||
typedef Compare_my_strcasecmp<table_alias_charset> Compare_t;
|
|
||||||
|
|
||||||
struct LEX_STRING_u : public LEX_STRING
|
|
||||||
{
|
|
||||||
LEX_STRING_u()
|
|
||||||
{
|
|
||||||
str= NULL;
|
|
||||||
LEX_STRING::length= 0;
|
|
||||||
}
|
|
||||||
LEX_STRING_u(const char *_str, uint32 _len, CHARSET_INFO *)
|
|
||||||
{
|
|
||||||
str= const_cast<char *>(_str);
|
|
||||||
LEX_STRING::length= _len;
|
|
||||||
}
|
|
||||||
uint32 length() const
|
|
||||||
{
|
|
||||||
return LEX_STRING::length;
|
|
||||||
}
|
|
||||||
const char *ptr() const
|
|
||||||
{
|
|
||||||
return LEX_STRING::str;
|
|
||||||
}
|
|
||||||
const LEX_STRING& lex_string() const
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Compare= Compare_strncmp, class Storage= LEX_STRING_u>
|
|
||||||
struct XString : public Storage
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
XString() {}
|
|
||||||
XString(char *_str, size_t _len) :
|
|
||||||
Storage(_str, _len, Compare::charset())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
XString(LEX_STRING& src) :
|
|
||||||
Storage(src.str, src.length, Compare::charset())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
XString(char *_str) :
|
|
||||||
Storage(_str, strlen(_str), Compare::charset())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
bool operator== (const XString& b) const
|
|
||||||
{
|
|
||||||
return Storage::length() == b.length() && 0 == Compare()(this->lex_string(), b.lex_string());
|
|
||||||
}
|
|
||||||
bool operator!= (const XString& b) const
|
|
||||||
{
|
|
||||||
return !(*this == b);
|
|
||||||
}
|
|
||||||
operator const char* () const
|
|
||||||
{
|
|
||||||
return Storage::ptr();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef XString<> LString;
|
|
||||||
typedef XString<Compare_fs> LString_fs;
|
|
||||||
|
|
||||||
typedef XString<Compare_strncmp, String> SString;
|
|
||||||
typedef XString<Compare_fs, String> SString_fs;
|
|
||||||
typedef XString<Compare_t, String> SString_t;
|
|
||||||
|
|
||||||
|
|
||||||
#define XSTRING_WITH_LEN(X) (X).ptr(), (X).length()
|
|
||||||
#define DB_WITH_LEN(X) (X).db, (X).db_length
|
|
||||||
#define TABLE_NAME_WITH_LEN(X) (X).table_name, (X).table_name_length
|
|
||||||
|
|
||||||
|
|
||||||
class Local_da : public Diagnostics_area
|
class Local_da : public Diagnostics_area
|
||||||
{
|
{
|
||||||
|
@ -416,7 +416,7 @@ VTMD_rename::try_rename(THD *thd, LString new_db, LString new_alias, const char
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool same_db= true;
|
bool same_db= true;
|
||||||
if (LString_fs(DB_WITH_LEN(about)) != new_db)
|
if (LString_fs(DB_WITH_LEN(about)) != LString_fs(new_db))
|
||||||
{
|
{
|
||||||
// Move archives before VTMD so if the operation is interrupted, it could be continued.
|
// Move archives before VTMD so if the operation is interrupted, it could be continued.
|
||||||
if (move_archives(thd, new_db))
|
if (move_archives(thd, new_db))
|
||||||
|
Reference in New Issue
Block a user