~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Monty Taylor
  • Date: 2008-08-16 21:06:22 UTC
  • Revision ID: monty@inaugust.com-20080816210622-zpnn13unyinqzn72
Updated po files.

Show diffs side-by-side

added added

removed removed

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