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
e6b8fa57
Commit
e6b8fa57
authored
Jan 18, 2003
by
Sinisa@sinisa.nasamreza.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SELECT ... INTO local_vars ...;
For Stored Procedures
parent
4b0adb20
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
12 deletions
+105
-12
mysql-test/r/sp.result
mysql-test/r/sp.result
+17
-0
mysql-test/t/sp.test
mysql-test/t/sp.test
+13
-0
sql/sql_class.cc
sql/sql_class.cc
+43
-8
sql/sql_class.h
sql/sql_class.h
+11
-2
sql/sql_yacc.yy
sql/sql_yacc.yy
+21
-2
No files found.
mysql-test/r/sp.result
View file @
e6b8fa57
...
...
@@ -124,6 +124,15 @@ insert into test.t1 values ("h1", x);
else
insert into test.t1 values ("h?", x);
end case;
create procedure sinisa()
begin
declare x char(16);
declare y int;
set x="aaaaa";
set y=22;
select id,data into x,y from test.t1 limit 2,1;
insert into test.t1 values (x, y);
end;
call foo42();
select * from t1;
id data
...
...
@@ -236,6 +245,13 @@ id data
h0 0
h1 1
h? 17
call sinisa();
select * from t1;
id data
h0 0
h1 1
h? 17
h? 17
delete from t1;
drop procedure foo42;
drop procedure bar;
...
...
@@ -258,4 +274,5 @@ drop procedure e;
drop procedure f;
drop procedure g;
drop procedure h;
drop procedure sinisa;
drop table t1;
mysql-test/t/sp.test
View file @
e6b8fa57
...
...
@@ -187,6 +187,16 @@ else
insert
into
test
.
t1
values
(
"h?"
,
x
);
end
case
|
create
procedure
sinisa
()
begin
declare
x
char
(
16
);
declare
y
int
;
set
x
=
"aaaaa"
;
set
y
=
22
;
select
id
,
data
into
x
,
y
from
test
.
t1
limit
2
,
1
;
insert
into
test
.
t1
values
(
x
,
y
);
end
|
delimiter
;
|
# Now, the CALL tests...
...
...
@@ -263,6 +273,8 @@ call h(0);
call
h
(
1
);
call
h
(
17
);
select
*
from
t1
;
call
sinisa
();
select
*
from
t1
;
delete
from
t1
;
drop
procedure
foo42
;
...
...
@@ -286,5 +298,6 @@ drop procedure e;
drop
procedure
f
;
drop
procedure
g
;
drop
procedure
h
;
drop
procedure
sinisa
;
drop
table
t1
;
sql/sql_class.cc
View file @
e6b8fa57
...
...
@@ -36,6 +36,7 @@
#endif
#include <mysys_err.h>
#include <assert.h>
#include <sp_rcontext.h>
/*****************************************************************************
...
...
@@ -960,37 +961,71 @@ bool select_exists_subselect::send_data(List<Item> &items)
int
select_dumpvar
::
prepare
(
List
<
Item
>
&
list
,
SELECT_LEX_UNIT
*
u
)
{
List_iterator_fast
<
Item
>
li
(
list
);
List_iterator_fast
<
LEX_STRING
>
gl
(
var_list
);
List_iterator_fast
<
my_var
>
gl
(
var_list
);
Item
*
item
;
my_var
*
mv
;
LEX_STRING
*
ls
;
if
(
var_list
.
elements
!=
list
.
elements
)
{
my_error
(
ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
,
MYF
(
0
));
return
1
;
}
unit
=
u
;
while
((
item
=
li
++
))
{
ls
=
gl
++
;
mv
=
gl
++
;
ls
=
&
mv
->
s
;
if
(
mv
->
local
)
{
(
void
)
local_vars
.
push_back
(
new
Item_splocal
(
mv
->
offset
));
}
else
{
Item_func_set_user_var
*
xx
=
new
Item_func_set_user_var
(
*
ls
,
item
);
xx
->
fix_fields
(
current_thd
,(
TABLE_LIST
*
)
current_
thd
->
lex
.
select_lex
.
table_list
.
first
,
&
item
);
xx
->
fix_fields
(
thd
,(
TABLE_LIST
*
)
thd
->
lex
.
select_lex
.
table_list
.
first
,
&
item
);
xx
->
fix_length_and_dec
();
vars
.
push_back
(
xx
);
}
}
return
0
;
}
bool
select_dumpvar
::
send_data
(
List
<
Item
>
&
items
)
{
List_iterator_fast
<
Item_func_set_user_var
>
li
(
vars
);
List_iterator_fast
<
Item_splocal
>
var_li
(
local_vars
);
List_iterator_fast
<
my_var
>
my_li
(
var_list
);
List_iterator_fast
<
Item
>
it
(
items
);
Item_func_set_user_var
*
xx
;
Item_splocal
*
yy
;
Item
*
item
;
my_var
*
zz
;
DBUG_ENTER
(
"send_data"
);
if
(
unit
->
offset_limit_cnt
)
{
// using limit offset,count
unit
->
offset_limit_cnt
--
;
DBUG_RETURN
(
0
);
}
if
(
row_count
++
)
{
my_error
(
ER_TOO_MANY_ROWS
,
MYF
(
0
));
DBUG_RETURN
(
1
);
}
while
((
xx
=
li
++
))
while
((
zz
=
my_li
++
)
&&
(
item
=
it
++
))
{
if
(
zz
->
local
)
{
if
((
yy
=
var_li
++
))
{
thd
->
spcont
->
set_item
(
yy
->
get_offset
(),
item
);
}
}
else
{
if
((
xx
=
li
++
))
xx
->
update
();
}
}
DBUG_RETURN
(
0
);
}
...
...
sql/sql_class.h
View file @
e6b8fa57
...
...
@@ -987,13 +987,22 @@ public:
bool
send_eof
();
};
class
my_var
:
public
Sql_alloc
{
public:
LEX_STRING
s
;
bool
local
;
uint
offset
;
my_var
(
LEX_STRING
&
j
,
bool
i
,
uint
o
)
:
s
(
j
),
local
(
i
),
offset
(
o
)
{}
~
my_var
()
{}
};
class
select_dumpvar
:
public
select_result
{
ha_rows
row_count
;
public:
List
<
LEX_STRING
>
var_list
;
List
<
my_var
>
var_list
;
List
<
Item_func_set_user_var
>
vars
;
select_dumpvar
(
void
)
{
var_list
.
empty
();
vars
.
empty
();
row_count
=
0
;}
List
<
Item_splocal
>
local_vars
;
select_dumpvar
(
void
)
{
var_list
.
empty
();
local_vars
.
empty
();
vars
.
empty
();
row_count
=
0
;}
~
select_dumpvar
()
{}
int
prepare
(
List
<
Item
>
&
list
,
SELECT_LEX_UNIT
*
u
);
bool
send_fields
(
List
<
Item
>
&
list
,
uint
flag
)
{
return
0
;}
...
...
sql/sql_yacc.yy
View file @
e6b8fa57
...
...
@@ -3313,10 +3313,29 @@ select_var_list:
| select_var_ident {}
;
select_var_ident: '@' ident_or_text
select_var_ident:
'@' ident_or_text
{
LEX *lex=Lex;
if (lex->result && ((select_dumpvar *)lex->result)->var_list.push_back((LEX_STRING*) sql_memdup(&$2,sizeof(LEX_STRING))))
if (lex->result)
((select_dumpvar *)lex->result)->var_list.push_back( new my_var($2,0,0));
else
YYABORT;
}
| ident_or_text
{
LEX *lex=Lex;
if (!lex->spcont)
YYABORT;
sp_pvar_t *t;
if (!(t=lex->spcont->find_pvar(&$1)))
{
send_error(lex->thd, ER_SYNTAX_ERROR);
YYABORT;
}
if (lex->result)
((select_dumpvar *)lex->result)->var_list.push_back( new my_var($1,1,t->offset));
else
YYABORT;
}
;
...
...
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