Commit 6726a6b8 authored by unknown's avatar unknown
Browse files

Post-review fixes, mainly fixing all print() methods for sp_instr* classes.

Also added mysql-test files:
 include/is_debug_build.inc
 r/is_debug_build.require
 r/sp-code.result
 t/sp-code.test


sql/sp_head.cc:
  Review fixes:
  - Some minor editorial changes
  - Fixed all print() methods for instructions:
    - reserve() enough space
    - check return value from reserve()
    - use qs_append, with length arg, whenever possible
sql/sp_pcontext.cc:
  Review fixes.
  Also fixed bug in find_cursor().
sql/sp_pcontext.h:
  Changed parameter names (review fix).
sql/sql_parse.cc:
  Moved comment. (Review fix)
mysql-test/include/is_debug_build.inc:
  New BitKeeper file ``mysql-test/include/is_debug_build.inc''
mysql-test/r/is_debug_build.require:
  New BitKeeper file ``mysql-test/r/is_debug_build.require''
mysql-test/r/sp-code.result:
  New BitKeeper file ``mysql-test/r/sp-code.result''
mysql-test/t/sp-code.test:
  New BitKeeper file ``mysql-test/t/sp-code.test''
parent 91ab7076
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
-- require r/is_debug_build.require
--disable_query_log
select instr(version(), "debug") > 0;
--enable_query_log
+2 −0
Original line number Diff line number Diff line
instr(version(), "debug") > 0
1
+65 −0
Original line number Diff line number Diff line
select version(), substring_index(version(), "-", -1);
version()	substring_index(version(), "-", -1)
5.0.17-debug-log	log
create procedure empty()
begin
end;
show procedure code empty;
Pos	Instruction
drop procedure empty;
create function almost_empty()
returns int
return 0;
show function code almost_empty;
Pos	Instruction
0	freturn 3 0
drop function almost_empty;
create procedure code_sample(x int, out err int, out nulls int)
begin
declare count int default 0;
set nulls = 0;
begin
declare c cursor for select name from t1;
declare exit handler for not found close c;
open c;
loop
begin
declare n varchar(20);
declare continue handler for sqlexception set err=1;
fetch c into n;
if isnull(n) then
set nulls = nulls + 1;
else
set count = count + 1;
update t2 set idx = count where name=n;
end if;
end;
end loop;
end;
select t.name, t.idx from t2 t order by idx asc;
end//
show procedure code code_sample;
Pos	Instruction
0	set count@3 0
1	set nulls@2 0
2	cpush c@0
3	hpush_jump 6 4 EXIT
4	cclose c@0
5	hreturn 0 19
6	copen c@0
7	set n@4 NULL
8	hpush_jump 11 5 CONTINUE
9	set err@1 1
10	hreturn 5
11	cfetch c@0 n@4
12	jump_if_not 15 isnull(n@4)
13	set nulls@2 (nulls@2 + 1)
14	jump 17
15	set count@3 (count@3 + 1)
16	stmt 4 "update t2 set idx = count where name=n"
17	hpop 1
18	jump 7
19	hpop 1
20	cpop 1
21	stmt 0 "select t.name, t.idx from t2 t order ..."
drop procedure code_sample;
+50 −0
Original line number Diff line number Diff line
#
# Test the debugging feature "show procedure/function code <name>" 
#

-- source include/is_debug_build.inc
select version(), substring_index(version(), "-", -1);

create procedure empty()
begin
end;
show procedure code empty;
drop procedure empty;

create function almost_empty()
    returns int
  return 0;
show function code almost_empty;
drop function almost_empty;

delimiter //;
create procedure code_sample(x int, out err int, out nulls int)
begin
  declare count int default 0;

  set nulls = 0;
  begin
    declare c cursor for select name from t1;
    declare exit handler for not found close c;

    open c;
    loop
      begin
        declare n varchar(20);
        declare continue handler for sqlexception set err=1;

        fetch c into n;
        if isnull(n) then
          set nulls = nulls + 1;
	else
          set count = count + 1;
          update t2 set idx = count where name=n;
        end if;
      end;
    end loop;
  end;
  select t.name, t.idx from t2 t order by idx asc;
end//
delimiter ;//
show procedure code code_sample;
drop procedure code_sample;
+95 −65
Original line number Diff line number Diff line
@@ -1853,14 +1853,13 @@ sp_head::show_routine_code(THD *thd)
  Protocol *protocol= thd->protocol;
  char buff[2048];
  String buffer(buff, sizeof(buff), system_charset_info);
  int res;
  List<Item> field_list;
  sp_instr *i;
  bool full_access;
  int res;
  uint ip;
  sp_instr *i;

  DBUG_ENTER("sp_head::show_routine_code");
  DBUG_PRINT("info", ("procedure %s", m_name.str));
  DBUG_PRINT("info", ("procedure: %s", m_name.str));

  if (check_show_routine_access(thd, this, &full_access) || !full_access)
    DBUG_RETURN(1);
@@ -1880,7 +1879,7 @@ sp_head::show_routine_code(THD *thd)

    buffer.set("", 0, system_charset_info);
    i->print(&buffer);
    protocol->store(buffer.c_ptr_quick(), buffer.length(), system_charset_info);
    protocol->store(buffer.ptr(), buffer.length(), system_charset_info);
    if ((res= protocol->write()))
      break;
  }
@@ -2055,10 +2054,12 @@ sp_instr_stmt::print(String *str)
{
  uint i, len;

  str->reserve(STMT_PRINT_MAXLEN+20);
  str->append("stmt ");
  /* Reserve enough space for 'stmt CMD "..."'; max+20 is more than enough. */
  if (str->reserve(STMT_PRINT_MAXLEN+20))
    return;
  str->qs_append("stmt ", 5);
  str->qs_append((uint)m_lex_keeper.sql_command());
  str->append(" \"");
  str->qs_append(" \"", 2);
  len= m_query.length;
  /*
    Print the query string (but not too much of it), just to indicate which
@@ -2068,13 +2069,15 @@ sp_instr_stmt::print(String *str)
    len= 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->append(' ');
      str->qs_append(' ');
    else
      str->append(m_query.str[i]);
      str->qs_append(m_query.str[i]);
  }
  if (m_query.length > STMT_PRINT_MAXLEN)
    str->append("...");        /* Indicate truncated string */
  str->append('"');
    str->qs_append("...", 3);      /* Indicate truncated string */
  str->qs_append('"');
}
#undef STMT_PRINT_MAXLEN

@@ -2119,15 +2122,16 @@ sp_instr_set::print(String *str)
  /* 'var' should always be non-null, but just in case... */
  if (var)
    rsrv+= var->name.length;
  str->reserve(rsrv);
  str->append("set ");
  if (str->reserve(rsrv))
    return;
  str->qs_append("set ", 4);
  if (var)
  {
    str->append(var->name.str, var->name.length);
    str->append('@');
    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);
}

@@ -2184,8 +2188,9 @@ sp_instr_jump::execute(THD *thd, uint *nextp)
void
sp_instr_jump::print(String *str)
{
  str->reserve(12);
  str->append("jump ");
  if (str->reserve(12))
    return;
  str->qs_append("jump ", 5);
  str->qs_append(m_dest);
}

@@ -2266,10 +2271,11 @@ sp_instr_jump_if::exec_core(THD *thd, uint *nextp)
void
sp_instr_jump_if::print(String *str)
{
  str->reserve(12);
  str->append("jump_if ");
  if (str->reserve(32))
    return;
  str->qs_append("jump_if ", 8);
  str->qs_append(m_dest);
  str->append(' ');
  str->qs_append(' ');
  m_expr->print(str);
}

@@ -2327,10 +2333,11 @@ 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("jump_if_not ");
  if (str->reserve(32))
    return;
  str->qs_append("jump_if_not ", 12);
  str->qs_append(m_dest);
  str->append(' ');
  str->qs_append(' ');
  m_expr->print(str);
}

@@ -2385,10 +2392,11 @@ sp_instr_freturn::exec_core(THD *thd, uint *nextp)
void
sp_instr_freturn::print(String *str)
{
  str->reserve(12);
  str->append("freturn ");
  if (str->reserve(32))
    return;
  str->qs_append("freturn ", 8);
  str->qs_append((uint)m_type);
  str->append(' ');
  str->qs_append(' ');
  m_value->print(str);
}

@@ -2413,27 +2421,28 @@ sp_instr_hpush_jump::execute(THD *thd, uint *nextp)
void
sp_instr_hpush_jump::print(String *str)
{
  str->reserve(32);
  str->append("hpush_jump ");
  if (str->reserve(32))
    return;
  str->qs_append("hpush_jump ", 11);
  str->qs_append(m_dest);
  str->append(' ');
  str->qs_append(' ');
  str->qs_append(m_frame);
  switch (m_type)
  {
  case SP_HANDLER_NONE:
    str->append(" NONE");       // This would be a bug
    str->qs_append(" NONE", 5); // This would be a bug
    break;
  case SP_HANDLER_EXIT:
    str->append(" EXIT");
    str->qs_append(" EXIT", 5);
    break;
  case SP_HANDLER_CONTINUE:
    str->append(" CONTINUE");
    str->qs_append(" CONTINUE", 9);
    break;
  case SP_HANDLER_UNDO:
    str->append(" UNDO");
    str->qs_append(" UNDO", 5);
    break;
  default:
    str->append(" UNKNOWN:");   // This would be a bug as well
    str->qs_append(" UNKNOWN:", 9); // This would be a bug as well
    str->qs_append(m_type);
  }
}
@@ -2470,8 +2479,9 @@ sp_instr_hpop::execute(THD *thd, uint *nextp)
void
sp_instr_hpop::print(String *str)
{
  str->reserve(12);
  str->append("hpop ");
  if (str->reserve(12))
    return;
  str->qs_append("hpop ", 5);
  str->qs_append(m_count);
}

@@ -2505,12 +2515,13 @@ sp_instr_hreturn::execute(THD *thd, uint *nextp)
void
sp_instr_hreturn::print(String *str)
{
  str->reserve(16);
  str->append("hreturn ");
  if (str->reserve(20))
    return;
  str->qs_append("hreturn ", 8);
  str->qs_append(m_frame);
  if (m_dest)
  {
    str->append(' ');
    str->qs_append(' ');
    str->qs_append(m_dest);
  }
}
@@ -2559,14 +2570,18 @@ void
sp_instr_cpush::print(String *str)
{
  LEX_STRING n;
  uint rsrv= 12;
  my_bool found= m_ctx->find_cursor(m_cursor, &n);

  str->reserve(32);
  str->append("cpush ");
  if (found)
    rsrv+= n.length;
  if (str->reserve(rsrv))
    return;
  str->qs_append("cpush ", 6);
  if (found)
  {
    str->append(n.str, n.length);
    str->append('@');
    str->qs_append(n.str, n.length);
    str->qs_append('@');
  }
  str->qs_append(m_cursor);
}
@@ -2589,8 +2604,9 @@ sp_instr_cpop::execute(THD *thd, uint *nextp)
void
sp_instr_cpop::print(String *str)
{
  str->reserve(12);
  str->append("cpop ");
  if (str->reserve(12))
    return;
  str->qs_append("cpop ", 5);
  str->qs_append(m_count);
}

@@ -2665,14 +2681,18 @@ void
sp_instr_copen::print(String *str)
{
  LEX_STRING n;
  uint rsrv= 16;
  my_bool found= m_ctx->find_cursor(m_cursor, &n);

  str->reserve(32);
  str->append("copen ");
  if (found)
    rsrv+= n.length;
  if (str->reserve(rsrv))
    return;
  str->qs_append("copen ", 6);
  if (found)
  {
    str->append(n.str, n.length);
    str->append('@');
    str->qs_append(n.str, n.length);
    str->qs_append('@');
  }
  str->qs_append(m_cursor);
}
@@ -2702,14 +2722,18 @@ void
sp_instr_cclose::print(String *str)
{
  LEX_STRING n;
  uint rsrv= 16;
  my_bool found= m_ctx->find_cursor(m_cursor, &n);

  str->reserve(32);
  str->append("cclose ");
  if (found)
    rsrv+= n.length;
  if (str->reserve(rsrv))
    return;
  str->qs_append("cclose ", 7);
  if (found)
  {
    str->append(n.str, n.length);
    str->append('@');
    str->qs_append(n.str, n.length);
    str->qs_append('@');
  }
  str->qs_append(m_cursor);
}
@@ -2740,22 +2764,27 @@ sp_instr_cfetch::print(String *str)
  List_iterator_fast<struct sp_pvar> li(m_varlist);
  sp_pvar_t *pv;
  LEX_STRING n;
  uint rsrv= 16;
  my_bool found= m_ctx->find_cursor(m_cursor, &n);

  str->reserve(32);
  str->append("cfetch ");
  if (found)
    rsrv+= n.length;
  if (str->reserve(rsrv))
    return;
  str->qs_append("cfetch ", 7);
  if (found)
  {
    str->append(n.str, n.length);
    str->append('@');
    str->qs_append(n.str, n.length);
    str->qs_append('@');
  }
  str->qs_append(m_cursor);
  while ((pv= li++))
  {
    str->reserve(16);
    str->append(' ');
    str->append(pv->name.str, pv->name.length);
    str->append('@');
    if (str->reserve(pv->name.length+10))
      return;
    str->qs_append(' ');
    str->qs_append(pv->name.str, pv->name.length);
    str->qs_append('@');
    str->qs_append(pv->offset);
  }
}
@@ -2779,8 +2808,9 @@ sp_instr_error::execute(THD *thd, uint *nextp)
void
sp_instr_error::print(String *str)
{
  str->reserve(12);
  str->append("error ");
  if (str->reserve(12))
    return;
  str->qs_append("error ", 6);
  str->qs_append(m_errcode);
}

Loading