Commit 7a20e528 authored by pem@mysql.comhem.se's avatar pem@mysql.comhem.se

In order to make ALTER PROCEDURE|FUNCTION work correctly, and in general to

make characteristics (and SHOW) work right, we had to separate the old
definition blob in the mysql.proc table into separate fields for parameters,
return type, and body, and handle the characteristics (like SQL SECURITY)
separately... and then reassemble the CREATE string for parsing, of course.
This is rather ugly, mostly the parser bit. (Hopefully that will be better
with the new parser.)
parent 7bfbfc30
...@@ -1063,8 +1063,10 @@ ...@@ -1063,8 +1063,10 @@
language enum('SQL') DEFAULT 'SQL' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL,
sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL, sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL,
is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL,
definition blob DEFAULT '' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL,
security_type enum('INVOKER','DEFINER') DEFAULT 'INVOKER' NOT NULL, param_list blob DEFAULT '' NOT NULL,
returns char(64) DEFAULT '' NOT NULL,
body blob DEFAULT '' NOT NULL,
definer char(77) binary DEFAULT '' NOT NULL, definer char(77) binary DEFAULT '' NOT NULL,
created timestamp, created timestamp,
modified timestamp, modified timestamp,
...@@ -1094,4 +1096,5 @@ ...@@ -1094,4 +1096,5 @@
PRIMARY KEY (schema,name,type) PRIMARY KEY (schema,name,type)
) comment='Stored Procedures'; ) comment='Stored Procedures';
-- --
\ No newline at end of file
...@@ -691,6 +691,43 @@ delete from t1; ...@@ -691,6 +691,43 @@ delete from t1;
delete from t2; delete from t2;
drop table t3; drop table t3;
drop procedure cur2; drop procedure cur2;
create procedure chistics()
language sql
not deterministic
sql security definer
comment 'Characteristics procedure test'
insert into t1 values ("chistics", 1);
call chistics();
select * from t1;
id data
chistics 1
delete from t1;
alter procedure chistics sql security invoker name chistics2;
show create procedure chistics2;
Procedure Create Procedure
chistics2 CREATE PROCEDURE chistics2()
SQL SECURITY INVOKER
COMMENT 'Characteristics procedure test'
insert into t1 values ("chistics", 1)
drop procedure chistics2;
create function chistics() returns int
language sql
deterministic
sql security invoker
comment 'Characteristics procedure test'
return 42;
select chistics();
chistics()
42
alter function chistics name chistics2 comment 'Characteristics function test';
show create function chistics2;
Function Create Function
chistics2 CREATE FUNCTION chistics2() RETURNS int
DETERMINISTIC
SQL SECURITY INVOKER
COMMENT 'Characteristics function test'
return 42
drop function chistics2;
insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3); insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3);
set @@sql_mode = 'ANSI'; set @@sql_mode = 'ANSI';
create procedure modes(out c1 int, out c2 int) create procedure modes(out c1 int, out c2 int)
...@@ -881,7 +918,7 @@ n f ...@@ -881,7 +918,7 @@ n f
drop table fac; drop table fac;
show function status like '%f%'; show function status like '%f%';
Name Type Definer Modified Created Security_type Comment Name Type Definer Modified Created Security_type Comment
fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER fac FUNCTION root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
drop procedure ifac; drop procedure ifac;
drop function fac; drop function fac;
show function status like '%f%'; show function status like '%f%';
...@@ -946,7 +983,7 @@ end while; ...@@ -946,7 +983,7 @@ end while;
end; end;
show create procedure opp; show create procedure opp;
Procedure Create Procedure Procedure Create Procedure
opp create procedure opp(n bigint unsigned, out pp bool) opp CREATE PROCEDURE opp(n bigint unsigned, out pp bool)
begin begin
declare r double; declare r double;
declare b, s bigint unsigned default 0; declare b, s bigint unsigned default 0;
...@@ -974,8 +1011,8 @@ end loop; ...@@ -974,8 +1011,8 @@ end loop;
end end
show procedure status like '%p%'; show procedure status like '%p%';
Name Type Definer Modified Created Security_type Comment Name Type Definer Modified Created Security_type Comment
ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER ip PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 INVOKER opp PROCEDURE root@localhost 0000-00-00 00:00:00 0000-00-00 00:00:00 DEFINER
call ip(200); call ip(200);
select * from primes where i=45 or i=100 or i=199; select * from primes where i=45 or i=100 or i=199;
i p i p
...@@ -1043,8 +1080,8 @@ alter procedure bar2 name bar comment "3333333333"; ...@@ -1043,8 +1080,8 @@ alter procedure bar2 name bar comment "3333333333";
alter procedure bar; alter procedure bar;
show create procedure bar; show create procedure bar;
Procedure Create Procedure Procedure Create Procedure
bar create procedure bar(x char(16), y int) bar CREATE PROCEDURE bar(x char(16), y int)
comment "111111111111" sql security invoker COMMENT '3333333333'
insert into test.t1 values (x, y) insert into test.t1 values (x, y)
show procedure status like 'bar'; show procedure status like 'bar';
Name Type Definer Modified Created Security_type Comment Name Type Definer Modified Created Security_type Comment
......
...@@ -816,6 +816,36 @@ drop table t3| ...@@ -816,6 +816,36 @@ drop table t3|
drop procedure cur2| drop procedure cur2|
# The few characteristics we parse
create procedure chistics()
language sql
not deterministic
sql security definer
comment 'Characteristics procedure test'
insert into t1 values ("chistics", 1)|
# Call it, just to make sure.
call chistics()|
select * from t1|
delete from t1|
alter procedure chistics sql security invoker name chistics2|
show create procedure chistics2|
drop procedure chistics2|
create function chistics() returns int
language sql
deterministic
sql security invoker
comment 'Characteristics procedure test'
return 42|
# Call it, just to make sure.
select chistics()|
alter function chistics name chistics2 comment 'Characteristics function test'|
show create function chistics2|
drop function chistics2|
# Check mode settings # Check mode settings
insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)| insert into t1 values ("foo", 1), ("bar", 2), ("zip", 3)|
......
...@@ -296,8 +296,10 @@ then ...@@ -296,8 +296,10 @@ then
c_p="$c_p language enum('SQL') DEFAULT 'SQL' NOT NULL," c_p="$c_p language enum('SQL') DEFAULT 'SQL' NOT NULL,"
c_p="$c_p sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL," c_p="$c_p sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL,"
c_p="$c_p is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL," c_p="$c_p is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL,"
c_p="$c_p definition blob DEFAULT '' NOT NULL," c_p="$c_p security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL,"
c_p="$c_p security_type enum('INVOKER','DEFINER') DEFAULT 'INVOKER' NOT NULL," c_p="$c_p param_list blob DEFAULT '' NOT NULL,"
c_p="$c_p returns char(64) DEFAULT '' NOT NULL,"
c_p="$c_p body blob DEFAULT '' NOT NULL,"
c_p="$c_p definer char(77) binary DEFAULT '' NOT NULL," c_p="$c_p definer char(77) binary DEFAULT '' NOT NULL,"
c_p="$c_p created timestamp," c_p="$c_p created timestamp,"
c_p="$c_p modified timestamp," c_p="$c_p modified timestamp,"
......
...@@ -147,8 +147,10 @@ CREATE TABLE IF NOT EXISTS proc ( ...@@ -147,8 +147,10 @@ CREATE TABLE IF NOT EXISTS proc (
language enum('SQL') DEFAULT 'SQL' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL,
sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL, sql_data_access enum('CONTAINS_SQL') DEFAULT 'CONTAINS_SQL' NOT NULL,
is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL,
definition blob DEFAULT '' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL,
security_type enum('INVOKER','DEFINER') DEFAULT 'INVOKER' NOT NULL, param_list blob DEFAULT '' NOT NULL,
returns char(64) DEFAULT '' NOT NULL,
body blob DEFAULT '' NOT NULL,
definer char(77) binary DEFAULT '' NOT NULL, definer char(77) binary DEFAULT '' NOT NULL,
created timestamp, created timestamp,
modified timestamp, modified timestamp,
......
This diff is collapsed.
...@@ -32,8 +32,7 @@ sp_head * ...@@ -32,8 +32,7 @@ sp_head *
sp_find_procedure(THD *thd, LEX_STRING *name); sp_find_procedure(THD *thd, LEX_STRING *name);
int int
sp_create_procedure(THD *thd, char *name, uint namelen, char *def, uint deflen, sp_create_procedure(THD *thd, sp_head *sp);
st_sp_chistics *chistics);
int int
sp_drop_procedure(THD *thd, char *name, uint namelen); sp_drop_procedure(THD *thd, char *name, uint namelen);
...@@ -54,8 +53,7 @@ sp_head * ...@@ -54,8 +53,7 @@ sp_head *
sp_find_function(THD *thd, LEX_STRING *name); sp_find_function(THD *thd, LEX_STRING *name);
int int
sp_create_function(THD *thd, char *name, uint namelen, char *def, uint deflen, sp_create_function(THD *thd, sp_head *sp);
st_sp_chistics *chistics);
int int
sp_drop_function(THD *thd, char *name, uint namelen); sp_drop_function(THD *thd, char *name, uint namelen);
......
...@@ -163,18 +163,51 @@ sp_head::sp_head() ...@@ -163,18 +163,51 @@ sp_head::sp_head()
} }
void void
sp_head::init(LEX_STRING *name, LEX *lex) sp_head::init(LEX *lex)
{ {
DBUG_ENTER("sp_head::init"); DBUG_ENTER("sp_head::init");
const char *dstr = (const char*)lex->buf;
lex->spcont= m_pcont= new sp_pcontext();
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
m_param_begin= m_param_end= m_returns_begin= m_returns_end= m_body_begin= 0;
m_name.str= m_params.str= m_retstr.str= m_body.str= m_defstr.str= 0;
m_name.length= m_params.length= m_retstr.length= m_body.length=
m_defstr.length= 0;
DBUG_VOID_RETURN;
}
void
sp_head::init_strings(LEX_STRING *name, LEX *lex)
{
DBUG_ENTER("sp_head::init_strings");
DBUG_PRINT("info", ("name: %*s", name->length, name->str)); DBUG_PRINT("info", ("name: %*s", name->length, name->str));
m_name.length= name->length; m_name.length= name->length;
m_name.str= lex->thd->strmake(name->str, name->length); m_name.str= lex->thd->strmake(name->str, name->length);
m_params.length= m_param_end- m_param_begin;
m_params.str= lex->thd->strmake((char *)m_param_begin, m_params.length);
if (m_returns_begin && m_returns_end)
{
/* QQ KLUDGE: We can't seem to cut out just the type in the parser
(without the RETURNS), so we'll have to do it here. :-( */
char *p= (char *)m_returns_begin+strspn((char *)m_returns_begin,"\t\n\r ");
p+= strcspn(p, "\t\n\r ");
p+= strspn(p, "\t\n\r ");
if (p < (char *)m_returns_end)
m_returns_begin= (uchar *)p;
/* While we're at it, trim the end too. */
p= (char *)m_returns_end-1;
while (p > (char *)m_returns_begin &&
(*p == '\t' || *p == '\n' || *p == '\r' || *p == ' '))
p-= 1;
m_returns_end= (uchar *)p+1;
m_retstr.length= m_returns_end - m_returns_begin;
m_retstr.str= lex->thd->strmake((char *)m_returns_begin, m_retstr.length);
}
m_body.length= lex->end_of_query - m_body_begin;
m_body.str= lex->thd->strmake((char *)m_body_begin, m_body.length);
m_defstr.length= lex->end_of_query - lex->buf; m_defstr.length= lex->end_of_query - lex->buf;
m_defstr.str= lex->thd->strmake(dstr, m_defstr.length); m_defstr.str= lex->thd->strmake((char *)lex->buf, m_defstr.length);
lex->spcont= m_pcont= new sp_pcontext();
my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -184,18 +217,12 @@ sp_head::create(THD *thd) ...@@ -184,18 +217,12 @@ sp_head::create(THD *thd)
DBUG_ENTER("sp_head::create"); DBUG_ENTER("sp_head::create");
int ret; int ret;
DBUG_PRINT("info", ("type: %d name: %s def: %s", DBUG_PRINT("info", ("type: %d name: %s params: %s body: %s",
m_type, m_name.str, m_defstr.str)); m_type, m_name.str, m_params.str, m_body.str));
if (m_type == TYPE_ENUM_FUNCTION) if (m_type == TYPE_ENUM_FUNCTION)
ret= sp_create_function(thd, ret= sp_create_function(thd, this);
m_name.str, m_name.length,
m_defstr.str, m_defstr.length,
m_chistics);
else else
ret= sp_create_procedure(thd, ret= sp_create_procedure(thd, this);
m_name.str, m_name.length,
m_defstr.str, m_defstr.length,
m_chistics);
DBUG_RETURN(ret); DBUG_RETURN(ret);
} }
......
...@@ -56,6 +56,18 @@ public: ...@@ -56,6 +56,18 @@ public:
List<char *> m_calls; // Called procedures. List<char *> m_calls; // Called procedures.
List<char *> m_tables; // Used tables. List<char *> m_tables; // Used tables.
#endif #endif
LEX_STRING m_name;
LEX_STRING m_params;
LEX_STRING m_retstr; // For FUNCTIONs only
LEX_STRING m_body;
LEX_STRING m_defstr;
char *m_creator;
uint m_creatorlen;
longlong m_created;
longlong m_modified;
// Pointers set during parsing
uchar *m_param_begin, *m_param_end, *m_returns_begin, *m_returns_end,
*m_body_begin;
static void * static void *
operator new(size_t size); operator new(size_t size);
...@@ -67,7 +79,11 @@ public: ...@@ -67,7 +79,11 @@ public:
// Initialize after we have reset mem_root // Initialize after we have reset mem_root
void void
init(LEX_STRING *name, LEX *lex); init(LEX *lex);
// Initialize strings after parsing header
void
init_strings(LEX_STRING *name, LEX *lex);
int int
create(THD *thd); create(THD *thd);
...@@ -136,6 +152,8 @@ public: ...@@ -136,6 +152,8 @@ public:
return m_name.str; return m_name.str;
} }
char *create_string(THD *thd, ulong *lenp);
inline Item_result result() inline Item_result result()
{ {
return sp_map_result_type(m_returns); return sp_map_result_type(m_returns);
...@@ -143,15 +161,13 @@ public: ...@@ -143,15 +161,13 @@ public:
void set_info(char *creator, uint creatorlen, void set_info(char *creator, uint creatorlen,
longlong created, longlong modified, longlong created, longlong modified,
bool suid, char *comment, uint commentlen) st_sp_chistics *chistics)
{ {
m_creator= creator; m_creator= creator;
m_creatorlen= creatorlen; m_creatorlen= creatorlen;
m_created= created; m_created= created;
m_modified= modified; m_modified= modified;
m_chistics->comment.length= commentlen; m_chistics= chistics;
m_chistics->comment.str= comment;
m_chistics->suid= (suid ? IS_SUID : IS_NOT_SUID);
} }
inline void reset_thd_mem_root(THD *thd) inline void reset_thd_mem_root(THD *thd)
...@@ -180,13 +196,6 @@ private: ...@@ -180,13 +196,6 @@ private:
Item *m_free_list; // Where the items go Item *m_free_list; // Where the items go
THD *m_thd; // Set if we have reset mem_root THD *m_thd; // Set if we have reset mem_root
LEX_STRING m_name;
LEX_STRING m_defstr;
char *m_creator;
uint m_creatorlen;
longlong m_created;
longlong m_modified;
sp_pcontext *m_pcont; // Parse context sp_pcontext *m_pcont; // Parse context
List<LEX> m_lex; // Temp. store for the other lex List<LEX> m_lex; // Temp. store for the other lex
DYNAMIC_ARRAY m_instr; // The "instructions" DYNAMIC_ARRAY m_instr; // The "instructions"
......
...@@ -1040,7 +1040,7 @@ create: ...@@ -1040,7 +1040,7 @@ create:
/* Order is important here: new - reset - init */ /* Order is important here: new - reset - init */
sp= new sp_head(); sp= new sp_head();
sp->reset_thd_mem_root(YYTHD); sp->reset_thd_mem_root(YYTHD);
sp->init(&$3, lex); sp->init(lex);
sp->m_type= TYPE_ENUM_PROCEDURE; sp->m_type= TYPE_ENUM_PROCEDURE;
lex->sphead= sp; lex->sphead= sp;
...@@ -1052,10 +1052,18 @@ create: ...@@ -1052,10 +1052,18 @@ create:
sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES; sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES); YYTHD->client_capabilities &= (~CLIENT_MULTI_QUERIES);
} }
'(' sp_pdparam_list ')' '('
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sphead->m_param_begin= lex->tok_start+1;
}
sp_pdparam_list
')'
{
LEX *lex= Lex;
lex->sphead->m_param_end= lex->tok_start;
lex->spcont->set_params(); lex->spcont->set_params();
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
} }
...@@ -1064,11 +1072,13 @@ create: ...@@ -1064,11 +1072,13 @@ create:
LEX *lex= Lex; LEX *lex= Lex;
lex->sphead->m_chistics= &lex->sp_chistics; lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->m_body_begin= lex->tok_start;
} }
sp_proc_stmt sp_proc_stmt
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sphead->init_strings(&$3, lex);
lex->sql_command= SQLCOM_CREATE_PROCEDURE; lex->sql_command= SQLCOM_CREATE_PROCEDURE;
/* Restore flag if it was cleared above */ /* Restore flag if it was cleared above */
if (lex->sphead->m_old_cmq) if (lex->sphead->m_old_cmq)
...@@ -1103,7 +1113,7 @@ create_function_tail: ...@@ -1103,7 +1113,7 @@ create_function_tail:
/* Order is important here: new - reset - init */ /* Order is important here: new - reset - init */
sp= new sp_head(); sp= new sp_head();
sp->reset_thd_mem_root(YYTHD); sp->reset_thd_mem_root(YYTHD);
sp->init(&lex->udf.name, lex); sp->init(lex);
sp->m_type= TYPE_ENUM_FUNCTION; sp->m_type= TYPE_ENUM_FUNCTION;
lex->sphead= sp; lex->sphead= sp;
...@@ -1114,16 +1124,25 @@ create_function_tail: ...@@ -1114,16 +1124,25 @@ create_function_tail:
*/ */
sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES; sp->m_old_cmq= YYTHD->client_capabilities & CLIENT_MULTI_QUERIES;
YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES; YYTHD->client_capabilities &= ~CLIENT_MULTI_QUERIES;
lex->sphead->m_param_begin= lex->tok_start+1;
} }
sp_fdparam_list ')' sp_fdparam_list ')'
{ {
Lex->spcont->set_params(); LEX *lex= Lex;
lex->spcont->set_params();
lex->sphead->m_param_end= lex->tok_start;
}
RETURNS_SYM
{
Lex->sphead->m_returns_begin= Lex->tok_start;
} }
RETURNS_SYM type type
{ {
LEX *lex= Lex; LEX *lex= Lex;
lex->sphead->m_returns= (enum enum_field_types)$7; lex->sphead->m_returns_end= lex->tok_start;
lex->sphead->m_returns= (enum enum_field_types)$8;
bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics)); bzero((char *)&lex->sp_chistics, sizeof(st_sp_chistics));
} }
sp_c_chistics sp_c_chistics
...@@ -1131,16 +1150,19 @@ create_function_tail: ...@@ -1131,16 +1150,19 @@ create_function_tail:
LEX *lex= Lex; LEX *lex= Lex;
lex->sphead->m_chistics= &lex->sp_chistics; lex->sphead->m_chistics= &lex->sp_chistics;
lex->sphead->m_body_begin= lex->tok_start;
} }
sp_proc_stmt sp_proc_stmt
{ {
LEX *lex= Lex; LEX *lex= Lex;
sp_head *sp= lex->sphead;
lex->sql_command= SQLCOM_CREATE_SPFUNCTION; lex->sql_command= SQLCOM_CREATE_SPFUNCTION;
sp->init_strings(&lex->udf.name, lex);
/* Restore flag if it was cleared above */ /* Restore flag if it was cleared above */
if (lex->sphead->m_old_cmq) if (sp->m_old_cmq)
YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES; YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
lex->sphead->restore_thd_mem_root(YYTHD); sp->restore_thd_mem_root(YYTHD);
} }
; ;
...@@ -5884,6 +5906,7 @@ keyword: ...@@ -5884,6 +5906,7 @@ keyword:
| RESET_SYM {} | RESET_SYM {}
| RESOURCES {} | RESOURCES {}
| RESTORE_SYM {} | RESTORE_SYM {}
| RETURNS_SYM {}
| ROLLBACK_SYM {} | ROLLBACK_SYM {}
| ROLLUP_SYM {} | ROLLUP_SYM {}
| ROWS_SYM {} | ROWS_SYM {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment