~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Monty Taylor
  • Date: 2008-12-24 01:49:53 UTC
  • mto: This revision was merged to the branch mainline in revision 751.
  • Revision ID: mordred@inaugust.com-20081224014953-rc9p7a162p74y889
Fixed connect.test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
15
19
 
16
20
 
17
21
/* Function with list databases, tables or fields */
18
22
#include <drizzled/server_includes.h>
19
23
#include <drizzled/sql_select.h>
20
 
#include <drizzled/sql_show.h>
21
 
#include "repl_failsafe.h"
 
24
#include <drizzled/show.h>
22
25
#include <mysys/my_dir.h>
23
 
 
24
 
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
 
26
#include <drizzled/gettext.h>
 
27
#include <drizzled/util/convert.h>
 
28
#include <drizzled/error.h>
 
29
#include <drizzled/tztime.h>
 
30
#include <drizzled/data_home.h>
 
31
#include <drizzled/item/cmpfunc.h>
 
32
#include <drizzled/item/return_int.h>
 
33
#include <drizzled/item/empty_string.h>
 
34
#include <drizzled/item/return_date_time.h>
 
35
#include <drizzled/virtual_column_info.h>
 
36
#include <drizzled/sql_base.h>
 
37
#include <drizzled/db.h>
 
38
#include <drizzled/field/timestamp.h>
 
39
#include <drizzled/field/decimal.h>
 
40
#include <drizzled/lock.h>
 
41
#include <drizzled/item/return_date_time.h>
 
42
#include <drizzled/item/empty_string.h>
 
43
 
 
44
#include <string>
 
45
#include <iostream>
 
46
#include <sstream>
 
47
 
 
48
using namespace std;
 
49
 
 
50
inline const char *
 
51
str_or_nil(const char *str)
 
52
{
 
53
  return str ? str : "<nil>";
 
54
}
25
55
 
26
56
/* Match the values of enum ha_choice */
27
57
static const char *ha_choice_values[] = {"", "0", "1"};
28
58
 
29
 
static void store_key_options(THD *thd, String *packet, TABLE *table,
 
59
static void store_key_options(Session *session, String *packet, Table *table,
30
60
                              KEY *key_info);
31
61
 
32
62
 
81
111
** List all table types supported
82
112
***************************************************************************/
83
113
 
84
 
static bool show_plugins(THD *thd, plugin_ref plugin,
 
114
static bool show_plugins(Session *session, plugin_ref plugin,
85
115
                            void *arg)
86
116
{
87
 
  TABLE *table= (TABLE*) arg;
 
117
  Table *table= (Table*) arg;
88
118
  struct st_mysql_plugin *plug= plugin_decl(plugin);
89
119
  struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
90
120
  const CHARSET_INFO * const cs= system_charset_info;
149
179
 
150
180
  switch (plug->license) {
151
181
  case PLUGIN_LICENSE_GPL:
152
 
    table->field[7]->store(PLUGIN_LICENSE_GPL_STRING, 
 
182
    table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
153
183
                           strlen(PLUGIN_LICENSE_GPL_STRING), cs);
154
184
    break;
155
185
  case PLUGIN_LICENSE_BSD:
156
 
    table->field[7]->store(PLUGIN_LICENSE_BSD_STRING, 
 
186
    table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
157
187
                           strlen(PLUGIN_LICENSE_BSD_STRING), cs);
158
188
    break;
159
189
  default:
160
 
    table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING, 
 
190
    table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
161
191
                           strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
162
192
    break;
163
193
  }
164
194
  table->field[7]->set_notnull();
165
195
 
166
 
  return schema_table_store_record(thd, table);
 
196
  return schema_table_store_record(session, table);
167
197
}
168
198
 
169
199
 
170
 
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
200
int fill_plugins(Session *session, TableList *tables, COND *)
171
201
{
172
 
  TABLE *table= tables->table;
 
202
  Table *table= tables->table;
173
203
 
174
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
204
  if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
175
205
                               ~PLUGIN_IS_FREED, table))
176
206
    return(1);
177
207
 
184
214
 
185
215
  SYNOPSIS
186
216
    find_files()
187
 
    thd                 thread handler
 
217
    session                 thread handler
188
218
    files               put found files in this list
189
 
    db                  database name to set in TABLE_LIST structure
 
219
    db                  database name to set in TableList structure
190
220
    path                path to database
191
221
    wild                filter for found files
192
222
    dir                 read databases in path if true, read .frm files in
200
230
 
201
231
 
202
232
find_files_result
203
 
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
 
233
find_files(Session *session, List<LEX_STRING> *files, const char *db,
204
234
           const char *path, const char *wild, bool dir)
205
235
{
206
 
  uint i;
 
236
  uint32_t i;
207
237
  char *ext;
208
238
  MY_DIR *dirp;
209
239
  FILEINFO *file;
210
240
  LEX_STRING *file_name= 0;
211
 
  uint file_name_len;
212
 
  TABLE_LIST table_list;
 
241
  uint32_t file_name_len;
 
242
  TableList table_list;
213
243
 
214
244
  if (wild && !wild[0])
215
245
    wild=0;
231
261
    file=dirp->dir_entry+i;
232
262
    if (dir)
233
263
    {                                           /* Return databases */
234
 
      if ((file->name[0] == '.' && 
 
264
      if ((file->name[0] == '.' &&
235
265
          ((file->name[1] == '.' && file->name[2] == '\0') ||
236
266
            file->name[1] == '\0')))
237
267
        continue;                               /* . or .. */
244
274
        char *end;
245
275
        *ext=0;                                 /* Remove extension */
246
276
        unpack_dirname(buff, file->name);
247
 
        end= strend(buff);
 
277
        end= strchr(buff, '\0');
248
278
        if (end != buff && end[-1] == FN_LIBCHAR)
249
279
          end[-1]= 0;                           // Remove end FN_LIBCHAR
250
280
        if (stat(buff, file->mystat))
257
287
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
258
288
      if (wild && wild_compare(uname, wild, 0))
259
289
        continue;
260
 
      if (!(file_name= 
261
 
            thd->make_lex_string(file_name, uname, file_name_len, true)))
 
290
      if (!(file_name=
 
291
            session->make_lex_string(file_name, uname, file_name_len, true)))
262
292
      {
263
293
        my_dirend(dirp);
264
294
        return(FIND_FILES_OOM);
268
298
    {
269
299
        // Return only .frm files which aren't temp files.
270
300
      if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),reg_ext) ||
271
 
          is_prefix(file->name, tmp_file_prefix))
 
301
          is_prefix(file->name, TMP_FILE_PREFIX))
272
302
        continue;
273
303
      *ext=0;
274
304
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
283
313
          continue;
284
314
      }
285
315
    }
286
 
    if (!(file_name= 
287
 
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
 
316
    if (!(file_name=
 
317
          session->make_lex_string(file_name, uname, file_name_len, true)) ||
288
318
        files->push_back(file_name))
289
319
    {
290
320
      my_dirend(dirp);
298
328
 
299
329
 
300
330
bool
301
 
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
 
331
mysqld_show_create(Session *session, TableList *table_list)
302
332
{
303
 
  Protocol *protocol= thd->protocol;
 
333
  Protocol *protocol= session->protocol;
304
334
  char buff[2048];
305
335
  String buffer(buff, sizeof(buff), system_charset_info);
306
336
 
307
337
  /* Only one table for now, but VIEW can involve several tables */
308
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
338
  if (open_normal_and_derived_tables(session, table_list, 0))
309
339
  {
310
 
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
 
340
    if (session->is_error())
311
341
      return(true);
312
342
 
313
343
    /*
314
344
      Clear all messages with 'error' level status and
315
 
      issue a warning with 'warning' level status in 
 
345
      issue a warning with 'warning' level status in
316
346
      case of invalid view and last error is ER_VIEW_INVALID
317
347
    */
318
 
    drizzle_reset_errors(thd, true);
319
 
    thd->clear_error();
 
348
    drizzle_reset_errors(session, true);
 
349
    session->clear_error();
320
350
  }
321
351
 
322
352
  buffer.length(0);
323
353
 
324
 
  if (store_create_info(thd, table_list, &buffer, NULL))
 
354
  if (store_create_info(session, table_list, &buffer, NULL))
325
355
    return(true);
326
356
 
327
357
  List<Item> field_list;
329
359
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
330
360
    // 1024 is for not to confuse old clients
331
361
    field_list.push_back(new Item_empty_string("Create Table",
332
 
                                               max(buffer.length(),(uint32_t)1024)));
 
362
                                               cmax(buffer.length(),(uint32_t)1024)));
333
363
  }
334
364
 
335
365
  if (protocol->send_fields(&field_list,
349
379
  if (protocol->write())
350
380
    return(true);
351
381
 
352
 
  my_eof(thd);
 
382
  my_eof(session);
353
383
  return(false);
354
384
}
355
385
 
356
 
bool mysqld_show_create_db(THD *thd, char *dbname,
 
386
bool mysqld_show_create_db(Session *session, char *dbname,
357
387
                           HA_CREATE_INFO *create_info)
358
388
{
359
389
  char buff[2048];
360
390
  String buffer(buff, sizeof(buff), system_charset_info);
361
 
  Protocol *protocol=thd->protocol;
 
391
  Protocol *protocol=session->protocol;
362
392
 
363
 
  if (store_db_create_info(thd, dbname, &buffer, create_info))
 
393
  if (store_db_create_info(session, dbname, &buffer, create_info))
364
394
  {
365
 
    /* 
 
395
    /*
366
396
      This assumes that the only reason for which store_db_create_info()
367
397
      can fail is incorrect database name (which is the case now).
368
398
    */
369
399
    my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
370
 
    return(true);    
 
400
    return(true);
371
401
  }
372
402
 
373
403
  List<Item> field_list;
384
414
 
385
415
  if (protocol->write())
386
416
    return(true);
387
 
  my_eof(thd);
 
417
  my_eof(session);
388
418
  return(false);
389
419
}
390
420
 
396
426
****************************************************************************/
397
427
 
398
428
void
399
 
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
 
429
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
400
430
{
401
 
  TABLE *table;
 
431
  Table *table;
402
432
 
403
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
433
  if (open_normal_and_derived_tables(session, table_list, 0))
404
434
    return;
405
435
  table= table_list->table;
406
436
 
409
439
  Field **ptr,*field;
410
440
  for (ptr=table->field ; (field= *ptr); ptr++)
411
441
  {
412
 
    if (!wild || !wild[0] || 
 
442
    if (!wild || !wild[0] ||
413
443
        !wild_case_compare(system_charset_info, field->field_name,wild))
414
444
    {
415
445
      field_list.push_back(new Item_field(field));
417
447
  }
418
448
  restore_record(table, s->default_values);              // Get empty record
419
449
  table->use_all_columns();
420
 
  if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
 
450
  if (session->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
421
451
    return;
422
 
  my_eof(thd);
 
452
  my_eof(session);
423
453
  return;
424
454
}
425
455
 
438
468
    0   No conflicting character
439
469
*/
440
470
 
441
 
static const char *require_quotes(const char *name, uint name_length)
 
471
static const char *require_quotes(const char *name, uint32_t name_length)
442
472
{
443
 
  uint length;
 
473
  uint32_t length;
444
474
  bool pure_digit= true;
445
475
  const char *end= name + name_length;
446
476
 
447
477
  for (; name < end ; name++)
448
478
  {
449
 
    uchar chr= (uchar) *name;
 
479
    unsigned char chr= (unsigned char) *name;
450
480
    length= my_mbcharlen(system_charset_info, chr);
451
481
    if (length == 1 && !system_charset_info->ident_map[chr])
452
482
      return name;
465
495
 
466
496
  SYNOPSIS
467
497
  append_identifier()
468
 
  thd                   thread handler
 
498
  session                   thread handler
469
499
  packet                target string
470
500
  name                  the identifier to be appended
471
501
  name_length           length of the appending identifier
472
502
*/
473
503
 
474
504
void
475
 
append_identifier(THD *thd, String *packet, const char *name, uint length)
 
505
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
476
506
{
477
507
  const char *name_end;
478
508
  char quote_char;
479
 
  int q= get_quote_char_for_identifier(thd, name, length);
 
509
  int q= get_quote_char_for_identifier(session, name, length);
480
510
 
481
511
  if (q == EOF)
482
512
  {
489
519
   it's a keyword
490
520
  */
491
521
 
492
 
  VOID(packet->reserve(length*2 + 2));
 
522
  packet->reserve(length*2 + 2);
493
523
  quote_char= (char) q;
494
524
  packet->append(&quote_char, 1, system_charset_info);
495
525
 
496
526
  for (name_end= name+length ; name < name_end ; name+= length)
497
527
  {
498
 
    uchar chr= (uchar) *name;
 
528
    unsigned char chr= (unsigned char) *name;
499
529
    length= my_mbcharlen(system_charset_info, chr);
500
530
    /*
501
531
      my_mbcharlen can return 0 on a wrong multibyte
506
536
    */
507
537
    if (!length)
508
538
      length= 1;
509
 
    if (length == 1 && chr == (uchar) quote_char)
 
539
    if (length == 1 && chr == (unsigned char) quote_char)
510
540
      packet->append(&quote_char, 1, system_charset_info);
511
541
    packet->append(name, length, system_charset_info);
512
542
  }
519
549
 
520
550
  SYNOPSIS
521
551
    get_quote_char_for_identifier()
522
 
    thd         Thread handler
 
552
    session             Thread handler
523
553
    name        name to quote
524
554
    length      length of name
525
555
 
537
567
    #     Quote character
538
568
*/
539
569
 
540
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
 
570
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
541
571
{
542
572
  if (length &&
543
573
      !is_keyword(name,length) &&
544
574
      !require_quotes(name, length) &&
545
 
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
 
575
      !(session->options & OPTION_QUOTE_SHOW_CREATE))
546
576
    return EOF;
547
 
  return '"';
 
577
  return '`';
548
578
}
549
579
 
550
580
 
551
581
/* Append directory name (if exists) to CREATE INFO */
552
582
 
553
 
static void append_directory(THD *thd __attribute__((unused)),
 
583
static void append_directory(Session *,
554
584
                             String *packet, const char *dir_type,
555
 
                             const char *filename)
 
585
                             const char *filename)
556
586
{
557
587
  if (filename)
558
588
  {
559
 
    uint length= dirname_length(filename);
 
589
    uint32_t length= dirname_length(filename);
560
590
    packet->append(' ');
561
591
    packet->append(dir_type);
562
592
    packet->append(STRING_WITH_LEN(" DIRECTORY='"));
568
598
 
569
599
#define LIST_PROCESS_HOST_LEN 64
570
600
 
571
 
static bool get_field_default_value(THD *thd __attribute__((unused)),
 
601
static bool get_field_default_value(Session *,
572
602
                                    Field *timestamp_field,
573
603
                                    Field *field, String *def_value,
574
604
                                    bool quoted)
576
606
  bool has_default;
577
607
  bool has_now_default;
578
608
 
579
 
  /* 
 
609
  /*
580
610
     We are using CURRENT_TIMESTAMP instead of NOW because it is
581
611
     more standard
582
612
  */
583
613
  has_now_default= (timestamp_field == field &&
584
614
                    field->unireg_check != Field::TIMESTAMP_UN_FIELD);
585
 
    
 
615
 
586
616
  has_default= (field->type() != DRIZZLE_TYPE_BLOB &&
587
617
                !(field->flags & NO_DEFAULT_VALUE_FLAG) &&
588
618
                field->unireg_check != Field::NEXT_NUMBER
601
631
      if (type.length())
602
632
      {
603
633
        String def_val;
604
 
        uint dummy_errors;
 
634
        uint32_t dummy_errors;
605
635
        /* convert to system_charset_info == utf8 */
606
636
        def_val.copy(type.ptr(), type.length(), field->charset(),
607
637
                     system_charset_info, &dummy_errors);
627
657
 
628
658
  SYNOPSIS
629
659
    store_create_info()
630
 
    thd               The thread
 
660
    session               The thread
631
661
    table_list        A list containing one table to write statement
632
662
                      for.
633
663
    packet            Pointer to a string where statement will be
636
666
                      to tailor the format of the statement.  Can be
637
667
                      NULL, in which case only SQL_MODE is considered
638
668
                      when building the statement.
639
 
  
 
669
 
640
670
  NOTE
641
671
    Currently always return 0, but might return error code in the
642
672
    future.
643
 
    
 
673
 
644
674
  RETURN
645
675
    0       OK
646
676
 */
647
677
 
648
 
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
 
678
int store_create_info(Session *session, TableList *table_list, String *packet,
649
679
                      HA_CREATE_INFO *create_info_arg)
650
680
{
651
681
  List<Item> field_list;
652
 
  char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
 
682
  char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
653
683
  const char *alias;
 
684
  string buff;
654
685
  String type(tmp, sizeof(tmp), system_charset_info);
655
686
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
656
687
  Field **ptr,*field;
657
 
  uint primary_key;
 
688
  uint32_t primary_key;
658
689
  KEY *key_info;
659
 
  TABLE *table= table_list->table;
 
690
  Table *table= table_list->table;
660
691
  handler *file= table->file;
661
692
  TABLE_SHARE *share= table->s;
662
693
  HA_CREATE_INFO create_info;
683
714
      alias= share->table_name.str;
684
715
    }
685
716
  }
686
 
  append_identifier(thd, packet, alias, strlen(alias));
 
717
  append_identifier(session, packet, alias, strlen(alias));
687
718
  packet->append(STRING_WITH_LEN(" (\n"));
688
719
  /*
689
720
    We need this to get default values from the table
690
721
    We have to restore the read_set if we are called from insert in case
691
722
    of row based replication.
692
723
  */
693
 
  old_map= tmp_use_all_columns(table, table->read_set);
 
724
  old_map= table->use_all_columns(table->read_set);
694
725
 
695
726
  for (ptr=table->field ; (field= *ptr); ptr++)
696
727
  {
697
 
    uint flags = field->flags;
 
728
    uint32_t flags = field->flags;
698
729
 
699
730
    if (ptr != table->field)
700
731
      packet->append(STRING_WITH_LEN(",\n"));
701
732
 
702
733
    packet->append(STRING_WITH_LEN("  "));
703
 
    append_identifier(thd,packet,field->field_name, strlen(field->field_name));
 
734
    append_identifier(session,packet,field->field_name, strlen(field->field_name));
704
735
    packet->append(' ');
705
736
    // check for surprises from the previous call to Field::sql_type()
706
737
    if (type.ptr() != tmp)
708
739
    else
709
740
      type.set_charset(system_charset_info);
710
741
 
 
742
    if (field->vcol_info)
 
743
    {
 
744
      packet->append(STRING_WITH_LEN("VIRTUAL "));
 
745
    }
 
746
 
711
747
    field->sql_type(type);
712
748
    packet->append(type.ptr(), type.length(), system_charset_info);
713
749
 
 
750
    if (field->vcol_info)
 
751
    {
 
752
      packet->append(STRING_WITH_LEN(" AS ("));
 
753
      packet->append(field->vcol_info->expr_str.str,
 
754
                     field->vcol_info->expr_str.length,
 
755
                     system_charset_info);
 
756
      packet->append(STRING_WITH_LEN(")"));
 
757
      if (field->is_stored)
 
758
        packet->append(STRING_WITH_LEN(" STORED"));
 
759
    }
 
760
 
714
761
    if (field->has_charset())
715
762
    {
716
763
      if (field->charset() != share->table_charset)
718
765
        packet->append(STRING_WITH_LEN(" CHARACTER SET "));
719
766
        packet->append(field->charset()->csname);
720
767
      }
721
 
      /* 
722
 
        For string types dump collation name only if 
 
768
      /*
 
769
        For string types dump collation name only if
723
770
        collation is not primary for the given charset
724
771
      */
725
772
      if (!(field->charset()->state & MY_CS_PRIMARY))
757
804
          packet->append(STRING_WITH_LEN(" DYNAMIC */"));
758
805
      }
759
806
    }
760
 
    if (get_field_default_value(thd, table->timestamp_field,
 
807
    if (!field->vcol_info &&
 
808
        get_field_default_value(session, table->timestamp_field,
761
809
                                field, &def_value, 1))
762
810
    {
763
811
      packet->append(STRING_WITH_LEN(" DEFAULT "));
784
832
  file->update_create_info(&create_info);
785
833
  primary_key= share->primary_key;
786
834
 
787
 
  for (uint i=0 ; i < share->keys ; i++,key_info++)
 
835
  for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
788
836
  {
789
837
    KEY_PART_INFO *key_part= key_info->key_part;
790
838
    bool found_primary=0;
791
839
    packet->append(STRING_WITH_LEN(",\n  "));
792
840
 
793
 
    if (i == primary_key && !strcmp(key_info->name, primary_key_name))
 
841
    if (i == primary_key && is_primary_key(key_info))
794
842
    {
795
843
      found_primary=1;
796
844
      /*
805
853
      packet->append(STRING_WITH_LEN("KEY "));
806
854
 
807
855
    if (!found_primary)
808
 
     append_identifier(thd, packet, key_info->name, strlen(key_info->name));
 
856
     append_identifier(session, packet, key_info->name, strlen(key_info->name));
809
857
 
810
858
    packet->append(STRING_WITH_LEN(" ("));
811
859
 
812
 
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
 
860
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
813
861
    {
814
862
      if (j)
815
863
        packet->append(',');
816
864
 
817
865
      if (key_part->field)
818
 
        append_identifier(thd,packet,key_part->field->field_name,
 
866
        append_identifier(session,packet,key_part->field->field_name,
819
867
                          strlen(key_part->field->field_name));
820
868
      if (key_part->field &&
821
869
          (key_part->length !=
822
870
           table->field[key_part->fieldnr-1]->key_length()))
823
871
      {
824
 
        char *end;
825
 
        buff[0] = '(';
826
 
        end= int10_to_str((long) key_part->length /
827
 
                          key_part->field->charset()->mbmaxlen,
828
 
                          buff + 1,10);
829
 
        *end++ = ')';
830
 
        packet->append(buff,(uint) (end-buff));
 
872
        buff= "(";
 
873
        buff= to_string(buff, (int32_t) key_part->length /
 
874
                              key_part->field->charset()->mbmaxlen);
 
875
        buff += ")";
 
876
        packet->append(buff.c_str(), buff.length());
831
877
      }
832
878
    }
833
879
    packet->append(')');
834
 
    store_key_options(thd, packet, table, key_info);
 
880
    store_key_options(session, packet, table, key_info);
835
881
  }
836
882
 
837
883
  /*
877
923
 
878
924
    if (create_info.auto_increment_value > 1)
879
925
    {
880
 
      char *end;
881
926
      packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
882
 
      end= int64_t10_to_str(create_info.auto_increment_value, buff,10);
883
 
      packet->append(buff, (uint) (end - buff));
884
 
    }
885
 
 
886
 
    
887
 
    if (share->table_charset)
888
 
    {
889
 
      /*
890
 
        IF   check_create_info
891
 
        THEN add DEFAULT CHARSET only if it was used when creating the table
892
 
      */
893
 
      if (!create_info_arg ||
894
 
          (create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
895
 
      {
896
 
        packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
897
 
        packet->append(share->table_charset->csname);
898
 
        if (!(share->table_charset->state & MY_CS_PRIMARY))
899
 
        {
900
 
          packet->append(STRING_WITH_LEN(" COLLATE="));
901
 
          packet->append(table->s->table_charset->name);
902
 
        }
903
 
      }
 
927
      buff= to_string(create_info.auto_increment_value);
 
928
      packet->append(buff.c_str(), buff.length());
904
929
    }
905
930
 
906
931
    if (share->min_rows)
907
932
    {
908
 
      char *end;
909
933
      packet->append(STRING_WITH_LEN(" MIN_ROWS="));
910
 
      end= int64_t10_to_str(share->min_rows, buff, 10);
911
 
      packet->append(buff, (uint) (end- buff));
 
934
      buff= to_string(share->min_rows);
 
935
      packet->append(buff.c_str(), buff.length());
912
936
    }
913
937
 
914
938
    if (share->max_rows && !table_list->schema_table)
915
939
    {
916
 
      char *end;
917
940
      packet->append(STRING_WITH_LEN(" MAX_ROWS="));
918
 
      end= int64_t10_to_str(share->max_rows, buff, 10);
919
 
      packet->append(buff, (uint) (end - buff));
 
941
      buff= to_string(share->max_rows);
 
942
      packet->append(buff.c_str(), buff.length());
920
943
    }
921
944
 
922
945
    if (share->avg_row_length)
923
946
    {
924
 
      char *end;
925
947
      packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
926
 
      end= int64_t10_to_str(share->avg_row_length, buff,10);
927
 
      packet->append(buff, (uint) (end - buff));
 
948
      buff= to_string(share->avg_row_length);
 
949
      packet->append(buff.c_str(), buff.length());
928
950
    }
929
951
 
930
952
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
953
975
    }
954
976
    if (table->s->key_block_size)
955
977
    {
956
 
      char *end;
957
978
      packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
958
 
      end= int64_t10_to_str(table->s->key_block_size, buff, 10);
959
 
      packet->append(buff, (uint) (end - buff));
 
979
      buff= to_string(table->s->key_block_size);
 
980
      packet->append(buff.c_str(), buff.length());
960
981
    }
961
982
    if (share->block_size)
962
983
    {
963
 
      char *end;
964
984
      packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
965
 
      end= int64_t10_to_str(share->block_size, buff,10);
966
 
      packet->append(buff, (uint) (end - buff));
 
985
      buff= to_string(share->block_size);
 
986
      packet->append(buff.c_str(), buff.length());
967
987
    }
968
988
    table->file->append_create_info(packet);
969
989
    if (share->comment.length)
976
996
      packet->append(STRING_WITH_LEN(" CONNECTION="));
977
997
      append_unescaped(packet, share->connect_string.str, share->connect_string.length);
978
998
    }
979
 
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
980
 
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
 
999
    append_directory(session, packet, "DATA",  create_info.data_file_name);
 
1000
    append_directory(session, packet, "INDEX", create_info.index_file_name);
981
1001
  }
982
 
  tmp_restore_column_map(table->read_set, old_map);
 
1002
  table->restore_column_map(old_map);
983
1003
  return(0);
984
1004
}
985
1005
 
996
1016
  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
997
1017
  in @c create_options are ignored.
998
1018
 
999
 
  @param  thd           The current thread instance.
 
1019
  @param  session           The current thread instance.
1000
1020
  @param  dbname        The name of the database.
1001
1021
  @param  buffer        A String instance where the statement is stored.
1002
 
  @param  create_info   If not NULL, the options member influences the resulting 
 
1022
  @param  create_info   If not NULL, the options member influences the resulting
1003
1023
                        CRATE statement.
1004
1024
 
1005
1025
  @returns true if errors are detected, false otherwise.
1006
1026
*/
1007
1027
 
1008
 
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
 
1028
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
1009
1029
                          HA_CREATE_INFO *create_info)
1010
1030
{
1011
1031
  HA_CREATE_INFO create;
1012
 
  uint create_options = create_info ? create_info->options : 0;
 
1032
  uint32_t create_options = create_info ? create_info->options : 0;
1013
1033
 
1014
1034
  if (!my_strcasecmp(system_charset_info, dbname,
1015
 
                     INFORMATION_SCHEMA_NAME.str))
 
1035
                     INFORMATION_SCHEMA_NAME.c_str()))
1016
1036
  {
1017
 
    dbname= INFORMATION_SCHEMA_NAME.str;
 
1037
    dbname= INFORMATION_SCHEMA_NAME.c_str();
1018
1038
    create.default_table_charset= system_charset_info;
1019
1039
  }
1020
1040
  else
1022
1042
    if (check_db_dir_existence(dbname))
1023
1043
      return(true);
1024
1044
 
1025
 
    load_db_opt_by_name(thd, dbname, &create);
 
1045
    load_db_opt_by_name(session, dbname, &create);
1026
1046
  }
1027
1047
 
1028
1048
  buffer->length(0);
1033
1053
  if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1034
1054
    buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1035
1055
 
1036
 
  append_identifier(thd, buffer, dbname, strlen(dbname));
 
1056
  append_identifier(session, buffer, dbname, strlen(dbname));
1037
1057
 
1038
1058
  if (create.default_table_charset)
1039
1059
  {
1051
1071
  return(false);
1052
1072
}
1053
1073
 
1054
 
static void store_key_options(THD *thd __attribute__((unused)),
1055
 
                              String *packet, TABLE *table,
 
1074
static void store_key_options(Session *,
 
1075
                              String *packet, Table *table,
1056
1076
                              KEY *key_info)
1057
1077
{
1058
1078
  char *end, buff[32];
1071
1091
    packet->append(buff, (uint) (end - buff));
1072
1092
  }
1073
1093
 
1074
 
  assert(test(key_info->flags & HA_USES_COMMENT) == 
 
1094
  assert(test(key_info->flags & HA_USES_COMMENT) ==
1075
1095
              (key_info->comment.length > 0));
1076
1096
  if (key_info->flags & HA_USES_COMMENT)
1077
1097
  {
1078
1098
    packet->append(STRING_WITH_LEN(" COMMENT "));
1079
 
    append_unescaped(packet, key_info->comment.str, 
 
1099
    append_unescaped(packet, key_info->comment.str,
1080
1100
                     key_info->comment.length);
1081
1101
  }
1082
1102
}
1093
1113
  {
1094
1114
    return (void*) sql_alloc((uint) size);
1095
1115
  }
1096
 
  static void operator delete(void *ptr __attribute__((unused)),
1097
 
                              size_t size __attribute__((unused)))
 
1116
  static void operator delete(void *, size_t)
1098
1117
  { TRASH(ptr, size); }
1099
1118
 
1100
1119
  ulong thread_id;
1101
1120
  time_t start_time;
1102
 
  uint   command;
 
1121
  uint32_t   command;
1103
1122
  const char *user,*host,*db,*proc_info,*state_info;
1104
1123
  char *query;
1105
1124
};
1108
1127
template class I_List<thread_info>;
1109
1128
#endif
1110
1129
 
1111
 
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
 
1130
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1112
1131
{
1113
1132
  Item *field;
1114
1133
  List<Item> field_list;
1115
1134
  I_List<thread_info> thread_infos;
1116
 
  ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
 
1135
  ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1117
1136
                           PROCESS_LIST_WIDTH);
1118
 
  Protocol *protocol= thd->protocol;
 
1137
  Protocol *protocol= session->protocol;
1119
1138
 
1120
1139
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1121
1140
  field_list.push_back(new Item_empty_string("User",16));
1132
1151
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1133
1152
    return;
1134
1153
 
1135
 
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1136
 
  if (!thd->killed)
 
1154
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1155
  if (!session->killed)
1137
1156
  {
1138
 
    I_List_iterator<THD> it(threads);
1139
 
    THD *tmp;
 
1157
    I_List_iterator<Session> it(threads);
 
1158
    Session *tmp;
1140
1159
    while ((tmp=it++))
1141
1160
    {
1142
 
      Security_context *tmp_sctx= tmp->security_ctx;
 
1161
      Security_context *tmp_sctx= &tmp->security_ctx;
1143
1162
      struct st_my_thread_var *mysys_var;
1144
 
      if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
 
1163
      if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user.c_str() && !strcmp(tmp_sctx->user.c_str(), user))))
1145
1164
      {
1146
 
        thread_info *thd_info= new thread_info;
 
1165
        thread_info *session_info= new thread_info;
1147
1166
 
1148
 
        thd_info->thread_id=tmp->thread_id;
1149
 
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
 
1167
        session_info->thread_id=tmp->thread_id;
 
1168
        session_info->user= session->strdup(tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1150
1169
                                    (tmp->system_thread ?
1151
1170
                                     "system user" : "unauthenticated user"));
1152
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
1153
 
        if ((thd_info->db=tmp->db))             // Safe test
1154
 
          thd_info->db=thd->strdup(thd_info->db);
1155
 
        thd_info->command=(int) tmp->command;
 
1171
        session_info->host= session->strdup(tmp_sctx->ip.c_str());
 
1172
        if ((session_info->db=tmp->db))             // Safe test
 
1173
          session_info->db=session->strdup(session_info->db);
 
1174
        session_info->command=(int) tmp->command;
1156
1175
        if ((mysys_var= tmp->mysys_var))
1157
1176
          pthread_mutex_lock(&mysys_var->mutex);
1158
 
        thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
1159
 
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
 
1177
        session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
 
1178
        session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1160
1179
                                       (tmp->net.reading_or_writing == 2 ?
1161
1180
                                        "Writing to net" :
1162
 
                                        thd_info->command == COM_SLEEP ? NullS :
 
1181
                                        session_info->command == COM_SLEEP ? NULL :
1163
1182
                                        "Reading from net") :
1164
 
                                       tmp->proc_info ? tmp->proc_info :
 
1183
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
1165
1184
                                       tmp->mysys_var &&
1166
1185
                                       tmp->mysys_var->current_cond ?
1167
 
                                       "Waiting on cond" : NullS);
 
1186
                                       "Waiting on cond" : NULL);
1168
1187
        if (mysys_var)
1169
1188
          pthread_mutex_unlock(&mysys_var->mutex);
1170
1189
 
1171
 
        thd_info->start_time= tmp->start_time;
1172
 
        thd_info->query=0;
 
1190
        session_info->start_time= tmp->start_time;
 
1191
        session_info->query=0;
1173
1192
        if (tmp->query)
1174
1193
        {
1175
 
          /* 
 
1194
          /*
1176
1195
            query_length is always set to 0 when we set query = NULL; see
1177
 
            the comment in sql_class.h why this prevents crashes in possible
 
1196
                  the comment in session.h why this prevents crashes in possible
1178
1197
            races with query_length
1179
1198
          */
1180
 
          uint length= min((uint32_t)max_query_length, tmp->query_length);
1181
 
          thd_info->query=(char*) thd->strmake(tmp->query,length);
 
1199
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
 
1200
          session_info->query=(char*) session->strmake(tmp->query,length);
1182
1201
        }
1183
 
        thread_infos.append(thd_info);
 
1202
        thread_infos.append(session_info);
1184
1203
      }
1185
1204
    }
1186
1205
  }
1187
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1206
  pthread_mutex_unlock(&LOCK_thread_count);
1188
1207
 
1189
 
  thread_info *thd_info;
1190
 
  time_t now= my_time(0);
1191
 
  while ((thd_info=thread_infos.get()))
 
1208
  thread_info *session_info;
 
1209
  time_t now= time(NULL);
 
1210
  while ((session_info=thread_infos.get()))
1192
1211
  {
1193
1212
    protocol->prepare_for_resend();
1194
 
    protocol->store((uint64_t) thd_info->thread_id);
1195
 
    protocol->store(thd_info->user, system_charset_info);
1196
 
    protocol->store(thd_info->host, system_charset_info);
1197
 
    protocol->store(thd_info->db, system_charset_info);
1198
 
    if (thd_info->proc_info)
1199
 
      protocol->store(thd_info->proc_info, system_charset_info);
 
1213
    protocol->store((uint64_t) session_info->thread_id);
 
1214
    protocol->store(session_info->user, system_charset_info);
 
1215
    protocol->store(session_info->host, system_charset_info);
 
1216
    protocol->store(session_info->db, system_charset_info);
 
1217
    if (session_info->proc_info)
 
1218
      protocol->store(session_info->proc_info, system_charset_info);
1200
1219
    else
1201
 
      protocol->store(command_name[thd_info->command].str, system_charset_info);
1202
 
    if (thd_info->start_time)
1203
 
      protocol->store((uint32_t) (now - thd_info->start_time));
 
1220
      protocol->store(command_name[session_info->command].str, system_charset_info);
 
1221
    if (session_info->start_time)
 
1222
      protocol->store((uint32_t) (now - session_info->start_time));
1204
1223
    else
1205
1224
      protocol->store_null();
1206
 
    protocol->store(thd_info->state_info, system_charset_info);
1207
 
    protocol->store(thd_info->query, system_charset_info);
 
1225
    protocol->store(session_info->state_info, system_charset_info);
 
1226
    protocol->store(session_info->query, system_charset_info);
1208
1227
    if (protocol->write())
1209
1228
      break; /* purecov: inspected */
1210
1229
  }
1211
 
  my_eof(thd);
 
1230
  my_eof(session);
1212
1231
  return;
1213
1232
}
1214
1233
 
1215
 
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1216
 
                            COND* cond __attribute__((unused)))
 
1234
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1217
1235
{
1218
 
  TABLE *table= tables->table;
 
1236
  Table *table= tables->table;
1219
1237
  const CHARSET_INFO * const cs= system_charset_info;
1220
1238
  char *user;
1221
 
  time_t now= my_time(0);
1222
 
 
1223
 
  user= NullS;
1224
 
 
1225
 
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1226
 
 
1227
 
  if (!thd->killed)
 
1239
  time_t now= time(NULL);
 
1240
 
 
1241
  if (now == (time_t)-1)
 
1242
    return 1;
 
1243
 
 
1244
  user= NULL;
 
1245
 
 
1246
  pthread_mutex_lock(&LOCK_thread_count);
 
1247
 
 
1248
  if (!session->killed)
1228
1249
  {
1229
 
    I_List_iterator<THD> it(threads);
1230
 
    THD* tmp;
 
1250
    I_List_iterator<Session> it(threads);
 
1251
    Session* tmp;
1231
1252
 
1232
1253
    while ((tmp= it++))
1233
1254
    {
1234
 
      Security_context *tmp_sctx= tmp->security_ctx;
 
1255
      Security_context *tmp_sctx= &tmp->security_ctx;
1235
1256
      struct st_my_thread_var *mysys_var;
1236
1257
      const char *val;
1237
1258
 
1242
1263
      /* ID */
1243
1264
      table->field[0]->store((int64_t) tmp->thread_id, true);
1244
1265
      /* USER */
1245
 
      val= tmp_sctx->user ? tmp_sctx->user :
 
1266
      val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1246
1267
            (tmp->system_thread ? "system user" : "unauthenticated user");
1247
1268
      table->field[1]->store(val, strlen(val), cs);
1248
1269
      /* HOST */
1249
 
      table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
 
1270
      table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
1250
1271
      /* DB */
1251
1272
      if (tmp->db)
1252
1273
      {
1257
1278
      if ((mysys_var= tmp->mysys_var))
1258
1279
        pthread_mutex_lock(&mysys_var->mutex);
1259
1280
      /* COMMAND */
1260
 
      if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
 
1281
      if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
1261
1282
        table->field[4]->store(val, strlen(val), cs);
1262
1283
      else
1263
1284
        table->field[4]->store(command_name[tmp->command].str,
1269
1290
      val= (char*) (tmp->net.reading_or_writing ?
1270
1291
                    (tmp->net.reading_or_writing == 2 ?
1271
1292
                     "Writing to net" :
1272
 
                     tmp->command == COM_SLEEP ? NullS :
 
1293
                     tmp->command == COM_SLEEP ? NULL :
1273
1294
                     "Reading from net") :
1274
 
                    tmp->proc_info ? tmp->proc_info :
 
1295
                    tmp->get_proc_info() ? tmp->get_proc_info() :
1275
1296
                    tmp->mysys_var &&
1276
1297
                    tmp->mysys_var->current_cond ?
1277
 
                    "Waiting on cond" : NullS);
 
1298
                    "Waiting on cond" : NULL);
1278
1299
      if (val)
1279
1300
      {
1280
1301
        table->field[6]->store(val, strlen(val), cs);
1288
1309
      if (tmp->query)
1289
1310
      {
1290
1311
        table->field[7]->store(tmp->query,
1291
 
                               min((uint32_t)PROCESS_LIST_INFO_WIDTH,
 
1312
                               cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
1292
1313
                                   tmp->query_length), cs);
1293
1314
        table->field[7]->set_notnull();
1294
1315
      }
1295
1316
 
1296
 
      if (schema_table_store_record(thd, table))
 
1317
      if (schema_table_store_record(session, table))
1297
1318
      {
1298
 
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1319
        pthread_mutex_unlock(&LOCK_thread_count);
1299
1320
        return(1);
1300
1321
      }
1301
1322
    }
1302
1323
  }
1303
1324
 
1304
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1325
  pthread_mutex_unlock(&LOCK_thread_count);
1305
1326
  return(0);
1306
1327
}
1307
1328
 
1322
1343
*/
1323
1344
static void shrink_var_array(DYNAMIC_ARRAY *array)
1324
1345
{
1325
 
  uint a,b;
 
1346
  uint32_t a,b;
1326
1347
  SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1327
1348
 
1328
1349
  for (a= b= 0; b < array->elements; b++)
1368
1389
    goto err;
1369
1390
  }
1370
1391
  while (list->name)
1371
 
    res|= insert_dynamic(&all_status_vars, (uchar*)list++);
1372
 
  res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
 
1392
    res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
 
1393
  res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
1373
1394
  all_status_vars.elements--; // but next insert_dynamic should overwite it
1374
1395
  if (status_vars_inited)
1375
1396
    sort_dynamic(&all_status_vars, show_var_cmp);
1402
1423
    /* Note that SHOW_LONG_NOFLUSH variables are not reset */
1403
1424
    if (ptr->type == SHOW_LONG)
1404
1425
      *(ulong*) ptr->value= 0;
1405
 
  }  
 
1426
  }
1406
1427
}
1407
1428
 
1408
1429
/*
1463
1484
  else
1464
1485
  {
1465
1486
    SHOW_VAR *all= dynamic_element(&all_status_vars, 0, SHOW_VAR *);
1466
 
    uint i;
 
1487
    uint32_t i;
1467
1488
    for (; list->name; list++)
1468
1489
    {
1469
1490
      for (i= 0; i < all_status_vars.elements; i++)
1484
1505
    *buf= my_toupper(system_charset_info, *buf);
1485
1506
}
1486
1507
 
1487
 
static bool show_status_array(THD *thd, const char *wild,
 
1508
static bool show_status_array(Session *session, const char *wild,
1488
1509
                              SHOW_VAR *variables,
1489
1510
                              enum enum_var_type value_type,
1490
1511
                              struct system_status_var *status_var,
1491
 
                              const char *prefix, TABLE *table,
 
1512
                              const char *prefix, Table *table,
1492
1513
                              bool ucase_names)
1493
1514
{
1494
 
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
 
1515
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1495
1516
  char * const buff= (char *) &buff_data;
1496
1517
  char *prefix_end;
1497
1518
  /* the variable name should not be longer than 64 characters */
1503
1524
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1504
1525
  null_lex_str.length= 0;
1505
1526
 
1506
 
  prefix_end=stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1527
  prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1528
  prefix_end+= strlen(prefix);
 
1529
 
1507
1530
  if (*prefix)
1508
1531
    *prefix_end++= '_';
1509
1532
  len=name_buffer + sizeof(name_buffer) - prefix_end;
1510
1533
 
1511
1534
  for (; variables->name; variables++)
1512
1535
  {
1513
 
    stpncpy(prefix_end, variables->name, len);
 
1536
    strncpy(prefix_end, variables->name, len);
1514
1537
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
1515
1538
    if (ucase_names)
1516
1539
      make_upper(name_buffer);
1520
1543
      Repeat as necessary, if new var is again SHOW_FUNC
1521
1544
    */
1522
1545
    for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1523
 
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
 
1546
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1524
1547
 
1525
1548
    SHOW_TYPE show_type=var->type;
1526
1549
    if (show_type == SHOW_ARRAY)
1527
1550
    {
1528
 
      show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
 
1551
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1529
1552
                        status_var, name_buffer, table, ucase_names);
1530
1553
    }
1531
1554
    else
1535
1558
      {
1536
1559
        char *value=var->value;
1537
1560
        const char *pos, *end;                  // We assign a lot of const's
1538
 
 
1539
1561
        pthread_mutex_lock(&LOCK_global_system_variables);
1540
1562
 
1541
1563
        if (show_type == SHOW_SYS)
1542
1564
        {
1543
1565
          show_type= ((sys_var*) value)->show_type();
1544
 
          value=     (char*) ((sys_var*) value)->value_ptr(thd, value_type,
 
1566
          value=     (char*) ((sys_var*) value)->value_ptr(session, value_type,
1545
1567
                                                           &null_lex_str);
1546
1568
        }
1547
1569
 
1571
1593
        case SHOW_LONGLONG:
1572
1594
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1573
1595
          break;
 
1596
        case SHOW_SIZE:
 
1597
          {
 
1598
            stringstream ss (stringstream::in);
 
1599
            ss << *(size_t*) value;
 
1600
 
 
1601
            string str= ss.str();
 
1602
            strncpy(buff, str.c_str(), str.length());
 
1603
            end= buff+ str.length();
 
1604
          }
 
1605
          break;
1574
1606
        case SHOW_HA_ROWS:
1575
1607
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1576
1608
          break;
1577
1609
        case SHOW_BOOL:
1578
 
          end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1610
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1579
1611
          break;
1580
1612
        case SHOW_MY_BOOL:
1581
 
          end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1613
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1582
1614
          break;
1583
1615
        case SHOW_INT:
1584
1616
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1587
1619
        {
1588
1620
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1589
1621
          pos= show_comp_option_name[(int) tmp];
1590
 
          end= strend(pos);
 
1622
          end= strchr(pos, '\0');
1591
1623
          break;
1592
1624
        }
1593
1625
        case SHOW_CHAR:
1594
1626
        {
1595
1627
          if (!(pos= value))
1596
1628
            pos= "";
1597
 
          end= strend(pos);
 
1629
          end= strchr(pos, '\0');
1598
1630
          break;
1599
1631
        }
1600
1632
       case SHOW_CHAR_PTR:
1601
1633
        {
1602
1634
          if (!(pos= *(char**) value))
1603
1635
            pos= "";
1604
 
          end= strend(pos);
 
1636
          end= strchr(pos, '\0');
1605
1637
          break;
1606
1638
        }
1607
1639
        case SHOW_KEY_CACHE_LONG:
1627
1659
 
1628
1660
        pthread_mutex_unlock(&LOCK_global_system_variables);
1629
1661
 
1630
 
        if (schema_table_store_record(thd, table))
 
1662
        if (schema_table_store_record(session, table))
1631
1663
          return(true);
1632
1664
      }
1633
1665
    }
1643
1675
{
1644
1676
 
1645
1677
  /* Ensure that thread id not killed during loop */
1646
 
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1647
 
 
1648
 
  I_List_iterator<THD> it(threads);
1649
 
  THD *tmp;
1650
 
  
 
1678
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1679
 
 
1680
  I_List_iterator<Session> it(threads);
 
1681
  Session *tmp;
 
1682
 
1651
1683
  /* Get global values as base */
1652
1684
  *to= global_status_var;
1653
 
  
 
1685
 
1654
1686
  /* Add to this status from existing threads */
1655
1687
  while ((tmp= it++))
1656
1688
    add_to_status(to, &tmp->status_var);
1657
 
  
1658
 
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1689
 
 
1690
  pthread_mutex_unlock(&LOCK_thread_count);
1659
1691
  return;
1660
1692
}
1661
1693
 
1676
1708
 
1677
1709
  SYNOPSIS
1678
1710
    schema_table_store_record()
1679
 
    thd                   thread handler
 
1711
    session                   thread handler
1680
1712
    table                 Information schema table to be updated
1681
1713
 
1682
1714
  RETURN
1684
1716
    1                     error
1685
1717
*/
1686
1718
 
1687
 
bool schema_table_store_record(THD *thd, TABLE *table)
 
1719
bool schema_table_store_record(Session *session, Table *table)
1688
1720
{
1689
1721
  int error;
1690
1722
  if ((error= table->file->ha_write_row(table->record[0])))
1691
1723
  {
1692
1724
    TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1693
1725
 
1694
 
    if (create_myisam_from_heap(thd, table, param->start_recinfo, 
 
1726
    if (create_myisam_from_heap(session, table, param->start_recinfo,
1695
1727
                                &param->recinfo, error, 0))
1696
1728
      return 1;
1697
1729
  }
1699
1731
}
1700
1732
 
1701
1733
 
1702
 
int make_table_list(THD *thd, SELECT_LEX *sel,
 
1734
int make_table_list(Session *session, SELECT_LEX *sel,
1703
1735
                    LEX_STRING *db_name, LEX_STRING *table_name)
1704
1736
{
1705
1737
  Table_ident *table_ident;
1706
 
  table_ident= new Table_ident(thd, *db_name, *table_name, 1);
 
1738
  table_ident= new Table_ident(session, *db_name, *table_name, 1);
1707
1739
  sel->init_query();
1708
 
  if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
 
1740
  if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1709
1741
    return 1;
1710
1742
  return 0;
1711
1743
}
1712
1744
 
1713
1745
 
1714
1746
/**
1715
 
  @brief    Get lookup value from the part of 'WHERE' condition 
 
1747
  @brief    Get lookup value from the part of 'WHERE' condition
1716
1748
 
1717
 
  @details This function gets lookup value from 
1718
 
           the part of 'WHERE' condition if it's possible and 
 
1749
  @details This function gets lookup value from
 
1750
           the part of 'WHERE' condition if it's possible and
1719
1751
           fill appropriate lookup_field_vals struct field
1720
1752
           with this value.
1721
1753
 
1722
 
  @param[in]      thd                   thread handler
 
1754
  @param[in]      session                   thread handler
1723
1755
  @param[in]      item_func             part of WHERE condition
1724
1756
  @param[in]      table                 I_S table
1725
 
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
 
1757
  @param[in, out] lookup_field_vals     Struct which holds lookup values
1726
1758
 
1727
1759
  @return
1728
1760
    0             success
1729
1761
    1             error, there can be no matching records for the condition
1730
1762
*/
1731
1763
 
1732
 
bool get_lookup_value(THD *thd, Item_func *item_func,
1733
 
                      TABLE_LIST *table, 
 
1764
bool get_lookup_value(Session *session, Item_func *item_func,
 
1765
                      TableList *table,
1734
1766
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1735
1767
{
1736
1768
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1774
1806
      return 1;
1775
1807
 
1776
1808
    /* Lookup value is database name */
1777
 
    if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1778
 
                               (uchar *) item_field->field_name,
 
1809
    if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
 
1810
                               (unsigned char *) item_field->field_name,
1779
1811
                               strlen(item_field->field_name), 0))
1780
1812
    {
1781
 
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
 
1813
      session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1782
1814
                           tmp_str->length(), false);
1783
1815
    }
1784
1816
    /* Lookup value is table name */
1785
 
    else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
 
1817
    else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1786
1818
                                    strlen(field_name2),
1787
 
                                    (uchar *) item_field->field_name,
 
1819
                                    (unsigned char *) item_field->field_name,
1788
1820
                                    strlen(item_field->field_name), 0))
1789
1821
    {
1790
 
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
 
1822
      session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1791
1823
                           tmp_str->length(), false);
1792
1824
    }
1793
1825
  }
1796
1828
 
1797
1829
 
1798
1830
/**
1799
 
  @brief    Calculates lookup values from 'WHERE' condition 
 
1831
  @brief    Calculates lookup values from 'WHERE' condition
1800
1832
 
1801
1833
  @details This function calculates lookup value(database name, table name)
1802
 
           from 'WHERE' condition if it's possible and 
 
1834
           from 'WHERE' condition if it's possible and
1803
1835
           fill lookup_field_vals struct fields with these values.
1804
1836
 
1805
 
  @param[in]      thd                   thread handler
 
1837
  @param[in]      session                   thread handler
1806
1838
  @param[in]      cond                  WHERE condition
1807
1839
  @param[in]      table                 I_S table
1808
 
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
 
1840
  @param[in, out] lookup_field_vals     Struct which holds lookup values
1809
1841
 
1810
1842
  @return
1811
1843
    0             success
1812
1844
    1             error, there can be no matching records for the condition
1813
1845
*/
1814
1846
 
1815
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
 
1847
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1816
1848
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1817
1849
{
1818
1850
  if (!cond)
1828
1860
      {
1829
1861
        if (item->type() == Item::FUNC_ITEM)
1830
1862
        {
1831
 
          if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
 
1863
          if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1832
1864
            return 1;
1833
1865
        }
1834
1866
        else
1835
1867
        {
1836
 
          if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
 
1868
          if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1837
1869
            return 1;
1838
1870
        }
1839
1871
      }
1841
1873
    return 0;
1842
1874
  }
1843
1875
  else if (cond->type() == Item::FUNC_ITEM &&
1844
 
           get_lookup_value(thd, (Item_func*) cond, table, lookup_field_vals))
 
1876
           get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals))
1845
1877
    return 1;
1846
1878
  return 0;
1847
1879
}
1848
1880
 
1849
1881
 
1850
 
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
 
1882
bool uses_only_table_name_fields(Item *item, TableList *table)
1851
1883
{
1852
1884
  if (item->type() == Item::FUNC_ITEM)
1853
1885
  {
1854
1886
    Item_func *item_func= (Item_func*)item;
1855
 
    for (uint i=0; i<item_func->argument_count(); i++)
 
1887
    for (uint32_t i=0; i<item_func->argument_count(); i++)
1856
1888
    {
1857
1889
      if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1858
1890
        return 0;
1869
1901
    const char *field_name2= schema_table->idx_field2 >= 0 ?
1870
1902
      field_info[schema_table->idx_field2].field_name : "";
1871
1903
    if (table->table != item_field->field->table ||
1872
 
        (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1873
 
                               (uchar *) item_field->field_name,
 
1904
        (cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
 
1905
                               (unsigned char *) item_field->field_name,
1874
1906
                               strlen(item_field->field_name), 0) &&
1875
 
         cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
1876
 
                               (uchar *) item_field->field_name,
 
1907
         cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
 
1908
                               (unsigned char *) item_field->field_name,
1877
1909
                               strlen(item_field->field_name), 0)))
1878
1910
      return 0;
1879
1911
  }
1887
1919
}
1888
1920
 
1889
1921
 
1890
 
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
 
1922
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
1891
1923
{
1892
1924
  if (!cond)
1893
1925
    return (COND*) 0;
1951
1983
           from LEX struct and fill lookup_field_vals struct field
1952
1984
           with these values.
1953
1985
 
1954
 
  @param[in]      thd                   thread handler
 
1986
  @param[in]      session                   thread handler
1955
1987
  @param[in]      cond                  WHERE condition
1956
1988
  @param[in]      tables                I_S table
1957
 
  @param[in, out] lookup_field_values   Struct which holds lookup values 
 
1989
  @param[in, out] lookup_field_values   Struct which holds lookup values
1958
1990
 
1959
1991
  @return
1960
1992
    0             success
1961
1993
    1             error, there can be no matching records for the condition
1962
1994
*/
1963
1995
 
1964
 
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
 
1996
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1965
1997
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1966
1998
{
1967
 
  LEX *lex= thd->lex;
1968
 
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
1999
  LEX *lex= session->lex;
 
2000
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1969
2001
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1970
2002
  switch (lex->sql_command) {
1971
2003
  case SQLCOM_SHOW_DATABASES:
1992
2024
      The "default" is for queries over I_S.
1993
2025
      All previous cases handle SHOW commands.
1994
2026
    */
1995
 
    return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
 
2027
    return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
1996
2028
  }
1997
2029
}
1998
2030
 
2008
2040
 
2009
2041
  SYNOPSIS
2010
2042
    make_db_list()
2011
 
    thd                   thread handler
 
2043
    session                   thread handler
2012
2044
    files                 list of db names
2013
2045
    wild                  wild string
2014
2046
    idx_field_vals        idx_field_vals->db_name contains db name or
2015
2047
                          wild string
2016
2048
    with_i_schema         returns 1 if we added 'IS' name to list
2017
 
                          otherwise returns 0 
 
2049
                          otherwise returns 0
2018
2050
 
2019
2051
  RETURN
2020
2052
    zero                  success
2021
2053
    non-zero              error
2022
2054
*/
2023
2055
 
2024
 
int make_db_list(THD *thd, List<LEX_STRING> *files,
 
2056
int make_db_list(Session *session, List<LEX_STRING> *files,
2025
2057
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
2026
2058
                 bool *with_i_schema)
2027
2059
{
2028
2060
  LEX_STRING *i_s_name_copy= 0;
2029
 
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2030
 
                                      INFORMATION_SCHEMA_NAME.str,
2031
 
                                      INFORMATION_SCHEMA_NAME.length, true);
 
2061
  i_s_name_copy= session->make_lex_string(i_s_name_copy,
 
2062
                                      INFORMATION_SCHEMA_NAME.c_str(),
 
2063
                                      INFORMATION_SCHEMA_NAME.length(), true);
2032
2064
  *with_i_schema= 0;
2033
2065
  if (lookup_field_vals->wild_db_value)
2034
2066
  {
2038
2070
      LIKE clause (see also get_index_field_values() function)
2039
2071
    */
2040
2072
    if (!lookup_field_vals->db_value.str ||
2041
 
        !wild_case_compare(system_charset_info, 
2042
 
                           INFORMATION_SCHEMA_NAME.str,
 
2073
        !wild_case_compare(system_charset_info,
 
2074
                           INFORMATION_SCHEMA_NAME.c_str(),
2043
2075
                           lookup_field_vals->db_value.str))
2044
2076
    {
2045
2077
      *with_i_schema= 1;
2046
2078
      if (files->push_back(i_s_name_copy))
2047
2079
        return 1;
2048
2080
    }
2049
 
    return (find_files(thd, files, NullS, mysql_data_home,
 
2081
    return (find_files(session, files, NULL, drizzle_data_home,
2050
2082
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2051
2083
  }
2052
2084
 
2057
2089
  */
2058
2090
  if (lookup_field_vals->db_value.str)
2059
2091
  {
2060
 
    if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
 
2092
    if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.c_str(),
2061
2093
                       lookup_field_vals->db_value.str))
2062
2094
    {
2063
2095
      *with_i_schema= 1;
2077
2109
  if (files->push_back(i_s_name_copy))
2078
2110
    return 1;
2079
2111
  *with_i_schema= 1;
2080
 
  return (find_files(thd, files, NullS,
2081
 
                     mysql_data_home, NullS, 1) != FIND_FILES_OK);
 
2112
  return (find_files(session, files, NULL,
 
2113
                     drizzle_data_home, NULL, 1) != FIND_FILES_OK);
2082
2114
}
2083
2115
 
2084
2116
 
2085
 
struct st_add_schema_table 
 
2117
struct st_add_schema_table
2086
2118
{
2087
2119
  List<LEX_STRING> *files;
2088
2120
  const char *wild;
2089
2121
};
2090
2122
 
2091
2123
 
2092
 
static bool add_schema_table(THD *thd, plugin_ref plugin,
 
2124
static bool add_schema_table(Session *session, plugin_ref plugin,
2093
2125
                                void* p_data)
2094
2126
{
2095
2127
  LEX_STRING *file_name= 0;
2113
2145
      return(0);
2114
2146
  }
2115
2147
 
2116
 
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
 
2148
  if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2117
2149
                                       strlen(schema_table->table_name),
2118
2150
                                       true)) &&
2119
2151
      !file_list->push_back(file_name))
2122
2154
}
2123
2155
 
2124
2156
 
2125
 
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
 
2157
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2126
2158
{
2127
2159
  LEX_STRING *file_name= 0;
2128
2160
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2144
2176
      else if (wild_compare(tmp_schema_table->table_name, wild, 0))
2145
2177
        continue;
2146
2178
    }
2147
 
    if ((file_name= 
2148
 
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
 
2179
    if ((file_name=
 
2180
         session->make_lex_string(file_name, tmp_schema_table->table_name,
2149
2181
                              strlen(tmp_schema_table->table_name), true)) &&
2150
2182
        !files->push_back(file_name))
2151
2183
      continue;
2154
2186
 
2155
2187
  add_data.files= files;
2156
2188
  add_data.wild= wild;
2157
 
  if (plugin_foreach(thd, add_schema_table,
 
2189
  if (plugin_foreach(session, add_schema_table,
2158
2190
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2159
2191
    return(1);
2160
2192
 
2168
2200
  @details        The function creates the list of table names in
2169
2201
                  database
2170
2202
 
2171
 
  @param[in]      thd                   thread handler
 
2203
  @param[in]      session                   thread handler
2172
2204
  @param[in]      table_names           List of table names in database
2173
2205
  @param[in]      lex                   pointer to LEX struct
2174
2206
  @param[in]      lookup_field_vals     pointer to LOOKUP_FIELD_VALUE struct
2182
2214
*/
2183
2215
 
2184
2216
static int
2185
 
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
 
2217
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2186
2218
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
2187
2219
                     bool with_i_schema, LEX_STRING *db_name)
2188
2220
{
2193
2225
  {
2194
2226
    if (with_i_schema)
2195
2227
    {
2196
 
      if (find_schema_table(thd, lookup_field_vals->table_value.str))
 
2228
      if (find_schema_table(session, lookup_field_vals->table_value.str))
2197
2229
      {
2198
2230
        if (table_names->push_back(&lookup_field_vals->table_value))
2199
2231
          return 1;
2200
2232
      }
2201
2233
    }
2202
2234
    else
2203
 
    {    
 
2235
    {
2204
2236
      if (table_names->push_back(&lookup_field_vals->table_value))
2205
2237
        return 1;
2206
2238
    }
2212
2244
    to the list
2213
2245
  */
2214
2246
  if (with_i_schema)
2215
 
    return (schema_tables_add(thd, table_names,
 
2247
    return (schema_tables_add(session, table_names,
2216
2248
                              lookup_field_vals->table_value.str));
2217
2249
 
2218
 
  find_files_result res= find_files(thd, table_names, db_name->str, path,
 
2250
  find_files_result res= find_files(session, table_names, db_name->str, path,
2219
2251
                                    lookup_field_vals->table_value.str, 0);
2220
2252
  if (res != FIND_FILES_OK)
2221
2253
  {
2229
2261
    {
2230
2262
      if (lex->sql_command != SQLCOM_SELECT)
2231
2263
        return 1;
2232
 
      thd->clear_error();
 
2264
      session->clear_error();
2233
2265
      return 2;
2234
2266
    }
2235
2267
    return 1;
2241
2273
/**
2242
2274
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2243
2275
 
2244
 
  @param[in]      thd                      thread handler
2245
 
  @param[in]      tables                   TABLE_LIST for I_S table
 
2276
  @param[in]      session                      thread handler
 
2277
  @param[in]      tables                   TableList for I_S table
2246
2278
  @param[in]      schema_table             pointer to I_S structure
2247
2279
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2248
2280
                                           which is used to save|restore original
2254
2286
    @retval       1           error
2255
2287
*/
2256
2288
 
2257
 
static int 
2258
 
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
 
2289
static int
 
2290
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2259
2291
                              ST_SCHEMA_TABLE *schema_table,
2260
2292
                              Open_tables_state *open_tables_state_backup)
2261
2293
{
2262
 
  LEX *lex= thd->lex;
 
2294
  LEX *lex= session->lex;
2263
2295
  bool res;
2264
2296
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2265
2297
  enum_sql_command save_sql_command= lex->sql_command;
2266
 
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
 
2298
  TableList *show_table_list= (TableList*) tables->schema_select_lex->
2267
2299
    table_list.first;
2268
 
  TABLE *table= tables->table;
 
2300
  Table *table= tables->table;
2269
2301
  int error= 1;
2270
2302
 
2271
2303
  lex->all_selects_list= tables->schema_select_lex;
2272
2304
  /*
2273
 
    Restore thd->temporary_tables to be able to process
 
2305
    Restore session->temporary_tables to be able to process
2274
2306
    temporary tables(only for 'show index' & 'show columns').
2275
2307
    This should be changed when processing of temporary tables for
2276
2308
    I_S tables will be done.
2277
2309
  */
2278
 
  thd->temporary_tables= open_tables_state_backup->temporary_tables;
 
2310
  session->temporary_tables= open_tables_state_backup->temporary_tables;
2279
2311
  /*
2280
2312
    Let us set fake sql_command so views won't try to merge
2281
2313
    themselves into main statement. If we don't do this,
2282
2314
    SELECT * from information_schema.xxxx will cause problems.
2283
 
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()' 
 
2315
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2284
2316
  */
2285
2317
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2286
 
  res= open_normal_and_derived_tables(thd, show_table_list,
 
2318
  res= open_normal_and_derived_tables(session, show_table_list,
2287
2319
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
2288
2320
  lex->sql_command= save_sql_command;
2289
2321
  /*
2290
2322
    get_all_tables() returns 1 on failure and 0 on success thus
2291
2323
    return only these and not the result code of ::process_table()
2292
2324
 
2293
 
    We should use show_table_list->alias instead of 
 
2325
    We should use show_table_list->alias instead of
2294
2326
    show_table_list->table_name because table_name
2295
2327
    could be changed during opening of I_S tables. It's safe
2296
 
    to use alias because alias contains original table name 
2297
 
    in this case(this part of code is used only for 
 
2328
    to use alias because alias contains original table name
 
2329
    in this case(this part of code is used only for
2298
2330
    'show columns' & 'show statistics' commands).
2299
2331
  */
2300
 
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
 
2332
   table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2301
2333
                                    strlen(show_table_list->alias), false);
2302
 
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
 
2334
   db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2303
2335
                                 show_table_list->db_length, false);
2304
 
      
2305
 
 
2306
 
   error= test(schema_table->process_table(thd, show_table_list,
 
2336
 
 
2337
 
 
2338
   error= test(schema_table->process_table(session, show_table_list,
2307
2339
                                           table, res, db_name,
2308
2340
                                           table_name));
2309
 
   thd->temporary_tables= 0;
2310
 
   close_tables_for_reopen(thd, &show_table_list);
 
2341
   session->temporary_tables= 0;
 
2342
   close_tables_for_reopen(session, &show_table_list);
2311
2343
   return(error);
2312
2344
}
2313
2345
 
2314
2346
 
2315
2347
/**
2316
 
  @brief          Fill I_S table for SHOW TABLE NAMES commands
 
2348
  @brief          Fill I_S table for SHOW Table NAMES commands
2317
2349
 
2318
 
  @param[in]      thd                      thread handler
2319
 
  @param[in]      table                    TABLE struct for I_S table
 
2350
  @param[in]      session                      thread handler
 
2351
  @param[in]      table                    Table struct for I_S table
2320
2352
  @param[in]      db_name                  database name
2321
2353
  @param[in]      table_name               table name
2322
2354
  @param[in]      with_i_schema            I_S table if true
2326
2358
    @retval       1           error
2327
2359
*/
2328
2360
 
2329
 
static int fill_schema_table_names(THD *thd, TABLE *table,
 
2361
static int fill_schema_table_names(Session *session, Table *table,
2330
2362
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2331
2363
                                   bool with_i_schema)
2332
2364
{
2337
2369
  }
2338
2370
  else
2339
2371
  {
2340
 
    enum legacy_db_type not_used;
2341
2372
    char path[FN_REFLEN];
2342
 
    (void) build_table_filename(path, sizeof(path), db_name->str, 
 
2373
    (void) build_table_filename(path, sizeof(path), db_name->str,
2343
2374
                                table_name->str, reg_ext, 0);
2344
 
    switch (mysql_frm_type(thd, path, &not_used)) {
2345
 
    case FRMTYPE_ERROR:
2346
 
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2347
 
                             system_charset_info);
2348
 
      break;
2349
 
    case FRMTYPE_TABLE:
2350
 
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
2351
 
                             system_charset_info);
2352
 
      break;
2353
 
    default:
2354
 
      assert(0);
2355
 
    }
2356
 
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2375
 
 
2376
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
 
2377
                             system_charset_info);
 
2378
 
 
2379
    if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2357
2380
    {
2358
 
      thd->clear_error();
 
2381
      session->clear_error();
2359
2382
      return 0;
2360
2383
    }
2361
2384
  }
2362
 
  if (schema_table_store_record(thd, table))
 
2385
  if (schema_table_store_record(session, table))
2363
2386
    return 1;
2364
2387
  return 0;
2365
2388
}
2381
2404
    @retval       SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2382
2405
*/
2383
2406
 
2384
 
static uint get_table_open_method(TABLE_LIST *tables,
 
2407
static uint32_t get_table_open_method(TableList *tables,
2385
2408
                                  ST_SCHEMA_TABLE *schema_table,
2386
 
                                  enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2409
                                  enum enum_schema_tables)
2387
2410
{
2388
2411
  /*
2389
2412
    determine which method will be used for table opening
2408
2431
/**
2409
2432
  @brief          Fill I_S table with data from FRM file only
2410
2433
 
2411
 
  @param[in]      thd                      thread handler
2412
 
  @param[in]      table                    TABLE struct for I_S table
 
2434
  @param[in]      session                      thread handler
 
2435
  @param[in]      table                    Table struct for I_S table
2413
2436
  @param[in]      schema_table             I_S table struct
2414
2437
  @param[in]      db_name                  database name
2415
2438
  @param[in]      table_name               table name
2422
2445
                              open_tables function for this table
2423
2446
*/
2424
2447
 
2425
 
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
 
2448
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2426
2449
                                      ST_SCHEMA_TABLE *schema_table,
2427
2450
                                      LEX_STRING *db_name,
2428
2451
                                      LEX_STRING *table_name,
2429
 
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2452
                                      enum enum_schema_tables)
2430
2453
{
2431
 
  TABLE *table= tables->table;
 
2454
  Table *table= tables->table;
2432
2455
  TABLE_SHARE *share;
2433
 
  TABLE tbl;
2434
 
  TABLE_LIST table_list;
2435
 
  uint res= 0;
 
2456
  Table tbl;
 
2457
  TableList table_list;
 
2458
  uint32_t res= 0;
2436
2459
  int error;
2437
2460
  char key[MAX_DBKEY_LENGTH];
2438
 
  uint key_length;
 
2461
  uint32_t key_length;
2439
2462
 
2440
 
  memset(&table_list, 0, sizeof(TABLE_LIST));
2441
 
  memset(&tbl, 0, sizeof(TABLE));
 
2463
  memset(&table_list, 0, sizeof(TableList));
 
2464
  memset(&tbl, 0, sizeof(Table));
2442
2465
 
2443
2466
  table_list.table_name= table_name->str;
2444
2467
  table_list.db= db_name->str;
2445
2468
 
2446
 
  key_length= create_table_def_key(thd, key, &table_list, 0);
 
2469
  key_length= create_table_def_key(session, key, &table_list, 0);
2447
2470
  pthread_mutex_lock(&LOCK_open);
2448
 
  share= get_table_share(thd, &table_list, key,
2449
 
                         key_length, OPEN_VIEW, &error);
 
2471
  share= get_table_share(session, &table_list, key,
 
2472
                         key_length, 0, &error);
2450
2473
  if (!share)
2451
2474
  {
2452
2475
    res= 0;
2456
2479
  {
2457
2480
    tbl.s= share;
2458
2481
    table_list.table= &tbl;
2459
 
    res= schema_table->process_table(thd, &table_list, table,
 
2482
    res= schema_table->process_table(session, &table_list, table,
2460
2483
                                     res, db_name, table_name);
2461
2484
  }
2462
2485
 
2464
2487
 
2465
2488
err:
2466
2489
  pthread_mutex_unlock(&LOCK_open);
2467
 
  thd->clear_error();
 
2490
  session->clear_error();
2468
2491
  return res;
2469
2492
}
2470
2493
 
2480
2503
                  from frm files and storage engine are filled by the function
2481
2504
                  get_all_tables().
2482
2505
 
2483
 
  @param[in]      thd                      thread handler
 
2506
  @param[in]      session                      thread handler
2484
2507
  @param[in]      tables                   I_S table
2485
2508
  @param[in]      cond                     'WHERE' condition
2486
2509
 
2489
2512
    @retval       1                        error
2490
2513
*/
2491
2514
 
2492
 
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
 
2515
int get_all_tables(Session *session, TableList *tables, COND *cond)
2493
2516
{
2494
 
  LEX *lex= thd->lex;
2495
 
  TABLE *table= tables->table;
 
2517
  LEX *lex= session->lex;
 
2518
  Table *table= tables->table;
2496
2519
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2497
2520
  enum_sql_command save_sql_command= lex->sql_command;
2498
2521
  SELECT_LEX *lsel= tables->schema_select_lex;
2505
2528
  List<LEX_STRING> db_names;
2506
2529
  List_iterator_fast<LEX_STRING> it(db_names);
2507
2530
  COND *partial_cond= 0;
2508
 
  uint derived_tables= lex->derived_tables; 
 
2531
  uint32_t derived_tables= lex->derived_tables;
2509
2532
  int error= 1;
2510
2533
  Open_tables_state open_tables_state_backup;
2511
2534
  Query_tables_list query_tables_list_backup;
2512
 
  uint table_open_method;
2513
 
  bool old_value= thd->no_warnings_for_error;
2514
 
 
2515
 
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
 
2535
  uint32_t table_open_method;
 
2536
  bool old_value= session->no_warnings_for_error;
2516
2537
 
2517
2538
  /*
2518
2539
    We should not introduce deadlocks even if we already have some
2519
2540
    tables open and locked, since we won't lock tables which we will
2520
2541
    open and will ignore possible name-locks for these tables.
2521
2542
  */
2522
 
  thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
 
2543
  session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2523
2544
 
2524
2545
  schema_table_idx= get_schema_table_idx(schema_table);
2525
2546
  tables->table_open_method= table_open_method=
2526
2547
    get_table_open_method(tables, schema_table, schema_table_idx);
2527
 
  /* 
 
2548
  /*
2528
2549
    this branch processes SHOW FIELDS, SHOW INDEXES commands.
2529
2550
    see sql_parse.cc, prepare_schema_table() function where
2530
2551
    this values are initialized
2531
2552
  */
2532
2553
  if (lsel && lsel->table_list.first)
2533
2554
  {
2534
 
    error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
 
2555
    error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2535
2556
                                         &open_tables_state_backup);
2536
2557
    goto err;
2537
2558
  }
2538
2559
 
2539
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2560
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2540
2561
  {
2541
2562
    error= 0;
2542
2563
    goto err;
2544
2565
 
2545
2566
  if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2546
2567
  {
2547
 
    /* 
 
2568
    /*
2548
2569
      if lookup value is empty string then
2549
2570
      it's impossible table name or db name
2550
2571
    */
2560
2581
      !lookup_field_vals.wild_db_value)
2561
2582
    tables->has_db_lookup_value= true;
2562
2583
  if (lookup_field_vals.table_value.length &&
2563
 
      !lookup_field_vals.wild_table_value) 
 
2584
      !lookup_field_vals.wild_table_value)
2564
2585
    tables->has_table_lookup_value= true;
2565
2586
 
2566
2587
  if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2575
2596
    goto err;
2576
2597
  }
2577
2598
 
2578
 
  if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
 
2599
  if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2579
2600
    goto err;
2580
2601
  it.rewind(); /* To get access to new elements in basis list */
2581
2602
  while ((db_name= it++))
2582
2603
  {
2583
2604
    {
2584
 
      thd->no_warnings_for_error= 1;
 
2605
      session->no_warnings_for_error= 1;
2585
2606
      List<LEX_STRING> table_names;
2586
 
      int res= make_table_name_list(thd, &table_names, lex,
 
2607
      int res= make_table_name_list(session, &table_names, lex,
2587
2608
                                    &lookup_field_vals,
2588
2609
                                    with_i_schema, db_name);
2589
2610
      if (res == 2)   /* Not fatal error, continue */
2604
2625
        {
2605
2626
          /*
2606
2627
            If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2607
 
            we can skip table opening and we don't have lookup value for 
 
2628
            we can skip table opening and we don't have lookup value for
2608
2629
            table name or lookup value is wild string(table name list is
2609
2630
            already created by make_table_name_list() function).
2610
2631
          */
2612
2633
              (!lookup_field_vals.table_value.length ||
2613
2634
               lookup_field_vals.wild_table_value))
2614
2635
          {
2615
 
            if (schema_table_store_record(thd, table))
 
2636
            if (schema_table_store_record(session, table))
2616
2637
              goto err;      /* Out of space in temporary table */
2617
2638
            continue;
2618
2639
          }
2619
2640
 
2620
 
          /* SHOW TABLE NAMES command */
 
2641
          /* SHOW Table NAMES command */
2621
2642
          if (schema_table_idx == SCH_TABLE_NAMES)
2622
2643
          {
2623
 
            if (fill_schema_table_names(thd, tables->table, db_name,
 
2644
            if (fill_schema_table_names(session, tables->table, db_name,
2624
2645
                                        table_name, with_i_schema))
2625
2646
              continue;
2626
2647
          }
2629
2650
            if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2630
2651
                !with_i_schema)
2631
2652
            {
2632
 
              if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
 
2653
              if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2633
2654
                                              table_name, schema_table_idx))
2634
2655
                continue;
2635
2656
            }
2640
2661
              Set the parent lex of 'sel' because it is needed by
2641
2662
              sel.init_query() which is called inside make_table_list.
2642
2663
            */
2643
 
            thd->no_warnings_for_error= 1;
 
2664
            session->no_warnings_for_error= 1;
2644
2665
            sel.parent_lex= lex;
2645
2666
            /* db_name can be changed in make_table_list() func */
2646
 
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
 
2667
            if (!session->make_lex_string(&orig_db_name, db_name->str,
2647
2668
                                      db_name->length, false))
2648
2669
              goto err;
2649
 
            if (make_table_list(thd, &sel, db_name, table_name))
 
2670
            if (make_table_list(session, &sel, db_name, table_name))
2650
2671
              goto err;
2651
 
            TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
 
2672
            TableList *show_table_list= (TableList*) sel.table_list.first;
2652
2673
            lex->all_selects_list= &sel;
2653
2674
            lex->derived_tables= 0;
2654
2675
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2655
2676
            show_table_list->i_s_requested_object=
2656
2677
              schema_table->i_s_requested_object;
2657
 
            res= open_normal_and_derived_tables(thd, show_table_list,
 
2678
            res= open_normal_and_derived_tables(session, show_table_list,
2658
2679
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
2659
2680
            lex->sql_command= save_sql_command;
2660
2681
            /*
2661
2682
              XXX:  show_table_list has a flag i_is_requested,
2662
2683
              and when it's set, open_normal_and_derived_tables()
2663
2684
              can return an error without setting an error message
2664
 
              in THD, which is a hack. This is why we have to
2665
 
              check for res, then for thd->is_error() only then
2666
 
              for thd->main_da.sql_errno().
 
2685
              in Session, which is a hack. This is why we have to
 
2686
              check for res, then for session->is_error() only then
 
2687
              for session->main_da.sql_errno().
2667
2688
            */
2668
 
            if (res && thd->is_error() &&
2669
 
                thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2689
            if (res && session->is_error() &&
 
2690
                session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2670
2691
            {
2671
2692
              /*
2672
2693
                Hide error for not existing table.
2675
2696
                table does not exist.
2676
2697
              */
2677
2698
              res= 0;
2678
 
              thd->clear_error();
 
2699
              session->clear_error();
2679
2700
            }
2680
2701
            else
2681
2702
            {
2682
2703
              /*
2683
 
                We should use show_table_list->alias instead of 
 
2704
                We should use show_table_list->alias instead of
2684
2705
                show_table_list->table_name because table_name
2685
2706
                could be changed during opening of I_S tables. It's safe
2686
 
                to use alias because alias contains original table name 
 
2707
                to use alias because alias contains original table name
2687
2708
                in this case.
2688
2709
              */
2689
 
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
 
2710
              session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2690
2711
                                   strlen(show_table_list->alias), false);
2691
 
              res= schema_table->process_table(thd, show_table_list, table,
 
2712
              res= schema_table->process_table(session, show_table_list, table,
2692
2713
                                               res, &orig_db_name,
2693
2714
                                               &tmp_lex_string);
2694
 
              close_tables_for_reopen(thd, &show_table_list);
 
2715
              close_tables_for_reopen(session, &show_table_list);
2695
2716
            }
2696
2717
            assert(!lex->query_tables_own_last);
2697
2718
            if (res)
2709
2730
 
2710
2731
  error= 0;
2711
2732
err:
2712
 
  thd->restore_backup_open_tables_state(&open_tables_state_backup);
2713
 
  lex->restore_backup_query_tables_list(&query_tables_list_backup);
 
2733
  session->restore_backup_open_tables_state(&open_tables_state_backup);
2714
2734
  lex->derived_tables= derived_tables;
2715
2735
  lex->all_selects_list= old_all_select_lex;
2716
2736
  lex->sql_command= save_sql_command;
2717
 
  thd->no_warnings_for_error= old_value;
 
2737
  session->no_warnings_for_error= old_value;
2718
2738
  return(error);
2719
2739
}
2720
2740
 
2721
2741
 
2722
 
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
 
2742
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2723
2743
                          const CHARSET_INFO * const cs)
2724
2744
{
2725
2745
  restore_record(table, s->default_values);
2726
2746
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2727
2747
  table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2728
2748
  table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2729
 
  return schema_table_store_record(thd, table);
 
2749
  return schema_table_store_record(session, table);
2730
2750
}
2731
2751
 
2732
2752
 
2733
 
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
 
2753
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2734
2754
{
2735
2755
  /*
2736
2756
    TODO: fill_schema_shemata() is called when new client is connected.
2742
2762
  LEX_STRING *db_name;
2743
2763
  bool with_i_schema;
2744
2764
  HA_CREATE_INFO create;
2745
 
  TABLE *table= tables->table;
 
2765
  Table *table= tables->table;
2746
2766
 
2747
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2767
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2748
2768
    return(0);
2749
 
  if (make_db_list(thd, &db_names, &lookup_field_vals,
 
2769
  if (make_db_list(session, &db_names, &lookup_field_vals,
2750
2770
                   &with_i_schema))
2751
2771
    return(1);
2752
2772
 
2757
2777
     !with_i_schema)
2758
2778
  {
2759
2779
    char path[FN_REFLEN+16];
2760
 
    uint path_len;
 
2780
    uint32_t path_len;
2761
2781
    struct stat stat_info;
2762
2782
    if (!lookup_field_vals.db_value.str[0])
2763
2783
      return(0);
2773
2793
  {
2774
2794
    if (with_i_schema)       // information schema name is always first in list
2775
2795
    {
2776
 
      if (store_schema_shemata(thd, table, db_name,
 
2796
      if (store_schema_shemata(session, table, db_name,
2777
2797
                               system_charset_info))
2778
2798
        return(1);
2779
2799
      with_i_schema= 0;
2780
2800
      continue;
2781
2801
    }
2782
2802
    {
2783
 
      load_db_opt_by_name(thd, db_name->str, &create);
2784
 
      if (store_schema_shemata(thd, table, db_name,
 
2803
      load_db_opt_by_name(session, db_name->str, &create);
 
2804
      if (store_schema_shemata(session, table, db_name,
2785
2805
                               create.default_table_charset))
2786
2806
        return(1);
2787
2807
    }
2790
2810
}
2791
2811
 
2792
2812
 
2793
 
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
2794
 
                                    TABLE *table, bool res,
 
2813
static int get_schema_tables_record(Session *session, TableList *tables,
 
2814
                                    Table *table, bool res,
2795
2815
                                    LEX_STRING *db_name,
2796
2816
                                    LEX_STRING *table_name)
2797
2817
{
2807
2827
    /*
2808
2828
      there was errors during opening tables
2809
2829
    */
2810
 
    const char *error= thd->is_error() ? thd->main_da.message() : "";
 
2830
    const char *error= session->is_error() ? session->main_da.message() : "";
2811
2831
    if (tables->schema_table)
2812
2832
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2813
2833
    else
2814
 
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
 
2834
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2815
2835
    table->field[20]->store(error, strlen(error), cs);
2816
 
    thd->clear_error();
 
2836
    session->clear_error();
2817
2837
  }
2818
2838
  else
2819
2839
  {
2820
2840
    char option_buff[400],*ptr;
2821
 
    TABLE *show_table= tables->table;
 
2841
    Table *show_table= tables->table;
2822
2842
    TABLE_SHARE *share= show_table->s;
2823
2843
    handler *file= show_table->file;
2824
2844
    handlerton *tmp_db_type= share->db_type();
2827
2847
    else if (share->tmp_table)
2828
2848
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2829
2849
    else
2830
 
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
 
2850
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2831
2851
 
2832
2852
    for (int i= 4; i < 20; i++)
2833
2853
    {
2837
2857
    }
2838
2858
    tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2839
2859
    table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2840
 
    table->field[5]->store((int64_t) share->frm_version, true);
 
2860
    table->field[5]->store((int64_t) 0, true);
2841
2861
 
2842
2862
    ptr=option_buff;
2843
2863
    if (share->min_rows)
2844
2864
    {
2845
 
      ptr=stpcpy(ptr," min_rows=");
2846
 
      ptr=int64_t10_to_str(share->min_rows,ptr,10);
 
2865
      ptr= strcpy(ptr," min_rows=")+10;
 
2866
      ptr= int64_t10_to_str(share->min_rows,ptr,10);
2847
2867
    }
2848
2868
    if (share->max_rows)
2849
2869
    {
2850
 
      ptr=stpcpy(ptr," max_rows=");
2851
 
      ptr=int64_t10_to_str(share->max_rows,ptr,10);
 
2870
      ptr= strcpy(ptr," max_rows=")+10;
 
2871
      ptr= int64_t10_to_str(share->max_rows,ptr,10);
2852
2872
    }
2853
2873
    if (share->avg_row_length)
2854
2874
    {
2855
 
      ptr=stpcpy(ptr," avg_row_length=");
2856
 
      ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
 
2875
      ptr= strcpy(ptr," avg_row_length=")+16;
 
2876
      ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2857
2877
    }
2858
2878
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
2859
 
      ptr=stpcpy(ptr," pack_keys=1");
 
2879
      ptr= strcpy(ptr," pack_keys=1")+12;
2860
2880
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2861
 
      ptr=stpcpy(ptr," pack_keys=0");
 
2881
      ptr= strcpy(ptr," pack_keys=0")+12;
2862
2882
    /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2863
2883
    if (share->db_create_options & HA_OPTION_CHECKSUM)
2864
 
      ptr=stpcpy(ptr," checksum=1");
 
2884
      ptr= strcpy(ptr," checksum=1")+11;
2865
2885
    if (share->page_checksum != HA_CHOICE_UNDEF)
2866
 
      ptr= strxmov(ptr, " page_checksum=",
2867
 
                   ha_choice_values[(uint) share->page_checksum], NullS);
 
2886
      ptr+= sprintf(ptr, " page_checksum=%s",
 
2887
                    ha_choice_values[(uint) share->page_checksum]);
2868
2888
    if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2869
 
      ptr=stpcpy(ptr," delay_key_write=1");
 
2889
      ptr= strcpy(ptr," delay_key_write=1")+18;
2870
2890
    if (share->row_type != ROW_TYPE_DEFAULT)
2871
 
      ptr=strxmov(ptr, " row_format=", 
2872
 
                  ha_row_type[(uint) share->row_type],
2873
 
                  NullS);
 
2891
      ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint)share->row_type]);
2874
2892
    if (share->block_size)
2875
2893
    {
2876
 
      ptr= stpcpy(ptr, " block_size=");
 
2894
      ptr= strcpy(ptr, " block_size=")+12;
2877
2895
      ptr= int64_t10_to_str(share->block_size, ptr, 10);
2878
2896
    }
2879
 
    
 
2897
 
2880
2898
    if (share->transactional != HA_CHOICE_UNDEF)
2881
2899
    {
2882
 
      ptr= strxmov(ptr, " TRANSACTIONAL=",
2883
 
                   (share->transactional == HA_CHOICE_YES ? "1" : "0"),
2884
 
                   NullS);
 
2900
      ptr+= sprintf(ptr, " TRANSACTIONAL=%s",
 
2901
                    (share->transactional == HA_CHOICE_YES ? "1" : "0"));
2885
2902
    }
2886
2903
    if (share->transactional != HA_CHOICE_UNDEF)
2887
 
      ptr= strxmov(ptr, " transactional=",
2888
 
                   ha_choice_values[(uint) share->transactional], NullS);
 
2904
      ptr+= sprintf(ptr, " transactional=%s",
 
2905
                    ha_choice_values[(uint) share->transactional]);
2889
2906
    table->field[19]->store(option_buff+1,
2890
 
                            (ptr == option_buff ? 0 : 
 
2907
                            (ptr == option_buff ? 0 :
2891
2908
                             (uint) (ptr-option_buff)-1), cs);
2892
2909
 
2893
2910
    tmp_buff= (share->table_charset ?
2952
2969
      }
2953
2970
      if (file->stats.create_time)
2954
2971
      {
2955
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2956
 
                                                  (my_time_t) file->stats.create_time);
 
2972
        session->variables.time_zone->gmt_sec_to_TIME(&time,
 
2973
                                                  (time_t) file->stats.create_time);
2957
2974
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2958
2975
        table->field[14]->set_notnull();
2959
2976
      }
2960
2977
      if (file->stats.update_time)
2961
2978
      {
2962
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2963
 
                                                  (my_time_t) file->stats.update_time);
 
2979
        session->variables.time_zone->gmt_sec_to_TIME(&time,
 
2980
                                                  (time_t) file->stats.update_time);
2964
2981
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2965
2982
        table->field[15]->set_notnull();
2966
2983
      }
2967
2984
      if (file->stats.check_time)
2968
2985
      {
2969
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2970
 
                                                  (my_time_t) file->stats.check_time);
 
2986
        session->variables.time_zone->gmt_sec_to_TIME(&time,
 
2987
                                                  (time_t) file->stats.check_time);
2971
2988
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2972
2989
        table->field[16]->set_notnull();
2973
2990
      }
2978
2995
      }
2979
2996
    }
2980
2997
  }
2981
 
  return(schema_table_store_record(thd, table));
 
2998
  return(schema_table_store_record(session, table));
2982
2999
}
2983
3000
 
2984
3001
 
2990
3007
  @param[in]      cs                I_S table charset
2991
3008
  @param[in]      offset            offset from beginning of table
2992
3009
                                    to DATE_TYPE column in I_S table
2993
 
                                    
 
3010
 
2994
3011
  @return         void
2995
3012
*/
2996
3013
 
2997
 
void store_column_type(TABLE *table, Field *field, const CHARSET_INFO * const cs,
2998
 
                       uint offset)
 
3014
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
 
3015
                       uint32_t offset)
2999
3016
{
3000
3017
  bool is_blob;
3001
3018
  int decimals, field_length;
3019
3036
    uint32_t octet_max_length= field->max_display_length();
3020
3037
    if (is_blob && octet_max_length != (uint32_t) 4294967295U)
3021
3038
      octet_max_length /= field->charset()->mbmaxlen;
3022
 
    int64_t char_max_len= is_blob ? 
 
3039
    int64_t char_max_len= is_blob ?
3023
3040
      (int64_t) octet_max_length / field->charset()->mbminlen :
3024
3041
      (int64_t) octet_max_length / field->charset()->mbmaxlen;
3025
3042
    /* CHARACTER_MAXIMUM_LENGTH column*/
3040
3057
  case DRIZZLE_TYPE_NEWDECIMAL:
3041
3058
    field_length= ((Field_new_decimal*) field)->precision;
3042
3059
    break;
3043
 
  case DRIZZLE_TYPE_TINY:
3044
 
  case DRIZZLE_TYPE_SHORT:
3045
3060
  case DRIZZLE_TYPE_LONG:
3046
3061
  case DRIZZLE_TYPE_LONGLONG:
3047
3062
    field_length= field->max_display_length() - 1;
3082
3097
}
3083
3098
 
3084
3099
 
3085
 
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
3086
 
                                    TABLE *table, bool res,
 
3100
static int get_schema_column_record(Session *session, TableList *tables,
 
3101
                                    Table *table, bool res,
3087
3102
                                    LEX_STRING *db_name,
3088
3103
                                    LEX_STRING *table_name)
3089
3104
{
3090
 
  LEX *lex= thd->lex;
3091
 
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
3105
  LEX *lex= session->lex;
 
3106
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3092
3107
  const CHARSET_INFO * const cs= system_charset_info;
3093
 
  TABLE *show_table;
 
3108
  Table *show_table;
3094
3109
  TABLE_SHARE *show_table_share;
3095
3110
  Field **ptr, *field, *timestamp_field;
3096
3111
  int count;
3102
3117
      /*
3103
3118
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3104
3119
        rather than in SHOW COLUMNS
3105
 
      */ 
3106
 
      if (thd->is_error())
3107
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3108
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3109
 
      thd->clear_error();
 
3120
      */
 
3121
      if (session->is_error())
 
3122
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3123
                     session->main_da.sql_errno(), session->main_da.message());
 
3124
      session->clear_error();
3110
3125
      res= 0;
3111
3126
    }
3112
3127
    return(res);
3133
3148
    if (!show_table->read_set)
3134
3149
    {
3135
3150
      /* to satisfy 'field->val_str' ASSERTs */
3136
 
      uchar *bitmaps;
3137
 
      uint bitmap_size= show_table_share->column_bitmap_size;
3138
 
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
 
3151
      unsigned char *bitmaps;
 
3152
      uint32_t bitmap_size= show_table_share->column_bitmap_size;
 
3153
      if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3139
3154
        return(0);
3140
3155
      bitmap_init(&show_table->def_read_set,
3141
3156
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3147
3162
 
3148
3163
  for (; (field= *ptr) ; ptr++)
3149
3164
  {
3150
 
    uchar *pos;
 
3165
    unsigned char *pos;
3151
3166
    char tmp[MAX_FIELD_WIDTH];
3152
3167
    String type(tmp,sizeof(tmp), system_charset_info);
3153
3168
    char *end;
3154
3169
 
3155
3170
    /* to satisfy 'field->val_str' ASSERTs */
3156
3171
    field->table= show_table;
3157
 
    show_table->in_use= thd;
 
3172
    show_table->in_use= session;
3158
3173
 
3159
3174
    if (wild && wild[0] &&
3160
3175
        wild_case_compare(system_charset_info, field->field_name,wild))
3170
3185
                           cs);
3171
3186
    table->field[4]->store((int64_t) count, true);
3172
3187
 
3173
 
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
 
3188
    if (get_field_default_value(session, timestamp_field, field, &type, 0))
3174
3189
    {
3175
3190
      table->field[5]->store(type.ptr(), type.length(), cs);
3176
3191
      table->field[5]->set_notnull();
3177
3192
    }
3178
 
    pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
 
3193
    pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
3179
3194
    table->field[6]->store((const char*) pos,
3180
3195
                           strlen((const char*) pos), cs);
3181
3196
    store_column_type(table, field, cs, 7);
3182
3197
 
3183
 
    pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
 
3198
    pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3184
3199
                 (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3185
3200
                 (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3186
3201
    table->field[15]->store((const char*) pos,
3193
3208
        field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3194
3209
      table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3195
3210
                              cs);
3196
 
 
 
3211
    if (field->vcol_info)
 
3212
          table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3197
3213
    table->field[18]->store(field->comment.str, field->comment.length, cs);
3198
3214
    {
3199
3215
      enum column_format_type column_format= (enum column_format_type)
3200
3216
        ((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3201
 
      pos=(uchar*)"Default";
 
3217
      pos=(unsigned char*)"Default";
3202
3218
      table->field[19]->store((const char*) pos,
3203
3219
                              strlen((const char*) pos), cs);
3204
 
      pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
 
3220
      pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3205
3221
                   column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3206
3222
                                                             "Dynamic");
3207
3223
      table->field[20]->store((const char*) pos,
3208
3224
                              strlen((const char*) pos), cs);
3209
3225
    }
3210
 
    if (schema_table_store_record(thd, table))
 
3226
    if (schema_table_store_record(session, table))
3211
3227
      return(1);
3212
3228
  }
3213
3229
  return(0);
3215
3231
 
3216
3232
 
3217
3233
 
3218
 
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
3234
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3219
3235
{
3220
3236
  CHARSET_INFO **cs;
3221
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3222
 
  TABLE *table= tables->table;
 
3237
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
 
3238
  Table *table= tables->table;
3223
3239
  const CHARSET_INFO * const scs= system_charset_info;
3224
3240
 
3225
3241
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3226
3242
  {
3227
3243
    const CHARSET_INFO * const tmp_cs= cs[0];
3228
 
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) && 
 
3244
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3229
3245
        (tmp_cs->state & MY_CS_AVAILABLE) &&
3230
3246
        !(tmp_cs->state & MY_CS_HIDDEN) &&
3231
3247
        !(wild && wild[0] &&
3238
3254
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3239
3255
      table->field[2]->store(comment, strlen(comment), scs);
3240
3256
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3241
 
      if (schema_table_store_record(thd, table))
 
3257
      if (schema_table_store_record(session, table))
3242
3258
        return 1;
3243
3259
    }
3244
3260
  }
3246
3262
}
3247
3263
 
3248
3264
 
3249
 
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
3265
int fill_schema_collation(Session *session, TableList *tables, COND *)
3250
3266
{
3251
3267
  CHARSET_INFO **cs;
3252
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3253
 
  TABLE *table= tables->table;
 
3268
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
 
3269
  Table *table= tables->table;
3254
3270
  const CHARSET_INFO * const scs= system_charset_info;
3255
3271
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3256
3272
  {
3263
3279
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3264
3280
    {
3265
3281
      const CHARSET_INFO *tmp_cl= cl[0];
3266
 
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
 
3282
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3267
3283
          !my_charset_same(tmp_cs, tmp_cl))
3268
3284
        continue;
3269
3285
      if (!(wild && wild[0] &&
3279
3295
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3280
3296
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3281
3297
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3282
 
        if (schema_table_store_record(thd, table))
 
3298
        if (schema_table_store_record(session, table))
3283
3299
          return 1;
3284
3300
      }
3285
3301
    }
3288
3304
}
3289
3305
 
3290
3306
 
3291
 
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
3307
int fill_schema_coll_charset_app(Session *session, TableList *tables, COND *)
3292
3308
{
3293
3309
  CHARSET_INFO **cs;
3294
 
  TABLE *table= tables->table;
 
3310
  Table *table= tables->table;
3295
3311
  const CHARSET_INFO * const scs= system_charset_info;
3296
3312
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3297
3313
  {
3298
3314
    CHARSET_INFO **cl;
3299
3315
    const CHARSET_INFO *tmp_cs= cs[0];
3300
 
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || 
 
3316
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3301
3317
        !(tmp_cs->state & MY_CS_PRIMARY))
3302
3318
      continue;
3303
3319
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3304
3320
    {
3305
3321
      const CHARSET_INFO *tmp_cl= cl[0];
3306
 
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
 
3322
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3307
3323
          !my_charset_same(tmp_cs,tmp_cl))
3308
3324
        continue;
3309
3325
      restore_record(table, s->default_values);
3310
3326
      table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3311
3327
      table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3312
 
      if (schema_table_store_record(thd, table))
 
3328
      if (schema_table_store_record(session, table))
3313
3329
        return 1;
3314
3330
    }
3315
3331
  }
3317
3333
}
3318
3334
 
3319
3335
 
3320
 
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
3321
 
                                  TABLE *table, bool res,
 
3336
static int get_schema_stat_record(Session *session, TableList *tables,
 
3337
                                  Table *table, bool res,
3322
3338
                                  LEX_STRING *db_name,
3323
3339
                                  LEX_STRING *table_name)
3324
3340
{
3325
3341
  const CHARSET_INFO * const cs= system_charset_info;
3326
3342
  if (res)
3327
3343
  {
3328
 
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
 
3344
    if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3329
3345
    {
3330
3346
      /*
3331
3347
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3332
3348
        rather than in SHOW KEYS
3333
3349
      */
3334
 
      if (thd->is_error())
3335
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3336
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3337
 
      thd->clear_error();
 
3350
      if (session->is_error())
 
3351
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3352
                     session->main_da.sql_errno(), session->main_da.message());
 
3353
      session->clear_error();
3338
3354
      res= 0;
3339
3355
    }
3340
3356
    return(res);
3341
3357
  }
3342
3358
  else
3343
3359
  {
3344
 
    TABLE *show_table= tables->table;
 
3360
    Table *show_table= tables->table;
3345
3361
    KEY *key_info=show_table->s->key_info;
3346
3362
    if (show_table->file)
3347
3363
      show_table->file->info(HA_STATUS_VARIABLE |
3348
3364
                             HA_STATUS_NO_LOCK |
3349
3365
                             HA_STATUS_TIME);
3350
 
    for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
 
3366
    for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3351
3367
    {
3352
3368
      KEY_PART_INFO *key_part= key_info->key_part;
3353
3369
      const char *str;
3354
 
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3370
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3355
3371
      {
3356
3372
        restore_record(table, s->default_values);
3357
3373
        table->field[1]->store(db_name->str, db_name->length, cs);
3392
3408
                                  key_part->field->charset()->mbmaxlen, true);
3393
3409
          table->field[10]->set_notnull();
3394
3410
        }
3395
 
        uint flags= key_part->field ? key_part->field->flags : 0;
 
3411
        uint32_t flags= key_part->field ? key_part->field->flags : 0;
3396
3412
        const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3397
3413
        table->field[12]->store(pos, strlen(pos), cs);
3398
3414
        if (!show_table->s->keys_in_use.is_set(i))
3400
3416
        else
3401
3417
          table->field[14]->store("", 0, cs);
3402
3418
        table->field[14]->set_notnull();
3403
 
        assert(test(key_info->flags & HA_USES_COMMENT) == 
 
3419
        assert(test(key_info->flags & HA_USES_COMMENT) ==
3404
3420
                   (key_info->comment.length > 0));
3405
3421
        if (key_info->flags & HA_USES_COMMENT)
3406
 
          table->field[15]->store(key_info->comment.str, 
 
3422
          table->field[15]->store(key_info->comment.str,
3407
3423
                                  key_info->comment.length, cs);
3408
 
        if (schema_table_store_record(thd, table))
 
3424
        if (schema_table_store_record(session, table))
3409
3425
          return(1);
3410
3426
      }
3411
3427
    }
3414
3430
}
3415
3431
 
3416
3432
 
3417
 
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
 
3433
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3418
3434
                       LEX_STRING *table_name, const char *key_name,
3419
 
                       uint key_len, const char *con_type, uint con_len)
 
3435
                       uint32_t key_len, const char *con_type, uint32_t con_len)
3420
3436
{
3421
3437
  const CHARSET_INFO * const cs= system_charset_info;
3422
3438
  restore_record(table, s->default_values);
3425
3441
  table->field[3]->store(db_name->str, db_name->length, cs);
3426
3442
  table->field[4]->store(table_name->str, table_name->length, cs);
3427
3443
  table->field[5]->store(con_type, con_len, cs);
3428
 
  return schema_table_store_record(thd, table);
 
3444
  return schema_table_store_record(session, table);
3429
3445
}
3430
3446
 
3431
3447
 
3432
 
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
3433
 
                                         TABLE *table, bool res,
 
3448
static int get_schema_constraints_record(Session *session, TableList *tables,
 
3449
                                         Table *table, bool res,
3434
3450
                                         LEX_STRING *db_name,
3435
3451
                                         LEX_STRING *table_name)
3436
3452
{
3437
3453
  if (res)
3438
3454
  {
3439
 
    if (thd->is_error())
3440
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3441
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3442
 
    thd->clear_error();
 
3455
    if (session->is_error())
 
3456
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3457
                   session->main_da.sql_errno(), session->main_da.message());
 
3458
    session->clear_error();
3443
3459
    return(0);
3444
3460
  }
3445
3461
  else
3446
3462
  {
3447
3463
    List<FOREIGN_KEY_INFO> f_key_list;
3448
 
    TABLE *show_table= tables->table;
 
3464
    Table *show_table= tables->table;
3449
3465
    KEY *key_info=show_table->key_info;
3450
 
    uint primary_key= show_table->s->primary_key;
3451
 
    show_table->file->info(HA_STATUS_VARIABLE | 
 
3466
    uint32_t primary_key= show_table->s->primary_key;
 
3467
    show_table->file->info(HA_STATUS_VARIABLE |
3452
3468
                           HA_STATUS_NO_LOCK |
3453
3469
                           HA_STATUS_TIME);
3454
 
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3470
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3455
3471
    {
3456
3472
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3457
3473
        continue;
3458
3474
 
3459
 
      if (i == primary_key && !strcmp(key_info->name, primary_key_name))
 
3475
      if (i == primary_key && is_primary_key(key_info))
3460
3476
      {
3461
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3477
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3462
3478
                              strlen(key_info->name),
3463
3479
                              STRING_WITH_LEN("PRIMARY KEY")))
3464
3480
          return(1);
3465
3481
      }
3466
3482
      else if (key_info->flags & HA_NOSAME)
3467
3483
      {
3468
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3484
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3469
3485
                              strlen(key_info->name),
3470
3486
                              STRING_WITH_LEN("UNIQUE")))
3471
3487
          return(1);
3472
3488
      }
3473
3489
    }
3474
3490
 
3475
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3491
    show_table->file->get_foreign_key_list(session, &f_key_list);
3476
3492
    FOREIGN_KEY_INFO *f_key_info;
3477
3493
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3478
3494
    while ((f_key_info=it++))
3479
3495
    {
3480
 
      if (store_constraints(thd, table, db_name, table_name, 
 
3496
      if (store_constraints(session, table, db_name, table_name,
3481
3497
                            f_key_info->forein_id->str,
3482
3498
                            strlen(f_key_info->forein_id->str),
3483
3499
                            "FOREIGN KEY", 11))
3488
3504
}
3489
3505
 
3490
3506
 
3491
 
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
 
3507
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3492
3508
                            LEX_STRING *table_name, const char *key_name,
3493
 
                            uint key_len, const char *con_type, uint con_len,
 
3509
                            uint32_t key_len, const char *con_type, uint32_t con_len,
3494
3510
                            int64_t idx)
3495
3511
{
3496
3512
  const CHARSET_INFO * const cs= system_charset_info;
3503
3519
}
3504
3520
 
3505
3521
 
3506
 
static int get_schema_key_column_usage_record(THD *thd,
3507
 
                                              TABLE_LIST *tables,
3508
 
                                              TABLE *table, bool res,
 
3522
static int get_schema_key_column_usage_record(Session *session,
 
3523
                                              TableList *tables,
 
3524
                                              Table *table, bool res,
3509
3525
                                              LEX_STRING *db_name,
3510
3526
                                              LEX_STRING *table_name)
3511
3527
{
3512
3528
  if (res)
3513
3529
  {
3514
 
    if (thd->is_error())
3515
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3516
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3517
 
    thd->clear_error();
 
3530
    if (session->is_error())
 
3531
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3532
                   session->main_da.sql_errno(), session->main_da.message());
 
3533
    session->clear_error();
3518
3534
    return(0);
3519
3535
  }
3520
3536
  else
3521
3537
  {
3522
3538
    List<FOREIGN_KEY_INFO> f_key_list;
3523
 
    TABLE *show_table= tables->table;
 
3539
    Table *show_table= tables->table;
3524
3540
    KEY *key_info=show_table->key_info;
3525
 
    uint primary_key= show_table->s->primary_key;
3526
 
    show_table->file->info(HA_STATUS_VARIABLE | 
 
3541
    uint32_t primary_key= show_table->s->primary_key;
 
3542
    show_table->file->info(HA_STATUS_VARIABLE |
3527
3543
                           HA_STATUS_NO_LOCK |
3528
3544
                           HA_STATUS_TIME);
3529
 
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3545
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3530
3546
    {
3531
3547
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3532
3548
        continue;
3533
 
      uint f_idx= 0;
 
3549
      uint32_t f_idx= 0;
3534
3550
      KEY_PART_INFO *key_part= key_info->key_part;
3535
 
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3551
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3536
3552
      {
3537
3553
        if (key_part->field)
3538
3554
        {
3540
3556
          restore_record(table, s->default_values);
3541
3557
          store_key_column_usage(table, db_name, table_name,
3542
3558
                                 key_info->name,
3543
 
                                 strlen(key_info->name), 
3544
 
                                 key_part->field->field_name, 
 
3559
                                 strlen(key_info->name),
 
3560
                                 key_part->field->field_name,
3545
3561
                                 strlen(key_part->field->field_name),
3546
3562
                                 (int64_t) f_idx);
3547
 
          if (schema_table_store_record(thd, table))
 
3563
          if (schema_table_store_record(session, table))
3548
3564
            return(1);
3549
3565
        }
3550
3566
      }
3551
3567
    }
3552
3568
 
3553
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3569
    show_table->file->get_foreign_key_list(session, &f_key_list);
3554
3570
    FOREIGN_KEY_INFO *f_key_info;
3555
3571
    List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3556
3572
    while ((f_key_info= fkey_it++))
3559
3575
      LEX_STRING *r_info;
3560
3576
      List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3561
3577
        it1(f_key_info->referenced_fields);
3562
 
      uint f_idx= 0;
 
3578
      uint32_t f_idx= 0;
3563
3579
      while ((f_info= it++))
3564
3580
      {
3565
3581
        r_info= it1++;
3577
3593
                               system_charset_info);
3578
3594
        table->field[9]->set_notnull();
3579
3595
        table->field[10]->store(f_key_info->referenced_table->str,
3580
 
                                f_key_info->referenced_table->length, 
 
3596
                                f_key_info->referenced_table->length,
3581
3597
                                system_charset_info);
3582
3598
        table->field[10]->set_notnull();
3583
3599
        table->field[11]->store(r_info->str, r_info->length,
3584
3600
                                system_charset_info);
3585
3601
        table->field[11]->set_notnull();
3586
 
        if (schema_table_store_record(thd, table))
 
3602
        if (schema_table_store_record(session, table))
3587
3603
          return(1);
3588
3604
      }
3589
3605
    }
3592
3608
}
3593
3609
 
3594
3610
 
3595
 
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
3611
int fill_open_tables(Session *session, TableList *tables, COND *)
3596
3612
{
3597
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3598
 
  TABLE *table= tables->table;
 
3613
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
 
3614
  Table *table= tables->table;
3599
3615
  const CHARSET_INFO * const cs= system_charset_info;
3600
 
  OPEN_TABLE_LIST *open_list;
3601
 
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3602
 
            && thd->is_fatal_error)
 
3616
  OPEN_TableList *open_list;
 
3617
  if (!(open_list=list_open_tables(session,session->lex->select_lex.db, wild))
 
3618
            && session->is_fatal_error)
3603
3619
    return(1);
3604
3620
 
3605
3621
  for (; open_list ; open_list=open_list->next)
3609
3625
    table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3610
3626
    table->field[2]->store((int64_t) open_list->in_use, true);
3611
3627
    table->field[3]->store((int64_t) open_list->locked, true);
3612
 
    if (schema_table_store_record(thd, table))
 
3628
    if (schema_table_store_record(session, table))
3613
3629
      return(1);
3614
3630
  }
3615
3631
  return(0);
3616
3632
}
3617
3633
 
3618
3634
 
3619
 
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
3635
int fill_variables(Session *session, TableList *tables, COND *)
3620
3636
{
3621
3637
  int res= 0;
3622
 
  LEX *lex= thd->lex;
3623
 
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
3638
  LEX *lex= session->lex;
 
3639
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3624
3640
  enum enum_schema_tables schema_table_idx=
3625
3641
    get_schema_table_idx(tables->schema_table);
3626
3642
  enum enum_var_type option_type= OPT_SESSION;
3631
3647
      schema_table_idx == SCH_GLOBAL_VARIABLES)
3632
3648
    option_type= OPT_GLOBAL;
3633
3649
 
3634
 
  rw_rdlock(&LOCK_system_variables_hash);
3635
 
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
 
3650
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
 
3651
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3636
3652
                         option_type, NULL, "", tables->table, upper_case_names);
3637
 
  rw_unlock(&LOCK_system_variables_hash);
 
3653
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
3638
3654
  return(res);
3639
3655
}
3640
3656
 
3641
3657
 
3642
 
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
 
3658
int fill_status(Session *session, TableList *tables, COND *)
3643
3659
{
3644
 
  LEX *lex= thd->lex;
3645
 
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
3660
  LEX *lex= session->lex;
 
3661
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3646
3662
  int res= 0;
3647
3663
  STATUS_VAR *tmp1, tmp;
3648
3664
  enum enum_schema_tables schema_table_idx=
3656
3672
    if (option_type == OPT_GLOBAL)
3657
3673
      tmp1= &tmp;
3658
3674
    else
3659
 
      tmp1= thd->initial_status_var;
 
3675
      tmp1= session->initial_status_var;
3660
3676
  }
3661
3677
  else if (schema_table_idx == SCH_GLOBAL_STATUS)
3662
3678
  {
3664
3680
    tmp1= &tmp;
3665
3681
  }
3666
3682
  else
3667
 
  { 
 
3683
  {
3668
3684
    option_type= OPT_SESSION;
3669
 
    tmp1= &thd->status_var;
 
3685
    tmp1= &session->status_var;
3670
3686
  }
3671
3687
 
3672
3688
  pthread_mutex_lock(&LOCK_status);
3673
3689
  if (option_type == OPT_GLOBAL)
3674
3690
    calc_sum_of_all_status(&tmp);
3675
 
  res= show_status_array(thd, wild,
 
3691
  res= show_status_array(session, wild,
3676
3692
                         (SHOW_VAR *)all_status_vars.buffer,
3677
3693
                         option_type, tmp1, "", tables->table,
3678
3694
                         upper_case_names);
3686
3702
 
3687
3703
  SYNOPSIS
3688
3704
    get_referential_constraints_record()
3689
 
    thd                 thread handle
 
3705
    session                 thread handle
3690
3706
    tables              table list struct(processed table)
3691
3707
    table               I_S table
3692
3708
    res                 1 means the error during opening of the processed table
3700
3716
*/
3701
3717
 
3702
3718
static int
3703
 
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3704
 
                                   TABLE *table, bool res,
 
3719
get_referential_constraints_record(Session *session, TableList *tables,
 
3720
                                   Table *table, bool res,
3705
3721
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3706
3722
{
3707
3723
  const CHARSET_INFO * const cs= system_charset_info;
3708
3724
 
3709
3725
  if (res)
3710
3726
  {
3711
 
    if (thd->is_error())
3712
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3713
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3714
 
    thd->clear_error();
 
3727
    if (session->is_error())
 
3728
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3729
                   session->main_da.sql_errno(), session->main_da.message());
 
3730
    session->clear_error();
3715
3731
    return(0);
3716
3732
  }
3717
3733
 
3718
3734
  {
3719
3735
    List<FOREIGN_KEY_INFO> f_key_list;
3720
 
    TABLE *show_table= tables->table;
3721
 
    show_table->file->info(HA_STATUS_VARIABLE | 
 
3736
    Table *show_table= tables->table;
 
3737
    show_table->file->info(HA_STATUS_VARIABLE |
3722
3738
                           HA_STATUS_NO_LOCK |
3723
3739
                           HA_STATUS_TIME);
3724
3740
 
3725
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3741
    show_table->file->get_foreign_key_list(session, &f_key_list);
3726
3742
    FOREIGN_KEY_INFO *f_key_info;
3727
3743
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3728
3744
    while ((f_key_info= it++))
3732
3748
      table->field[9]->store(table_name->str, table_name->length, cs);
3733
3749
      table->field[2]->store(f_key_info->forein_id->str,
3734
3750
                             f_key_info->forein_id->length, cs);
3735
 
      table->field[4]->store(f_key_info->referenced_db->str, 
 
3751
      table->field[4]->store(f_key_info->referenced_db->str,
3736
3752
                             f_key_info->referenced_db->length, cs);
3737
 
      table->field[10]->store(f_key_info->referenced_table->str, 
 
3753
      table->field[10]->store(f_key_info->referenced_table->str,
3738
3754
                             f_key_info->referenced_table->length, cs);
3739
3755
      if (f_key_info->referenced_key_name)
3740
3756
      {
3741
 
        table->field[5]->store(f_key_info->referenced_key_name->str, 
 
3757
        table->field[5]->store(f_key_info->referenced_key_name->str,
3742
3758
                               f_key_info->referenced_key_name->length, cs);
3743
3759
        table->field[5]->set_notnull();
3744
3760
      }
3745
3761
      else
3746
3762
        table->field[5]->set_null();
3747
3763
      table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3748
 
      table->field[7]->store(f_key_info->update_method->str, 
 
3764
      table->field[7]->store(f_key_info->update_method->str,
3749
3765
                             f_key_info->update_method->length, cs);
3750
 
      table->field[8]->store(f_key_info->delete_method->str, 
 
3766
      table->field[8]->store(f_key_info->delete_method->str,
3751
3767
                             f_key_info->delete_method->length, cs);
3752
 
      if (schema_table_store_record(thd, table))
 
3768
      if (schema_table_store_record(session, table))
3753
3769
        return(1);
3754
3770
    }
3755
3771
  }
3757
3773
}
3758
3774
 
3759
3775
 
3760
 
struct schema_table_ref 
 
3776
struct schema_table_ref
3761
3777
{
3762
3778
  const char *table_name;
3763
3779
  ST_SCHEMA_TABLE *schema_table;
3769
3785
 
3770
3786
  SYNOPSIS
3771
3787
    find_schema_table_in_plugin()
3772
 
    thd                 thread handler
 
3788
    session                 thread handler
3773
3789
    plugin              plugin
3774
3790
    table_name          table name
3775
3791
 
3777
3793
    0   table not found
3778
3794
    1   found the schema table
3779
3795
*/
3780
 
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
3781
 
                                           plugin_ref plugin,
3782
 
                                           void* p_table)
 
3796
static bool find_schema_table_in_plugin(Session *, plugin_ref plugin,
 
3797
                                        void* p_table)
3783
3798
{
3784
3799
  schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3785
3800
  const char* table_name= p_schema_table->table_name;
3801
3816
 
3802
3817
  SYNOPSIS
3803
3818
    find_schema_table()
3804
 
    thd                 thread handler
 
3819
    session                 thread handler
3805
3820
    table_name          table name
3806
3821
 
3807
3822
  RETURN
3809
3824
    #   pointer to 'schema_tables' element
3810
3825
*/
3811
3826
 
3812
 
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
 
3827
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3813
3828
{
3814
3829
  schema_table_ref schema_table_a;
3815
3830
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3823
3838
  }
3824
3839
 
3825
3840
  schema_table_a.table_name= table_name;
3826
 
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
 
3841
  if (plugin_foreach(session, find_schema_table_in_plugin,
3827
3842
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3828
3843
    return(schema_table_a.schema_table);
3829
3844
 
3843
3858
  @note
3844
3859
 
3845
3860
  @param
3846
 
    thd                   thread handler
 
3861
    session                       thread handler
3847
3862
 
3848
3863
  @param table_list Used to pass I_S table information(fields info, tables
3849
3864
  parameters etc) and table name.
3852
3867
  @retval  NULL           Can't create table
3853
3868
*/
3854
3869
 
3855
 
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
 
3870
Table *create_schema_table(Session *session, TableList *table_list)
3856
3871
{
3857
3872
  int field_count= 0;
3858
3873
  Item *item;
3859
 
  TABLE *table;
 
3874
  Table *table;
3860
3875
  List<Item> field_list;
3861
3876
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3862
3877
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3865
3880
  for (; fields_info->field_name; fields_info++)
3866
3881
  {
3867
3882
    switch (fields_info->field_type) {
3868
 
    case DRIZZLE_TYPE_TINY:
3869
3883
    case DRIZZLE_TYPE_LONG:
3870
 
    case DRIZZLE_TYPE_SHORT:
3871
3884
    case DRIZZLE_TYPE_LONGLONG:
3872
3885
      if (!(item= new Item_return_int(fields_info->field_name,
3873
3886
                                      fields_info->field_length,
3878
3891
      }
3879
3892
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3880
3893
      break;
3881
 
    case DRIZZLE_TYPE_NEWDATE:
 
3894
    case DRIZZLE_TYPE_DATE:
3882
3895
    case DRIZZLE_TYPE_TIME:
3883
3896
    case DRIZZLE_TYPE_TIMESTAMP:
3884
3897
    case DRIZZLE_TYPE_DATETIME:
3889
3902
      }
3890
3903
      break;
3891
3904
    case DRIZZLE_TYPE_DOUBLE:
3892
 
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC, 
 
3905
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
3893
3906
                           fields_info->field_length)) == NULL)
3894
3907
        return(NULL);
3895
3908
      break;
3929
3942
    field_count++;
3930
3943
  }
3931
3944
  TMP_TABLE_PARAM *tmp_table_param =
3932
 
    (TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
 
3945
    (TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3933
3946
  tmp_table_param->init();
3934
3947
  tmp_table_param->table_charset= cs;
3935
3948
  tmp_table_param->field_count= field_count;
3936
3949
  tmp_table_param->schema_table= 1;
3937
 
  SELECT_LEX *select_lex= thd->lex->current_select;
3938
 
  if (!(table= create_tmp_table(thd, tmp_table_param,
3939
 
                                field_list, (ORDER*) 0, 0, 0, 
3940
 
                                (select_lex->options | thd->options |
 
3950
  SELECT_LEX *select_lex= session->lex->current_select;
 
3951
  if (!(table= create_tmp_table(session, tmp_table_param,
 
3952
                                field_list, (order_st*) 0, 0, 0,
 
3953
                                (select_lex->options | session->options |
3941
3954
                                 TMP_TABLE_ALL_COLUMNS),
3942
3955
                                HA_POS_ERROR, table_list->alias)))
3943
3956
    return(0);
3944
3957
  my_bitmap_map* bitmaps=
3945
 
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
 
3958
    (my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3946
3959
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3947
3960
              false);
3948
3961
  table->read_set= &table->def_read_set;
3959
3972
 
3960
3973
  SYNOPSIS
3961
3974
    make_old_format()
3962
 
    thd                 thread handler
 
3975
    session                     thread handler
3963
3976
    schema_table        pointer to 'schema_tables' element
3964
3977
 
3965
3978
  RETURN
3967
3980
   0    success
3968
3981
*/
3969
3982
 
3970
 
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3983
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3971
3984
{
3972
3985
  ST_FIELD_INFO *field_info= schema_table->fields_info;
3973
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
3986
  Name_resolution_context *context= &session->lex->select_lex.context;
3974
3987
  for (; field_info->field_name; field_info++)
3975
3988
  {
3976
3989
    if (field_info->old_name)
3977
3990
    {
3978
3991
      Item_field *field= new Item_field(context,
3979
 
                                        NullS, NullS, field_info->field_name);
 
3992
                                        NULL, NULL, field_info->field_name);
3980
3993
      if (field)
3981
3994
      {
3982
3995
        field->set_name(field_info->old_name,
3983
3996
                        strlen(field_info->old_name),
3984
3997
                        system_charset_info);
3985
 
        if (add_item_to_list(thd, field))
 
3998
        if (add_item_to_list(session, field))
3986
3999
          return 1;
3987
4000
      }
3988
4001
    }
3991
4004
}
3992
4005
 
3993
4006
 
3994
 
int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4007
int make_schemata_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3995
4008
{
3996
4009
  char tmp[128];
3997
 
  LEX *lex= thd->lex;
 
4010
  LEX *lex= session->lex;
3998
4011
  SELECT_LEX *sel= lex->current_select;
3999
4012
  Name_resolution_context *context= &sel->context;
4000
4013
 
4003
4016
    ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
4004
4017
    String buffer(tmp,sizeof(tmp), system_charset_info);
4005
4018
    Item_field *field= new Item_field(context,
4006
 
                                      NullS, NullS, field_info->field_name);
4007
 
    if (!field || add_item_to_list(thd, field))
 
4019
                                      NULL, NULL, field_info->field_name);
 
4020
    if (!field || add_item_to_list(session, field))
4008
4021
      return 1;
4009
4022
    buffer.length(0);
4010
4023
    buffer.append(field_info->old_name);
4020
4033
}
4021
4034
 
4022
4035
 
4023
 
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4036
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4024
4037
{
4025
4038
  char tmp[128];
4026
 
  String buffer(tmp,sizeof(tmp), thd->charset());
4027
 
  LEX *lex= thd->lex;
 
4039
  String buffer(tmp,sizeof(tmp), session->charset());
 
4040
  LEX *lex= session->lex;
4028
4041
  Name_resolution_context *context= &lex->select_lex.context;
4029
4042
 
4030
4043
  ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4038
4051
    buffer.append(')');
4039
4052
  }
4040
4053
  Item_field *field= new Item_field(context,
4041
 
                                    NullS, NullS, field_info->field_name);
4042
 
  if (add_item_to_list(thd, field))
 
4054
                                    NULL, NULL, field_info->field_name);
 
4055
  if (add_item_to_list(session, field))
4043
4056
    return 1;
4044
4057
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4045
 
  if (thd->lex->verbose)
 
4058
  if (session->lex->verbose)
4046
4059
  {
4047
4060
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4048
4061
    field_info= &schema_table->fields_info[3];
4049
 
    field= new Item_field(context, NullS, NullS, field_info->field_name);
4050
 
    if (add_item_to_list(thd, field))
 
4062
    field= new Item_field(context, NULL, NULL, field_info->field_name);
 
4063
    if (add_item_to_list(session, field))
4051
4064
      return 1;
4052
4065
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4053
4066
                    system_charset_info);
4056
4069
}
4057
4070
 
4058
4071
 
4059
 
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4072
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4060
4073
{
4061
4074
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4062
4075
  int *field_num= fields_arr;
4063
4076
  ST_FIELD_INFO *field_info;
4064
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
4077
  Name_resolution_context *context= &session->lex->select_lex.context;
4065
4078
 
4066
4079
  for (; *field_num >= 0; field_num++)
4067
4080
  {
4068
4081
    field_info= &schema_table->fields_info[*field_num];
4069
 
    if (!thd->lex->verbose && (*field_num == 13 ||
 
4082
    if (!session->lex->verbose && (*field_num == 13 ||
4070
4083
                               *field_num == 17 ||
4071
4084
                               *field_num == 18))
4072
4085
      continue;
4073
4086
    Item_field *field= new Item_field(context,
4074
 
                                      NullS, NullS, field_info->field_name);
 
4087
                                      NULL, NULL, field_info->field_name);
4075
4088
    if (field)
4076
4089
    {
4077
4090
      field->set_name(field_info->old_name,
4078
4091
                      strlen(field_info->old_name),
4079
4092
                      system_charset_info);
4080
 
      if (add_item_to_list(thd, field))
 
4093
      if (add_item_to_list(session, field))
4081
4094
        return 1;
4082
4095
    }
4083
4096
  }
4085
4098
}
4086
4099
 
4087
4100
 
4088
 
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4101
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4089
4102
{
4090
4103
  int fields_arr[]= {0, 2, 1, 3, -1};
4091
4104
  int *field_num= fields_arr;
4092
4105
  ST_FIELD_INFO *field_info;
4093
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
4106
  Name_resolution_context *context= &session->lex->select_lex.context;
4094
4107
 
4095
4108
  for (; *field_num >= 0; field_num++)
4096
4109
  {
4097
4110
    field_info= &schema_table->fields_info[*field_num];
4098
4111
    Item_field *field= new Item_field(context,
4099
 
                                      NullS, NullS, field_info->field_name);
 
4112
                                      NULL, NULL, field_info->field_name);
4100
4113
    if (field)
4101
4114
    {
4102
4115
      field->set_name(field_info->old_name,
4103
4116
                      strlen(field_info->old_name),
4104
4117
                      system_charset_info);
4105
 
      if (add_item_to_list(thd, field))
 
4118
      if (add_item_to_list(session, field))
4106
4119
        return 1;
4107
4120
    }
4108
4121
  }
4115
4128
 
4116
4129
  SYNOPSIS
4117
4130
  mysql_schema_table()
4118
 
    thd                thread handler
 
4131
    session                thread handler
4119
4132
    lex                pointer to LEX
4120
4133
    table_list         pointer to table_list
4121
4134
 
4124
4137
    1   error
4125
4138
*/
4126
4139
 
4127
 
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
 
4140
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list)
4128
4141
{
4129
 
  TABLE *table;
4130
 
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
 
4142
  Table *table;
 
4143
  if (!(table= table_list->schema_table->create_table(session, table_list)))
4131
4144
    return(1);
4132
4145
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4133
4146
  /*
4144
4157
  table_list->table_name= table->s->table_name.str;
4145
4158
  table_list->table_name_length= table->s->table_name.length;
4146
4159
  table_list->table= table;
4147
 
  table->next= thd->derived_tables;
4148
 
  thd->derived_tables= table;
 
4160
  table->next= session->derived_tables;
 
4161
  session->derived_tables= table;
4149
4162
  table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4150
4163
 
4151
4164
  if (table_list->schema_table_reformed) // show command
4160
4173
      for (transl= table_list->field_translation; transl < end; transl++)
4161
4174
      {
4162
4175
        if (!transl->item->fixed &&
4163
 
            transl->item->fix_fields(thd, &transl->item))
 
4176
            transl->item->fix_fields(session, &transl->item))
4164
4177
          return(1);
4165
4178
      }
4166
4179
      return(0);
4167
4180
    }
4168
4181
    List_iterator_fast<Item> it(sel->item_list);
4169
4182
    if (!(transl=
4170
 
          (Field_translator*)(thd->stmt_arena->
4171
 
                              alloc(sel->item_list.elements *
 
4183
          (Field_translator*)(session->alloc(sel->item_list.elements *
4172
4184
                                    sizeof(Field_translator)))))
4173
4185
    {
4174
4186
      return(1);
4177
4189
    {
4178
4190
      transl->item= item;
4179
4191
      transl->name= item->name;
4180
 
      if (!item->fixed && item->fix_fields(thd, &transl->item))
 
4192
      if (!item->fixed && item->fix_fields(session, &transl->item))
4181
4193
      {
4182
4194
        return(1);
4183
4195
      }
4195
4207
 
4196
4208
  SYNOPSIS
4197
4209
    make_schema_select()
4198
 
    thd                  thread handler
 
4210
    session                  thread handler
4199
4211
    sel                  pointer to SELECT_LEX
4200
4212
    schema_table_idx     index of 'schema_tables' element
4201
4213
 
4204
4216
    1   error
4205
4217
*/
4206
4218
 
4207
 
int make_schema_select(THD *thd, SELECT_LEX *sel,
 
4219
int make_schema_select(Session *session, SELECT_LEX *sel,
4208
4220
                       enum enum_schema_tables schema_table_idx)
4209
4221
{
4210
4222
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4213
4225
     We have to make non const db_name & table_name
4214
4226
     because of lower_case_table_names
4215
4227
  */
4216
 
  thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4217
 
                       INFORMATION_SCHEMA_NAME.length, 0);
4218
 
  thd->make_lex_string(&table, schema_table->table_name,
 
4228
  session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
 
4229
                       INFORMATION_SCHEMA_NAME.length(), 0);
 
4230
  session->make_lex_string(&table, schema_table->table_name,
4219
4231
                       strlen(schema_table->table_name), 0);
4220
 
  if (schema_table->old_format(thd, schema_table) ||   /* Handle old syntax */
4221
 
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
 
4232
  if (schema_table->old_format(session, schema_table) ||   /* Handle old syntax */
 
4233
      !sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4222
4234
                              0, 0, TL_READ))
4223
4235
  {
4224
4236
    return(1);
4244
4256
                              enum enum_schema_table_state executed_place)
4245
4257
{
4246
4258
  JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4247
 
  THD *thd= join->thd;
4248
 
  LEX *lex= thd->lex;
 
4259
  Session *session= join->session;
 
4260
  LEX *lex= session->lex;
4249
4261
  bool result= 0;
4250
4262
 
4251
 
  thd->no_warnings_for_error= 1;
 
4263
  session->no_warnings_for_error= 1;
4252
4264
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4253
4265
  {
4254
4266
    if (!tab->table || !tab->table->pos_in_table_list)
4255
4267
      break;
4256
4268
 
4257
 
    TABLE_LIST *table_list= tab->table->pos_in_table_list;
 
4269
    TableList *table_list= tab->table->pos_in_table_list;
4258
4270
    if (table_list->schema_table)
4259
4271
    {
4260
4272
      bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4262
4274
 
4263
4275
 
4264
4276
      /* skip I_S optimizations specific to get_all_tables */
4265
 
      if (thd->lex->describe &&
 
4277
      if (session->lex->describe &&
4266
4278
          (table_list->schema_table->fill_table != get_all_tables))
4267
4279
        continue;
4268
4280
 
4296
4308
      else
4297
4309
        table_list->table->file->stats.records= 0;
4298
4310
 
4299
 
      if (table_list->schema_table->fill_table(thd, table_list,
 
4311
      if (table_list->schema_table->fill_table(session, table_list,
4300
4312
                                               tab->select_cond))
4301
4313
      {
4302
4314
        result= 1;
4309
4321
      table_list->schema_table_state= executed_place;
4310
4322
    }
4311
4323
  }
4312
 
  thd->no_warnings_for_error= 0;
 
4324
  session->no_warnings_for_error= 0;
4313
4325
  return(result);
4314
4326
}
4315
4327
 
4339
4351
  {"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4340
4352
  {"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4341
4353
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4342
 
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4354
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4343
4355
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4344
 
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4356
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4345
4357
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4346
4358
  {"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4347
4359
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4348
 
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4360
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4349
4361
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4350
4362
  {"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4351
4363
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4352
 
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0, 
 
4364
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4353
4365
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4354
4366
  {"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4355
4367
  {"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4548
4560
 
4549
4561
ST_FIELD_INFO plugin_fields_info[]=
4550
4562
{
4551
 
  {"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name", 
 
4563
  {"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4552
4564
   SKIP_OPEN_TABLE},
4553
4565
  {"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4554
4566
  {"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4593
4605
 
4594
4606
ST_SCHEMA_TABLE schema_tables[]=
4595
4607
{
4596
 
  {"CHARACTER_SETS", charsets_fields_info, create_schema_table, 
 
4608
  {"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4597
4609
   fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4598
 
  {"COLLATIONS", collation_fields_info, create_schema_table, 
 
4610
  {"COLLATIONS", collation_fields_info, create_schema_table,
4599
4611
   fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4600
4612
  {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4601
4613
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4602
 
  {"COLUMNS", columns_fields_info, create_schema_table, 
 
4614
  {"COLUMNS", columns_fields_info, create_schema_table,
4603
4615
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4604
 
   OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
 
4616
   OPTIMIZE_I_S_TABLE},
4605
4617
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4606
4618
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4607
4619
  {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4624
4636
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4625
4637
  {"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4626
4638
   fill_variables, make_old_format, 0, -1, -1, 0, 0},
4627
 
  {"STATISTICS", stat_fields_info, create_schema_table, 
 
4639
  {"STATISTICS", stat_fields_info, create_schema_table,
4628
4640
   get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4629
4641
   OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4630
 
  {"STATUS", variables_fields_info, create_schema_table, fill_status, 
 
4642
  {"STATUS", variables_fields_info, create_schema_table, fill_status,
4631
4643
   make_old_format, 0, -1, -1, 1, 0},
4632
 
  {"TABLES", tables_fields_info, create_schema_table, 
 
4644
  {"TABLES", tables_fields_info, create_schema_table,
4633
4645
   get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4634
4646
   OPTIMIZE_I_S_TABLE},
4635
4647
  {"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4651
4663
{
4652
4664
  ST_SCHEMA_TABLE *schema_table;
4653
4665
 
4654
 
  if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4655
 
                                MYF(MY_WME | MY_ZEROFILL))))
4656
 
      return(1);
 
4666
  if ((schema_table= new ST_SCHEMA_TABLE) == NULL)
 
4667
    return(1);
 
4668
  memset(schema_table, 0, sizeof(ST_SCHEMA_TABLE));
 
4669
 
4657
4670
  /* Historical Requirement */
4658
4671
  plugin->data= schema_table; // shortcut for the future
4659
4672
  if (plugin->plugin->init)
4660
4673
  {
4661
4674
    schema_table->create_table= create_schema_table;
4662
4675
    schema_table->old_format= make_old_format;
4663
 
    schema_table->idx_field1= -1, 
4664
 
    schema_table->idx_field2= -1; 
 
4676
    schema_table->idx_field1= -1,
 
4677
    schema_table->idx_field2= -1;
4665
4678
 
4666
4679
    /* Make the name available to the init() function. */
4667
4680
    schema_table->table_name= plugin->name.str;
4668
4681
 
4669
4682
    if (plugin->plugin->init(schema_table))
4670
4683
    {
4671
 
      sql_print_error("Plugin '%s' init function returned error.",
 
4684
      sql_print_error(_("Plugin '%s' init function returned error."),
4672
4685
                      plugin->name.str);
4673
4686
      goto err;
4674
4687
    }
4675
 
    
 
4688
 
4676
4689
    /* Make sure the plugin name is not set inside the init() function. */
4677
4690
    schema_table->table_name= plugin->name.str;
4678
4691
  }
4679
4692
 
4680
 
  return(0);
 
4693
  return 0;
4681
4694
err:
4682
 
  my_free(schema_table, MYF(0));
4683
 
  return(1);
 
4695
  delete schema_table;
 
4696
 
 
4697
  return 1;
4684
4698
}
4685
4699
 
4686
4700
int finalize_schema_table(st_plugin_int *plugin)
4688
4702
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4689
4703
 
4690
4704
  if (schema_table && plugin->plugin->deinit)
4691
 
    my_free(schema_table, MYF(0));
 
4705
    delete schema_table;
4692
4706
 
4693
4707
  return(0);
4694
4708
}