Commit 0afb6ff6 authored by unknown's avatar unknown
Browse files

Fixes to embedded server to be able to run tests with it

(Needed for "list of pushes" web page and autopush)


include/mysql.h:
  Fix to embedded server to be able to run tests on it
libmysql/libmysql.c:
  Fix to embedded server to be able to run tests on it
libmysqld/emb_qcache.cc:
  Fix to embedded server to be able to run tests on it
libmysqld/embedded_priv.h:
  Fix to embedded server to be able to run tests on it
libmysqld/lib_sql.cc:
  Fix to embedded server to be able to run tests on it
libmysqld/libmysqld.c:
  Fix to embedded server to be able to run tests on it
mysql-test/mysql-test-run.sh:
  Fix to embedded server to be able to run tests on it
mysql-test/r/binlog.result:
  Updated test for embedded server
mysql-test/r/ctype_cp932.result:
  Updated test for embedded server
mysql-test/r/innodb.result:
  Updated test for embedded server
mysql-test/r/mysqltest.result:
  Updated test for embedded server
mysql-test/r/query_cache.result:
  Updated test for embedded server
mysql-test/r/query_cache_notembedded.result:
  Updated test for embedded server
mysql-test/r/sp-error.result:
  Updated test for embedded server
mysql-test/r/sp.result:
  Updated test for embedded server
mysql-test/r/subselect.result:
  Updated test for embedded server
mysql-test/r/view.result:
  Updated test for embedded server
mysql-test/r/view_grant.result:
  Updated test for embedded server
mysql-test/t/backup.test:
  Updated test for embedded server
mysql-test/t/binlog.test:
  Updated test for embedded server
mysql-test/t/blackhole.test:
  Updated test for embedded server
mysql-test/t/compress.test:
  Updated test for embedded server
mysql-test/t/ctype_cp932.test:
  Updated test for embedded server
mysql-test/t/delayed.test:
  Updated test for embedded server
mysql-test/t/handler.test:
  Updated test for embedded server
mysql-test/t/innodb.test:
  Updated test for embedded server
mysql-test/t/mysql.test:
  Updated test for embedded server
mysql-test/t/mysql_client_test.test:
  Updated test for embedded server
mysql-test/t/mysqltest.test:
  Updated test for embedded server
mysql-test/t/query_cache.test:
  Updated test for embedded server
mysql-test/t/query_cache_notembedded.test:
  Updated test for embedded server
mysql-test/t/read_only.test:
  Updated test for embedded server
mysql-test/t/skip_grants.test:
  Updated test for embedded server
mysql-test/t/sp-destruct.test:
  Updated test for embedded server
mysql-test/t/sp-error.test:
  Updated test for embedded server
mysql-test/t/sp-threads.test:
  Updated test for embedded server
mysql-test/t/sp.test:
  Updated test for embedded server
mysql-test/t/subselect.test:
  Updated test for embedded server
mysql-test/t/temp_table.test:
  Updated test for embedded server
mysql-test/t/view.test:
  Updated test for embedded server
mysql-test/t/view_grant.test:
  Updated test for embedded server
mysql-test/t/wait_timeout.test:
  Updated test for embedded server
mysys/mf_dirname.c:
  Review fix: Don't access data outside of array
mysys/my_bitmap.c:
  Remove compiler warnings
scripts/mysql_fix_privilege_tables.sql:
  Add flush privileges to .sql script so that one doesn't have to reboot mysqld when one runs the mysql_fix_privilege_script
sql-common/client.c:
  Updated test for embedded server
sql/item.cc:
  Remove DBUG_PRINT statement that can cause crashes when running with --debug
sql/mysqld.cc:
  Fix to embedded server to be able to run tests on it
sql/protocol.cc:
  Fix to embedded server to be able to run tests on it
  (Trivial reconstruction of code)
sql/protocol.h:
  Fix to embedded server to be able to run tests on it
sql/sql_base.cc:
  Better comment
sql/sql_class.cc:
  Fix to embedded server to be able to run tests on it
sql/sql_class.h:
  Fix to embedded server to be able to run tests on it
sql/sql_cursor.cc:
  Fix to embedded server to be able to run tests on it
sql/sql_parse.cc:
  Fix to embedded server to be able to run tests on it
  Don't crash for disabled commands when using embedded server
sql/sql_prepare.cc:
  Fix to embedded server to be able to run tests on it
mysql-test/r/ctype_cp932_notembedded.result:
  New BitKeeper file ``mysql-test/r/ctype_cp932_notembedded.result''
mysql-test/r/innodb_notembedded.result:
  New BitKeeper file ``mysql-test/r/innodb_notembedded.result''
mysql-test/r/sp.result.orig:
  New BitKeeper file ``mysql-test/r/sp.result.orig''
mysql-test/r/sp_notembedded.result:
  New BitKeeper file ``mysql-test/r/sp_notembedded.result''
mysql-test/r/subselect_notembedded.result:
  New BitKeeper file ``mysql-test/r/subselect_notembedded.result''
mysql-test/t/ctype_cp932_notembedded.test:
  New BitKeeper file ``mysql-test/t/ctype_cp932_notembedded.test''
mysql-test/t/innodb_notembedded.test:
  New BitKeeper file ``mysql-test/t/innodb_notembedded.test''
mysql-test/t/sp.test.orig:
  New BitKeeper file ``mysql-test/t/sp.test.orig''
mysql-test/t/sp_notembedded.test:
  New BitKeeper file ``mysql-test/t/sp_notembedded.test''
mysql-test/t/subselect_notembedded.test:
  New BitKeeper file ``mysql-test/t/subselect_notembedded.test''
parent ef1316fa
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -130,14 +130,14 @@ typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */

#include "my_alloc.h"

typedef struct embedded_query_result EMBEDDED_QUERY_RESULT;
typedef struct st_mysql_data {
  my_ulonglong rows;
  unsigned int fields;
  MYSQL_ROWS *data;
  MEM_ROOT alloc;
#if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)
  MYSQL_ROWS **prev_ptr;
#endif
  /* extra info for embedded library */
  struct embedded_query_result *embedded_info;
} MYSQL_DATA;

enum mysql_option 
@@ -287,6 +287,8 @@ typedef struct st_mysql
    from mysql_stmt_close if close had to cancel result set of this object.
  */
  my_bool *unbuffered_fetch_owner;
  /* needed for embedded server - no net buffer to store the 'info' */
  char *info_buffer;
} MYSQL;

typedef struct st_mysql_res {
@@ -755,6 +757,7 @@ typedef struct st_mysql_methods
  const char *(*read_statistics)(MYSQL *mysql);
  my_bool (*next_result)(MYSQL *mysql);
  int (*read_change_user_result)(MYSQL *mysql, char *buff, const char *passwd);
  int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
#endif
} MYSQL_METHODS;

+6 −6
Original line number Diff line number Diff line
@@ -2727,13 +2727,13 @@ stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row)
    /* Send row request to the server */
    int4store(buff, stmt->stmt_id);
    int4store(buff + 4, stmt->prefetch_rows); /* number of rows to fetch */
    if (cli_advanced_command(mysql, COM_STMT_FETCH, buff, sizeof(buff),
                             NullS, 0, 1))
    if ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH,
                                            buff, sizeof(buff), NullS, 0, 1))
    {
      set_stmt_errmsg(stmt, net->last_error, net->last_errno, net->sqlstate);
      return 1;
    }
    if (cli_read_binary_rows(stmt))
    if ((*mysql->methods->read_rows_from_cursor)(stmt))
      return 1;
    stmt->server_status= mysql->server_status;

@@ -5143,9 +5143,9 @@ my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode)
  DBUG_ENTER("mysql_autocommit");
  DBUG_PRINT("enter", ("mode : %d", auto_mode));

  if (auto_mode) /* set to true */
    DBUG_RETURN((my_bool) mysql_real_query(mysql, "set autocommit=1", 16));
  DBUG_RETURN((my_bool) mysql_real_query(mysql, "set autocommit=0", 16));
  DBUG_RETURN((my_bool) mysql_real_query(mysql, auto_mode ?
                                         "set autocommit=1":"set autocommit=0",
                                         16));
}


+69 −60
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#ifdef HAVE_QUERY_CACHE
#include <mysql.h>
#include "emb_qcache.h"
#include "embedded_priv.h"

void Querycache_stream::store_char(char c)
{
@@ -284,22 +285,25 @@ int Querycache_stream::load_column(MEM_ROOT *alloc, char** column)

uint emb_count_querycache_size(THD *thd)
{
  uint result;
  MYSQL *mysql= thd->mysql;
  MYSQL_FIELD *field= mysql->fields;
  MYSQL_FIELD *field_end= field + mysql->field_count;
  MYSQL_ROWS *cur_row=NULL;
  my_ulonglong n_rows=0;
  uint result= 0;
  MYSQL_FIELD *field;
  MYSQL_FIELD *field_end;
  MYSQL_ROWS *cur_row;
  my_ulonglong n_rows;
  MYSQL_DATA *data= thd->first_data;

  while (data->embedded_info->next)
    data= data->embedded_info->next;
  field= data->embedded_info->fields_list;
  field_end= field + data->fields;
  
  if (!field)
    return 0;
  if (thd->data)
  {
    *thd->data->prev_ptr= NULL; // this marks the last record
    cur_row= thd->data->data;
    n_rows= thd->data->rows;
  }
  result= (uint) (4+8 + (42 + 4*n_rows)*mysql->field_count);
    return result;
  *data->embedded_info->prev_ptr= NULL; // this marks the last record
  cur_row= data->data;
  n_rows= data->rows;
  /* n_fields + n_rows + (field_info + strlen * n_rows) * n_fields */
  result+= (uint) (4+8 + (42 + 4*n_rows)*data->fields);

  for(; field < field_end; field++)
  {
@@ -313,7 +317,7 @@ uint emb_count_querycache_size(THD *thd)
  for (; cur_row; cur_row=cur_row->next)
  {
    MYSQL_ROW col= cur_row->data;
    MYSQL_ROW col_end= col + mysql->field_count;
    MYSQL_ROW col_end= col + data->fields;
    for (; col < col_end; col++)
      if (*col)
        result+= *(uint *)((*col) - sizeof(uint));
@@ -323,24 +327,28 @@ uint emb_count_querycache_size(THD *thd)

void emb_store_querycache_result(Querycache_stream *dst, THD *thd)
{
  MYSQL *mysql= thd->mysql;
  MYSQL_FIELD *field= mysql->fields;
  MYSQL_FIELD *field_end= field + mysql->field_count;
  MYSQL_ROWS *cur_row= NULL;
  my_ulonglong n_rows= 0;
  MYSQL_FIELD *field;
  MYSQL_FIELD *field_end;
  MYSQL_ROWS *cur_row;
  my_ulonglong n_rows;
  MYSQL_DATA *data= thd->first_data;

  DBUG_ENTER("emb_store_querycache_result");

  while (data->embedded_info->next)
    data= data->embedded_info->next;
  field= data->embedded_info->fields_list;
  field_end= field + data->fields;

  if (!field)
    return;
    DBUG_VOID_RETURN;

  if (thd->data)
  {
    *thd->data->prev_ptr= NULL; // this marks the last record
    cur_row= thd->data->data;
    n_rows= thd->data->rows;
  }
  *data->embedded_info->prev_ptr= NULL; // this marks the last record
  cur_row= data->data;
  n_rows= data->rows;

  dst->store_int((uint)mysql->field_count);
  dst->store_ll((uint)n_rows);
  dst->store_int((uint)data->fields);
  dst->store_ll((ulonglong)n_rows);

  for(; field < field_end; field++)
  {
@@ -356,14 +364,13 @@ void emb_store_querycache_result(Querycache_stream *dst, THD *thd)
    dst->store_str(field->org_table, field->org_table_length);
    dst->store_str(field->db, field->db_length);
    dst->store_str(field->catalog, field->catalog_length);

    dst->store_safe_str(field->def, field->def_length);
  }
  
  for (; cur_row; cur_row=cur_row->next)
  {
    MYSQL_ROW col= cur_row->data;
    MYSQL_ROW col_end= col + mysql->field_count;
    MYSQL_ROW col_end= col + data->fields;
    for (; col < col_end; col++)
    {
      uint len= *col ? *(uint *)((*col) - sizeof(uint)) : 0;
@@ -371,28 +378,34 @@ void emb_store_querycache_result(Querycache_stream *dst, THD *thd)
    }
  }
  DBUG_ASSERT(emb_count_querycache_size(thd) == dst->stored_size);
  DBUG_VOID_RETURN;
}

int emb_load_querycache_result(THD *thd, Querycache_stream *src)
{
  MYSQL *mysql= thd->mysql;
  MYSQL_DATA *data;
  MYSQL_DATA *data= thd->alloc_new_dataset();
  MYSQL_FIELD *field;
  MYSQL_FIELD *field_end;
  MEM_ROOT *f_alloc= &mysql->field_alloc;
  MEM_ROOT *f_alloc;
  MYSQL_ROWS *row, *end_row;
  MYSQL_ROWS **prev_row;
  ulonglong rows;
  MYSQL_ROW columns;
  DBUG_ENTER("emb_load_querycache_result");

  mysql->field_count= src->load_int();
  if (!data)
    goto err;
  init_alloc_root(&data->alloc, 8192,0);
  f_alloc= &data->alloc;

  data->fields= src->load_int();
  rows= src->load_ll();

  if (!(field= (MYSQL_FIELD *)
	alloc_root(&mysql->field_alloc,mysql->field_count*sizeof(MYSQL_FIELD))))
        alloc_root(f_alloc,data->fields*sizeof(MYSQL_FIELD))))
    goto err;
  mysql->fields= field;
  for(field_end= field+mysql->field_count; field < field_end; field++)
  data->embedded_info->fields_list= field;
  for(field_end= field+data->fields; field < field_end; field++)
  {
    field->length= src->load_int();
    field->max_length= (unsigned int)src->load_int();
@@ -411,38 +424,34 @@ int emb_load_querycache_result(THD *thd, Querycache_stream *src)
      goto err;
  }
  
  if (!rows)
    return 0;
  if (!(data= (MYSQL_DATA*)my_malloc(sizeof(MYSQL_DATA), 
				     MYF(MY_WME | MY_ZEROFILL))))
    goto err;
  thd->data= data;
  init_alloc_root(&data->alloc, 8192,0);
  row= (MYSQL_ROWS *)alloc_root(&data->alloc, (uint) (rows * sizeof(MYSQL_ROWS) +
				rows * (mysql->field_count+1)*sizeof(char*)));
  row= (MYSQL_ROWS *)alloc_root(&data->alloc,
                                (uint) (rows * sizeof(MYSQL_ROWS) +
                                        rows*(data->fields+1)*sizeof(char*)));
  end_row= row + rows;
  columns= (MYSQL_ROW)end_row;
  
  data->rows= rows;
  data->fields= mysql->field_count;
  data->data= row;
  if (!rows)
    goto return_ok;

  for (prev_row= &row->next; row < end_row; prev_row= &row->next, row++)
  {
    *prev_row= row;
    row->data= columns;
    MYSQL_ROW col_end= columns + mysql->field_count;
    MYSQL_ROW col_end= columns + data->fields;
    for (; columns < col_end; columns++)
      src->load_column(&data->alloc, columns);

    *(columns++)= NULL;
  }
  *prev_row= NULL;
  data->prev_ptr= prev_row;

  return 0;
  data->embedded_info->prev_ptr= prev_row;
return_ok:
  send_eof(thd);
  DBUG_RETURN(0);
err:
  return 1;
  DBUG_RETURN(1);
}

#endif /*HAVE_QUERY_CACHE*/
+14 −7
Original line number Diff line number Diff line
@@ -16,18 +16,25 @@

/* Prototypes for the embedded version of MySQL */

#include <my_global.h>
#include <mysql.h>
#include <mysql_embed.h>
#include <mysqld_error.h>
#include <my_pthread.h>

C_MODE_START
void lib_connection_phase(NET *net, int phase);
void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
void *create_embedded_thd(int client_flag, char *db);
int check_embedded_connection(MYSQL *mysql);
void free_old_query(MYSQL *mysql);
void embedded_get_error(MYSQL *mysql);
extern MYSQL_METHODS embedded_methods;

/* This one is used by embedded library to gather returning data */
typedef struct embedded_query_result
{
  MYSQL_ROWS **prev_ptr;
  unsigned int warning_count, server_status;
  struct st_mysql_data *next;
  my_ulonglong affected_rows, insert_id;
  char info[MYSQL_ERRMSG_SIZE];
  MYSQL_FIELD *fields_list;
  unsigned int last_errno;
  char sqlstate[SQLSTATE_LENGTH+1];
} EQR;

C_MODE_END
+367 −145

File changed.

Preview size limit exceeded, changes collapsed.

Loading