Commit 4c7ece26 authored by Bjorn Munch's avatar Bjorn Munch

merge 5.5-mtr => 5.5

parents 0dc19044 288a3b91
...@@ -502,6 +502,31 @@ struct st_command *curr_command= 0; ...@@ -502,6 +502,31 @@ struct st_command *curr_command= 0;
char builtin_echo[FN_REFLEN]; char builtin_echo[FN_REFLEN];
struct st_replace_regex
{
DYNAMIC_ARRAY regex_arr; /* stores a list of st_regex subsitutions */
/*
Temporary storage areas for substitutions. To reduce unnessary copying
and memory freeing/allocation, we pre-allocate two buffers, and alternate
their use, one for input/one for output, the roles changing on the next
st_regex substition. At the end of substitutions buf points to the
one containing the final result.
*/
char* buf;
char* even_buf;
char* odd_buf;
int even_buf_len;
int odd_buf_len;
};
struct st_replace_regex *glob_replace_regex= 0;
struct st_replace;
struct st_replace *glob_replace= 0;
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
const char *from, int len);
static void cleanup_and_exit(int exit_code) __attribute__((noreturn)); static void cleanup_and_exit(int exit_code) __attribute__((noreturn));
void die(const char *fmt, ...) void die(const char *fmt, ...)
...@@ -531,6 +556,7 @@ void str_to_file2(const char *fname, char *str, int size, my_bool append); ...@@ -531,6 +556,7 @@ void str_to_file2(const char *fname, char *str, int size, my_bool append);
void fix_win_paths(const char *val, int len); void fix_win_paths(const char *val, int len);
const char *get_errname_from_code (uint error_code); const char *get_errname_from_code (uint error_code);
int multi_reg_replace(struct st_replace_regex* r,char* val);
#ifdef __WIN__ #ifdef __WIN__
void free_tmp_sh_file(); void free_tmp_sh_file();
...@@ -2432,7 +2458,23 @@ void var_query_set(VAR *var, const char *query, const char** query_end) ...@@ -2432,7 +2458,23 @@ void var_query_set(VAR *var, const char *query, const char** query_end)
if (row[i]) if (row[i])
{ {
/* Add column to tab separated string */ /* Add column to tab separated string */
dynstr_append_mem(&result, row[i], lengths[i]); char *val= row[i];
int len= lengths[i];
if (glob_replace_regex)
{
/* Regex replace */
if (!multi_reg_replace(glob_replace_regex, (char*)val))
{
val= glob_replace_regex->buf;
len= strlen(val);
}
}
if (glob_replace)
replace_strings_append(glob_replace, &result, val, len);
else
dynstr_append_mem(&result, val, len);
} }
dynstr_append_mem(&result, "\t", 1); dynstr_append_mem(&result, "\t", 1);
} }
...@@ -3344,8 +3386,9 @@ void do_copy_file(struct st_command *command) ...@@ -3344,8 +3386,9 @@ void do_copy_file(struct st_command *command)
' '); ' ');
DBUG_PRINT("info", ("Copy %s to %s", ds_from_file.str, ds_to_file.str)); DBUG_PRINT("info", ("Copy %s to %s", ds_from_file.str, ds_to_file.str));
/* MY_HOLD_ORIGINAL_MODES prevents attempts to chown the file */
error= (my_copy(ds_from_file.str, ds_to_file.str, error= (my_copy(ds_from_file.str, ds_to_file.str,
MYF(MY_DONT_OVERWRITE_FILE)) != 0); MYF(MY_DONT_OVERWRITE_FILE | MY_HOLD_ORIGINAL_MODES)) != 0);
handle_command_error(command, error); handle_command_error(command, error);
dynstr_free(&ds_from_file); dynstr_free(&ds_from_file);
dynstr_free(&ds_to_file); dynstr_free(&ds_to_file);
...@@ -9119,16 +9162,11 @@ typedef struct st_pointer_array { /* when using array-strings */ ...@@ -9119,16 +9162,11 @@ typedef struct st_pointer_array { /* when using array-strings */
uint array_allocs,max_count,length,max_length; uint array_allocs,max_count,length,max_length;
} POINTER_ARRAY; } POINTER_ARRAY;
struct st_replace;
struct st_replace *init_replace(char * *from, char * *to, uint count, struct st_replace *init_replace(char * *from, char * *to, uint count,
char * word_end_chars); char * word_end_chars);
int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name); int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name);
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
const char *from, int len);
void free_pointer_array(POINTER_ARRAY *pa); void free_pointer_array(POINTER_ARRAY *pa);
struct st_replace *glob_replace;
/* /*
Get arguments for replace. The syntax is: Get arguments for replace. The syntax is:
replace from to [from to ...] replace from to [from to ...]
...@@ -9272,26 +9310,6 @@ struct st_regex ...@@ -9272,26 +9310,6 @@ struct st_regex
int icase; /* true if the match is case insensitive */ int icase; /* true if the match is case insensitive */
}; };
struct st_replace_regex
{
DYNAMIC_ARRAY regex_arr; /* stores a list of st_regex subsitutions */
/*
Temporary storage areas for substitutions. To reduce unnessary copying
and memory freeing/allocation, we pre-allocate two buffers, and alternate
their use, one for input/one for output, the roles changing on the next
st_regex substition. At the end of substitutions buf points to the
one containing the final result.
*/
char* buf;
char* even_buf;
char* odd_buf;
int even_buf_len;
int odd_buf_len;
};
struct st_replace_regex *glob_replace_regex= 0;
int reg_replace(char** buf_p, int* buf_len_p, char *pattern, char *replace, int reg_replace(char** buf_p, int* buf_len_p, char *pattern, char *replace,
char *string, int icase); char *string, int icase);
...@@ -9490,7 +9508,13 @@ void do_get_replace_regex(struct st_command *command) ...@@ -9490,7 +9508,13 @@ void do_get_replace_regex(struct st_command *command)
{ {
char *expr= command->first_argument; char *expr= command->first_argument;
free_replace_regex(); free_replace_regex();
if (!(glob_replace_regex=init_replace_regex(expr))) /* Allow variable for the *entire* list of replacements */
if (*expr == '$')
{
VAR *val= var_get(expr, NULL, 0, 1);
expr= val ? val->str_val : NULL;
}
if (expr && *expr && !(glob_replace_regex=init_replace_regex(expr)))
die("Could not init replace_regex"); die("Could not init replace_regex");
command->last_argument= command->end; command->last_argument= command->end;
} }
......
...@@ -15,7 +15,6 @@ source include/show_binlog_events.inc; ...@@ -15,7 +15,6 @@ source include/show_binlog_events.inc;
# absolutely need variables names to be quoted and strings to be # absolutely need variables names to be quoted and strings to be
# escaped). # escaped).
flush logs; flush logs;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
let $MYSQLD_DATADIR= `select @@datadir`; let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001 --exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t2; drop table t2;
......
...@@ -549,6 +549,7 @@ mysqltest: At line 1: Wrong column number to replace_column in 'replace_column 1 ...@@ -549,6 +549,7 @@ mysqltest: At line 1: Wrong column number to replace_column in 'replace_column 1
select "LONG_STRING" as x; select "LONG_STRING" as x;
x x
LONG_STRING LONG_STRING
dog
mysqltest: At line 1: Invalid integer argument "10!" mysqltest: At line 1: Invalid integer argument "10!"
mysqltest: At line 1: Invalid integer argument "a" mysqltest: At line 1: Invalid integer argument "a"
mysqltest: At line 1: Missing required argument 'connection name' to command 'connect' mysqltest: At line 1: Missing required argument 'connection name' to command 'connect'
...@@ -662,6 +663,11 @@ a D ...@@ -662,6 +663,11 @@ a D
1 1 1 1
1 4 1 4
drop table t1; drop table t1;
y
txt
b is b and more is more
txt
a is a and less is more
create table t2 ( a char(10)); create table t2 ( a char(10));
garbage; garbage;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1
......
...@@ -1745,6 +1745,12 @@ let $long_rep= $long_rep,$long_rep; ...@@ -1745,6 +1745,12 @@ let $long_rep= $long_rep,$long_rep;
--replace_result $long_rep LONG_STRING --replace_result $long_rep LONG_STRING
eval select "$long_rep" as x; eval select "$long_rep" as x;
# Test replace within ``
--replace_result cat dog
--let $animal= `select "cat" as pet`
--echo $animal
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Test sync_with_master # Test sync_with_master
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
...@@ -2065,6 +2071,23 @@ insert into t1 values (2,4); ...@@ -2065,6 +2071,23 @@ insert into t1 values (2,4);
select * from t1; select * from t1;
drop table t1; drop table t1;
# Test usage with ``
--replace_regex /x/y/
--let $result= `select "x" as col`
--echo $result
# Test usage with a variable as pattern list
--disable_query_log
--let $patt= /a /b / /less/more/
--replace_regex $patt
select "a is a and less is more" as txt;
--let $patt=
--replace_regex $patt
select "a is a and less is more" as txt;
--enable_query_log
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# BUG #11754855 : Passing variable to --error # BUG #11754855 : Passing variable to --error
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment