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
483efba2
Commit
483efba2
authored
Mar 26, 2003
by
pem@mysql.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed save/restore of current database when calling a procedure.
parent
25785647
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
0 deletions
+57
-0
Docs/sp-imp-spec.txt
Docs/sp-imp-spec.txt
+20
-0
mysql-test/r/sp.result
mysql-test/r/sp.result
+10
-0
mysql-test/t/sp.test
mysql-test/t/sp.test
+12
-0
sql/sp_head.cc
sql/sp_head.cc
+15
-0
No files found.
Docs/sp-imp-spec.txt
View file @
483efba2
...
...
@@ -243,6 +243,23 @@
5) On success, set the new values of the OUT and INOUT parameters in
the caller's frame.
- USE database
Before executing the instruction we also keeps the current default
database (if any). If this was changed during execution (i.e. a "USE"
statement has been executed), we restore the current database to the
original.
This is the most useful way to handle USE in procedures. If we didn't,
the caller would find himself in a different database after calling
a function, which can be confusing.
Restoring the database also gives full freedom to the procedure writer:
- It's possible to write "general" procedures that are independent of
the actual database name.
- It's possible to write procedures that work on a particular database
by calling USE, without having to use fully qualified table names
everywhere (which doesn't help if you want to call other, "general",
procedures anyway).
- Evaluating Items
...
...
@@ -340,6 +357,9 @@
Dropping is done by simply getting the procedure with the sp_find()
function and calling sp_drop() (both in sp.{cc,h}).
DROP PROCEDURE/FUNCTION also supports the non-standard "IF EXISTS",
analogous to other DROP statements in MySQL.
- Class and function APIs
...
...
mysql-test/r/sp.result
View file @
483efba2
...
...
@@ -18,6 +18,16 @@ id data
foo 42
delete from t1;
drop procedure foo42;
create procedure u()
use sptmp;
create database sptmp;
use test;
call u();
select database();
database()
test
drop database sptmp;
drop procedure u;
create procedure bar(x char(16), y int)
insert into test.t1 values (x, y);
call bar("bar", 666);
...
...
mysql-test/t/sp.test
View file @
483efba2
...
...
@@ -31,6 +31,18 @@ delete from t1;
drop
procedure
foo42
;
# USE test: Make sure we remain in the same DB.
create
procedure
u
()
use
sptmp
;
create
database
sptmp
;
use
test
;
call
u
();
select
database
();
drop
database
sptmp
;
drop
procedure
u
;
# Single statement, two IN params.
create
procedure
bar
(
x
char
(
16
),
y
int
)
insert
into
test
.
t1
values
(
x
,
y
);
...
...
sql/sp_head.cc
View file @
483efba2
...
...
@@ -131,9 +131,14 @@ int
sp_head
::
execute
(
THD
*
thd
)
{
DBUG_ENTER
(
"sp_head::execute"
);
char
*
olddbname
;
char
*
olddbptr
=
thd
->
db
;
int
ret
=
0
;
uint
ip
=
0
;
if
(
olddbptr
)
olddbname
=
my_strdup
(
olddbptr
,
MYF
(
MY_WME
));
do
{
sp_instr
*
i
;
...
...
@@ -144,6 +149,16 @@ sp_head::execute(THD *thd)
DBUG_PRINT
(
"execute"
,
(
"Instruction %u"
,
ip
));
ret
=
i
->
execute
(
thd
,
&
ip
);
}
while
(
ret
==
0
);
/* If the DB has changed, the pointer has changed too, but the
original thd->db will then have been freed */
if
(
olddbptr
&&
olddbptr
!=
thd
->
db
&&
olddbname
)
{
/* QQ Maybe we should issue some special error message or warning here,
if this fails?? */
ret
=
mysql_change_db
(
thd
,
olddbname
);
my_free
(
olddbname
,
MYF
(
0
));
}
DBUG_RETURN
(
ret
);
}
...
...
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