summaryrefslogtreecommitdiff
path: root/sql/sp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sp.cc')
-rw-r--r--sql/sp.cc84
1 files changed, 46 insertions, 38 deletions
diff --git a/sql/sp.cc b/sql/sp.cc
index 20fac74c150..ba822b8c77b 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -21,8 +21,8 @@
#include "sp_head.h"
#include "sp_cache.h"
-static char *
-create_string(THD *thd, ulong *lenp,
+static bool
+create_string(THD *thd, String *buf,
int sp_type,
sp_name *name,
const char *params, ulong paramslen,
@@ -215,8 +215,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
}
{
- char *defstr;
- ulong deflen;
+ String defstr;
LEX *oldlex= thd->lex;
char olddb[128];
bool dbchanged;
@@ -227,13 +226,14 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
thd->variables.sql_mode= sql_mode;
thd->variables.select_limit= HA_POS_ERROR;
- if (!(defstr= create_string(thd, &deflen,
- type,
- name,
- params, strlen(params),
- returns, strlen(returns),
- body, strlen(body),
- &chistics)))
+ defstr.set_charset(system_charset_info);
+ if (!create_string(thd, &defstr,
+ type,
+ name,
+ params, strlen(params),
+ returns, strlen(returns),
+ body, strlen(body),
+ &chistics))
{
ret= SP_INTERNAL_ERROR;
goto done;
@@ -254,7 +254,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
List<Item> vals= thd->lex->value_list;
mysql_init_query(thd, TRUE);
- lex_start(thd, (uchar*)defstr, deflen);
+ lex_start(thd, (uchar*)defstr.c_ptr(), defstr.length());
thd->lex->value_list= vals;
}
@@ -280,7 +280,7 @@ db_find_routine(THD *thd, int type, sp_name *name, sp_head **sphp)
goto done;
*sphp= thd->lex->sphead;
(*sphp)->set_info((char *)definer, (uint)strlen(definer),
- created, modified, &chistics);
+ created, modified, &chistics, sql_mode);
}
thd->lex->sql_command= oldcmd;
thd->variables.sql_mode= old_sql_mode;
@@ -941,9 +941,12 @@ sp_cache_functions(THD *thd, LEX *lex)
return ret;
}
-
-static char *
-create_string(THD *thd, ulong *lenp,
+/*
+ * Generates the CREATE... string from the table information.
+ * Returns TRUE on success, FALSE on (alloc) failure.
+ */
+static bool
+create_string(THD *thd, String *buf,
int type,
sp_name *name,
const char *params, ulong paramslen,
@@ -951,35 +954,40 @@ create_string(THD *thd, ulong *lenp,
const char *body, ulong bodylen,
st_sp_chistics *chistics)
{
- char *buf, *ptr;
- ulong buflen;
-
- buflen= 100 + name->m_qname.length + paramslen + returnslen + bodylen +
- chistics->comment.length;
- if (!(buf= thd->alloc(buflen)))
- return 0;
-
- ptr= strxmov(buf, "CREATE ",
- (type == TYPE_ENUM_FUNCTION) ? "FUNCTION" : "PROCEDURE",
- " `", name->m_db.str, "`.`", name->m_name.str, "`(", params, ")",
- NullS);
+ /* Make some room to begin with */
+ if (buf->alloc(100 + name->m_qname.length + paramslen + returnslen + bodylen +
+ chistics->comment.length))
+ return FALSE;
+ buf->append("CREATE ", 7);
if (type == TYPE_ENUM_FUNCTION)
- ptr= strxmov(ptr, " RETURNS ", returns, NullS);
- *ptr++= '\n';
-
+ buf->append("FUNCTION ", 9);
+ else
+ buf->append("PROCEDURE ", 10);
+ append_identifier(thd, buf, name->m_db.str, name->m_db.length);
+ buf->append('.');
+ append_identifier(thd, buf, name->m_name.str, name->m_name.length);
+ buf->append('(');
+ buf->append(params, paramslen);
+ buf->append(')');
+ if (type == TYPE_ENUM_FUNCTION)
+ {
+ buf->append(" RETURNS ", 9);
+ buf->append(returns, returnslen);
+ }
+ buf->append('\n');
if (chistics->detistic)
- ptr= strmov(ptr, " DETERMINISTIC\n");
+ buf->append( " DETERMINISTIC\n", 18);
if (chistics->suid == IS_NOT_SUID)
- ptr= strmov(ptr, " SQL SECURITY INVOKER\n");
+ buf->append(" SQL SECURITY INVOKER\n", 25);
if (chistics->comment.length)
{
- ptr= strmov(strnmov(strmov(ptr, " COMMENT '"),chistics->comment.str,
- chistics->comment.length),"'\n");
+ buf->append(" COMMENT ");
+ append_unescaped(buf, chistics->comment.str, chistics->comment.length);
+ buf->append('\n');
}
- ptr= strmov(ptr, body);
- *lenp= (ptr-buf);
- return buf;
+ buf->append(body, bodylen);
+ return TRUE;
}