summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2005-11-22 13:24:53 +0100
committerunknown <pem@mysql.com>2005-11-22 13:24:53 +0100
commitd213bf04871436e743185c789b015e10766da272 (patch)
tree86c284656a77326c24b551af05b4ea94db1c17ee /sql/sp_head.cc
parent929e6e05bedfaac9b9425cd84addef10a99b8919 (diff)
parent6553362b96dcc681a01091ee3dd422681ebaf964 (diff)
downloadmariadb-git-d213bf04871436e743185c789b015e10766da272.tar.gz
Merge mysql.com:/usr/local/bk/mysql-5.0
into mysql.com:/usr/home/pem/show-sp-code/mysql-5.0 sql/sp_head.h: Auto merged sql/sql_parse.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/sp_head.cc: Merge fixes (STRING_WITH_LEN in string append calls).
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc280
1 files changed, 224 insertions, 56 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index ace74492def..a3a7af7ab67 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -105,6 +105,8 @@ sp_get_flags_for_command(LEX *lex)
case SQLCOM_SHOW_TABLES:
case SQLCOM_SHOW_VARIABLES:
case SQLCOM_SHOW_WARNS:
+ case SQLCOM_SHOW_PROC_CODE:
+ case SQLCOM_SHOW_FUNC_CODE:
flags= sp_head::MULTI_RESULTS;
break;
/*
@@ -1740,7 +1742,7 @@ sp_head::show_create_procedure(THD *thd)
LINT_INIT(sql_mode_len);
if (check_show_routine_access(thd, this, &full_access))
- return 1;
+ DBUG_RETURN(1);
sql_mode_str=
sys_var_thd_sql_mode::symbolic_mode_representation(thd,
@@ -1753,10 +1755,7 @@ sp_head::show_create_procedure(THD *thd)
max(buffer.length(), 1024)));
if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
Protocol::SEND_EOF))
- {
- res= 1;
- goto done;
- }
+ DBUG_RETURN(1);
protocol->prepare_for_resend();
protocol->store(m_name.str, m_name.length, system_charset_info);
protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info);
@@ -1765,7 +1764,6 @@ sp_head::show_create_procedure(THD *thd)
res= protocol->write();
send_eof(thd);
- done:
DBUG_RETURN(res);
}
@@ -1810,7 +1808,7 @@ sp_head::show_create_function(THD *thd)
LINT_INIT(sql_mode_len);
if (check_show_routine_access(thd, this, &full_access))
- return 1;
+ DBUG_RETURN(1);
sql_mode_str=
sys_var_thd_sql_mode::symbolic_mode_representation(thd,
@@ -1822,10 +1820,7 @@ sp_head::show_create_function(THD *thd)
max(buffer.length(),1024)));
if (protocol->send_fields(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- {
- res= 1;
- goto done;
- }
+ DBUG_RETURN(1);
protocol->prepare_for_resend();
protocol->store(m_name.str, m_name.length, system_charset_info);
protocol->store((char*) sql_mode_str, sql_mode_len, system_charset_info);
@@ -1834,7 +1829,6 @@ sp_head::show_create_function(THD *thd)
res= protocol->write();
send_eof(thd);
- done:
DBUG_RETURN(res);
}
@@ -1894,6 +1888,50 @@ sp_head::opt_mark(uint ip)
}
+#ifndef DBUG_OFF
+int
+sp_head::show_routine_code(THD *thd)
+{
+ Protocol *protocol= thd->protocol;
+ char buff[2048];
+ String buffer(buff, sizeof(buff), system_charset_info);
+ List<Item> field_list;
+ sp_instr *i;
+ bool full_access;
+ int res;
+ uint ip;
+ DBUG_ENTER("sp_head::show_routine_code");
+ DBUG_PRINT("info", ("procedure: %s", m_name.str));
+
+ if (check_show_routine_access(thd, this, &full_access) || !full_access)
+ DBUG_RETURN(1);
+
+ field_list.push_back(new Item_uint("Pos", 9));
+ // 1024 is for not to confuse old clients
+ field_list.push_back(new Item_empty_string("Instruction",
+ max(buffer.length(), 1024)));
+ if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS |
+ Protocol::SEND_EOF))
+ DBUG_RETURN(1);
+
+ for (ip= 0; (i = get_instr(ip)) ; ip++)
+ {
+ protocol->prepare_for_resend();
+ protocol->store((longlong)ip);
+
+ buffer.set("", 0, system_charset_info);
+ i->print(&buffer);
+ protocol->store(buffer.ptr(), buffer.length(), system_charset_info);
+ if ((res= protocol->write()))
+ break;
+ }
+ send_eof(thd);
+
+ DBUG_RETURN(res);
+}
+#endif // ifndef DBUG_OFF
+
+
/*
Prepare LEX and thread for execution of instruction, if requested open
and lock LEX's tables, execute instruction's core function, perform
@@ -2052,14 +2090,43 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
DBUG_RETURN(res);
}
+/*
+ Sufficient max length of printed destinations and frame offsets (all uints).
+*/
+#define SP_INSTR_UINT_MAXLEN 8
+
+#define SP_STMT_PRINT_MAXLEN 40
void
sp_instr_stmt::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("stmt "));
+ uint i, len;
+
+ /* stmt CMD "..." */
+ if (str->reserve(SP_STMT_PRINT_MAXLEN+SP_INSTR_UINT_MAXLEN+8))
+ return;
+ str->qs_ append(STRING_WITH_LEN("stmt "));
str->qs_append((uint)m_lex_keeper.sql_command());
+ str->qs_append(" \"", 2);
+ len= m_query.length;
+ /*
+ Print the query string (but not too much of it), just to indicate which
+ statement it is.
+ */
+ if (len > SP_STMT_PRINT_MAXLEN)
+ len= SP_STMT_PRINT_MAXLEN-3;
+ /* Copy the query string and replace '\n' with ' ' in the process */
+ for (i= 0 ; i < len ; i++)
+ {
+ if (m_query.str[i] == '\n')
+ str->qs_append(' ');
+ else
+ str->qs_append(m_query.str[i]);
+ }
+ if (m_query.length > SP_STMT_PRINT_MAXLEN)
+ str->qs_append("...", 3); /* Indicate truncated string */
+ str->qs_append('"');
}
-
+#undef SP_STMT_PRINT_MAXLEN
int
sp_instr_stmt::exec_core(THD *thd, uint *nextp)
@@ -2096,10 +2163,23 @@ sp_instr_set::exec_core(THD *thd, uint *nextp)
void
sp_instr_set::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("set "));
+ /* set name@offset ... */
+ int rsrv = SP_INSTR_UINT_MAXLEN+6;
+ sp_pvar_t *var = m_ctx->find_pvar(m_offset);
+
+ /* 'var' should always be non-null, but just in case... */
+ if (var)
+ rsrv+= var->name.length;
+ if (str->reserve(rsrv))
+ return;
+ str->qs_append(STRING_WITH_LEN("set "));
+ if (var)
+ {
+ str->qs_append(var->name.str, var->name.length);
+ str->qs_append('@');
+ }
str->qs_append(m_offset);
- str->append(' ');
+ str->qs_append(' ');
m_value->print(str);
}
@@ -2132,7 +2212,7 @@ sp_instr_set_trigger_field::exec_core(THD *thd, uint *nextp)
void
sp_instr_set_trigger_field::print(String *str)
{
- str->append(STRING_WITH_LEN("set "));
+ str->append(STRING_WITH_LEN("set_trigger_field "));
trigger_field->print(str);
str->append(STRING_WITH_LEN(":="));
value->print(str);
@@ -2156,8 +2236,10 @@ sp_instr_jump::execute(THD *thd, uint *nextp)
void
sp_instr_jump::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("jump "));
+ /* jump dest */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN+5))
+ return;
+ str->qs_append(STRING_WITH_LEN("jump "));
str->qs_append(m_dest);
}
@@ -2238,10 +2320,12 @@ sp_instr_jump_if::exec_core(THD *thd, uint *nextp)
void
sp_instr_jump_if::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("jump_if "));
+ /* jump_if dest ... */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN+8+32)) // Add some for the expr. too
+ return;
+ str->qs_append(STRING_WITH_LEN("jump_if "));
str->qs_append(m_dest);
- str->append(' ');
+ str->qs_append(' ');
m_expr->print(str);
}
@@ -2299,10 +2383,12 @@ sp_instr_jump_if_not::exec_core(THD *thd, uint *nextp)
void
sp_instr_jump_if_not::print(String *str)
{
- str->reserve(16);
- str->append(STRING_WITH_LEN("jump_if_not "));
+ /* jump_if_not dest ... */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN+12+32)) // Add some for the expr. too
+ return;
+ str->qs_append(STRING_WITH_LEN("jump_if_not "));
str->qs_append(m_dest);
- str->append(' ');
+ str->qs_append(' ');
m_expr->print(str);
}
@@ -2357,10 +2443,12 @@ sp_instr_freturn::exec_core(THD *thd, uint *nextp)
void
sp_instr_freturn::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("freturn "));
+ /* freturn type expr... */
+ if (str->reserve(UINT_MAX+8+32)) // Add some for the expr. too
+ return;
+ str->qs_append(STRING_WITH_LEN("freturn "));
str->qs_append((uint)m_type);
- str->append(' ');
+ str->qs_append(' ');
m_value->print(str);
}
@@ -2385,15 +2473,31 @@ sp_instr_hpush_jump::execute(THD *thd, uint *nextp)
void
sp_instr_hpush_jump::print(String *str)
{
- str->reserve(32);
- str->append(STRING_WITH_LEN("hpush_jump "));
+ /* hpush_jump dest fsize type */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN*2 + 21))
+ return;
+ str->qs_append(STRING_WITH_LEN("hpush_jump "));
str->qs_append(m_dest);
- str->append(STRING_WITH_LEN(" t="));
- str->qs_append(m_type);
- str->append(STRING_WITH_LEN(" f="));
+ str->qs_append(' ');
str->qs_append(m_frame);
- str->append(STRING_WITH_LEN(" h="));
- str->qs_append(m_ip+1);
+ switch (m_type)
+ {
+ case SP_HANDLER_NONE:
+ str->qs_append(" NONE", 5); // This would be a bug
+ break;
+ case SP_HANDLER_EXIT:
+ str->qs_append(" EXIT", 5);
+ break;
+ case SP_HANDLER_CONTINUE:
+ str->qs_append(" CONTINUE", 9);
+ break;
+ case SP_HANDLER_UNDO:
+ str->qs_append(" UNDO", 5);
+ break;
+ default:
+ str->qs_append(" UNKNOWN:", 9); // This would be a bug as well
+ str->qs_append(m_type);
+ }
}
uint
@@ -2428,8 +2532,10 @@ sp_instr_hpop::execute(THD *thd, uint *nextp)
void
sp_instr_hpop::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("hpop "));
+ /* hpop count */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN+5))
+ return;
+ str->qs_append(STRING_WITH_LEN("hpop "));
str->qs_append(m_count);
}
@@ -2463,12 +2569,14 @@ sp_instr_hreturn::execute(THD *thd, uint *nextp)
void
sp_instr_hreturn::print(String *str)
{
- str->reserve(16);
- str->append(STRING_WITH_LEN("hreturn "));
+ /* hreturn framesize dest */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN*2 + 9))
+ return;
+ str->qs_append(STRING_WITH_LEN("hreturn "));
str->qs_append(m_frame);
if (m_dest)
{
- str->append(' ');
+ str->qs_append(' ');
str->qs_append(m_dest);
}
}
@@ -2516,7 +2624,22 @@ sp_instr_cpush::execute(THD *thd, uint *nextp)
void
sp_instr_cpush::print(String *str)
{
- str->append(STRING_WITH_LEN("cpush"));
+ LEX_STRING n;
+ my_bool found= m_ctx->find_cursor(m_cursor, &n);
+ /* cpush name@offset */
+ uint rsrv= SP_INSTR_UINT_MAXLEN+7;
+
+ if (found)
+ rsrv+= n.length;
+ if (str->reserve(rsrv))
+ return;
+ str->qs_append(STRING_WITH_LENGTH("cpush "));
+ if (found)
+ {
+ str->qs_append(n.str, n.length);
+ str->qs_append('@');
+ }
+ str->qs_append(m_cursor);
}
@@ -2537,8 +2660,10 @@ sp_instr_cpop::execute(THD *thd, uint *nextp)
void
sp_instr_cpop::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("cpop "));
+ /* cpop count */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN+5))
+ return;
+ str->qs_append(STRING_WITH_LEN("cpop "));
str->qs_append(m_count);
}
@@ -2612,8 +2737,21 @@ sp_instr_copen::exec_core(THD *thd, uint *nextp)
void
sp_instr_copen::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("copen "));
+ LEX_STRING n;
+ my_bool found= m_ctx->find_cursor(m_cursor, &n);
+ /* copen name@offset */
+ uint rsrv= SP_INSTR_UINT_MAXLEN+7;
+
+ if (found)
+ rsrv+= n.length;
+ if (str->reserve(rsrv))
+ return;
+ str->qs_append(STRING_WITH_LEN("copen "));
+ if (found)
+ {
+ str->qs_append(n.str, n.length);
+ str->qs_append('@');
+ }
str->qs_append(m_cursor);
}
@@ -2641,8 +2779,21 @@ sp_instr_cclose::execute(THD *thd, uint *nextp)
void
sp_instr_cclose::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("cclose "));
+ LEX_STRING n;
+ my_bool found= m_ctx->find_cursor(m_cursor, &n);
+ /* cclose name@offset */
+ uint rsrv= SP_INSTR_UINT_MAXLEN+8;
+
+ if (found)
+ rsrv+= n.length;
+ if (str->reserve(rsrv))
+ return;
+ str->qs_append(STRING_WITH_LEN("cclose "));
+ if (found)
+ {
+ str->qs_append(n.str, n.length);
+ str->qs_append('@');
+ }
str->qs_append(m_cursor);
}
@@ -2671,14 +2822,29 @@ sp_instr_cfetch::print(String *str)
{
List_iterator_fast<struct sp_pvar> li(m_varlist);
sp_pvar_t *pv;
-
- str->reserve(12);
- str->append(STRING_WITH_LEN("cfetch "));
+ LEX_STRING n;
+ my_bool found= m_ctx->find_cursor(m_cursor, &n);
+ /* cfetch name@offset vars... */
+ uint rsrv= SP_INSTR_UINT_MAXLEN+8;
+
+ if (found)
+ rsrv+= n.length;
+ if (str->reserve(rsrv))
+ return;
+ str->qs_append(STRING_WITH_LEN("cfetch "));
+ if (found)
+ {
+ str->qs_append(n.str, n.length);
+ str->qs_append('@');
+ }
str->qs_append(m_cursor);
while ((pv= li++))
{
- str->reserve(8);
- str->append(' ');
+ if (str->reserve(pv->name.length+SP_INSTR_UINT_MAXLEN+2))
+ return;
+ str->qs_append(' ');
+ str->qs_append(pv->name.str, pv->name.length);
+ str->qs_append('@');
str->qs_append(pv->offset);
}
}
@@ -2702,8 +2868,10 @@ sp_instr_error::execute(THD *thd, uint *nextp)
void
sp_instr_error::print(String *str)
{
- str->reserve(12);
- str->append(STRING_WITH_LEN("error "));
+ /* error code */
+ if (str->reserve(SP_INSTR_UINT_MAXLEN+6))
+ return;
+ str->qs_append(STRING_WITH_LEN("error "));
str->qs_append(m_errcode);
}