~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
/* Match the values of enum ha_choice */
33
33
static const char *ha_choice_values[] = {"", "0", "1"};
34
34
 
35
 
static void store_key_options(Session *thd, String *packet, Table *table,
 
35
static void store_key_options(Session *session, String *packet, Table *table,
36
36
                              KEY *key_info);
37
37
 
38
38
 
87
87
** List all table types supported
88
88
***************************************************************************/
89
89
 
90
 
static bool show_plugins(Session *thd, plugin_ref plugin,
 
90
static bool show_plugins(Session *session, plugin_ref plugin,
91
91
                            void *arg)
92
92
{
93
93
  Table *table= (Table*) arg;
169
169
  }
170
170
  table->field[7]->set_notnull();
171
171
 
172
 
  return schema_table_store_record(thd, table);
 
172
  return schema_table_store_record(session, table);
173
173
}
174
174
 
175
175
 
176
 
int fill_plugins(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
176
int fill_plugins(Session *session, TableList *tables, COND *cond __attribute__((unused)))
177
177
{
178
178
  Table *table= tables->table;
179
179
 
180
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
180
  if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
181
181
                               ~PLUGIN_IS_FREED, table))
182
182
    return(1);
183
183
 
190
190
 
191
191
  SYNOPSIS
192
192
    find_files()
193
 
    thd                 thread handler
 
193
    session                 thread handler
194
194
    files               put found files in this list
195
195
    db                  database name to set in TableList structure
196
196
    path                path to database
206
206
 
207
207
 
208
208
find_files_result
209
 
find_files(Session *thd, List<LEX_STRING> *files, const char *db,
 
209
find_files(Session *session, List<LEX_STRING> *files, const char *db,
210
210
           const char *path, const char *wild, bool dir)
211
211
{
212
212
  uint32_t i;
264
264
      if (wild && wild_compare(uname, wild, 0))
265
265
        continue;
266
266
      if (!(file_name= 
267
 
            thd->make_lex_string(file_name, uname, file_name_len, true)))
 
267
            session->make_lex_string(file_name, uname, file_name_len, true)))
268
268
      {
269
269
        my_dirend(dirp);
270
270
        return(FIND_FILES_OOM);
290
290
      }
291
291
    }
292
292
    if (!(file_name= 
293
 
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
 
293
          session->make_lex_string(file_name, uname, file_name_len, true)) ||
294
294
        files->push_back(file_name))
295
295
    {
296
296
      my_dirend(dirp);
304
304
 
305
305
 
306
306
bool
307
 
mysqld_show_create(Session *thd, TableList *table_list)
 
307
mysqld_show_create(Session *session, TableList *table_list)
308
308
{
309
 
  Protocol *protocol= thd->protocol;
 
309
  Protocol *protocol= session->protocol;
310
310
  char buff[2048];
311
311
  String buffer(buff, sizeof(buff), system_charset_info);
312
312
 
313
313
  /* Only one table for now, but VIEW can involve several tables */
314
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
314
  if (open_normal_and_derived_tables(session, table_list, 0))
315
315
  {
316
 
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
 
316
    if (session->is_error() && session->main_da.sql_errno() != ER_VIEW_INVALID)
317
317
      return(true);
318
318
 
319
319
    /*
321
321
      issue a warning with 'warning' level status in 
322
322
      case of invalid view and last error is ER_VIEW_INVALID
323
323
    */
324
 
    drizzle_reset_errors(thd, true);
325
 
    thd->clear_error();
 
324
    drizzle_reset_errors(session, true);
 
325
    session->clear_error();
326
326
  }
327
327
 
328
328
  buffer.length(0);
329
329
 
330
 
  if (store_create_info(thd, table_list, &buffer, NULL))
 
330
  if (store_create_info(session, table_list, &buffer, NULL))
331
331
    return(true);
332
332
 
333
333
  List<Item> field_list;
355
355
  if (protocol->write())
356
356
    return(true);
357
357
 
358
 
  my_eof(thd);
 
358
  my_eof(session);
359
359
  return(false);
360
360
}
361
361
 
362
 
bool mysqld_show_create_db(Session *thd, char *dbname,
 
362
bool mysqld_show_create_db(Session *session, char *dbname,
363
363
                           HA_CREATE_INFO *create_info)
364
364
{
365
365
  char buff[2048];
366
366
  String buffer(buff, sizeof(buff), system_charset_info);
367
 
  Protocol *protocol=thd->protocol;
 
367
  Protocol *protocol=session->protocol;
368
368
 
369
 
  if (store_db_create_info(thd, dbname, &buffer, create_info))
 
369
  if (store_db_create_info(session, dbname, &buffer, create_info))
370
370
  {
371
371
    /* 
372
372
      This assumes that the only reason for which store_db_create_info()
390
390
 
391
391
  if (protocol->write())
392
392
    return(true);
393
 
  my_eof(thd);
 
393
  my_eof(session);
394
394
  return(false);
395
395
}
396
396
 
402
402
****************************************************************************/
403
403
 
404
404
void
405
 
mysqld_list_fields(Session *thd, TableList *table_list, const char *wild)
 
405
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
406
406
{
407
407
  Table *table;
408
408
 
409
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
409
  if (open_normal_and_derived_tables(session, table_list, 0))
410
410
    return;
411
411
  table= table_list->table;
412
412
 
423
423
  }
424
424
  restore_record(table, s->default_values);              // Get empty record
425
425
  table->use_all_columns();
426
 
  if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
 
426
  if (session->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
427
427
    return;
428
 
  my_eof(thd);
 
428
  my_eof(session);
429
429
  return;
430
430
}
431
431
 
471
471
 
472
472
  SYNOPSIS
473
473
  append_identifier()
474
 
  thd                   thread handler
 
474
  session                   thread handler
475
475
  packet                target string
476
476
  name                  the identifier to be appended
477
477
  name_length           length of the appending identifier
478
478
*/
479
479
 
480
480
void
481
 
append_identifier(Session *thd, String *packet, const char *name, uint32_t length)
 
481
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
482
482
{
483
483
  const char *name_end;
484
484
  char quote_char;
485
 
  int q= get_quote_char_for_identifier(thd, name, length);
 
485
  int q= get_quote_char_for_identifier(session, name, length);
486
486
 
487
487
  if (q == EOF)
488
488
  {
525
525
 
526
526
  SYNOPSIS
527
527
    get_quote_char_for_identifier()
528
 
    thd         Thread handler
 
528
    session             Thread handler
529
529
    name        name to quote
530
530
    length      length of name
531
531
 
543
543
    #     Quote character
544
544
*/
545
545
 
546
 
int get_quote_char_for_identifier(Session *thd, const char *name, uint32_t length)
 
546
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
547
547
{
548
548
  if (length &&
549
549
      !is_keyword(name,length) &&
550
550
      !require_quotes(name, length) &&
551
 
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
 
551
      !(session->options & OPTION_QUOTE_SHOW_CREATE))
552
552
    return EOF;
553
553
  return '`';
554
554
}
556
556
 
557
557
/* Append directory name (if exists) to CREATE INFO */
558
558
 
559
 
static void append_directory(Session *thd __attribute__((unused)),
 
559
static void append_directory(Session *session __attribute__((unused)),
560
560
                             String *packet, const char *dir_type,
561
561
                             const char *filename)
562
562
{
574
574
 
575
575
#define LIST_PROCESS_HOST_LEN 64
576
576
 
577
 
static bool get_field_default_value(Session *thd __attribute__((unused)),
 
577
static bool get_field_default_value(Session *session __attribute__((unused)),
578
578
                                    Field *timestamp_field,
579
579
                                    Field *field, String *def_value,
580
580
                                    bool quoted)
633
633
 
634
634
  SYNOPSIS
635
635
    store_create_info()
636
 
    thd               The thread
 
636
    session               The thread
637
637
    table_list        A list containing one table to write statement
638
638
                      for.
639
639
    packet            Pointer to a string where statement will be
651
651
    0       OK
652
652
 */
653
653
 
654
 
int store_create_info(Session *thd, TableList *table_list, String *packet,
 
654
int store_create_info(Session *session, TableList *table_list, String *packet,
655
655
                      HA_CREATE_INFO *create_info_arg)
656
656
{
657
657
  List<Item> field_list;
690
690
      alias= share->table_name.str;
691
691
    }
692
692
  }
693
 
  append_identifier(thd, packet, alias, strlen(alias));
 
693
  append_identifier(session, packet, alias, strlen(alias));
694
694
  packet->append(STRING_WITH_LEN(" (\n"));
695
695
  /*
696
696
    We need this to get default values from the table
707
707
      packet->append(STRING_WITH_LEN(",\n"));
708
708
 
709
709
    packet->append(STRING_WITH_LEN("  "));
710
 
    append_identifier(thd,packet,field->field_name, strlen(field->field_name));
 
710
    append_identifier(session,packet,field->field_name, strlen(field->field_name));
711
711
    packet->append(' ');
712
712
    // check for surprises from the previous call to Field::sql_type()
713
713
    if (type.ptr() != tmp)
781
781
      }
782
782
    }
783
783
    if (!field->vcol_info &&
784
 
        get_field_default_value(thd, table->timestamp_field,
 
784
        get_field_default_value(session, table->timestamp_field,
785
785
                                field, &def_value, 1))
786
786
    {
787
787
      packet->append(STRING_WITH_LEN(" DEFAULT "));
829
829
      packet->append(STRING_WITH_LEN("KEY "));
830
830
 
831
831
    if (!found_primary)
832
 
     append_identifier(thd, packet, key_info->name, strlen(key_info->name));
 
832
     append_identifier(session, packet, key_info->name, strlen(key_info->name));
833
833
 
834
834
    packet->append(STRING_WITH_LEN(" ("));
835
835
 
839
839
        packet->append(',');
840
840
 
841
841
      if (key_part->field)
842
 
        append_identifier(thd,packet,key_part->field->field_name,
 
842
        append_identifier(session,packet,key_part->field->field_name,
843
843
                          strlen(key_part->field->field_name));
844
844
      if (key_part->field &&
845
845
          (key_part->length !=
853
853
      }
854
854
    }
855
855
    packet->append(')');
856
 
    store_key_options(thd, packet, table, key_info);
 
856
    store_key_options(session, packet, table, key_info);
857
857
  }
858
858
 
859
859
  /*
972
972
      packet->append(STRING_WITH_LEN(" CONNECTION="));
973
973
      append_unescaped(packet, share->connect_string.str, share->connect_string.length);
974
974
    }
975
 
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
976
 
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
 
975
    append_directory(session, packet, "DATA",  create_info.data_file_name);
 
976
    append_directory(session, packet, "INDEX", create_info.index_file_name);
977
977
  }
978
978
  table->restore_column_map(old_map);
979
979
  return(0);
992
992
  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
993
993
  in @c create_options are ignored.
994
994
 
995
 
  @param  thd           The current thread instance.
 
995
  @param  session           The current thread instance.
996
996
  @param  dbname        The name of the database.
997
997
  @param  buffer        A String instance where the statement is stored.
998
998
  @param  create_info   If not NULL, the options member influences the resulting 
1001
1001
  @returns true if errors are detected, false otherwise.
1002
1002
*/
1003
1003
 
1004
 
bool store_db_create_info(Session *thd, const char *dbname, String *buffer,
 
1004
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
1005
1005
                          HA_CREATE_INFO *create_info)
1006
1006
{
1007
1007
  HA_CREATE_INFO create;
1018
1018
    if (check_db_dir_existence(dbname))
1019
1019
      return(true);
1020
1020
 
1021
 
    load_db_opt_by_name(thd, dbname, &create);
 
1021
    load_db_opt_by_name(session, dbname, &create);
1022
1022
  }
1023
1023
 
1024
1024
  buffer->length(0);
1029
1029
  if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1030
1030
    buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1031
1031
 
1032
 
  append_identifier(thd, buffer, dbname, strlen(dbname));
 
1032
  append_identifier(session, buffer, dbname, strlen(dbname));
1033
1033
 
1034
1034
  if (create.default_table_charset)
1035
1035
  {
1047
1047
  return(false);
1048
1048
}
1049
1049
 
1050
 
static void store_key_options(Session *thd __attribute__((unused)),
 
1050
static void store_key_options(Session *session __attribute__((unused)),
1051
1051
                              String *packet, Table *table,
1052
1052
                              KEY *key_info)
1053
1053
{
1104
1104
template class I_List<thread_info>;
1105
1105
#endif
1106
1106
 
1107
 
void mysqld_list_processes(Session *thd,const char *user, bool verbose)
 
1107
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1108
1108
{
1109
1109
  Item *field;
1110
1110
  List<Item> field_list;
1111
1111
  I_List<thread_info> thread_infos;
1112
 
  ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
 
1112
  ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1113
1113
                           PROCESS_LIST_WIDTH);
1114
 
  Protocol *protocol= thd->protocol;
 
1114
  Protocol *protocol= session->protocol;
1115
1115
 
1116
1116
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1117
1117
  field_list.push_back(new Item_empty_string("User",16));
1129
1129
    return;
1130
1130
 
1131
1131
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1132
 
  if (!thd->killed)
 
1132
  if (!session->killed)
1133
1133
  {
1134
1134
    I_List_iterator<Session> it(threads);
1135
1135
    Session *tmp;
1139
1139
      struct st_my_thread_var *mysys_var;
1140
1140
      if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1141
1141
      {
1142
 
        thread_info *thd_info= new thread_info;
 
1142
        thread_info *session_info= new thread_info;
1143
1143
 
1144
 
        thd_info->thread_id=tmp->thread_id;
1145
 
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
 
1144
        session_info->thread_id=tmp->thread_id;
 
1145
        session_info->user= session->strdup(tmp_sctx->user ? tmp_sctx->user :
1146
1146
                                    (tmp->system_thread ?
1147
1147
                                     "system user" : "unauthenticated user"));
1148
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
1149
 
        if ((thd_info->db=tmp->db))             // Safe test
1150
 
          thd_info->db=thd->strdup(thd_info->db);
1151
 
        thd_info->command=(int) tmp->command;
 
1148
        session_info->host= session->strdup(tmp_sctx->ip);
 
1149
        if ((session_info->db=tmp->db))             // Safe test
 
1150
          session_info->db=session->strdup(session_info->db);
 
1151
        session_info->command=(int) tmp->command;
1152
1152
        if ((mysys_var= tmp->mysys_var))
1153
1153
          pthread_mutex_lock(&mysys_var->mutex);
1154
 
        thd_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1155
 
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
 
1154
        session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
 
1155
        session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1156
1156
                                       (tmp->net.reading_or_writing == 2 ?
1157
1157
                                        "Writing to net" :
1158
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1158
                                        session_info->command == COM_SLEEP ? NULL :
1159
1159
                                        "Reading from net") :
1160
1160
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
1161
1161
                                       tmp->mysys_var &&
1164
1164
        if (mysys_var)
1165
1165
          pthread_mutex_unlock(&mysys_var->mutex);
1166
1166
 
1167
 
        thd_info->start_time= tmp->start_time;
1168
 
        thd_info->query=0;
 
1167
        session_info->start_time= tmp->start_time;
 
1168
        session_info->query=0;
1169
1169
        if (tmp->query)
1170
1170
        {
1171
1171
          /* 
1174
1174
            races with query_length
1175
1175
          */
1176
1176
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1177
 
          thd_info->query=(char*) thd->strmake(tmp->query,length);
 
1177
          session_info->query=(char*) session->strmake(tmp->query,length);
1178
1178
        }
1179
 
        thread_infos.append(thd_info);
 
1179
        thread_infos.append(session_info);
1180
1180
      }
1181
1181
    }
1182
1182
  }
1183
1183
  pthread_mutex_unlock(&LOCK_thread_count);
1184
1184
 
1185
 
  thread_info *thd_info;
 
1185
  thread_info *session_info;
1186
1186
  time_t now= my_time(0);
1187
 
  while ((thd_info=thread_infos.get()))
 
1187
  while ((session_info=thread_infos.get()))
1188
1188
  {
1189
1189
    protocol->prepare_for_resend();
1190
 
    protocol->store((uint64_t) thd_info->thread_id);
1191
 
    protocol->store(thd_info->user, system_charset_info);
1192
 
    protocol->store(thd_info->host, system_charset_info);
1193
 
    protocol->store(thd_info->db, system_charset_info);
1194
 
    if (thd_info->proc_info)
1195
 
      protocol->store(thd_info->proc_info, system_charset_info);
 
1190
    protocol->store((uint64_t) session_info->thread_id);
 
1191
    protocol->store(session_info->user, system_charset_info);
 
1192
    protocol->store(session_info->host, system_charset_info);
 
1193
    protocol->store(session_info->db, system_charset_info);
 
1194
    if (session_info->proc_info)
 
1195
      protocol->store(session_info->proc_info, system_charset_info);
1196
1196
    else
1197
 
      protocol->store(command_name[thd_info->command].str, system_charset_info);
1198
 
    if (thd_info->start_time)
1199
 
      protocol->store((uint32_t) (now - thd_info->start_time));
 
1197
      protocol->store(command_name[session_info->command].str, system_charset_info);
 
1198
    if (session_info->start_time)
 
1199
      protocol->store((uint32_t) (now - session_info->start_time));
1200
1200
    else
1201
1201
      protocol->store_null();
1202
 
    protocol->store(thd_info->state_info, system_charset_info);
1203
 
    protocol->store(thd_info->query, system_charset_info);
 
1202
    protocol->store(session_info->state_info, system_charset_info);
 
1203
    protocol->store(session_info->query, system_charset_info);
1204
1204
    if (protocol->write())
1205
1205
      break; /* purecov: inspected */
1206
1206
  }
1207
 
  my_eof(thd);
 
1207
  my_eof(session);
1208
1208
  return;
1209
1209
}
1210
1210
 
1211
 
int fill_schema_processlist(Session* thd, TableList* tables,
 
1211
int fill_schema_processlist(Session* session, TableList* tables,
1212
1212
                            COND* cond __attribute__((unused)))
1213
1213
{
1214
1214
  Table *table= tables->table;
1220
1220
 
1221
1221
  pthread_mutex_lock(&LOCK_thread_count);
1222
1222
 
1223
 
  if (!thd->killed)
 
1223
  if (!session->killed)
1224
1224
  {
1225
1225
    I_List_iterator<Session> it(threads);
1226
1226
    Session* tmp;
1289
1289
        table->field[7]->set_notnull();
1290
1290
      }
1291
1291
 
1292
 
      if (schema_table_store_record(thd, table))
 
1292
      if (schema_table_store_record(session, table))
1293
1293
      {
1294
1294
        pthread_mutex_unlock(&LOCK_thread_count);
1295
1295
        return(1);
1480
1480
    *buf= my_toupper(system_charset_info, *buf);
1481
1481
}
1482
1482
 
1483
 
static bool show_status_array(Session *thd, const char *wild,
 
1483
static bool show_status_array(Session *session, const char *wild,
1484
1484
                              SHOW_VAR *variables,
1485
1485
                              enum enum_var_type value_type,
1486
1486
                              struct system_status_var *status_var,
1516
1516
      Repeat as necessary, if new var is again SHOW_FUNC
1517
1517
    */
1518
1518
    for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1519
 
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
 
1519
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1520
1520
 
1521
1521
    SHOW_TYPE show_type=var->type;
1522
1522
    if (show_type == SHOW_ARRAY)
1523
1523
    {
1524
 
      show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
 
1524
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1525
1525
                        status_var, name_buffer, table, ucase_names);
1526
1526
    }
1527
1527
    else
1537
1537
        if (show_type == SHOW_SYS)
1538
1538
        {
1539
1539
          show_type= ((sys_var*) value)->show_type();
1540
 
          value=     (char*) ((sys_var*) value)->value_ptr(thd, value_type,
 
1540
          value=     (char*) ((sys_var*) value)->value_ptr(session, value_type,
1541
1541
                                                           &null_lex_str);
1542
1542
        }
1543
1543
 
1623
1623
 
1624
1624
        pthread_mutex_unlock(&LOCK_global_system_variables);
1625
1625
 
1626
 
        if (schema_table_store_record(thd, table))
 
1626
        if (schema_table_store_record(session, table))
1627
1627
          return(true);
1628
1628
      }
1629
1629
    }
1672
1672
 
1673
1673
  SYNOPSIS
1674
1674
    schema_table_store_record()
1675
 
    thd                   thread handler
 
1675
    session                   thread handler
1676
1676
    table                 Information schema table to be updated
1677
1677
 
1678
1678
  RETURN
1680
1680
    1                     error
1681
1681
*/
1682
1682
 
1683
 
bool schema_table_store_record(Session *thd, Table *table)
 
1683
bool schema_table_store_record(Session *session, Table *table)
1684
1684
{
1685
1685
  int error;
1686
1686
  if ((error= table->file->ha_write_row(table->record[0])))
1687
1687
  {
1688
1688
    TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1689
1689
 
1690
 
    if (create_myisam_from_heap(thd, table, param->start_recinfo, 
 
1690
    if (create_myisam_from_heap(session, table, param->start_recinfo, 
1691
1691
                                &param->recinfo, error, 0))
1692
1692
      return 1;
1693
1693
  }
1695
1695
}
1696
1696
 
1697
1697
 
1698
 
int make_table_list(Session *thd, SELECT_LEX *sel,
 
1698
int make_table_list(Session *session, SELECT_LEX *sel,
1699
1699
                    LEX_STRING *db_name, LEX_STRING *table_name)
1700
1700
{
1701
1701
  Table_ident *table_ident;
1702
 
  table_ident= new Table_ident(thd, *db_name, *table_name, 1);
 
1702
  table_ident= new Table_ident(session, *db_name, *table_name, 1);
1703
1703
  sel->init_query();
1704
 
  if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
 
1704
  if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1705
1705
    return 1;
1706
1706
  return 0;
1707
1707
}
1715
1715
           fill appropriate lookup_field_vals struct field
1716
1716
           with this value.
1717
1717
 
1718
 
  @param[in]      thd                   thread handler
 
1718
  @param[in]      session                   thread handler
1719
1719
  @param[in]      item_func             part of WHERE condition
1720
1720
  @param[in]      table                 I_S table
1721
1721
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
1725
1725
    1             error, there can be no matching records for the condition
1726
1726
*/
1727
1727
 
1728
 
bool get_lookup_value(Session *thd, Item_func *item_func,
 
1728
bool get_lookup_value(Session *session, Item_func *item_func,
1729
1729
                      TableList *table, 
1730
1730
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1731
1731
{
1774
1774
                               (unsigned char *) item_field->field_name,
1775
1775
                               strlen(item_field->field_name), 0))
1776
1776
    {
1777
 
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
 
1777
      session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1778
1778
                           tmp_str->length(), false);
1779
1779
    }
1780
1780
    /* Lookup value is table name */
1783
1783
                                    (unsigned char *) item_field->field_name,
1784
1784
                                    strlen(item_field->field_name), 0))
1785
1785
    {
1786
 
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
 
1786
      session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1787
1787
                           tmp_str->length(), false);
1788
1788
    }
1789
1789
  }
1798
1798
           from 'WHERE' condition if it's possible and 
1799
1799
           fill lookup_field_vals struct fields with these values.
1800
1800
 
1801
 
  @param[in]      thd                   thread handler
 
1801
  @param[in]      session                   thread handler
1802
1802
  @param[in]      cond                  WHERE condition
1803
1803
  @param[in]      table                 I_S table
1804
1804
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
1808
1808
    1             error, there can be no matching records for the condition
1809
1809
*/
1810
1810
 
1811
 
bool calc_lookup_values_from_cond(Session *thd, COND *cond, TableList *table,
 
1811
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1812
1812
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1813
1813
{
1814
1814
  if (!cond)
1824
1824
      {
1825
1825
        if (item->type() == Item::FUNC_ITEM)
1826
1826
        {
1827
 
          if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
 
1827
          if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1828
1828
            return 1;
1829
1829
        }
1830
1830
        else
1831
1831
        {
1832
 
          if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
 
1832
          if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1833
1833
            return 1;
1834
1834
        }
1835
1835
      }
1837
1837
    return 0;
1838
1838
  }
1839
1839
  else if (cond->type() == Item::FUNC_ITEM &&
1840
 
           get_lookup_value(thd, (Item_func*) cond, table, lookup_field_vals))
 
1840
           get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals))
1841
1841
    return 1;
1842
1842
  return 0;
1843
1843
}
1947
1947
           from LEX struct and fill lookup_field_vals struct field
1948
1948
           with these values.
1949
1949
 
1950
 
  @param[in]      thd                   thread handler
 
1950
  @param[in]      session                   thread handler
1951
1951
  @param[in]      cond                  WHERE condition
1952
1952
  @param[in]      tables                I_S table
1953
1953
  @param[in, out] lookup_field_values   Struct which holds lookup values 
1957
1957
    1             error, there can be no matching records for the condition
1958
1958
*/
1959
1959
 
1960
 
bool get_lookup_field_values(Session *thd, COND *cond, TableList *tables,
 
1960
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1961
1961
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1962
1962
{
1963
 
  LEX *lex= thd->lex;
 
1963
  LEX *lex= session->lex;
1964
1964
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1965
1965
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1966
1966
  switch (lex->sql_command) {
1988
1988
      The "default" is for queries over I_S.
1989
1989
      All previous cases handle SHOW commands.
1990
1990
    */
1991
 
    return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
 
1991
    return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
1992
1992
  }
1993
1993
}
1994
1994
 
2004
2004
 
2005
2005
  SYNOPSIS
2006
2006
    make_db_list()
2007
 
    thd                   thread handler
 
2007
    session                   thread handler
2008
2008
    files                 list of db names
2009
2009
    wild                  wild string
2010
2010
    idx_field_vals        idx_field_vals->db_name contains db name or
2017
2017
    non-zero              error
2018
2018
*/
2019
2019
 
2020
 
int make_db_list(Session *thd, List<LEX_STRING> *files,
 
2020
int make_db_list(Session *session, List<LEX_STRING> *files,
2021
2021
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
2022
2022
                 bool *with_i_schema)
2023
2023
{
2024
2024
  LEX_STRING *i_s_name_copy= 0;
2025
 
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
 
2025
  i_s_name_copy= session->make_lex_string(i_s_name_copy,
2026
2026
                                      INFORMATION_SCHEMA_NAME.str,
2027
2027
                                      INFORMATION_SCHEMA_NAME.length, true);
2028
2028
  *with_i_schema= 0;
2042
2042
      if (files->push_back(i_s_name_copy))
2043
2043
        return 1;
2044
2044
    }
2045
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
2045
    return (find_files(session, files, NULL, mysql_data_home,
2046
2046
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2047
2047
  }
2048
2048
 
2073
2073
  if (files->push_back(i_s_name_copy))
2074
2074
    return 1;
2075
2075
  *with_i_schema= 1;
2076
 
  return (find_files(thd, files, NULL,
 
2076
  return (find_files(session, files, NULL,
2077
2077
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
2078
2078
}
2079
2079
 
2085
2085
};
2086
2086
 
2087
2087
 
2088
 
static bool add_schema_table(Session *thd, plugin_ref plugin,
 
2088
static bool add_schema_table(Session *session, plugin_ref plugin,
2089
2089
                                void* p_data)
2090
2090
{
2091
2091
  LEX_STRING *file_name= 0;
2109
2109
      return(0);
2110
2110
  }
2111
2111
 
2112
 
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
 
2112
  if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2113
2113
                                       strlen(schema_table->table_name),
2114
2114
                                       true)) &&
2115
2115
      !file_list->push_back(file_name))
2118
2118
}
2119
2119
 
2120
2120
 
2121
 
int schema_tables_add(Session *thd, List<LEX_STRING> *files, const char *wild)
 
2121
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2122
2122
{
2123
2123
  LEX_STRING *file_name= 0;
2124
2124
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2141
2141
        continue;
2142
2142
    }
2143
2143
    if ((file_name= 
2144
 
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
 
2144
         session->make_lex_string(file_name, tmp_schema_table->table_name,
2145
2145
                              strlen(tmp_schema_table->table_name), true)) &&
2146
2146
        !files->push_back(file_name))
2147
2147
      continue;
2150
2150
 
2151
2151
  add_data.files= files;
2152
2152
  add_data.wild= wild;
2153
 
  if (plugin_foreach(thd, add_schema_table,
 
2153
  if (plugin_foreach(session, add_schema_table,
2154
2154
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2155
2155
    return(1);
2156
2156
 
2164
2164
  @details        The function creates the list of table names in
2165
2165
                  database
2166
2166
 
2167
 
  @param[in]      thd                   thread handler
 
2167
  @param[in]      session                   thread handler
2168
2168
  @param[in]      table_names           List of table names in database
2169
2169
  @param[in]      lex                   pointer to LEX struct
2170
2170
  @param[in]      lookup_field_vals     pointer to LOOKUP_FIELD_VALUE struct
2178
2178
*/
2179
2179
 
2180
2180
static int
2181
 
make_table_name_list(Session *thd, List<LEX_STRING> *table_names, LEX *lex,
 
2181
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2182
2182
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
2183
2183
                     bool with_i_schema, LEX_STRING *db_name)
2184
2184
{
2189
2189
  {
2190
2190
    if (with_i_schema)
2191
2191
    {
2192
 
      if (find_schema_table(thd, lookup_field_vals->table_value.str))
 
2192
      if (find_schema_table(session, lookup_field_vals->table_value.str))
2193
2193
      {
2194
2194
        if (table_names->push_back(&lookup_field_vals->table_value))
2195
2195
          return 1;
2208
2208
    to the list
2209
2209
  */
2210
2210
  if (with_i_schema)
2211
 
    return (schema_tables_add(thd, table_names,
 
2211
    return (schema_tables_add(session, table_names,
2212
2212
                              lookup_field_vals->table_value.str));
2213
2213
 
2214
 
  find_files_result res= find_files(thd, table_names, db_name->str, path,
 
2214
  find_files_result res= find_files(session, table_names, db_name->str, path,
2215
2215
                                    lookup_field_vals->table_value.str, 0);
2216
2216
  if (res != FIND_FILES_OK)
2217
2217
  {
2225
2225
    {
2226
2226
      if (lex->sql_command != SQLCOM_SELECT)
2227
2227
        return 1;
2228
 
      thd->clear_error();
 
2228
      session->clear_error();
2229
2229
      return 2;
2230
2230
    }
2231
2231
    return 1;
2237
2237
/**
2238
2238
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2239
2239
 
2240
 
  @param[in]      thd                      thread handler
 
2240
  @param[in]      session                      thread handler
2241
2241
  @param[in]      tables                   TableList for I_S table
2242
2242
  @param[in]      schema_table             pointer to I_S structure
2243
2243
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2251
2251
*/
2252
2252
 
2253
2253
static int 
2254
 
fill_schema_show_cols_or_idxs(Session *thd, TableList *tables,
 
2254
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2255
2255
                              ST_SCHEMA_TABLE *schema_table,
2256
2256
                              Open_tables_state *open_tables_state_backup)
2257
2257
{
2258
 
  LEX *lex= thd->lex;
 
2258
  LEX *lex= session->lex;
2259
2259
  bool res;
2260
2260
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2261
2261
  enum_sql_command save_sql_command= lex->sql_command;
2266
2266
 
2267
2267
  lex->all_selects_list= tables->schema_select_lex;
2268
2268
  /*
2269
 
    Restore thd->temporary_tables to be able to process
 
2269
    Restore session->temporary_tables to be able to process
2270
2270
    temporary tables(only for 'show index' & 'show columns').
2271
2271
    This should be changed when processing of temporary tables for
2272
2272
    I_S tables will be done.
2273
2273
  */
2274
 
  thd->temporary_tables= open_tables_state_backup->temporary_tables;
 
2274
  session->temporary_tables= open_tables_state_backup->temporary_tables;
2275
2275
  /*
2276
2276
    Let us set fake sql_command so views won't try to merge
2277
2277
    themselves into main statement. If we don't do this,
2279
2279
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()' 
2280
2280
  */
2281
2281
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2282
 
  res= open_normal_and_derived_tables(thd, show_table_list,
 
2282
  res= open_normal_and_derived_tables(session, show_table_list,
2283
2283
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
2284
2284
  lex->sql_command= save_sql_command;
2285
2285
  /*
2293
2293
    in this case(this part of code is used only for 
2294
2294
    'show columns' & 'show statistics' commands).
2295
2295
  */
2296
 
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
 
2296
   table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2297
2297
                                    strlen(show_table_list->alias), false);
2298
 
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
 
2298
   db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2299
2299
                                 show_table_list->db_length, false);
2300
2300
      
2301
2301
 
2302
 
   error= test(schema_table->process_table(thd, show_table_list,
 
2302
   error= test(schema_table->process_table(session, show_table_list,
2303
2303
                                           table, res, db_name,
2304
2304
                                           table_name));
2305
 
   thd->temporary_tables= 0;
2306
 
   close_tables_for_reopen(thd, &show_table_list);
 
2305
   session->temporary_tables= 0;
 
2306
   close_tables_for_reopen(session, &show_table_list);
2307
2307
   return(error);
2308
2308
}
2309
2309
 
2311
2311
/**
2312
2312
  @brief          Fill I_S table for SHOW Table NAMES commands
2313
2313
 
2314
 
  @param[in]      thd                      thread handler
 
2314
  @param[in]      session                      thread handler
2315
2315
  @param[in]      table                    Table struct for I_S table
2316
2316
  @param[in]      db_name                  database name
2317
2317
  @param[in]      table_name               table name
2322
2322
    @retval       1           error
2323
2323
*/
2324
2324
 
2325
 
static int fill_schema_table_names(Session *thd, Table *table,
 
2325
static int fill_schema_table_names(Session *session, Table *table,
2326
2326
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2327
2327
                                   bool with_i_schema)
2328
2328
{
2337
2337
    char path[FN_REFLEN];
2338
2338
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2339
2339
                                table_name->str, reg_ext, 0);
2340
 
    if (mysql_frm_type(thd, path, &not_used)) 
 
2340
    if (mysql_frm_type(session, path, &not_used)) 
2341
2341
    {
2342
2342
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2343
2343
                             system_charset_info);
2348
2348
                             system_charset_info);
2349
2349
    }
2350
2350
 
2351
 
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2351
    if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2352
2352
    {
2353
 
      thd->clear_error();
 
2353
      session->clear_error();
2354
2354
      return 0;
2355
2355
    }
2356
2356
  }
2357
 
  if (schema_table_store_record(thd, table))
 
2357
  if (schema_table_store_record(session, table))
2358
2358
    return 1;
2359
2359
  return 0;
2360
2360
}
2403
2403
/**
2404
2404
  @brief          Fill I_S table with data from FRM file only
2405
2405
 
2406
 
  @param[in]      thd                      thread handler
 
2406
  @param[in]      session                      thread handler
2407
2407
  @param[in]      table                    Table struct for I_S table
2408
2408
  @param[in]      schema_table             I_S table struct
2409
2409
  @param[in]      db_name                  database name
2417
2417
                              open_tables function for this table
2418
2418
*/
2419
2419
 
2420
 
static int fill_schema_table_from_frm(Session *thd,TableList *tables,
 
2420
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2421
2421
                                      ST_SCHEMA_TABLE *schema_table,
2422
2422
                                      LEX_STRING *db_name,
2423
2423
                                      LEX_STRING *table_name,
2438
2438
  table_list.table_name= table_name->str;
2439
2439
  table_list.db= db_name->str;
2440
2440
 
2441
 
  key_length= create_table_def_key(thd, key, &table_list, 0);
 
2441
  key_length= create_table_def_key(session, key, &table_list, 0);
2442
2442
  pthread_mutex_lock(&LOCK_open);
2443
 
  share= get_table_share(thd, &table_list, key,
 
2443
  share= get_table_share(session, &table_list, key,
2444
2444
                         key_length, 0, &error);
2445
2445
  if (!share)
2446
2446
  {
2451
2451
  {
2452
2452
    tbl.s= share;
2453
2453
    table_list.table= &tbl;
2454
 
    res= schema_table->process_table(thd, &table_list, table,
 
2454
    res= schema_table->process_table(session, &table_list, table,
2455
2455
                                     res, db_name, table_name);
2456
2456
  }
2457
2457
 
2459
2459
 
2460
2460
err:
2461
2461
  pthread_mutex_unlock(&LOCK_open);
2462
 
  thd->clear_error();
 
2462
  session->clear_error();
2463
2463
  return res;
2464
2464
}
2465
2465
 
2475
2475
                  from frm files and storage engine are filled by the function
2476
2476
                  get_all_tables().
2477
2477
 
2478
 
  @param[in]      thd                      thread handler
 
2478
  @param[in]      session                      thread handler
2479
2479
  @param[in]      tables                   I_S table
2480
2480
  @param[in]      cond                     'WHERE' condition
2481
2481
 
2484
2484
    @retval       1                        error
2485
2485
*/
2486
2486
 
2487
 
int get_all_tables(Session *thd, TableList *tables, COND *cond)
 
2487
int get_all_tables(Session *session, TableList *tables, COND *cond)
2488
2488
{
2489
 
  LEX *lex= thd->lex;
 
2489
  LEX *lex= session->lex;
2490
2490
  Table *table= tables->table;
2491
2491
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2492
2492
  enum_sql_command save_sql_command= lex->sql_command;
2505
2505
  Open_tables_state open_tables_state_backup;
2506
2506
  Query_tables_list query_tables_list_backup;
2507
2507
  uint32_t table_open_method;
2508
 
  bool old_value= thd->no_warnings_for_error;
 
2508
  bool old_value= session->no_warnings_for_error;
2509
2509
 
2510
2510
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2511
2511
 
2514
2514
    tables open and locked, since we won't lock tables which we will
2515
2515
    open and will ignore possible name-locks for these tables.
2516
2516
  */
2517
 
  thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
 
2517
  session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2518
2518
 
2519
2519
  schema_table_idx= get_schema_table_idx(schema_table);
2520
2520
  tables->table_open_method= table_open_method=
2526
2526
  */
2527
2527
  if (lsel && lsel->table_list.first)
2528
2528
  {
2529
 
    error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
 
2529
    error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2530
2530
                                         &open_tables_state_backup);
2531
2531
    goto err;
2532
2532
  }
2533
2533
 
2534
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2534
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2535
2535
  {
2536
2536
    error= 0;
2537
2537
    goto err;
2570
2570
    goto err;
2571
2571
  }
2572
2572
 
2573
 
  if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
 
2573
  if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2574
2574
    goto err;
2575
2575
  it.rewind(); /* To get access to new elements in basis list */
2576
2576
  while ((db_name= it++))
2577
2577
  {
2578
2578
    {
2579
 
      thd->no_warnings_for_error= 1;
 
2579
      session->no_warnings_for_error= 1;
2580
2580
      List<LEX_STRING> table_names;
2581
 
      int res= make_table_name_list(thd, &table_names, lex,
 
2581
      int res= make_table_name_list(session, &table_names, lex,
2582
2582
                                    &lookup_field_vals,
2583
2583
                                    with_i_schema, db_name);
2584
2584
      if (res == 2)   /* Not fatal error, continue */
2607
2607
              (!lookup_field_vals.table_value.length ||
2608
2608
               lookup_field_vals.wild_table_value))
2609
2609
          {
2610
 
            if (schema_table_store_record(thd, table))
 
2610
            if (schema_table_store_record(session, table))
2611
2611
              goto err;      /* Out of space in temporary table */
2612
2612
            continue;
2613
2613
          }
2615
2615
          /* SHOW Table NAMES command */
2616
2616
          if (schema_table_idx == SCH_TABLE_NAMES)
2617
2617
          {
2618
 
            if (fill_schema_table_names(thd, tables->table, db_name,
 
2618
            if (fill_schema_table_names(session, tables->table, db_name,
2619
2619
                                        table_name, with_i_schema))
2620
2620
              continue;
2621
2621
          }
2624
2624
            if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2625
2625
                !with_i_schema)
2626
2626
            {
2627
 
              if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
 
2627
              if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2628
2628
                                              table_name, schema_table_idx))
2629
2629
                continue;
2630
2630
            }
2635
2635
              Set the parent lex of 'sel' because it is needed by
2636
2636
              sel.init_query() which is called inside make_table_list.
2637
2637
            */
2638
 
            thd->no_warnings_for_error= 1;
 
2638
            session->no_warnings_for_error= 1;
2639
2639
            sel.parent_lex= lex;
2640
2640
            /* db_name can be changed in make_table_list() func */
2641
 
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
 
2641
            if (!session->make_lex_string(&orig_db_name, db_name->str,
2642
2642
                                      db_name->length, false))
2643
2643
              goto err;
2644
 
            if (make_table_list(thd, &sel, db_name, table_name))
 
2644
            if (make_table_list(session, &sel, db_name, table_name))
2645
2645
              goto err;
2646
2646
            TableList *show_table_list= (TableList*) sel.table_list.first;
2647
2647
            lex->all_selects_list= &sel;
2649
2649
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2650
2650
            show_table_list->i_s_requested_object=
2651
2651
              schema_table->i_s_requested_object;
2652
 
            res= open_normal_and_derived_tables(thd, show_table_list,
 
2652
            res= open_normal_and_derived_tables(session, show_table_list,
2653
2653
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
2654
2654
            lex->sql_command= save_sql_command;
2655
2655
            /*
2657
2657
              and when it's set, open_normal_and_derived_tables()
2658
2658
              can return an error without setting an error message
2659
2659
              in Session, which is a hack. This is why we have to
2660
 
              check for res, then for thd->is_error() only then
2661
 
              for thd->main_da.sql_errno().
 
2660
              check for res, then for session->is_error() only then
 
2661
              for session->main_da.sql_errno().
2662
2662
            */
2663
 
            if (res && thd->is_error() &&
2664
 
                thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2663
            if (res && session->is_error() &&
 
2664
                session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2665
2665
            {
2666
2666
              /*
2667
2667
                Hide error for not existing table.
2670
2670
                table does not exist.
2671
2671
              */
2672
2672
              res= 0;
2673
 
              thd->clear_error();
 
2673
              session->clear_error();
2674
2674
            }
2675
2675
            else
2676
2676
            {
2681
2681
                to use alias because alias contains original table name 
2682
2682
                in this case.
2683
2683
              */
2684
 
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
 
2684
              session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2685
2685
                                   strlen(show_table_list->alias), false);
2686
 
              res= schema_table->process_table(thd, show_table_list, table,
 
2686
              res= schema_table->process_table(session, show_table_list, table,
2687
2687
                                               res, &orig_db_name,
2688
2688
                                               &tmp_lex_string);
2689
 
              close_tables_for_reopen(thd, &show_table_list);
 
2689
              close_tables_for_reopen(session, &show_table_list);
2690
2690
            }
2691
2691
            assert(!lex->query_tables_own_last);
2692
2692
            if (res)
2704
2704
 
2705
2705
  error= 0;
2706
2706
err:
2707
 
  thd->restore_backup_open_tables_state(&open_tables_state_backup);
 
2707
  session->restore_backup_open_tables_state(&open_tables_state_backup);
2708
2708
  lex->restore_backup_query_tables_list(&query_tables_list_backup);
2709
2709
  lex->derived_tables= derived_tables;
2710
2710
  lex->all_selects_list= old_all_select_lex;
2711
2711
  lex->sql_command= save_sql_command;
2712
 
  thd->no_warnings_for_error= old_value;
 
2712
  session->no_warnings_for_error= old_value;
2713
2713
  return(error);
2714
2714
}
2715
2715
 
2716
2716
 
2717
 
bool store_schema_shemata(Session* thd, Table *table, LEX_STRING *db_name,
 
2717
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2718
2718
                          const CHARSET_INFO * const cs)
2719
2719
{
2720
2720
  restore_record(table, s->default_values);
2721
2721
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2722
2722
  table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2723
2723
  table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2724
 
  return schema_table_store_record(thd, table);
 
2724
  return schema_table_store_record(session, table);
2725
2725
}
2726
2726
 
2727
2727
 
2728
 
int fill_schema_schemata(Session *thd, TableList *tables, COND *cond)
 
2728
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2729
2729
{
2730
2730
  /*
2731
2731
    TODO: fill_schema_shemata() is called when new client is connected.
2739
2739
  HA_CREATE_INFO create;
2740
2740
  Table *table= tables->table;
2741
2741
 
2742
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2742
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2743
2743
    return(0);
2744
 
  if (make_db_list(thd, &db_names, &lookup_field_vals,
 
2744
  if (make_db_list(session, &db_names, &lookup_field_vals,
2745
2745
                   &with_i_schema))
2746
2746
    return(1);
2747
2747
 
2768
2768
  {
2769
2769
    if (with_i_schema)       // information schema name is always first in list
2770
2770
    {
2771
 
      if (store_schema_shemata(thd, table, db_name,
 
2771
      if (store_schema_shemata(session, table, db_name,
2772
2772
                               system_charset_info))
2773
2773
        return(1);
2774
2774
      with_i_schema= 0;
2775
2775
      continue;
2776
2776
    }
2777
2777
    {
2778
 
      load_db_opt_by_name(thd, db_name->str, &create);
2779
 
      if (store_schema_shemata(thd, table, db_name,
 
2778
      load_db_opt_by_name(session, db_name->str, &create);
 
2779
      if (store_schema_shemata(session, table, db_name,
2780
2780
                               create.default_table_charset))
2781
2781
        return(1);
2782
2782
    }
2785
2785
}
2786
2786
 
2787
2787
 
2788
 
static int get_schema_tables_record(Session *thd, TableList *tables,
 
2788
static int get_schema_tables_record(Session *session, TableList *tables,
2789
2789
                                    Table *table, bool res,
2790
2790
                                    LEX_STRING *db_name,
2791
2791
                                    LEX_STRING *table_name)
2802
2802
    /*
2803
2803
      there was errors during opening tables
2804
2804
    */
2805
 
    const char *error= thd->is_error() ? thd->main_da.message() : "";
 
2805
    const char *error= session->is_error() ? session->main_da.message() : "";
2806
2806
    if (tables->schema_table)
2807
2807
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2808
2808
    else
2809
2809
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2810
2810
    table->field[20]->store(error, strlen(error), cs);
2811
 
    thd->clear_error();
 
2811
    session->clear_error();
2812
2812
  }
2813
2813
  else
2814
2814
  {
2947
2947
      }
2948
2948
      if (file->stats.create_time)
2949
2949
      {
2950
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
 
2950
        session->variables.time_zone->gmt_sec_to_TIME(&time,
2951
2951
                                                  (my_time_t) file->stats.create_time);
2952
2952
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2953
2953
        table->field[14]->set_notnull();
2954
2954
      }
2955
2955
      if (file->stats.update_time)
2956
2956
      {
2957
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
 
2957
        session->variables.time_zone->gmt_sec_to_TIME(&time,
2958
2958
                                                  (my_time_t) file->stats.update_time);
2959
2959
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2960
2960
        table->field[15]->set_notnull();
2961
2961
      }
2962
2962
      if (file->stats.check_time)
2963
2963
      {
2964
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
 
2964
        session->variables.time_zone->gmt_sec_to_TIME(&time,
2965
2965
                                                  (my_time_t) file->stats.check_time);
2966
2966
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2967
2967
        table->field[16]->set_notnull();
2973
2973
      }
2974
2974
    }
2975
2975
  }
2976
 
  return(schema_table_store_record(thd, table));
 
2976
  return(schema_table_store_record(session, table));
2977
2977
}
2978
2978
 
2979
2979
 
3075
3075
}
3076
3076
 
3077
3077
 
3078
 
static int get_schema_column_record(Session *thd, TableList *tables,
 
3078
static int get_schema_column_record(Session *session, TableList *tables,
3079
3079
                                    Table *table, bool res,
3080
3080
                                    LEX_STRING *db_name,
3081
3081
                                    LEX_STRING *table_name)
3082
3082
{
3083
 
  LEX *lex= thd->lex;
 
3083
  LEX *lex= session->lex;
3084
3084
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3085
3085
  const CHARSET_INFO * const cs= system_charset_info;
3086
3086
  Table *show_table;
3096
3096
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3097
3097
        rather than in SHOW COLUMNS
3098
3098
      */ 
3099
 
      if (thd->is_error())
3100
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3101
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3102
 
      thd->clear_error();
 
3099
      if (session->is_error())
 
3100
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3101
                     session->main_da.sql_errno(), session->main_da.message());
 
3102
      session->clear_error();
3103
3103
      res= 0;
3104
3104
    }
3105
3105
    return(res);
3128
3128
      /* to satisfy 'field->val_str' ASSERTs */
3129
3129
      unsigned char *bitmaps;
3130
3130
      uint32_t bitmap_size= show_table_share->column_bitmap_size;
3131
 
      if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
 
3131
      if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3132
3132
        return(0);
3133
3133
      bitmap_init(&show_table->def_read_set,
3134
3134
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3147
3147
 
3148
3148
    /* to satisfy 'field->val_str' ASSERTs */
3149
3149
    field->table= show_table;
3150
 
    show_table->in_use= thd;
 
3150
    show_table->in_use= session;
3151
3151
 
3152
3152
    if (wild && wild[0] &&
3153
3153
        wild_case_compare(system_charset_info, field->field_name,wild))
3163
3163
                           cs);
3164
3164
    table->field[4]->store((int64_t) count, true);
3165
3165
 
3166
 
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
 
3166
    if (get_field_default_value(session, timestamp_field, field, &type, 0))
3167
3167
    {
3168
3168
      table->field[5]->store(type.ptr(), type.length(), cs);
3169
3169
      table->field[5]->set_notnull();
3201
3201
      table->field[20]->store((const char*) pos,
3202
3202
                              strlen((const char*) pos), cs);
3203
3203
    }
3204
 
    if (schema_table_store_record(thd, table))
 
3204
    if (schema_table_store_record(session, table))
3205
3205
      return(1);
3206
3206
  }
3207
3207
  return(0);
3209
3209
 
3210
3210
 
3211
3211
 
3212
 
int fill_schema_charsets(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3212
int fill_schema_charsets(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3213
3213
{
3214
3214
  CHARSET_INFO **cs;
3215
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3215
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3216
3216
  Table *table= tables->table;
3217
3217
  const CHARSET_INFO * const scs= system_charset_info;
3218
3218
 
3232
3232
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3233
3233
      table->field[2]->store(comment, strlen(comment), scs);
3234
3234
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3235
 
      if (schema_table_store_record(thd, table))
 
3235
      if (schema_table_store_record(session, table))
3236
3236
        return 1;
3237
3237
    }
3238
3238
  }
3240
3240
}
3241
3241
 
3242
3242
 
3243
 
int fill_schema_collation(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3243
int fill_schema_collation(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3244
3244
{
3245
3245
  CHARSET_INFO **cs;
3246
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3246
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3247
3247
  Table *table= tables->table;
3248
3248
  const CHARSET_INFO * const scs= system_charset_info;
3249
3249
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3273
3273
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3274
3274
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3275
3275
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3276
 
        if (schema_table_store_record(thd, table))
 
3276
        if (schema_table_store_record(session, table))
3277
3277
          return 1;
3278
3278
      }
3279
3279
    }
3282
3282
}
3283
3283
 
3284
3284
 
3285
 
int fill_schema_coll_charset_app(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3285
int fill_schema_coll_charset_app(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3286
3286
{
3287
3287
  CHARSET_INFO **cs;
3288
3288
  Table *table= tables->table;
3303
3303
      restore_record(table, s->default_values);
3304
3304
      table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3305
3305
      table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3306
 
      if (schema_table_store_record(thd, table))
 
3306
      if (schema_table_store_record(session, table))
3307
3307
        return 1;
3308
3308
    }
3309
3309
  }
3311
3311
}
3312
3312
 
3313
3313
 
3314
 
static int get_schema_stat_record(Session *thd, TableList *tables,
 
3314
static int get_schema_stat_record(Session *session, TableList *tables,
3315
3315
                                  Table *table, bool res,
3316
3316
                                  LEX_STRING *db_name,
3317
3317
                                  LEX_STRING *table_name)
3319
3319
  const CHARSET_INFO * const cs= system_charset_info;
3320
3320
  if (res)
3321
3321
  {
3322
 
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
 
3322
    if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3323
3323
    {
3324
3324
      /*
3325
3325
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3326
3326
        rather than in SHOW KEYS
3327
3327
      */
3328
 
      if (thd->is_error())
3329
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3330
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3331
 
      thd->clear_error();
 
3328
      if (session->is_error())
 
3329
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3330
                     session->main_da.sql_errno(), session->main_da.message());
 
3331
      session->clear_error();
3332
3332
      res= 0;
3333
3333
    }
3334
3334
    return(res);
3399
3399
        if (key_info->flags & HA_USES_COMMENT)
3400
3400
          table->field[15]->store(key_info->comment.str, 
3401
3401
                                  key_info->comment.length, cs);
3402
 
        if (schema_table_store_record(thd, table))
 
3402
        if (schema_table_store_record(session, table))
3403
3403
          return(1);
3404
3404
      }
3405
3405
    }
3408
3408
}
3409
3409
 
3410
3410
 
3411
 
bool store_constraints(Session *thd, Table *table, LEX_STRING *db_name,
 
3411
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3412
3412
                       LEX_STRING *table_name, const char *key_name,
3413
3413
                       uint32_t key_len, const char *con_type, uint32_t con_len)
3414
3414
{
3419
3419
  table->field[3]->store(db_name->str, db_name->length, cs);
3420
3420
  table->field[4]->store(table_name->str, table_name->length, cs);
3421
3421
  table->field[5]->store(con_type, con_len, cs);
3422
 
  return schema_table_store_record(thd, table);
 
3422
  return schema_table_store_record(session, table);
3423
3423
}
3424
3424
 
3425
3425
 
3426
 
static int get_schema_constraints_record(Session *thd, TableList *tables,
 
3426
static int get_schema_constraints_record(Session *session, TableList *tables,
3427
3427
                                         Table *table, bool res,
3428
3428
                                         LEX_STRING *db_name,
3429
3429
                                         LEX_STRING *table_name)
3430
3430
{
3431
3431
  if (res)
3432
3432
  {
3433
 
    if (thd->is_error())
3434
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3435
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3436
 
    thd->clear_error();
 
3433
    if (session->is_error())
 
3434
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3435
                   session->main_da.sql_errno(), session->main_da.message());
 
3436
    session->clear_error();
3437
3437
    return(0);
3438
3438
  }
3439
3439
  else
3452
3452
 
3453
3453
      if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3454
3454
      {
3455
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3455
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3456
3456
                              strlen(key_info->name),
3457
3457
                              STRING_WITH_LEN("PRIMARY KEY")))
3458
3458
          return(1);
3459
3459
      }
3460
3460
      else if (key_info->flags & HA_NOSAME)
3461
3461
      {
3462
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3462
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3463
3463
                              strlen(key_info->name),
3464
3464
                              STRING_WITH_LEN("UNIQUE")))
3465
3465
          return(1);
3466
3466
      }
3467
3467
    }
3468
3468
 
3469
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3469
    show_table->file->get_foreign_key_list(session, &f_key_list);
3470
3470
    FOREIGN_KEY_INFO *f_key_info;
3471
3471
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3472
3472
    while ((f_key_info=it++))
3473
3473
    {
3474
 
      if (store_constraints(thd, table, db_name, table_name, 
 
3474
      if (store_constraints(session, table, db_name, table_name, 
3475
3475
                            f_key_info->forein_id->str,
3476
3476
                            strlen(f_key_info->forein_id->str),
3477
3477
                            "FOREIGN KEY", 11))
3497
3497
}
3498
3498
 
3499
3499
 
3500
 
static int get_schema_key_column_usage_record(Session *thd,
 
3500
static int get_schema_key_column_usage_record(Session *session,
3501
3501
                                              TableList *tables,
3502
3502
                                              Table *table, bool res,
3503
3503
                                              LEX_STRING *db_name,
3505
3505
{
3506
3506
  if (res)
3507
3507
  {
3508
 
    if (thd->is_error())
3509
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3510
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3511
 
    thd->clear_error();
 
3508
    if (session->is_error())
 
3509
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3510
                   session->main_da.sql_errno(), session->main_da.message());
 
3511
    session->clear_error();
3512
3512
    return(0);
3513
3513
  }
3514
3514
  else
3538
3538
                                 key_part->field->field_name, 
3539
3539
                                 strlen(key_part->field->field_name),
3540
3540
                                 (int64_t) f_idx);
3541
 
          if (schema_table_store_record(thd, table))
 
3541
          if (schema_table_store_record(session, table))
3542
3542
            return(1);
3543
3543
        }
3544
3544
      }
3545
3545
    }
3546
3546
 
3547
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3547
    show_table->file->get_foreign_key_list(session, &f_key_list);
3548
3548
    FOREIGN_KEY_INFO *f_key_info;
3549
3549
    List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3550
3550
    while ((f_key_info= fkey_it++))
3577
3577
        table->field[11]->store(r_info->str, r_info->length,
3578
3578
                                system_charset_info);
3579
3579
        table->field[11]->set_notnull();
3580
 
        if (schema_table_store_record(thd, table))
 
3580
        if (schema_table_store_record(session, table))
3581
3581
          return(1);
3582
3582
      }
3583
3583
    }
3586
3586
}
3587
3587
 
3588
3588
 
3589
 
int fill_open_tables(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3589
int fill_open_tables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3590
3590
{
3591
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3591
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3592
3592
  Table *table= tables->table;
3593
3593
  const CHARSET_INFO * const cs= system_charset_info;
3594
3594
  OPEN_TableList *open_list;
3595
 
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3596
 
            && thd->is_fatal_error)
 
3595
  if (!(open_list=list_open_tables(session,session->lex->select_lex.db, wild))
 
3596
            && session->is_fatal_error)
3597
3597
    return(1);
3598
3598
 
3599
3599
  for (; open_list ; open_list=open_list->next)
3603
3603
    table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3604
3604
    table->field[2]->store((int64_t) open_list->in_use, true);
3605
3605
    table->field[3]->store((int64_t) open_list->locked, true);
3606
 
    if (schema_table_store_record(thd, table))
 
3606
    if (schema_table_store_record(session, table))
3607
3607
      return(1);
3608
3608
  }
3609
3609
  return(0);
3610
3610
}
3611
3611
 
3612
3612
 
3613
 
int fill_variables(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3613
int fill_variables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3614
3614
{
3615
3615
  int res= 0;
3616
 
  LEX *lex= thd->lex;
 
3616
  LEX *lex= session->lex;
3617
3617
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3618
3618
  enum enum_schema_tables schema_table_idx=
3619
3619
    get_schema_table_idx(tables->schema_table);
3626
3626
    option_type= OPT_GLOBAL;
3627
3627
 
3628
3628
  rw_rdlock(&LOCK_system_variables_hash);
3629
 
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
 
3629
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3630
3630
                         option_type, NULL, "", tables->table, upper_case_names);
3631
3631
  rw_unlock(&LOCK_system_variables_hash);
3632
3632
  return(res);
3633
3633
}
3634
3634
 
3635
3635
 
3636
 
int fill_status(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3636
int fill_status(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3637
3637
{
3638
 
  LEX *lex= thd->lex;
 
3638
  LEX *lex= session->lex;
3639
3639
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3640
3640
  int res= 0;
3641
3641
  STATUS_VAR *tmp1, tmp;
3650
3650
    if (option_type == OPT_GLOBAL)
3651
3651
      tmp1= &tmp;
3652
3652
    else
3653
 
      tmp1= thd->initial_status_var;
 
3653
      tmp1= session->initial_status_var;
3654
3654
  }
3655
3655
  else if (schema_table_idx == SCH_GLOBAL_STATUS)
3656
3656
  {
3660
3660
  else
3661
3661
  { 
3662
3662
    option_type= OPT_SESSION;
3663
 
    tmp1= &thd->status_var;
 
3663
    tmp1= &session->status_var;
3664
3664
  }
3665
3665
 
3666
3666
  pthread_mutex_lock(&LOCK_status);
3667
3667
  if (option_type == OPT_GLOBAL)
3668
3668
    calc_sum_of_all_status(&tmp);
3669
 
  res= show_status_array(thd, wild,
 
3669
  res= show_status_array(session, wild,
3670
3670
                         (SHOW_VAR *)all_status_vars.buffer,
3671
3671
                         option_type, tmp1, "", tables->table,
3672
3672
                         upper_case_names);
3680
3680
 
3681
3681
  SYNOPSIS
3682
3682
    get_referential_constraints_record()
3683
 
    thd                 thread handle
 
3683
    session                 thread handle
3684
3684
    tables              table list struct(processed table)
3685
3685
    table               I_S table
3686
3686
    res                 1 means the error during opening of the processed table
3694
3694
*/
3695
3695
 
3696
3696
static int
3697
 
get_referential_constraints_record(Session *thd, TableList *tables,
 
3697
get_referential_constraints_record(Session *session, TableList *tables,
3698
3698
                                   Table *table, bool res,
3699
3699
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3700
3700
{
3702
3702
 
3703
3703
  if (res)
3704
3704
  {
3705
 
    if (thd->is_error())
3706
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3707
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3708
 
    thd->clear_error();
 
3705
    if (session->is_error())
 
3706
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3707
                   session->main_da.sql_errno(), session->main_da.message());
 
3708
    session->clear_error();
3709
3709
    return(0);
3710
3710
  }
3711
3711
 
3716
3716
                           HA_STATUS_NO_LOCK |
3717
3717
                           HA_STATUS_TIME);
3718
3718
 
3719
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3719
    show_table->file->get_foreign_key_list(session, &f_key_list);
3720
3720
    FOREIGN_KEY_INFO *f_key_info;
3721
3721
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3722
3722
    while ((f_key_info= it++))
3743
3743
                             f_key_info->update_method->length, cs);
3744
3744
      table->field[8]->store(f_key_info->delete_method->str, 
3745
3745
                             f_key_info->delete_method->length, cs);
3746
 
      if (schema_table_store_record(thd, table))
 
3746
      if (schema_table_store_record(session, table))
3747
3747
        return(1);
3748
3748
    }
3749
3749
  }
3763
3763
 
3764
3764
  SYNOPSIS
3765
3765
    find_schema_table_in_plugin()
3766
 
    thd                 thread handler
 
3766
    session                 thread handler
3767
3767
    plugin              plugin
3768
3768
    table_name          table name
3769
3769
 
3771
3771
    0   table not found
3772
3772
    1   found the schema table
3773
3773
*/
3774
 
static bool find_schema_table_in_plugin(Session *thd __attribute__((unused)),
 
3774
static bool find_schema_table_in_plugin(Session *session __attribute__((unused)),
3775
3775
                                           plugin_ref plugin,
3776
3776
                                           void* p_table)
3777
3777
{
3795
3795
 
3796
3796
  SYNOPSIS
3797
3797
    find_schema_table()
3798
 
    thd                 thread handler
 
3798
    session                 thread handler
3799
3799
    table_name          table name
3800
3800
 
3801
3801
  RETURN
3803
3803
    #   pointer to 'schema_tables' element
3804
3804
*/
3805
3805
 
3806
 
ST_SCHEMA_TABLE *find_schema_table(Session *thd, const char* table_name)
 
3806
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3807
3807
{
3808
3808
  schema_table_ref schema_table_a;
3809
3809
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3817
3817
  }
3818
3818
 
3819
3819
  schema_table_a.table_name= table_name;
3820
 
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
 
3820
  if (plugin_foreach(session, find_schema_table_in_plugin, 
3821
3821
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3822
3822
    return(schema_table_a.schema_table);
3823
3823
 
3837
3837
  @note
3838
3838
 
3839
3839
  @param
3840
 
    thd                   thread handler
 
3840
    session                       thread handler
3841
3841
 
3842
3842
  @param table_list Used to pass I_S table information(fields info, tables
3843
3843
  parameters etc) and table name.
3846
3846
  @retval  NULL           Can't create table
3847
3847
*/
3848
3848
 
3849
 
Table *create_schema_table(Session *thd, TableList *table_list)
 
3849
Table *create_schema_table(Session *session, TableList *table_list)
3850
3850
{
3851
3851
  int field_count= 0;
3852
3852
  Item *item;
3921
3921
    field_count++;
3922
3922
  }
3923
3923
  TMP_TABLE_PARAM *tmp_table_param =
3924
 
    (TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
 
3924
    (TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3925
3925
  tmp_table_param->init();
3926
3926
  tmp_table_param->table_charset= cs;
3927
3927
  tmp_table_param->field_count= field_count;
3928
3928
  tmp_table_param->schema_table= 1;
3929
 
  SELECT_LEX *select_lex= thd->lex->current_select;
3930
 
  if (!(table= create_tmp_table(thd, tmp_table_param,
 
3929
  SELECT_LEX *select_lex= session->lex->current_select;
 
3930
  if (!(table= create_tmp_table(session, tmp_table_param,
3931
3931
                                field_list, (order_st*) 0, 0, 0, 
3932
 
                                (select_lex->options | thd->options |
 
3932
                                (select_lex->options | session->options |
3933
3933
                                 TMP_TABLE_ALL_COLUMNS),
3934
3934
                                HA_POS_ERROR, table_list->alias)))
3935
3935
    return(0);
3936
3936
  my_bitmap_map* bitmaps=
3937
 
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
 
3937
    (my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3938
3938
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3939
3939
              false);
3940
3940
  table->read_set= &table->def_read_set;
3951
3951
 
3952
3952
  SYNOPSIS
3953
3953
    make_old_format()
3954
 
    thd                 thread handler
 
3954
    session                     thread handler
3955
3955
    schema_table        pointer to 'schema_tables' element
3956
3956
 
3957
3957
  RETURN
3959
3959
   0    success
3960
3960
*/
3961
3961
 
3962
 
int make_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
 
3962
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3963
3963
{
3964
3964
  ST_FIELD_INFO *field_info= schema_table->fields_info;
3965
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
3965
  Name_resolution_context *context= &session->lex->select_lex.context;
3966
3966
  for (; field_info->field_name; field_info++)
3967
3967
  {
3968
3968
    if (field_info->old_name)
3974
3974
        field->set_name(field_info->old_name,
3975
3975
                        strlen(field_info->old_name),
3976
3976
                        system_charset_info);
3977
 
        if (add_item_to_list(thd, field))
 
3977
        if (add_item_to_list(session, field))
3978
3978
          return 1;
3979
3979
      }
3980
3980
    }
3983
3983
}
3984
3984
 
3985
3985
 
3986
 
int make_schemata_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
 
3986
int make_schemata_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3987
3987
{
3988
3988
  char tmp[128];
3989
 
  LEX *lex= thd->lex;
 
3989
  LEX *lex= session->lex;
3990
3990
  SELECT_LEX *sel= lex->current_select;
3991
3991
  Name_resolution_context *context= &sel->context;
3992
3992
 
3996
3996
    String buffer(tmp,sizeof(tmp), system_charset_info);
3997
3997
    Item_field *field= new Item_field(context,
3998
3998
                                      NULL, NULL, field_info->field_name);
3999
 
    if (!field || add_item_to_list(thd, field))
 
3999
    if (!field || add_item_to_list(session, field))
4000
4000
      return 1;
4001
4001
    buffer.length(0);
4002
4002
    buffer.append(field_info->old_name);
4012
4012
}
4013
4013
 
4014
4014
 
4015
 
int make_table_names_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
 
4015
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4016
4016
{
4017
4017
  char tmp[128];
4018
 
  String buffer(tmp,sizeof(tmp), thd->charset());
4019
 
  LEX *lex= thd->lex;
 
4018
  String buffer(tmp,sizeof(tmp), session->charset());
 
4019
  LEX *lex= session->lex;
4020
4020
  Name_resolution_context *context= &lex->select_lex.context;
4021
4021
 
4022
4022
  ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4031
4031
  }
4032
4032
  Item_field *field= new Item_field(context,
4033
4033
                                    NULL, NULL, field_info->field_name);
4034
 
  if (add_item_to_list(thd, field))
 
4034
  if (add_item_to_list(session, field))
4035
4035
    return 1;
4036
4036
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4037
 
  if (thd->lex->verbose)
 
4037
  if (session->lex->verbose)
4038
4038
  {
4039
4039
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4040
4040
    field_info= &schema_table->fields_info[3];
4041
4041
    field= new Item_field(context, NULL, NULL, field_info->field_name);
4042
 
    if (add_item_to_list(thd, field))
 
4042
    if (add_item_to_list(session, field))
4043
4043
      return 1;
4044
4044
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4045
4045
                    system_charset_info);
4048
4048
}
4049
4049
 
4050
4050
 
4051
 
int make_columns_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
 
4051
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4052
4052
{
4053
4053
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4054
4054
  int *field_num= fields_arr;
4055
4055
  ST_FIELD_INFO *field_info;
4056
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
4056
  Name_resolution_context *context= &session->lex->select_lex.context;
4057
4057
 
4058
4058
  for (; *field_num >= 0; field_num++)
4059
4059
  {
4060
4060
    field_info= &schema_table->fields_info[*field_num];
4061
 
    if (!thd->lex->verbose && (*field_num == 13 ||
 
4061
    if (!session->lex->verbose && (*field_num == 13 ||
4062
4062
                               *field_num == 17 ||
4063
4063
                               *field_num == 18))
4064
4064
      continue;
4069
4069
      field->set_name(field_info->old_name,
4070
4070
                      strlen(field_info->old_name),
4071
4071
                      system_charset_info);
4072
 
      if (add_item_to_list(thd, field))
 
4072
      if (add_item_to_list(session, field))
4073
4073
        return 1;
4074
4074
    }
4075
4075
  }
4077
4077
}
4078
4078
 
4079
4079
 
4080
 
int make_character_sets_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
 
4080
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4081
4081
{
4082
4082
  int fields_arr[]= {0, 2, 1, 3, -1};
4083
4083
  int *field_num= fields_arr;
4084
4084
  ST_FIELD_INFO *field_info;
4085
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
4085
  Name_resolution_context *context= &session->lex->select_lex.context;
4086
4086
 
4087
4087
  for (; *field_num >= 0; field_num++)
4088
4088
  {
4094
4094
      field->set_name(field_info->old_name,
4095
4095
                      strlen(field_info->old_name),
4096
4096
                      system_charset_info);
4097
 
      if (add_item_to_list(thd, field))
 
4097
      if (add_item_to_list(session, field))
4098
4098
        return 1;
4099
4099
    }
4100
4100
  }
4107
4107
 
4108
4108
  SYNOPSIS
4109
4109
  mysql_schema_table()
4110
 
    thd                thread handler
 
4110
    session                thread handler
4111
4111
    lex                pointer to LEX
4112
4112
    table_list         pointer to table_list
4113
4113
 
4116
4116
    1   error
4117
4117
*/
4118
4118
 
4119
 
int mysql_schema_table(Session *thd, LEX *lex, TableList *table_list)
 
4119
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list)
4120
4120
{
4121
4121
  Table *table;
4122
 
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
 
4122
  if (!(table= table_list->schema_table->create_table(session, table_list)))
4123
4123
    return(1);
4124
4124
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4125
4125
  /*
4136
4136
  table_list->table_name= table->s->table_name.str;
4137
4137
  table_list->table_name_length= table->s->table_name.length;
4138
4138
  table_list->table= table;
4139
 
  table->next= thd->derived_tables;
4140
 
  thd->derived_tables= table;
 
4139
  table->next= session->derived_tables;
 
4140
  session->derived_tables= table;
4141
4141
  table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4142
4142
 
4143
4143
  if (table_list->schema_table_reformed) // show command
4152
4152
      for (transl= table_list->field_translation; transl < end; transl++)
4153
4153
      {
4154
4154
        if (!transl->item->fixed &&
4155
 
            transl->item->fix_fields(thd, &transl->item))
 
4155
            transl->item->fix_fields(session, &transl->item))
4156
4156
          return(1);
4157
4157
      }
4158
4158
      return(0);
4159
4159
    }
4160
4160
    List_iterator_fast<Item> it(sel->item_list);
4161
4161
    if (!(transl=
4162
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
 
4162
          (Field_translator*)(session->alloc(sel->item_list.elements *
4163
4163
                                    sizeof(Field_translator)))))
4164
4164
    {
4165
4165
      return(1);
4168
4168
    {
4169
4169
      transl->item= item;
4170
4170
      transl->name= item->name;
4171
 
      if (!item->fixed && item->fix_fields(thd, &transl->item))
 
4171
      if (!item->fixed && item->fix_fields(session, &transl->item))
4172
4172
      {
4173
4173
        return(1);
4174
4174
      }
4186
4186
 
4187
4187
  SYNOPSIS
4188
4188
    make_schema_select()
4189
 
    thd                  thread handler
 
4189
    session                  thread handler
4190
4190
    sel                  pointer to SELECT_LEX
4191
4191
    schema_table_idx     index of 'schema_tables' element
4192
4192
 
4195
4195
    1   error
4196
4196
*/
4197
4197
 
4198
 
int make_schema_select(Session *thd, SELECT_LEX *sel,
 
4198
int make_schema_select(Session *session, SELECT_LEX *sel,
4199
4199
                       enum enum_schema_tables schema_table_idx)
4200
4200
{
4201
4201
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4204
4204
     We have to make non const db_name & table_name
4205
4205
     because of lower_case_table_names
4206
4206
  */
4207
 
  thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
 
4207
  session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4208
4208
                       INFORMATION_SCHEMA_NAME.length, 0);
4209
 
  thd->make_lex_string(&table, schema_table->table_name,
 
4209
  session->make_lex_string(&table, schema_table->table_name,
4210
4210
                       strlen(schema_table->table_name), 0);
4211
 
  if (schema_table->old_format(thd, schema_table) ||   /* Handle old syntax */
4212
 
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
 
4211
  if (schema_table->old_format(session, schema_table) ||   /* Handle old syntax */
 
4212
      !sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4213
4213
                              0, 0, TL_READ))
4214
4214
  {
4215
4215
    return(1);
4235
4235
                              enum enum_schema_table_state executed_place)
4236
4236
{
4237
4237
  JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4238
 
  Session *thd= join->thd;
4239
 
  LEX *lex= thd->lex;
 
4238
  Session *session= join->session;
 
4239
  LEX *lex= session->lex;
4240
4240
  bool result= 0;
4241
4241
 
4242
 
  thd->no_warnings_for_error= 1;
 
4242
  session->no_warnings_for_error= 1;
4243
4243
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4244
4244
  {
4245
4245
    if (!tab->table || !tab->table->pos_in_table_list)
4253
4253
 
4254
4254
 
4255
4255
      /* skip I_S optimizations specific to get_all_tables */
4256
 
      if (thd->lex->describe &&
 
4256
      if (session->lex->describe &&
4257
4257
          (table_list->schema_table->fill_table != get_all_tables))
4258
4258
        continue;
4259
4259
 
4287
4287
      else
4288
4288
        table_list->table->file->stats.records= 0;
4289
4289
 
4290
 
      if (table_list->schema_table->fill_table(thd, table_list,
 
4290
      if (table_list->schema_table->fill_table(session, table_list,
4291
4291
                                               tab->select_cond))
4292
4292
      {
4293
4293
        result= 1;
4300
4300
      table_list->schema_table_state= executed_place;
4301
4301
    }
4302
4302
  }
4303
 
  thd->no_warnings_for_error= 0;
 
4303
  session->no_warnings_for_error= 0;
4304
4304
  return(result);
4305
4305
}
4306
4306