Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
d59b94e7
Commit
d59b94e7
authored
Apr 13, 2017
by
Daniel Black
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add replace_regex to not ignore the regex in "$var /regex/val/"
parent
ea414622
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
27 deletions
+55
-27
client/mysqltest.cc
client/mysqltest.cc
+49
-25
mysql-test/r/mysqltest.result
mysql-test/r/mysqltest.result
+3
-1
mysql-test/t/mysqltest.test
mysql-test/t/mysqltest.test
+3
-1
No files found.
client/mysqltest.cc
View file @
d59b94e7
...
@@ -9891,25 +9891,39 @@ bool parse_re_part(char *start_re, char *end_re,
...
@@ -9891,25 +9891,39 @@ bool parse_re_part(char *start_re, char *end_re,
Returns: st_replace_regex struct with pairs of substitutions
Returns: st_replace_regex struct with pairs of substitutions
*/
*/
void
append_replace_regex
(
char
*
,
char
*
,
struct
st_replace_regex
*
,
char
**
);
struct
st_replace_regex
*
init_replace_regex
(
char
*
expr
)
struct
st_replace_regex
*
init_replace_regex
(
char
*
expr
)
{
{
char
*
expr_end
,
*
buf_p
;
struct
st_replace_regex
*
res
;
struct
st_replace_regex
*
res
;
char
*
buf
,
*
expr_end
;
char
*
p
,
start_re
,
end_re
=
1
;
char
*
buf_p
;
uint
expr_len
=
strlen
(
expr
);
uint
expr_len
=
strlen
(
expr
);
struct
st_regex
reg
;
/* my_malloc() will die on fail with MY_FAE */
/* my_malloc() will die on fail with MY_FAE */
res
=
(
struct
st_replace_regex
*
)
my_malloc
(
res
=
(
struct
st_replace_regex
*
)
my_malloc
(
sizeof
(
*
res
)
+
expr_len
,
MYF
(
MY_FAE
+
MY_WME
));
sizeof
(
*
res
)
+
8192
,
MYF
(
MY_FAE
+
MY_WME
));
my_init_dynamic_array
(
&
res
->
regex_arr
,
sizeof
(
struct
st_regex
),
128
,
128
,
MYF
(
0
));
my_init_dynamic_array
(
&
res
->
regex_arr
,
sizeof
(
struct
st_regex
),
128
,
128
,
MYF
(
0
));
buf
=
(
char
*
)
res
+
sizeof
(
*
res
);
expr_end
=
expr
+
expr_len
;
expr_end
=
expr
+
expr_len
;
buf_p
=
(
char
*
)
res
+
sizeof
(
*
res
);
append_replace_regex
(
expr
,
expr_end
,
res
,
&
buf_p
);
res
->
odd_buf_len
=
res
->
even_buf_len
=
8192
;
res
->
even_buf
=
(
char
*
)
my_malloc
(
res
->
even_buf_len
,
MYF
(
MY_WME
+
MY_FAE
));
res
->
odd_buf
=
(
char
*
)
my_malloc
(
res
->
odd_buf_len
,
MYF
(
MY_WME
+
MY_FAE
));
res
->
buf
=
res
->
even_buf
;
return
res
;
}
void
append_replace_regex
(
char
*
expr
,
char
*
expr_end
,
struct
st_replace_regex
*
res
,
char
**
buf_p
)
{
char
*
p
,
start_re
,
end_re
=
1
;
struct
st_regex
reg
;
p
=
expr
;
p
=
expr
;
buf_p
=
buf
;
/* for each regexp substitution statement */
/* for each regexp substitution statement */
while
(
p
<
expr_end
)
while
(
p
<
expr_end
)
...
@@ -9928,13 +9942,34 @@ struct st_replace_regex* init_replace_regex(char* expr)
...
@@ -9928,13 +9942,34 @@ struct st_replace_regex* init_replace_regex(char* expr)
}
}
start_re
=
0
;
start_re
=
0
;
reg
.
pattern
=
buf_p
;
reg
.
pattern
=
*
buf_p
;
if
(
parse_re_part
(
&
start_re
,
&
end_re
,
&
p
,
expr_end
,
&
buf_p
))
goto
err
;
/* Allow variable for the *entire* list of replacements */
if
(
*
p
==
'$'
)
{
const
char
*
v_end
;
VAR
*
val
=
var_get
(
p
,
&
v_end
,
0
,
1
);
if
(
val
)
{
char
*
expr
,
*
expr_end
;
expr
=
val
->
str_val
;
expr_end
=
expr
+
val
->
str_val_len
;
append_replace_regex
(
expr
,
expr_end
,
res
,
buf_p
);
}
p
=
(
char
*
)
v_end
+
1
;
continue
;
}
else
{
if
(
parse_re_part
(
&
start_re
,
&
end_re
,
&
p
,
expr_end
,
buf_p
))
goto
err
;
reg
.
replace
=
buf_p
;
reg
.
replace
=
*
buf_p
;
if
(
parse_re_part
(
&
start_re
,
&
end_re
,
&
p
,
expr_end
,
&
buf_p
))
if
(
parse_re_part
(
&
start_re
,
&
end_re
,
&
p
,
expr_end
,
buf_p
))
goto
err
;
goto
err
;
}
/* Check if we should do matching case insensitive */
/* Check if we should do matching case insensitive */
if
(
p
<
expr_end
&&
*
p
==
'i'
)
if
(
p
<
expr_end
&&
*
p
==
'i'
)
...
@@ -9947,17 +9982,12 @@ struct st_replace_regex* init_replace_regex(char* expr)
...
@@ -9947,17 +9982,12 @@ struct st_replace_regex* init_replace_regex(char* expr)
if
(
insert_dynamic
(
&
res
->
regex_arr
,(
uchar
*
)
&
reg
))
if
(
insert_dynamic
(
&
res
->
regex_arr
,(
uchar
*
)
&
reg
))
die
(
"Out of memory"
);
die
(
"Out of memory"
);
}
}
res
->
odd_buf_len
=
res
->
even_buf_len
=
8192
;
res
->
even_buf
=
(
char
*
)
my_malloc
(
res
->
even_buf_len
,
MYF
(
MY_WME
+
MY_FAE
));
res
->
odd_buf
=
(
char
*
)
my_malloc
(
res
->
odd_buf_len
,
MYF
(
MY_WME
+
MY_FAE
));
res
->
buf
=
res
->
even_buf
;
return
res
;
return
;
err:
err:
my_free
(
res
);
my_free
(
res
);
die
(
"Error parsing replace_regex
\"
%s
\"
"
,
expr
);
die
(
"Error parsing replace_regex
\"
%s
\"
"
,
expr
);
return
0
;
}
}
/*
/*
...
@@ -10037,12 +10067,6 @@ void do_get_replace_regex(struct st_command *command)
...
@@ -10037,12 +10067,6 @@ 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
();
/* 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
)))
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
;
...
...
mysql-test/r/mysqltest.result
View file @
d59b94e7
...
@@ -672,7 +672,9 @@ drop table t1;
...
@@ -672,7 +672,9 @@ drop table t1;
y
y
txt
txt
b is b and more is more
b is b and more is more
txt
txt2
b is b or more is more
txt3
a is a and less is more
a is a and less is more
sflfdt 'ABCDfF bbddff h' bs txt;
sflfdt 'ABCDfF bbddff h' bs txt;
txt
txt
...
...
mysql-test/t/mysqltest.test
View file @
d59b94e7
...
@@ -2084,9 +2084,11 @@ drop table t1;
...
@@ -2084,9 +2084,11 @@ drop table t1;
--
let
$patt
=
/
a
/
b
/
/
less
/
more
/
--
let
$patt
=
/
a
/
b
/
/
less
/
more
/
--
replace_regex
$patt
--
replace_regex
$patt
select
"a is a and less is more"
as
txt
;
select
"a is a and less is more"
as
txt
;
--
replace_regex
$patt
/
and
/
or
/
select
"a is a and less is more"
as
txt2
;
--
let
$patt
=
--
let
$patt
=
--
replace_regex
$patt
--
replace_regex
$patt
select
"a is a and less is more"
as
txt
;
select
"a is a and less is more"
as
txt
3
;
--
enable_query_log
--
enable_query_log
#
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment