summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2003-12-12 14:05:29 +0100
committerunknown <pem@mysql.comhem.se>2003-12-12 14:05:29 +0100
commitcabd28c68c68c2d673b778d43bd3fdbabb0a8968 (patch)
treef518c8cbe887552b0437489a710a7050031bc2f1 /sql/sp_head.cc
parentb5627bb00c8c60caefd428e70bfddfc7f03a5667 (diff)
downloadmariadb-git-cabd28c68c68c2d673b778d43bd3fdbabb0a8968.tar.gz
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.) Docs/sp-imp-spec.txt: Separated the definitions string of the procedure into different columns in the mysql.proc schema. mysql-test/r/sp.result: New characteristics tests. mysql-test/t/sp.test: New characteristics tests. scripts/mysql_create_system_tables.sh: Separated the definitions string of the procedure into different columns in the mysql.proc schema. scripts/mysql_fix_privilege_tables.sql: Separated the definitions string of the procedure into different columns in the mysql.proc schema. sql/sp.cc: Separated the definitions string of the procedure into different columns. Rewrote much of the code related this (have a assemble the definition string from its different parts now) and the way characteristics are now handled, in order to make ALTER actually work. sql/sp.h: Changed prototypes. sql/sp_head.cc: Rewrote much of the code related to the new mysql.proc schema with separate definition fields (have to assemble the definition string from its different parts now) and the way characteristics are now handled, in order to make ALTER actually work. sql/sp_head.h: Separated the different parts of the definition strings: name, parameters, return type (for functions) and body. sql/sql_yacc.yy: Separated the different parts of the definition strings: name, parameters, return type (for functions) and body. This is ugly and messy; hopefully there's a more elegant way to do this when the new parser is installed.
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc57
1 files changed, 42 insertions, 15 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 39669c5b86f..cfaf08b7972 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -163,18 +163,51 @@ sp_head::sp_head()
}
void
-sp_head::init(LEX_STRING *name, LEX *lex)
+sp_head::init(LEX *lex)
{
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));
m_name.length= 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.str= lex->thd->strmake(dstr, m_defstr.length);
- lex->spcont= m_pcont= new sp_pcontext();
- my_init_dynamic_array(&m_instr, sizeof(sp_instr *), 16, 8);
+ m_defstr.str= lex->thd->strmake((char *)lex->buf, m_defstr.length);
DBUG_VOID_RETURN;
}
@@ -184,18 +217,12 @@ sp_head::create(THD *thd)
DBUG_ENTER("sp_head::create");
int ret;
- DBUG_PRINT("info", ("type: %d name: %s def: %s",
- m_type, m_name.str, m_defstr.str));
+ DBUG_PRINT("info", ("type: %d name: %s params: %s body: %s",
+ m_type, m_name.str, m_params.str, m_body.str));
if (m_type == TYPE_ENUM_FUNCTION)
- ret= sp_create_function(thd,
- m_name.str, m_name.length,
- m_defstr.str, m_defstr.length,
- m_chistics);
+ ret= sp_create_function(thd, this);
else
- ret= sp_create_procedure(thd,
- m_name.str, m_name.length,
- m_defstr.str, m_defstr.length,
- m_chistics);
+ ret= sp_create_procedure(thd, this);
DBUG_RETURN(ret);
}