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
d16d40be
Commit
d16d40be
authored
Jan 27, 2016
by
Alexey Botchkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-5273 Prepared statement doesn't return metadata after prepare.
SHOW CREATE PROCEDURE/FUNCTION fixed.
parent
34df3140
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
sql/sp_head.cc
sql/sp_head.cc
+63
-0
sql/sp_head.h
sql/sp_head.h
+3
-0
sql/sql_prepare.cc
sql/sql_prepare.cc
+37
-0
tests/mysql_client_test.c
tests/mysql_client_test.c
+14
-0
No files found.
sql/sp_head.cc
View file @
d16d40be
...
@@ -2531,6 +2531,69 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access)
...
@@ -2531,6 +2531,69 @@ bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access)
}
}
/**
Collect metadata for SHOW CREATE statement for stored routines.
@param thd Thread context.
@param type Stored routine type
@param type Stored routine type
(TYPE_ENUM_PROCEDURE or TYPE_ENUM_FUNCTION)
@return Error status.
@retval FALSE on success
@retval TRUE on error
*/
void
sp_head
::
show_create_routine_get_fields
(
THD
*
thd
,
int
type
,
List
<
Item
>
*
fields
)
{
const
char
*
col1_caption
=
type
==
TYPE_ENUM_PROCEDURE
?
"Procedure"
:
"Function"
;
const
char
*
col3_caption
=
type
==
TYPE_ENUM_PROCEDURE
?
"Create Procedure"
:
"Create Function"
;
MEM_ROOT
*
mem_root
=
thd
->
mem_root
;
/* Send header. */
fields
->
push_back
(
new
(
mem_root
)
Item_empty_string
(
thd
,
col1_caption
,
NAME_CHAR_LEN
),
mem_root
);
fields
->
push_back
(
new
(
mem_root
)
Item_empty_string
(
thd
,
"sql_mode"
,
256
),
mem_root
);
{
/*
NOTE: SQL statement field must be not less than 1024 in order not to
confuse old clients.
*/
Item_empty_string
*
stmt_fld
=
new
(
mem_root
)
Item_empty_string
(
thd
,
col3_caption
,
1024
);
stmt_fld
->
maybe_null
=
TRUE
;
fields
->
push_back
(
stmt_fld
,
mem_root
);
}
fields
->
push_back
(
new
(
mem_root
)
Item_empty_string
(
thd
,
"character_set_client"
,
MY_CS_NAME_SIZE
),
mem_root
);
fields
->
push_back
(
new
(
mem_root
)
Item_empty_string
(
thd
,
"collation_connection"
,
MY_CS_NAME_SIZE
),
mem_root
);
fields
->
push_back
(
new
(
mem_root
)
Item_empty_string
(
thd
,
"Database Collation"
,
MY_CS_NAME_SIZE
),
mem_root
);
}
/**
/**
Implement SHOW CREATE statement for stored routines.
Implement SHOW CREATE statement for stored routines.
...
...
sql/sp_head.h
View file @
d16d40be
...
@@ -340,6 +340,9 @@ class sp_head :private Query_arena
...
@@ -340,6 +340,9 @@ class sp_head :private Query_arena
bool
bool
execute_procedure
(
THD
*
thd
,
List
<
Item
>
*
args
);
execute_procedure
(
THD
*
thd
,
List
<
Item
>
*
args
);
static
void
show_create_routine_get_fields
(
THD
*
thd
,
int
type
,
List
<
Item
>
*
fields
);
bool
bool
show_create_routine
(
THD
*
thd
,
int
type
);
show_create_routine
(
THD
*
thd
,
int
type
);
...
...
sql/sql_prepare.cc
View file @
d16d40be
...
@@ -1963,6 +1963,29 @@ static bool mysql_test_show_binlogs(Prepared_statement *stmt)
...
@@ -1963,6 +1963,29 @@ static bool mysql_test_show_binlogs(Prepared_statement *stmt)
}
}
/**
Validate and prepare for execution SHOW CREATE PROC/FUNC statement.
@param stmt prepared statement
@retval
FALSE success
@retval
TRUE error, error message is set in THD
*/
static
bool
mysql_test_show_create_routine
(
Prepared_statement
*
stmt
,
int
type
)
{
DBUG_ENTER
(
"mysql_test_show_binlogs"
);
THD
*
thd
=
stmt
->
thd
;
List
<
Item
>
fields
;
sp_head
::
show_create_routine_get_fields
(
thd
,
type
,
&
fields
);
DBUG_RETURN
(
send_stmt_metadata
(
thd
,
stmt
,
&
fields
));
}
/**
/**
@brief Validate and prepare for execution CREATE VIEW statement
@brief Validate and prepare for execution CREATE VIEW statement
...
@@ -2338,6 +2361,20 @@ static bool check_prepared_statement(Prepared_statement *stmt)
...
@@ -2338,6 +2361,20 @@ static bool check_prepared_statement(Prepared_statement *stmt)
DBUG_RETURN
(
FALSE
);
DBUG_RETURN
(
FALSE
);
}
}
break
;
break
;
case
SQLCOM_SHOW_CREATE_PROC
:
if
(
!
(
res
=
mysql_test_show_create_routine
(
stmt
,
TYPE_ENUM_PROCEDURE
)))
{
/* Statement and field info has already been sent */
DBUG_RETURN
(
FALSE
);
}
break
;
case
SQLCOM_SHOW_CREATE_FUNC
:
if
(
!
(
res
=
mysql_test_show_create_routine
(
stmt
,
TYPE_ENUM_FUNCTION
)))
{
/* Statement and field info has already been sent */
DBUG_RETURN
(
FALSE
);
}
break
;
case
SQLCOM_CREATE_VIEW
:
case
SQLCOM_CREATE_VIEW
:
if
(
lex
->
create_view_mode
==
VIEW_ALTER
)
if
(
lex
->
create_view_mode
==
VIEW_ALTER
)
{
{
...
...
tests/mysql_client_test.c
View file @
d16d40be
...
@@ -457,6 +457,20 @@ static void test_prepare_simple()
...
@@ -457,6 +457,20 @@ static void test_prepare_simple()
DIE_UNLESS
(
mysql_stmt_field_count
(
stmt
)
==
4
);
DIE_UNLESS
(
mysql_stmt_field_count
(
stmt
)
==
4
);
mysql_stmt_close
(
stmt
);
mysql_stmt_close
(
stmt
);
/* show create procedure */
strmov
(
query
,
"SHOW CREATE PROCEDURE e1;"
);
stmt
=
mysql_simple_prepare
(
mysql
,
query
);
check_stmt
(
stmt
);
DIE_UNLESS
(
mysql_stmt_field_count
(
stmt
)
==
6
);
mysql_stmt_close
(
stmt
);
/* show create function */
strmov
(
query
,
"SHOW CREATE FUNCTION e1;"
);
stmt
=
mysql_simple_prepare
(
mysql
,
query
);
check_stmt
(
stmt
);
DIE_UNLESS
(
mysql_stmt_field_count
(
stmt
)
==
6
);
mysql_stmt_close
(
stmt
);
/* now fetch the results ..*/
/* now fetch the results ..*/
rc
=
mysql_commit
(
mysql
);
rc
=
mysql_commit
(
mysql
);
myquery
(
rc
);
myquery
(
rc
);
...
...
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