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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
daac3886
Commit
daac3886
authored
Apr 07, 2006
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge mysql.com:/extern/mysql/bk/mysql-5.0-runtime
into mysql.com:/extern/mysql/5.0/generic/mysql-5.0-runtime
parents
cab73a60
148cf113
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
233 additions
and
204 deletions
+233
-204
sql/sp_head.cc
sql/sp_head.cc
+11
-11
sql/sp_head.h
sql/sp_head.h
+3
-3
sql/sp_pcontext.cc
sql/sp_pcontext.cc
+81
-80
sql/sp_pcontext.h
sql/sp_pcontext.h
+78
-52
sql/sp_rcontext.cc
sql/sp_rcontext.cc
+12
-12
sql/sp_rcontext.h
sql/sp_rcontext.h
+4
-4
sql/sql_yacc.yy
sql/sql_yacc.yy
+44
-42
No files found.
sql/sp_head.cc
View file @
daac3886
...
@@ -1214,7 +1214,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
...
@@ -1214,7 +1214,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount,
DBUG_ENTER
(
"sp_head::execute_function"
);
DBUG_ENTER
(
"sp_head::execute_function"
);
DBUG_PRINT
(
"info"
,
(
"function %s"
,
m_name
.
str
));
DBUG_PRINT
(
"info"
,
(
"function %s"
,
m_name
.
str
));
params
=
m_pcont
->
context_
pvars
();
params
=
m_pcont
->
context_
var_count
();
/*
/*
Check that the function is called with all specified arguments.
Check that the function is called with all specified arguments.
...
@@ -1391,7 +1391,7 @@ bool
...
@@ -1391,7 +1391,7 @@ bool
sp_head
::
execute_procedure
(
THD
*
thd
,
List
<
Item
>
*
args
)
sp_head
::
execute_procedure
(
THD
*
thd
,
List
<
Item
>
*
args
)
{
{
bool
err_status
=
FALSE
;
bool
err_status
=
FALSE
;
uint
params
=
m_pcont
->
context_
pvars
();
uint
params
=
m_pcont
->
context_
var_count
();
sp_rcontext
*
save_spcont
,
*
octx
;
sp_rcontext
*
save_spcont
,
*
octx
;
sp_rcontext
*
nctx
=
NULL
;
sp_rcontext
*
nctx
=
NULL
;
DBUG_ENTER
(
"sp_head::execute_procedure"
);
DBUG_ENTER
(
"sp_head::execute_procedure"
);
...
@@ -1443,15 +1443,15 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
...
@@ -1443,15 +1443,15 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
for
(
uint
i
=
0
;
i
<
params
;
i
++
)
for
(
uint
i
=
0
;
i
<
params
;
i
++
)
{
{
Item
*
arg_item
=
it_args
++
;
Item
*
arg_item
=
it_args
++
;
sp_
pvar_t
*
pvar
=
m_pcont
->
find_pvar
(
i
);
sp_
variable_t
*
spvar
=
m_pcont
->
find_variable
(
i
);
if
(
!
arg_item
)
if
(
!
arg_item
)
break
;
break
;
if
(
!
pvar
)
if
(
!
s
pvar
)
continue
;
continue
;
if
(
pvar
->
mode
!=
sp_param_in
)
if
(
s
pvar
->
mode
!=
sp_param_in
)
{
{
if
(
!
arg_item
->
is_splocal
()
&&
!
item_is_user_var
(
arg_item
))
if
(
!
arg_item
->
is_splocal
()
&&
!
item_is_user_var
(
arg_item
))
{
{
...
@@ -1461,7 +1461,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
...
@@ -1461,7 +1461,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
}
}
}
}
if
(
pvar
->
mode
==
sp_param_out
)
if
(
s
pvar
->
mode
==
sp_param_out
)
{
{
Item_null
*
null_item
=
new
Item_null
();
Item_null
*
null_item
=
new
Item_null
();
...
@@ -1521,9 +1521,9 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
...
@@ -1521,9 +1521,9 @@ sp_head::execute_procedure(THD *thd, List<Item> *args)
if
(
!
arg_item
)
if
(
!
arg_item
)
break
;
break
;
sp_
pvar_t
*
pvar
=
m_pcont
->
find_pvar
(
i
);
sp_
variable_t
*
spvar
=
m_pcont
->
find_variable
(
i
);
if
(
pvar
->
mode
==
sp_param_in
)
if
(
s
pvar
->
mode
==
sp_param_in
)
continue
;
continue
;
if
(
arg_item
->
is_splocal
())
if
(
arg_item
->
is_splocal
())
...
@@ -2388,7 +2388,7 @@ sp_instr_set::print(String *str)
...
@@ -2388,7 +2388,7 @@ sp_instr_set::print(String *str)
{
{
/* set name@offset ... */
/* set name@offset ... */
int
rsrv
=
SP_INSTR_UINT_MAXLEN
+
6
;
int
rsrv
=
SP_INSTR_UINT_MAXLEN
+
6
;
sp_
pvar_t
*
var
=
m_ctx
->
find_pvar
(
m_offset
);
sp_
variable_t
*
var
=
m_ctx
->
find_variable
(
m_offset
);
/* 'var' should always be non-null, but just in case... */
/* 'var' should always be non-null, but just in case... */
if
(
var
)
if
(
var
)
...
@@ -3004,8 +3004,8 @@ sp_instr_cfetch::execute(THD *thd, uint *nextp)
...
@@ -3004,8 +3004,8 @@ sp_instr_cfetch::execute(THD *thd, uint *nextp)
void
void
sp_instr_cfetch
::
print
(
String
*
str
)
sp_instr_cfetch
::
print
(
String
*
str
)
{
{
List_iterator_fast
<
struct
sp_
pvar
>
li
(
m_varlist
);
List_iterator_fast
<
struct
sp_
variable
>
li
(
m_varlist
);
sp_
pvar
_t
*
pv
;
sp_
variable
_t
*
pv
;
LEX_STRING
n
;
LEX_STRING
n
;
my_bool
found
=
m_ctx
->
find_cursor
(
m_cursor
,
&
n
);
my_bool
found
=
m_ctx
->
find_cursor
(
m_cursor
,
&
n
);
/* cfetch name@offset vars... */
/* cfetch name@offset vars... */
...
...
sql/sp_head.h
View file @
daac3886
...
@@ -44,7 +44,7 @@ class sp_instr;
...
@@ -44,7 +44,7 @@ class sp_instr;
class
sp_instr_opt_meta
;
class
sp_instr_opt_meta
;
class
sp_instr_jump_if_not
;
class
sp_instr_jump_if_not
;
struct
sp_cond_type
;
struct
sp_cond_type
;
struct
sp_
pvar
;
struct
sp_
variable
;
class
sp_name
:
public
Sql_alloc
class
sp_name
:
public
Sql_alloc
{
{
...
@@ -1074,7 +1074,7 @@ public:
...
@@ -1074,7 +1074,7 @@ public:
virtual
void
print
(
String
*
str
);
virtual
void
print
(
String
*
str
);
void
add_to_varlist
(
struct
sp_
pvar
*
var
)
void
add_to_varlist
(
struct
sp_
variable
*
var
)
{
{
m_varlist
.
push_back
(
var
);
m_varlist
.
push_back
(
var
);
}
}
...
@@ -1082,7 +1082,7 @@ public:
...
@@ -1082,7 +1082,7 @@ public:
private:
private:
uint
m_cursor
;
uint
m_cursor
;
List
<
struct
sp_
pvar
>
m_varlist
;
List
<
struct
sp_
variable
>
m_varlist
;
};
// class sp_instr_cfetch : public sp_instr
};
// class sp_instr_cfetch : public sp_instr
...
...
sql/sp_pcontext.cc
View file @
daac3886
...
@@ -27,10 +27,10 @@
...
@@ -27,10 +27,10 @@
#include "sp_head.h"
#include "sp_head.h"
/*
/*
*
Sanity check for SQLSTATEs. Will not check if it's really an existing
Sanity check for SQLSTATEs. Will not check if it's really an existing
*
state (there are just too many), but will check length and bad characters.
state (there are just too many), but will check length and bad characters.
*
Returns TRUE if it's ok, FALSE if it's bad.
Returns TRUE if it's ok, FALSE if it's bad.
*/
*/
bool
bool
sp_cond_check
(
LEX_STRING
*
sqlstate
)
sp_cond_check
(
LEX_STRING
*
sqlstate
)
{
{
...
@@ -51,25 +51,25 @@ sp_cond_check(LEX_STRING *sqlstate)
...
@@ -51,25 +51,25 @@ sp_cond_check(LEX_STRING *sqlstate)
}
}
sp_pcontext
::
sp_pcontext
(
sp_pcontext
*
prev
)
sp_pcontext
::
sp_pcontext
(
sp_pcontext
*
prev
)
:
Sql_alloc
(),
m_
total_pvars
(
0
),
m_csubsize
(
0
),
m_hsubsize
(
0
),
:
Sql_alloc
(),
m_
max_var_index
(
0
),
m_max_cursor_index
(
0
),
m_max_handler_index
(
0
),
m_handlers
(
0
),
m_parent
(
prev
),
m_pboundary
(
0
)
m_
context_
handlers
(
0
),
m_parent
(
prev
),
m_pboundary
(
0
)
{
{
VOID
(
my_init_dynamic_array
(
&
m_
pvar
,
sizeof
(
sp_pvar
_t
*
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_
vars
,
sizeof
(
sp_variable
_t
*
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_case_expr_id_lst
,
sizeof
(
int
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_case_expr_id_lst
,
sizeof
(
int
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_cond
,
sizeof
(
sp_cond_type_t
*
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_cond
s
,
sizeof
(
sp_cond_type_t
*
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_cursor
,
sizeof
(
LEX_STRING
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_cursor
s
,
sizeof
(
LEX_STRING
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_handler
,
sizeof
(
sp_cond_type_t
*
),
16
,
8
));
VOID
(
my_init_dynamic_array
(
&
m_handler
s
,
sizeof
(
sp_cond_type_t
*
),
16
,
8
));
m_label
.
empty
();
m_label
.
empty
();
m_children
.
empty
();
m_children
.
empty
();
if
(
!
prev
)
if
(
!
prev
)
{
{
m_
poffset
=
m_c
offset
=
0
;
m_
var_offset
=
m_cursor_
offset
=
0
;
m_num_case_exprs
=
0
;
m_num_case_exprs
=
0
;
}
}
else
else
{
{
m_
poffset
=
prev
->
m_poffset
+
prev
->
m_total_pvars
;
m_
var_offset
=
prev
->
m_var_offset
+
prev
->
m_max_var_index
;
m_c
offset
=
prev
->
current_cursors
();
m_c
ursor_offset
=
prev
->
current_cursor_count
();
m_num_case_exprs
=
prev
->
get_num_case_exprs
();
m_num_case_exprs
=
prev
->
get_num_case_exprs
();
}
}
}
}
...
@@ -85,11 +85,11 @@ sp_pcontext::destroy()
...
@@ -85,11 +85,11 @@ sp_pcontext::destroy()
m_children
.
empty
();
m_children
.
empty
();
m_label
.
empty
();
m_label
.
empty
();
delete_dynamic
(
&
m_
pvar
);
delete_dynamic
(
&
m_
vars
);
delete_dynamic
(
&
m_case_expr_id_lst
);
delete_dynamic
(
&
m_case_expr_id_lst
);
delete_dynamic
(
&
m_cond
);
delete_dynamic
(
&
m_cond
s
);
delete_dynamic
(
&
m_cursor
);
delete_dynamic
(
&
m_cursor
s
);
delete_dynamic
(
&
m_handler
);
delete_dynamic
(
&
m_handler
s
);
}
}
sp_pcontext
*
sp_pcontext
*
...
@@ -105,15 +105,15 @@ sp_pcontext::push_context()
...
@@ -105,15 +105,15 @@ sp_pcontext::push_context()
sp_pcontext
*
sp_pcontext
*
sp_pcontext
::
pop_context
()
sp_pcontext
::
pop_context
()
{
{
m_parent
->
m_
total_pvars
=
m_parent
->
m_total_pvars
+
m_total_pvars
;
m_parent
->
m_
max_var_index
+=
m_max_var_index
;
uint
submax
=
max_handler
s
();
uint
submax
=
max_handler
_index
();
if
(
submax
>
m_parent
->
m_
hsubsize
)
if
(
submax
>
m_parent
->
m_
max_handler_index
)
m_parent
->
m_
hsubsize
=
submax
;
m_parent
->
m_
max_handler_index
=
submax
;
submax
=
max_cursor
s
();
submax
=
max_cursor
_index
();
if
(
submax
>
m_parent
->
m_
csubsize
)
if
(
submax
>
m_parent
->
m_
max_cursor_index
)
m_parent
->
m_
csubsize
=
submax
;
m_parent
->
m_
max_cursor_index
=
submax
;
if
(
m_num_case_exprs
>
m_parent
->
m_num_case_exprs
)
if
(
m_num_case_exprs
>
m_parent
->
m_num_case_exprs
)
m_parent
->
m_num_case_exprs
=
m_num_case_exprs
;
m_parent
->
m_num_case_exprs
=
m_num_case_exprs
;
...
@@ -130,12 +130,12 @@ sp_pcontext::diff_handlers(sp_pcontext *ctx, bool exclusive)
...
@@ -130,12 +130,12 @@ sp_pcontext::diff_handlers(sp_pcontext *ctx, bool exclusive)
while
(
pctx
&&
pctx
!=
ctx
)
while
(
pctx
&&
pctx
!=
ctx
)
{
{
n
+=
pctx
->
m_handlers
;
n
+=
pctx
->
m_
context_
handlers
;
last_ctx
=
pctx
;
last_ctx
=
pctx
;
pctx
=
pctx
->
parent_context
();
pctx
=
pctx
->
parent_context
();
}
}
if
(
pctx
)
if
(
pctx
)
return
(
exclusive
&&
last_ctx
?
n
-
last_ctx
->
m_handlers
:
n
);
return
(
exclusive
&&
last_ctx
?
n
-
last_ctx
->
m_
context_
handlers
:
n
);
return
0
;
// Didn't find ctx
return
0
;
// Didn't find ctx
}
}
...
@@ -148,32 +148,33 @@ sp_pcontext::diff_cursors(sp_pcontext *ctx, bool exclusive)
...
@@ -148,32 +148,33 @@ sp_pcontext::diff_cursors(sp_pcontext *ctx, bool exclusive)
while
(
pctx
&&
pctx
!=
ctx
)
while
(
pctx
&&
pctx
!=
ctx
)
{
{
n
+=
pctx
->
m_cursor
.
elements
;
n
+=
pctx
->
m_cursor
s
.
elements
;
last_ctx
=
pctx
;
last_ctx
=
pctx
;
pctx
=
pctx
->
parent_context
();
pctx
=
pctx
->
parent_context
();
}
}
if
(
pctx
)
if
(
pctx
)
return
(
exclusive
&&
last_ctx
?
n
-
last_ctx
->
m_cursor
.
elements
:
n
);
return
(
exclusive
&&
last_ctx
?
n
-
last_ctx
->
m_cursor
s
.
elements
:
n
);
return
0
;
// Didn't find ctx
return
0
;
// Didn't find ctx
}
}
/* This does a linear search (from newer to older variables, in case
/*
** we have shadowed names).
This does a linear search (from newer to older variables, in case
** It's possible to have a more efficient allocation and search method,
we have shadowed names).
** but it might not be worth it. The typical number of parameters and
It's possible to have a more efficient allocation and search method,
** variables will in most cases be low (a handfull).
but it might not be worth it. The typical number of parameters and
** ...and, this is only called during parsing.
variables will in most cases be low (a handfull).
...and, this is only called during parsing.
*/
*/
sp_
pvar
_t
*
sp_
variable
_t
*
sp_pcontext
::
find_
pvar
(
LEX_STRING
*
name
,
my_bool
scoped
)
sp_pcontext
::
find_
variable
(
LEX_STRING
*
name
,
my_bool
scoped
)
{
{
uint
i
=
m_
pvar
.
elements
-
m_pboundary
;
uint
i
=
m_
vars
.
elements
-
m_pboundary
;
while
(
i
--
)
while
(
i
--
)
{
{
sp_
pvar
_t
*
p
;
sp_
variable
_t
*
p
;
get_dynamic
(
&
m_
pvar
,
(
gptr
)
&
p
,
i
);
get_dynamic
(
&
m_
vars
,
(
gptr
)
&
p
,
i
);
if
(
my_strnncoll
(
system_charset_info
,
if
(
my_strnncoll
(
system_charset_info
,
(
const
uchar
*
)
name
->
str
,
name
->
length
,
(
const
uchar
*
)
name
->
str
,
name
->
length
,
(
const
uchar
*
)
p
->
name
.
str
,
p
->
name
.
length
)
==
0
)
(
const
uchar
*
)
p
->
name
.
str
,
p
->
name
.
length
)
==
0
)
...
@@ -182,7 +183,7 @@ sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped)
...
@@ -182,7 +183,7 @@ sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped)
}
}
}
}
if
(
!
scoped
&&
m_parent
)
if
(
!
scoped
&&
m_parent
)
return
m_parent
->
find_
pvar
(
name
,
scoped
);
return
m_parent
->
find_
variable
(
name
,
scoped
);
return
NULL
;
return
NULL
;
}
}
...
@@ -192,40 +193,40 @@ sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped)
...
@@ -192,40 +193,40 @@ sp_pcontext::find_pvar(LEX_STRING *name, my_bool scoped)
- When evaluating parameters at the beginning, and setting out parameters
- When evaluating parameters at the beginning, and setting out parameters
at the end, of invokation. (Top frame only, so no recursion then.)
at the end, of invokation. (Top frame only, so no recursion then.)
- For printing of sp_instr_set. (Debug mode only.)
- For printing of sp_instr_set. (Debug mode only.)
*/
*/
sp_
pvar
_t
*
sp_
variable
_t
*
sp_pcontext
::
find_
pvar
(
uint
offset
)
sp_pcontext
::
find_
variable
(
uint
offset
)
{
{
if
(
m_
poffset
<=
offset
&&
offset
<
m_poffset
+
m_pvar
.
elements
)
if
(
m_
var_offset
<=
offset
&&
offset
<
m_var_offset
+
m_vars
.
elements
)
{
// This frame
{
// This frame
sp_
pvar
_t
*
p
;
sp_
variable
_t
*
p
;
get_dynamic
(
&
m_
pvar
,
(
gptr
)
&
p
,
offset
-
m_p
offset
);
get_dynamic
(
&
m_
vars
,
(
gptr
)
&
p
,
offset
-
m_var_
offset
);
return
p
;
return
p
;
}
}
if
(
m_parent
)
if
(
m_parent
)
return
m_parent
->
find_
pvar
(
offset
);
// Some previous frame
return
m_parent
->
find_
variable
(
offset
);
// Some previous frame
return
NULL
;
// index out of bounds
return
NULL
;
// index out of bounds
}
}
sp_
pvar
_t
*
sp_
variable
_t
*
sp_pcontext
::
push_
pvar
(
LEX_STRING
*
name
,
enum
enum_field_types
type
,
sp_pcontext
::
push_
variable
(
LEX_STRING
*
name
,
enum
enum_field_types
type
,
sp_param_mode_t
mode
)
sp_param_mode_t
mode
)
{
{
sp_
pvar_t
*
p
=
(
sp_pvar_t
*
)
sql_alloc
(
sizeof
(
sp_pvar
_t
));
sp_
variable_t
*
p
=
(
sp_variable_t
*
)
sql_alloc
(
sizeof
(
sp_variable
_t
));
if
(
!
p
)
if
(
!
p
)
return
NULL
;
return
NULL
;
++
m_
total_pvars
;
++
m_
max_var_index
;
p
->
name
.
str
=
name
->
str
;
p
->
name
.
str
=
name
->
str
;
p
->
name
.
length
=
name
->
length
;
p
->
name
.
length
=
name
->
length
;
p
->
type
=
type
;
p
->
type
=
type
;
p
->
mode
=
mode
;
p
->
mode
=
mode
;
p
->
offset
=
current_
pvars
();
p
->
offset
=
current_
var_count
();
p
->
dflt
=
NULL
;
p
->
dflt
=
NULL
;
insert_dynamic
(
&
m_
pvar
,
(
gptr
)
&
p
);
insert_dynamic
(
&
m_
vars
,
(
gptr
)
&
p
);
return
p
;
return
p
;
}
}
...
@@ -272,23 +273,23 @@ sp_pcontext::push_cond(LEX_STRING *name, sp_cond_type_t *val)
...
@@ -272,23 +273,23 @@ sp_pcontext::push_cond(LEX_STRING *name, sp_cond_type_t *val)
p
->
name
.
str
=
name
->
str
;
p
->
name
.
str
=
name
->
str
;
p
->
name
.
length
=
name
->
length
;
p
->
name
.
length
=
name
->
length
;
p
->
val
=
val
;
p
->
val
=
val
;
insert_dynamic
(
&
m_cond
,
(
gptr
)
&
p
);
insert_dynamic
(
&
m_cond
s
,
(
gptr
)
&
p
);
}
}
}
}
/*
/*
* See comment for find_pvar
() above
See comment for find_variable
() above
*/
*/
sp_cond_type_t
*
sp_cond_type_t
*
sp_pcontext
::
find_cond
(
LEX_STRING
*
name
,
my_bool
scoped
)
sp_pcontext
::
find_cond
(
LEX_STRING
*
name
,
my_bool
scoped
)
{
{
uint
i
=
m_cond
.
elements
;
uint
i
=
m_cond
s
.
elements
;
while
(
i
--
)
while
(
i
--
)
{
{
sp_cond_t
*
p
;
sp_cond_t
*
p
;
get_dynamic
(
&
m_cond
,
(
gptr
)
&
p
,
i
);
get_dynamic
(
&
m_cond
s
,
(
gptr
)
&
p
,
i
);
if
(
my_strnncoll
(
system_charset_info
,
if
(
my_strnncoll
(
system_charset_info
,
(
const
uchar
*
)
name
->
str
,
name
->
length
,
(
const
uchar
*
)
name
->
str
,
name
->
length
,
(
const
uchar
*
)
p
->
name
.
str
,
p
->
name
.
length
)
==
0
)
(
const
uchar
*
)
p
->
name
.
str
,
p
->
name
.
length
)
==
0
)
...
@@ -302,20 +303,20 @@ sp_pcontext::find_cond(LEX_STRING *name, my_bool scoped)
...
@@ -302,20 +303,20 @@ sp_pcontext::find_cond(LEX_STRING *name, my_bool scoped)
}
}
/*
/*
*
This only searches the current context, for error checking of
This only searches the current context, for error checking of
*
duplicates.
duplicates.
*
Returns TRUE if found.
Returns TRUE if found.
*/
*/
bool
bool
sp_pcontext
::
find_handler
(
sp_cond_type_t
*
cond
)
sp_pcontext
::
find_handler
(
sp_cond_type_t
*
cond
)
{
{
uint
i
=
m_handler
.
elements
;
uint
i
=
m_handler
s
.
elements
;
while
(
i
--
)
while
(
i
--
)
{
{
sp_cond_type_t
*
p
;
sp_cond_type_t
*
p
;
get_dynamic
(
&
m_handler
,
(
gptr
)
&
p
,
i
);
get_dynamic
(
&
m_handler
s
,
(
gptr
)
&
p
,
i
);
if
(
cond
->
type
==
p
->
type
)
if
(
cond
->
type
==
p
->
type
)
{
{
switch
(
p
->
type
)
switch
(
p
->
type
)
...
@@ -341,31 +342,31 @@ sp_pcontext::push_cursor(LEX_STRING *name)
...
@@ -341,31 +342,31 @@ sp_pcontext::push_cursor(LEX_STRING *name)
{
{
LEX_STRING
n
;
LEX_STRING
n
;
if
(
m_cursor
.
elements
==
m_csubsize
)
if
(
m_cursor
s
.
elements
==
m_max_cursor_index
)
m_
csubsize
+=
1
;
m_
max_cursor_index
+=
1
;
n
.
str
=
name
->
str
;
n
.
str
=
name
->
str
;
n
.
length
=
name
->
length
;
n
.
length
=
name
->
length
;
insert_dynamic
(
&
m_cursor
,
(
gptr
)
&
n
);
insert_dynamic
(
&
m_cursor
s
,
(
gptr
)
&
n
);
}
}
/*
/*
* See comment for find_pvar
() above
See comment for find_variable
() above
*/
*/
my_bool
my_bool
sp_pcontext
::
find_cursor
(
LEX_STRING
*
name
,
uint
*
poff
,
my_bool
scoped
)
sp_pcontext
::
find_cursor
(
LEX_STRING
*
name
,
uint
*
poff
,
my_bool
scoped
)
{
{
uint
i
=
m_cursor
.
elements
;
uint
i
=
m_cursor
s
.
elements
;
while
(
i
--
)
while
(
i
--
)
{
{
LEX_STRING
n
;
LEX_STRING
n
;
get_dynamic
(
&
m_cursor
,
(
gptr
)
&
n
,
i
);
get_dynamic
(
&
m_cursor
s
,
(
gptr
)
&
n
,
i
);
if
(
my_strnncoll
(
system_charset_info
,
if
(
my_strnncoll
(
system_charset_info
,
(
const
uchar
*
)
name
->
str
,
name
->
length
,
(
const
uchar
*
)
name
->
str
,
name
->
length
,
(
const
uchar
*
)
n
.
str
,
n
.
length
)
==
0
)
(
const
uchar
*
)
n
.
str
,
n
.
length
)
==
0
)
{
{
*
poff
=
m_coffset
+
i
;
*
poff
=
m_c
ursor_
offset
+
i
;
return
TRUE
;
return
TRUE
;
}
}
}
}
...
@@ -380,10 +381,10 @@ sp_pcontext::retrieve_field_definitions(List<create_field> *field_def_lst)
...
@@ -380,10 +381,10 @@ sp_pcontext::retrieve_field_definitions(List<create_field> *field_def_lst)
{
{
/* Put local/context fields in the result list. */
/* Put local/context fields in the result list. */
for
(
uint
i
=
0
;
i
<
m_
pvar
.
elements
;
++
i
)
for
(
uint
i
=
0
;
i
<
m_
vars
.
elements
;
++
i
)
{
{
sp_
pvar
_t
*
var_def
;
sp_
variable
_t
*
var_def
;
get_dynamic
(
&
m_
pvar
,
(
gptr
)
&
var_def
,
i
);
get_dynamic
(
&
m_
vars
,
(
gptr
)
&
var_def
,
i
);
field_def_lst
->
push_back
(
&
var_def
->
field_def
);
field_def_lst
->
push_back
(
&
var_def
->
field_def
);
}
}
...
@@ -400,17 +401,17 @@ sp_pcontext::retrieve_field_definitions(List<create_field> *field_def_lst)
...
@@ -400,17 +401,17 @@ sp_pcontext::retrieve_field_definitions(List<create_field> *field_def_lst)
/*
/*
Find a cursor by offset from the top.
Find a cursor by offset from the top.
This is only used for debugging.
This is only used for debugging.
*/
*/
my_bool
my_bool
sp_pcontext
::
find_cursor
(
uint
offset
,
LEX_STRING
*
n
)
sp_pcontext
::
find_cursor
(
uint
offset
,
LEX_STRING
*
n
)
{
{
if
(
m_coffset
<=
offset
&&
offset
<
m_coffset
+
m_cursor
.
elements
)
if
(
m_cursor_offset
<=
offset
&&
offset
<
m_cursor_offset
+
m_cursors
.
elements
)
{
// This frame
{
// This frame
get_dynamic
(
&
m_cursor
,
(
gptr
)
n
,
offset
-
m_c
offset
);
get_dynamic
(
&
m_cursor
s
,
(
gptr
)
n
,
offset
-
m_cursor_
offset
);
return
TRUE
;
return
TRUE
;
}
}
if
(
m_parent
)
if
(
m_parent
)
return
m_parent
->
find_cursor
(
offset
,
n
);
// Some previous frame
return
m_parent
->
find_cursor
(
offset
,
n
);
// Some previous frame
return
FALSE
;
// index out of bounds
return
FALSE
;
// index out of bounds
}
}
sql/sp_pcontext.h
View file @
daac3886
...
@@ -29,22 +29,23 @@ typedef enum
...
@@ -29,22 +29,23 @@ typedef enum
sp_param_inout
sp_param_inout
}
sp_param_mode_t
;
}
sp_param_mode_t
;
typedef
struct
sp_
pvar
typedef
struct
sp_
variable
{
{
LEX_STRING
name
;
LEX_STRING
name
;
enum
enum_field_types
type
;
enum
enum_field_types
type
;
sp_param_mode_t
mode
;
sp_param_mode_t
mode
;
/*
/*
offset -- basically, this is an index of variable in the scope of root
offset -- this the index to the variable's value in the runtime frame.
parsing context. This means, that all variables in a stored routine
This is calculated during parsing and used when creating sp_instr_set
have distinct indexes/offsets.
instructions and Item_splocal items.
I.e. values are set/referred by array indexing in runtime.
*/
*/
uint
offset
;
uint
offset
;
Item
*
dflt
;
Item
*
dflt
;
create_field
field_def
;
create_field
field_def
;
}
sp_
pvar
_t
;
}
sp_
variable
_t
;
#define SP_LAB_REF 0 // Unresolved reference (for goto)
#define SP_LAB_REF 0 // Unresolved reference (for goto)
...
@@ -76,9 +77,10 @@ typedef struct sp_cond_type
...
@@ -76,9 +77,10 @@ typedef struct sp_cond_type
uint
mysqlerr
;
uint
mysqlerr
;
}
sp_cond_type_t
;
}
sp_cond_type_t
;
/* Sanity check for SQLSTATEs. Will not check if it's really an existing
/*
* state (there are just too many), but will check length bad characters.
Sanity check for SQLSTATEs. Will not check if it's really an existing
*/
state (there are just too many), but will check length bad characters.
*/
extern
bool
extern
bool
sp_cond_check
(
LEX_STRING
*
sqlstate
);
sp_cond_check
(
LEX_STRING
*
sqlstate
);
...
@@ -90,7 +92,17 @@ typedef struct sp_cond
...
@@ -90,7 +92,17 @@ typedef struct sp_cond
/*
/*
This seems to be an "SP parsing context" or something.
The parse-time context, used to keep track on declared variables/parameters,
conditions, handlers, cursors and labels, during parsing.
sp_contexts are organized as a tree, with one object for each begin-end
block, plus a root-context for the parameters.
This is used during parsing for looking up defined names (e.g. declared
variables and visible labels), for error checking, and to calculate offsets
to be used at runtime. (During execution variable values, active handlers
and cursors, etc, are referred to by an index in a stack.)
The pcontext tree is also kept during execution and is used for error
checking (e.g. correct number of parameters), and in the future, used by
the debugger.
*/
*/
class
sp_pcontext
:
public
Sql_alloc
class
sp_pcontext
:
public
Sql_alloc
...
@@ -134,50 +146,64 @@ class sp_pcontext : public Sql_alloc
...
@@ -134,50 +146,64 @@ class sp_pcontext : public Sql_alloc
// Parameters and variables
// Parameters and variables
//
//
/*
The maximum number of variables used in this and all child contexts
In the root, this gives us the number of slots needed for variables
during execution.
*/
inline
uint
inline
uint
total_pvars
()
max_var_index
()
{
{
return
m_
total_pvars
;
return
m_
max_var_index
;
}
}
/*
The current number of variables used in the parents (from the root),
including this context.
*/
inline
uint
inline
uint
current_
pvars
()
current_
var_count
()
{
{
return
m_
poffset
+
m_pvar
.
elements
;
return
m_
var_offset
+
m_vars
.
elements
;
}
}
/* The number of variables in this context alone */
inline
uint
inline
uint
context_
pvars
()
context_
var_count
()
{
{
return
m_
pvar
.
elements
;
return
m_
vars
.
elements
;
}
}
/* Map index in this pcontext to runtime offset */
inline
uint
inline
uint
pvar_context2index
(
uint
i
)
var_context2runtime
(
uint
i
)
{
{
return
m_
p
offset
+
i
;
return
m_
var_
offset
+
i
;
}
}
/* Set type of variable. 'i' is the offset from the top */
inline
void
inline
void
set_type
(
uint
i
,
enum
enum_field_types
type
)
set_type
(
uint
i
,
enum
enum_field_types
type
)
{
{
sp_
pvar_t
*
p
=
find_pvar
(
i
);
sp_
variable_t
*
p
=
find_variable
(
i
);
if
(
p
)
if
(
p
)
p
->
type
=
type
;
p
->
type
=
type
;
}
}
/* Set default value of variable. 'i' is the offset from the top */
inline
void
inline
void
set_default
(
uint
i
,
Item
*
it
)
set_default
(
uint
i
,
Item
*
it
)
{
{
sp_
pvar_t
*
p
=
find_pvar
(
i
);
sp_
variable_t
*
p
=
find_variable
(
i
);
if
(
p
)
if
(
p
)
p
->
dflt
=
it
;
p
->
dflt
=
it
;
}
}
sp_pvar_t
*
sp_variable_t
*
push_pvar
(
LEX_STRING
*
name
,
enum
enum_field_types
type
,
sp_param_mode_t
mode
);
push_variable
(
LEX_STRING
*
name
,
enum
enum_field_types
type
,
sp_param_mode_t
mode
);
/*
/*
Retrieve definitions of fields from the current context and its
Retrieve definitions of fields from the current context and its
...
@@ -187,12 +213,12 @@ class sp_pcontext : public Sql_alloc
...
@@ -187,12 +213,12 @@ class sp_pcontext : public Sql_alloc
retrieve_field_definitions
(
List
<
create_field
>
*
field_def_lst
);
retrieve_field_definitions
(
List
<
create_field
>
*
field_def_lst
);
// Find by name
// Find by name
sp_
pvar
_t
*
sp_
variable
_t
*
find_
pvar
(
LEX_STRING
*
name
,
my_bool
scoped
=
0
);
find_
variable
(
LEX_STRING
*
name
,
my_bool
scoped
=
0
);
// Find by offset
// Find by offset
(from the top)
sp_
pvar
_t
*
sp_
variable
_t
*
find_
pvar
(
uint
offset
);
find_
variable
(
uint
offset
);
/*
/*
Set the current scope boundary (for default values).
Set the current scope boundary (for default values).
...
@@ -280,7 +306,7 @@ class sp_pcontext : public Sql_alloc
...
@@ -280,7 +306,7 @@ class sp_pcontext : public Sql_alloc
pop_cond
(
uint
num
)
pop_cond
(
uint
num
)
{
{
while
(
num
--
)
while
(
num
--
)
pop_dynamic
(
&
m_cond
);
pop_dynamic
(
&
m_cond
s
);
}
}
sp_cond_type_t
*
sp_cond_type_t
*
...
@@ -293,22 +319,22 @@ class sp_pcontext : public Sql_alloc
...
@@ -293,22 +319,22 @@ class sp_pcontext : public Sql_alloc
inline
void
inline
void
push_handler
(
sp_cond_type_t
*
cond
)
push_handler
(
sp_cond_type_t
*
cond
)
{
{
insert_dynamic
(
&
m_handler
,
(
gptr
)
&
cond
);
insert_dynamic
(
&
m_handler
s
,
(
gptr
)
&
cond
);
}
}
bool
bool
find_handler
(
sp_cond_type
*
cond
);
find_handler
(
sp_cond_type
*
cond
);
inline
uint
inline
uint
max_handler
s
()
max_handler
_index
()
{
{
return
m_
hsubsize
+
m
_handlers
;
return
m_
max_handler_index
+
m_context
_handlers
;
}
}
inline
void
inline
void
add_handlers
(
uint
n
)
add_handlers
(
uint
n
)
{
{
m_handlers
+=
n
;
m_
context_
handlers
+=
n
;
}
}
//
//
...
@@ -326,51 +352,51 @@ class sp_pcontext : public Sql_alloc
...
@@ -326,51 +352,51 @@ class sp_pcontext : public Sql_alloc
find_cursor
(
uint
offset
,
LEX_STRING
*
n
);
find_cursor
(
uint
offset
,
LEX_STRING
*
n
);
inline
uint
inline
uint
max_cursor
s
()
max_cursor
_index
()
{
{
return
m_
csubsize
+
m_cursor
.
elements
;
return
m_
max_cursor_index
+
m_cursors
.
elements
;
}
}
inline
uint
inline
uint
current_cursor
s
()
current_cursor
_count
()
{
{
return
m_c
offset
+
m_cursor
.
elements
;
return
m_c
ursor_offset
+
m_cursors
.
elements
;
}
}
protected:
protected:
/*
/*
m_
total_pvars
-- number of variables (including all types of arguments)
m_
max_var_index
-- number of variables (including all types of arguments)
in this context including all children contexts.
in this context including all children contexts.
m_
total_pvars >= m_pvar
.elements.
m_
max_var_index >= m_vars
.elements.
m_
total_pvars
of the root parsing context contains number of all
m_
max_var_index
of the root parsing context contains number of all
variables (including arguments) in all enclosed contexts.
variables (including arguments) in all enclosed contexts.
*/
*/
uint
m_
total_pvars
;
uint
m_
max_var_index
;
// The maximum sub context's framesizes
// The maximum sub context's framesizes
uint
m_
csubsize
;
uint
m_
max_cursor_index
;
uint
m_
hsubsize
;
uint
m_
max_handler_index
;
uint
m_
handlers
;
// No. of handlers in this context
uint
m_
context_handlers
;
// No. of handlers in this context
private:
private:
sp_pcontext
*
m_parent
;
// Parent context
sp_pcontext
*
m_parent
;
// Parent context
/*
/*
m_
poffset -- basically,
this is an index of the first variable in this
m_
var_offset --
this is an index of the first variable in this
parsing context.
parsing context.
m_
p
offset is 0 for root context.
m_
var_
offset is 0 for root context.
Since now each variable is stored in separate place, no reuse is done,
Since now each variable is stored in separate place, no reuse is done,
so m_
p
offset is different for all enclosed contexts.
so m_
var_
offset is different for all enclosed contexts.
*/
*/
uint
m_
p
offset
;
uint
m_
var_
offset
;
uint
m_coffset
;
// Cursor offset for this context
uint
m_c
ursor_
offset
;
// Cursor offset for this context
/*
/*
Boundary for finding variables in this context. This is the number
Boundary for finding variables in this context. This is the number
...
@@ -382,11 +408,11 @@ private:
...
@@ -382,11 +408,11 @@ private:
int
m_num_case_exprs
;
int
m_num_case_exprs
;
DYNAMIC_ARRAY
m_
pvar
;
// Parameters/variables
DYNAMIC_ARRAY
m_
vars
;
// Parameters/variables
DYNAMIC_ARRAY
m_case_expr_id_lst
;
/* Stack of CASE expression ids. */
DYNAMIC_ARRAY
m_case_expr_id_lst
;
/* Stack of CASE expression ids. */
DYNAMIC_ARRAY
m_cond
;
// Conditions
DYNAMIC_ARRAY
m_cond
s
;
// Conditions
DYNAMIC_ARRAY
m_cursor
;
// Cursors
DYNAMIC_ARRAY
m_cursor
s
;
// Cursors
DYNAMIC_ARRAY
m_handler
;
// Handlers, for checking of
duplicates
DYNAMIC_ARRAY
m_handler
s
;
// Handlers, for checking for
duplicates
List
<
sp_label_t
>
m_label
;
// The label list
List
<
sp_label_t
>
m_label
;
// The label list
...
...
sql/sp_rcontext.cc
View file @
daac3886
...
@@ -73,16 +73,16 @@ bool sp_rcontext::init(THD *thd)
...
@@ -73,16 +73,16 @@ bool sp_rcontext::init(THD *thd)
return
return
!
(
m_handler
=
!
(
m_handler
=
(
sp_handler_t
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
s
()
*
(
sp_handler_t
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
_index
()
*
sizeof
(
sp_handler_t
)))
||
sizeof
(
sp_handler_t
)))
||
!
(
m_hstack
=
!
(
m_hstack
=
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
s
()
*
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
_index
()
*
sizeof
(
uint
)))
||
sizeof
(
uint
)))
||
!
(
m_in_handler
=
!
(
m_in_handler
=
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
s
()
*
(
uint
*
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_handler
_index
()
*
sizeof
(
uint
)))
||
sizeof
(
uint
)))
||
!
(
m_cstack
=
!
(
m_cstack
=
(
sp_cursor
**
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_cursor
s
()
*
(
sp_cursor
**
)
thd
->
alloc
(
m_root_parsing_ctx
->
max_cursor
_index
()
*
sizeof
(
sp_cursor
*
)))
||
sizeof
(
sp_cursor
*
)))
||
!
(
m_case_expr_holders
=
!
(
m_case_expr_holders
=
(
Item_cache
**
)
thd
->
calloc
(
m_root_parsing_ctx
->
get_num_case_exprs
()
*
(
Item_cache
**
)
thd
->
calloc
(
m_root_parsing_ctx
->
get_num_case_exprs
()
*
...
@@ -105,12 +105,12 @@ sp_rcontext::init_var_table(THD *thd)
...
@@ -105,12 +105,12 @@ sp_rcontext::init_var_table(THD *thd)
{
{
List
<
create_field
>
field_def_lst
;
List
<
create_field
>
field_def_lst
;
if
(
!
m_root_parsing_ctx
->
total_pvars
())
if
(
!
m_root_parsing_ctx
->
max_var_index
())
return
FALSE
;
return
FALSE
;
m_root_parsing_ctx
->
retrieve_field_definitions
(
&
field_def_lst
);
m_root_parsing_ctx
->
retrieve_field_definitions
(
&
field_def_lst
);
DBUG_ASSERT
(
field_def_lst
.
elements
==
m_root_parsing_ctx
->
total_pvars
());
DBUG_ASSERT
(
field_def_lst
.
elements
==
m_root_parsing_ctx
->
max_var_index
());
if
(
!
(
m_var_table
=
create_virtual_tmp_table
(
thd
,
field_def_lst
)))
if
(
!
(
m_var_table
=
create_virtual_tmp_table
(
thd
,
field_def_lst
)))
return
TRUE
;
return
TRUE
;
...
@@ -134,7 +134,7 @@ bool
...
@@ -134,7 +134,7 @@ bool
sp_rcontext
::
init_var_items
()
sp_rcontext
::
init_var_items
()
{
{
uint
idx
;
uint
idx
;
uint
num_vars
=
m_root_parsing_ctx
->
total_pvars
();
uint
num_vars
=
m_root_parsing_ctx
->
max_var_index
();
if
(
!
(
m_var_items
=
(
Item
**
)
sql_alloc
(
num_vars
*
sizeof
(
Item
*
))))
if
(
!
(
m_var_items
=
(
Item
**
)
sql_alloc
(
num_vars
*
sizeof
(
Item
*
))))
return
TRUE
;
return
TRUE
;
...
@@ -381,7 +381,7 @@ sp_cursor::destroy()
...
@@ -381,7 +381,7 @@ sp_cursor::destroy()
int
int
sp_cursor
::
fetch
(
THD
*
thd
,
List
<
struct
sp_
pvar
>
*
vars
)
sp_cursor
::
fetch
(
THD
*
thd
,
List
<
struct
sp_
variable
>
*
vars
)
{
{
if
(
!
server_side_cursor
)
if
(
!
server_side_cursor
)
{
{
...
@@ -528,9 +528,9 @@ int Select_fetch_into_spvars::prepare(List<Item> &fields, SELECT_LEX_UNIT *u)
...
@@ -528,9 +528,9 @@ int Select_fetch_into_spvars::prepare(List<Item> &fields, SELECT_LEX_UNIT *u)
bool
Select_fetch_into_spvars
::
send_data
(
List
<
Item
>
&
items
)
bool
Select_fetch_into_spvars
::
send_data
(
List
<
Item
>
&
items
)
{
{
List_iterator_fast
<
struct
sp_
pvar
>
pv
_iter
(
*
spvar_list
);
List_iterator_fast
<
struct
sp_
variable
>
spvar
_iter
(
*
spvar_list
);
List_iterator_fast
<
Item
>
item_iter
(
items
);
List_iterator_fast
<
Item
>
item_iter
(
items
);
sp_
pvar_t
*
pv
;
sp_
variable_t
*
spvar
;
Item
*
item
;
Item
*
item
;
/* Must be ensured by the caller */
/* Must be ensured by the caller */
...
@@ -540,9 +540,9 @@ bool Select_fetch_into_spvars::send_data(List<Item> &items)
...
@@ -540,9 +540,9 @@ bool Select_fetch_into_spvars::send_data(List<Item> &items)
Assign the row fetched from a server side cursor to stored
Assign the row fetched from a server side cursor to stored
procedure variables.
procedure variables.
*/
*/
for
(;
pv
=
pv
_iter
++
,
item
=
item_iter
++
;
)
for
(;
spvar
=
spvar
_iter
++
,
item
=
item_iter
++
;
)
{
{
if
(
thd
->
spcont
->
set_variable
(
thd
,
pv
->
offset
,
item
))
if
(
thd
->
spcont
->
set_variable
(
thd
,
spvar
->
offset
,
item
))
return
TRUE
;
return
TRUE
;
}
}
return
FALSE
;
return
FALSE
;
...
...
sql/sp_rcontext.h
View file @
daac3886
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
struct
sp_cond_type
;
struct
sp_cond_type
;
class
sp_cursor
;
class
sp_cursor
;
struct
sp_
pvar
;
struct
sp_
variable
;
class
sp_lex_keeper
;
class
sp_lex_keeper
;
class
sp_instr_cpush
;
class
sp_instr_cpush
;
...
@@ -265,12 +265,12 @@ private:
...
@@ -265,12 +265,12 @@ private:
class
Select_fetch_into_spvars
:
public
select_result_interceptor
class
Select_fetch_into_spvars
:
public
select_result_interceptor
{
{
List
<
struct
sp_
pvar
>
*
spvar_list
;
List
<
struct
sp_
variable
>
*
spvar_list
;
uint
field_count
;
uint
field_count
;
public:
public:
Select_fetch_into_spvars
()
{}
/* Remove gcc warning */
Select_fetch_into_spvars
()
{}
/* Remove gcc warning */
uint
get_field_count
()
{
return
field_count
;
}
uint
get_field_count
()
{
return
field_count
;
}
void
set_spvar_list
(
List
<
struct
sp_
pvar
>
*
vars
)
{
spvar_list
=
vars
;
}
void
set_spvar_list
(
List
<
struct
sp_
variable
>
*
vars
)
{
spvar_list
=
vars
;
}
virtual
bool
send_eof
()
{
return
FALSE
;
}
virtual
bool
send_eof
()
{
return
FALSE
;
}
virtual
bool
send_data
(
List
<
Item
>
&
items
);
virtual
bool
send_data
(
List
<
Item
>
&
items
);
...
@@ -307,7 +307,7 @@ public:
...
@@ -307,7 +307,7 @@ public:
}
}
int
int
fetch
(
THD
*
,
List
<
struct
sp_
pvar
>
*
vars
);
fetch
(
THD
*
,
List
<
struct
sp_
variable
>
*
vars
);
inline
sp_instr_cpush
*
inline
sp_instr_cpush
*
get_instr
()
get_instr
()
...
...
sql/sql_yacc.yy
View file @
daac3886
...
@@ -1461,22 +1461,23 @@ sp_fdparam:
...
@@ -1461,22 +1461,23 @@ sp_fdparam:
LEX *lex= Lex;
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$1, TRUE))
if (spc->find_
variable
(&$1, TRUE))
{
{
my_error(ER_SP_DUP_PARAM, MYF(0), $1.str);
my_error(ER_SP_DUP_PARAM, MYF(0), $1.str);
YYABORT;
YYABORT;
}
}
sp_pvar_t *pvar= spc->push_pvar(&$1, (enum enum_field_types)$3,
sp_variable_t *spvar= spc->push_variable(&$1,
(enum enum_field_types)$3,
sp_param_in);
sp_param_in);
if (lex->sphead->fill_field_definition(YYTHD, lex,
if (lex->sphead->fill_field_definition(YYTHD, lex,
(enum enum_field_types) $3,
(enum enum_field_types) $3,
&pvar->field_def))
&
s
pvar->field_def))
{
{
YYABORT;
YYABORT;
}
}
pvar->field_def.field_name=
pvar->name.str;
spvar->field_def.field_name= s
pvar->name.str;
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
s
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
}
}
;
;
...
@@ -1497,22 +1498,23 @@ sp_pdparam:
...
@@ -1497,22 +1498,23 @@ sp_pdparam:
LEX *lex= Lex;
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$3, TRUE))
if (spc->find_
variable
(&$3, TRUE))
{
{
my_error(ER_SP_DUP_PARAM, MYF(0), $3.str);
my_error(ER_SP_DUP_PARAM, MYF(0), $3.str);
YYABORT;
YYABORT;
}
}
sp_pvar_t *pvar= spc->push_pvar(&$3, (enum enum_field_types)$4,
sp_variable_t *spvar= spc->push_variable(&$3,
(enum enum_field_types)$4,
(sp_param_mode_t)$1);
(sp_param_mode_t)$1);
if (lex->sphead->fill_field_definition(YYTHD, lex,
if (lex->sphead->fill_field_definition(YYTHD, lex,
(enum enum_field_types) $4,
(enum enum_field_types) $4,
&pvar->field_def))
&
s
pvar->field_def))
{
{
YYABORT;
YYABORT;
}
}
pvar->field_def.field_name=
pvar->name.str;
spvar->field_def.field_name= s
pvar->name.str;
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
s
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
}
}
;
;
...
@@ -1576,7 +1578,7 @@ sp_decl:
...
@@ -1576,7 +1578,7 @@ sp_decl:
{
{
LEX *lex= Lex;
LEX *lex= Lex;
sp_pcontext *pctx= lex->spcont;
sp_pcontext *pctx= lex->spcont;
uint num_vars= pctx->context_
pvars
();
uint num_vars= pctx->context_
var_count
();
enum enum_field_types var_type= (enum enum_field_types) $4;
enum enum_field_types var_type= (enum enum_field_types) $4;
Item *dflt_value_item= $5;
Item *dflt_value_item= $5;
create_field *create_field_op;
create_field *create_field_op;
...
@@ -1589,23 +1591,23 @@ sp_decl:
...
@@ -1589,23 +1591,23 @@ sp_decl:
for (uint i = num_vars-$2 ; i < num_vars ; i++)
for (uint i = num_vars-$2 ; i < num_vars ; i++)
{
{
uint var_idx= pctx->
pvar_context2index
(i);
uint var_idx= pctx->
var_context2runtime
(i);
sp_
pvar_t *pvar= pctx->find_pvar
(var_idx);
sp_
variable_t *spvar= pctx->find_variable
(var_idx);
if (!pvar)
if (!
s
pvar)
YYABORT;
YYABORT;
pvar->type= var_type;
s
pvar->type= var_type;
pvar->dflt= dflt_value_item;
s
pvar->dflt= dflt_value_item;
if (lex->sphead->fill_field_definition(YYTHD, lex, var_type,
if (lex->sphead->fill_field_definition(YYTHD, lex, var_type,
&pvar->field_def))
&
s
pvar->field_def))
{
{
YYABORT;
YYABORT;
}
}
pvar->field_def.field_name=
pvar->name.str;
spvar->field_def.field_name= s
pvar->name.str;
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
s
pvar->field_def.pack_flag |= FIELDFLAG_MAYBE_NULL;
/* The last instruction is responsible for freeing LEX. */
/* The last instruction is responsible for freeing LEX. */
...
@@ -1642,7 +1644,7 @@ sp_decl:
...
@@ -1642,7 +1644,7 @@ sp_decl:
sp_pcontext *ctx= lex->spcont;
sp_pcontext *ctx= lex->spcont;
sp_instr_hpush_jump *i=
sp_instr_hpush_jump *i=
new sp_instr_hpush_jump(sp->instructions(), ctx, $2,
new sp_instr_hpush_jump(sp->instructions(), ctx, $2,
ctx->current_
pvars
());
ctx->current_
var_count
());
sp->add_instr(i);
sp->add_instr(i);
sp->push_backpatch(i, ctx->push_label((char *)"", 0));
sp->push_backpatch(i, ctx->push_label((char *)"", 0));
...
@@ -1659,7 +1661,7 @@ sp_decl:
...
@@ -1659,7 +1661,7 @@ sp_decl:
if ($2 == SP_HANDLER_CONTINUE)
if ($2 == SP_HANDLER_CONTINUE)
{
{
i= new sp_instr_hreturn(sp->instructions(), ctx,
i= new sp_instr_hreturn(sp->instructions(), ctx,
ctx->current_
pvars
());
ctx->current_
var_count
());
sp->add_instr(i);
sp->add_instr(i);
}
}
else
else
...
@@ -1690,7 +1692,7 @@ sp_decl:
...
@@ -1690,7 +1692,7 @@ sp_decl:
YYABORT;
YYABORT;
}
}
i= new sp_instr_cpush(sp->instructions(), ctx, $5,
i= new sp_instr_cpush(sp->instructions(), ctx, $5,
ctx->current_cursor
s
());
ctx->current_cursor
_count
());
sp->add_instr(i);
sp->add_instr(i);
ctx->push_cursor(&$2);
ctx->push_cursor(&$2);
$$.vars= $$.conds= $$.hndlrs= 0;
$$.vars= $$.conds= $$.hndlrs= 0;
...
@@ -1845,12 +1847,12 @@ sp_decl_idents:
...
@@ -1845,12 +1847,12 @@ sp_decl_idents:
LEX *lex= Lex;
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$1, TRUE))
if (spc->find_
variable
(&$1, TRUE))
{
{
my_error(ER_SP_DUP_VAR, MYF(0), $1.str);
my_error(ER_SP_DUP_VAR, MYF(0), $1.str);
YYABORT;
YYABORT;
}
}
spc->push_
pvar
(&$1, (enum_field_types)0, sp_param_in);
spc->push_
variable
(&$1, (enum_field_types)0, sp_param_in);
$$= 1;
$$= 1;
}
}
| sp_decl_idents ',' ident
| sp_decl_idents ',' ident
...
@@ -1860,12 +1862,12 @@ sp_decl_idents:
...
@@ -1860,12 +1862,12 @@ sp_decl_idents:
LEX *lex= Lex;
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
if (spc->find_
pvar
(&$3, TRUE))
if (spc->find_
variable
(&$3, TRUE))
{
{
my_error(ER_SP_DUP_VAR, MYF(0), $3.str);
my_error(ER_SP_DUP_VAR, MYF(0), $3.str);
YYABORT;
YYABORT;
}
}
spc->push_
pvar
(&$3, (enum_field_types)0, sp_param_in);
spc->push_
variable
(&$3, (enum_field_types)0, sp_param_in);
$$= $1 + 1;
$$= $1 + 1;
}
}
;
;
...
@@ -2198,9 +2200,9 @@ sp_fetch_list:
...
@@ -2198,9 +2200,9 @@ sp_fetch_list:
LEX *lex= Lex;
LEX *lex= Lex;
sp_head *sp= lex->sphead;
sp_head *sp= lex->sphead;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
if (!spc || !(spv = spc->find_
pvar
(&$1)))
if (!spc || !(spv = spc->find_
variable
(&$1)))
{
{
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
YYABORT;
YYABORT;
...
@@ -2219,9 +2221,9 @@ sp_fetch_list:
...
@@ -2219,9 +2221,9 @@ sp_fetch_list:
LEX *lex= Lex;
LEX *lex= Lex;
sp_head *sp= lex->sphead;
sp_head *sp= lex->sphead;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
if (!spc || !(spv = spc->find_
pvar
(&$3)))
if (!spc || !(spv = spc->find_
variable
(&$3)))
{
{
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str);
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $3.str);
YYABORT;
YYABORT;
...
@@ -5868,9 +5870,9 @@ select_var_ident:
...
@@ -5868,9 +5870,9 @@ select_var_ident:
| ident_or_text
| ident_or_text
{
{
LEX *lex=Lex;
LEX *lex=Lex;
sp_
pvar
_t *t;
sp_
variable
_t *t;
if (!lex->spcont || !(t=lex->spcont->find_
pvar
(&$1)))
if (!lex->spcont || !(t=lex->spcont->find_
variable
(&$1)))
{
{
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
my_error(ER_SP_UNDECLARED_VAR, MYF(0), $1.str);
YYABORT;
YYABORT;
...
@@ -7200,10 +7202,10 @@ order_ident:
...
@@ -7200,10 +7202,10 @@ order_ident:
simple_ident:
simple_ident:
ident
ident
{
{
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
LEX *lex = Lex;
LEX *lex = Lex;
sp_pcontext *spc = lex->spcont;
sp_pcontext *spc = lex->spcont;
if (spc && (spv = spc->find_
pvar
(&$1)))
if (spc && (spv = spc->find_
variable
(&$1)))
{
{
/* We're compiling a stored procedure and found a variable */
/* We're compiling a stored procedure and found a variable */
Item_splocal *splocal;
Item_splocal *splocal;
...
@@ -7947,7 +7949,7 @@ sys_option_value:
...
@@ -7947,7 +7949,7 @@ sys_option_value:
{
{
/* An SP local variable */
/* An SP local variable */
sp_pcontext *ctx= lex->spcont;
sp_pcontext *ctx= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
sp_instr_set *sp_set;
sp_instr_set *sp_set;
Item *it;
Item *it;
if ($1)
if ($1)
...
@@ -7956,7 +7958,7 @@ sys_option_value:
...
@@ -7956,7 +7958,7 @@ sys_option_value:
YYABORT;
YYABORT;
}
}
spv= ctx->find_
pvar
(&$2.base_name);
spv= ctx->find_
variable
(&$2.base_name);
if ($4)
if ($4)
it= $4;
it= $4;
...
@@ -8006,7 +8008,7 @@ option_value:
...
@@ -8006,7 +8008,7 @@ option_value:
names.str= (char *)"names";
names.str= (char *)"names";
names.length= 5;
names.length= 5;
if (spc && spc->find_
pvar
(&names))
if (spc && spc->find_
variable
(&names))
my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str);
my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), names.str);
else
else
yyerror(ER(ER_SYNTAX_ERROR));
yyerror(ER(ER_SYNTAX_ERROR));
...
@@ -8036,7 +8038,7 @@ option_value:
...
@@ -8036,7 +8038,7 @@ option_value:
pw.str= (char *)"password";
pw.str= (char *)"password";
pw.length= 8;
pw.length= 8;
if (spc && spc->find_
pvar
(&pw))
if (spc && spc->find_
variable
(&pw))
{
{
my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), pw.str);
my_error(ER_SP_BAD_VAR_SHADOW, MYF(0), pw.str);
YYABORT;
YYABORT;
...
@@ -8058,10 +8060,10 @@ internal_variable_name:
...
@@ -8058,10 +8060,10 @@ internal_variable_name:
{
{
LEX *lex= Lex;
LEX *lex= Lex;
sp_pcontext *spc= lex->spcont;
sp_pcontext *spc= lex->spcont;
sp_
pvar
_t *spv;
sp_
variable
_t *spv;
/* We have to lookup here since local vars can shadow sysvars */
/* We have to lookup here since local vars can shadow sysvars */
if (!spc || !(spv = spc->find_
pvar
(&$1)))
if (!spc || !(spv = spc->find_
variable
(&$1)))
{
{
/* Not an SP local variable */
/* Not an SP local variable */
sys_var *tmp=find_sys_var($1.str, $1.length);
sys_var *tmp=find_sys_var($1.str, $1.length);
...
...
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