Commit 32691e6e authored by unknown's avatar unknown
Browse files

Merge rkalimullin@bk-internal.mysql.com:/home/bk/mysql-5.0

into  mysql.com:/usr/home/ram/work/5.0.b16511

parents 6400ef8b 1a9ed28b
Loading
Loading
Loading
Loading
+73 −89
Original line number Diff line number Diff line
@@ -3029,49 +3029,76 @@ static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val)


/*
  Append all results to the dynamic string separated with '\t'
  Values may be converted with 'replace_column'
  Append the result for one field to the dynamic string ds
*/

static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
{
  MYSQL_ROW row;
  uint num_fields= mysql_num_fields(res);
  MYSQL_FIELD *fields= !display_result_vertically ? 0 : mysql_fetch_fields(res);
  ulong *lengths;
  while ((row = mysql_fetch_row(res)))
  {
    uint i;
    lengths = mysql_fetch_lengths(res);
    for (i = 0; i < num_fields; i++)
static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD* field,
                         const char* val, ulonglong len, bool is_null)
{
      const char *val= row[i];
      ulonglong len= lengths[i];

      if (i < max_replace_column && replace_column[i])
  char buf[256];
  if (col_idx < max_replace_column && replace_column[col_idx])
  {
	val= replace_column[i];
    val= replace_column[col_idx];
    len= strlen(val);
  }
      if (!val)
  else if (is_null)
  {
    val= "NULL";
    len= 4;
  }
#ifdef __WIN__
  else if (field->type == MYSQL_TYPE_DOUBLE &&
           field->decimals >= 31)
  {
    /* Convert 1.2e+018 to 1.2e+18 and 1.2e-018 to 1.2e-18 */
    char *start= strchr(val, 'e');
    if (start && strlen(start) >= 5 &&
        (start[1] == '-' || start[1] == '+') && start[2] == '0')
    {
      start+=2; /* Now points at first '0' */
      /* Move all chars after the first '0' one step left */
      memmove(start, start + 1, strlen(start));
      len--;
    }
  }
#endif

  if (!display_result_vertically)
  {
	if (i)
    if (col_idx)
      dynstr_append_mem(ds, "\t", 1);
    replace_dynstr_append_mem(ds, val, (int)len);
  }
  else
  {
	dynstr_append(ds, fields[i].name);
    dynstr_append(ds, field->name);
    dynstr_append_mem(ds, "\t", 1);
    replace_dynstr_append_mem(ds, val, (int)len);
    dynstr_append_mem(ds, "\n", 1);
  }
}


/*
  Append all results to the dynamic string separated with '\t'
  Values may be converted with 'replace_column'
*/

static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
{
  MYSQL_ROW row;
  uint num_fields= mysql_num_fields(res);
  MYSQL_FIELD *fields= mysql_fetch_fields(res);
  ulong *lengths;

  while ((row = mysql_fetch_row(res)))
  {
    uint i;
    lengths = mysql_fetch_lengths(res);
    for (i = 0; i < num_fields; i++)
      append_field(ds, i, &fields[i],
                   (const char*)row[i], lengths[i], !row[i]);
    if (!display_result_vertically)
      dynstr_append_mem(ds, "\n", 1);
  }
@@ -3085,13 +3112,12 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
*/

static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt,
			       MYSQL_FIELD *field, uint num_fields)
                               MYSQL_FIELD *fields, uint num_fields)
{
  MYSQL_BIND *bind;
  my_bool *is_null;
  ulong *length;
  ulonglong num_rows;
  uint col_idx, row_idx;
  uint i;

  /* Allocate array with bind structs, lengths and NULL flags */
  bind= (MYSQL_BIND*) my_malloc(num_fields * sizeof(MYSQL_BIND),
@@ -3101,71 +3127,29 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt,
  is_null= (my_bool*) my_malloc(num_fields * sizeof(my_bool),
				MYF(MY_WME | MY_FAE));

  for (col_idx= 0; col_idx < num_fields; col_idx++)
  /* Allocate data for the result of each field */
  for (i= 0; i < num_fields; i++)
  {
    /* Allocate data for output */
    uint max_length= field[col_idx].max_length + 1;
    char *str_data= (char *) my_malloc(max_length, MYF(MY_WME | MY_FAE));

    bind[col_idx].buffer_type= MYSQL_TYPE_STRING;
    bind[col_idx].buffer= (char *)str_data;
    bind[col_idx].buffer_length= max_length;
    bind[col_idx].is_null= &is_null[col_idx];
    bind[col_idx].length= &length[col_idx];
    uint max_length= fields[i].max_length + 1;
    bind[i].buffer_type= MYSQL_TYPE_STRING;
    bind[i].buffer= (char *)my_malloc(max_length, MYF(MY_WME | MY_FAE));
    bind[i].buffer_length= max_length;
    bind[i].is_null= &is_null[i];
    bind[i].length= &length[i];

    DBUG_PRINT("bind", ("col[%d]: buffer_type: %d, buffer_length: %d",
			col_idx,
			bind[col_idx].buffer_type,
			bind[col_idx].buffer_length));
			i, bind[i].buffer_type, bind[i].buffer_length));
  }

  /* Fill in the data into the structures created above */
  if (mysql_stmt_bind_result(stmt, bind))
    die("mysql_stmt_bind_result failed: %d: %s",
	mysql_stmt_errno(stmt), mysql_stmt_error(stmt));

  /* Read result from each row */
  num_rows= mysql_stmt_num_rows(stmt);
  for (row_idx= 0; row_idx < num_rows; row_idx++)
  {
    if (mysql_stmt_fetch(stmt))
      die("mysql_stmt_fetch failed: %d %s",
	  mysql_stmt_errno(stmt), mysql_stmt_error(stmt));

    /* Read result from each column */
    for (col_idx= 0; col_idx < num_fields; col_idx++)
    {
      const char *val;
      ulonglong len;
      if (col_idx < max_replace_column && replace_column[col_idx])
      {
	val= replace_column[col_idx];
	len= strlen(val);
      }
      else if (*bind[col_idx].is_null)
      {
	val= "NULL";
	len= 4;
      }
      else
      {
	val= (const char *) bind[col_idx].buffer;
	len= *bind[col_idx].length;
      }
      if (!display_result_vertically)
  while (mysql_stmt_fetch(stmt) == 0)
  {
	if (col_idx)                      /* No tab before first col */
	  dynstr_append_mem(ds, "\t", 1);
	replace_dynstr_append_mem(ds, val, (int)len);
      }
      else
      {
	dynstr_append(ds, field[col_idx].name);
	dynstr_append_mem(ds, "\t", 1);
	replace_dynstr_append_mem(ds, val, (int)len);
	dynstr_append_mem(ds, "\n", 1);
      }
    }
    for (i= 0; i < num_fields; i++)
      append_field(ds, i, &fields[i], (const char *) bind[i].buffer,
                   *bind[i].length, *bind[i].is_null);
    if (!display_result_vertically)
      dynstr_append_mem(ds, "\n", 1);
  }
@@ -3176,10 +3160,10 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt,

  free_replace_column();

  for (col_idx= 0; col_idx < num_fields; col_idx++)
  for (i= 0; i < num_fields; i++)
  {
    /* Free data for output */
    my_free((gptr)bind[col_idx].buffer, MYF(MY_WME | MY_FAE));
    my_free((gptr)bind[i].buffer, MYF(MY_WME | MY_FAE));
  }
  /* Free array with bind structs, lengths and NULL flags */
  my_free((gptr)bind    , MYF(MY_WME | MY_FAE));
+29 −0
Original line number Diff line number Diff line
@@ -1147,3 +1147,32 @@ show procedure status;
Db	Name	Type	Definer	Modified	Created	Security_type	Comment
test	 bug15658	PROCEDURE	root@localhost	0000-00-00 00:00:00	0000-00-00 00:00:00	DEFINER	
drop procedure ` bug15658`;
drop function if exists bug14270;
drop table if exists t1;
create table t1 (s1 int primary key);
create function bug14270() returns int
begin
load index into cache t1;
return 1;
end|
ERROR 0A000: Not allowed to return a result set from a function
create function bug14270() returns int
begin
cache index t1 key (`primary`) in keycache1;
return 1;
end|
ERROR 0A000: Not allowed to return a result set from a function
drop table t1;
drop procedure if exists bug15091;
create procedure bug15091()
begin
declare selectstr varchar(6000) default ' ';
declare conditionstr varchar(5000)  default '';
set selectstr = concat(selectstr,
' and ',
c.operatorid,
'in (',conditionstr, ')');
end|
call bug15091();
ERROR 42S02: Unknown table 'c' in field list
drop procedure bug15091;
+23 −0
Original line number Diff line number Diff line
@@ -291,3 +291,26 @@ drop user user1_bug14834@localhost;
drop user user2_bug14834@localhost;
drop user user3_bug14834@localhost;
drop database db_bug14834;
create database db_bug14533;
use db_bug14533;
create table t1 (id int);
create user user_bug14533@localhost identified by '';
create procedure bug14533_1()
sql security definer
desc db_bug14533.t1;
create procedure bug14533_2()
sql security definer
select * from db_bug14533.t1;
grant execute on procedure db_bug14533.bug14533_1 to user_bug14533@localhost;
grant execute on procedure db_bug14533.bug14533_2 to user_bug14533@localhost;
call db_bug14533.bug14533_1();
Field	Type	Null	Key	Default	Extra
id	int(11)	YES		NULL	
call db_bug14533.bug14533_2();
id
desc db_bug14533.t1;
ERROR 42000: SELECT command denied to user 'user_bug14533'@'localhost' for table 't1'
select * from db_bug14533.t1;
ERROR 42000: SELECT command denied to user 'user_bug14533'@'localhost' for table 't1'
drop user user_bug14533@localhost;
drop database db_bug14533;
+19 −0
Original line number Diff line number Diff line
@@ -4497,4 +4497,23 @@ drop procedure if exists bug15231_1|
drop procedure if exists bug15231_2|
drop procedure if exists bug15231_3|
drop procedure if exists bug15231_4|
drop procedure if exists bug15011|
create table t3 (c1 int primary key)|
insert into t3 values (1)|
create procedure bug15011()
deterministic
begin
declare continue handler for 1062
select 'Outer' as 'Handler';
begin
declare continue handler for 1062
select 'Inner' as 'Handler';
insert into t3 values (1);
end;
end|
call bug15011()|
Handler
Inner
drop procedure bug15011|
drop table t3|
drop table t1,t2;
+2 −2
Original line number Diff line number Diff line
@@ -31,14 +31,14 @@ select * from t1;
f1	f2
10	10
100000	100000
1.23457e+9	1234567890
1.23457e+09	1234567890
1e+10	10000000000
1e+15	1e+15
1e+20	1e+20
3.40282e+38	1e+50
3.40282e+38	1e+150
-10	-10
1e-5	1e-5
1e-05	1e-05
1e-10	1e-10
1e-15	1e-15
1e-20	1e-20
Loading