~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Brian Aker
  • Date: 2009-02-20 22:48:37 UTC
  • Revision ID: brian@tangent.org-20090220224837-fw5wrf46n4ru3e6a
First pass of stripping uint

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
15
19
 
16
20
 
17
21
/* Function with list databases, tables or fields */
18
22
#include <drizzled/server_includes.h>
19
23
#include <drizzled/sql_select.h>
20
 
#include <drizzled/sql_show.h>
21
 
#include "repl_failsafe.h"
 
24
#include <drizzled/show.h>
22
25
#include <mysys/my_dir.h>
23
 
#include <libdrizzle/gettext.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
extern "C"
 
52
int show_var_cmp(const void *var1, const void *var2);
24
53
 
25
54
inline const char *
26
55
str_or_nil(const char *str)
31
60
/* Match the values of enum ha_choice */
32
61
static const char *ha_choice_values[] = {"", "0", "1"};
33
62
 
34
 
static void store_key_options(THD *thd, String *packet, Table *table,
 
63
static void store_key_options(Session *session, String *packet, Table *table,
35
64
                              KEY *key_info);
36
65
 
37
66
 
86
115
** List all table types supported
87
116
***************************************************************************/
88
117
 
89
 
static bool show_plugins(THD *thd, plugin_ref plugin,
90
 
                            void *arg)
 
118
static bool show_plugins(Session *session, plugin_ref plugin, void *arg)
91
119
{
92
120
  Table *table= (Table*) arg;
93
121
  struct st_mysql_plugin *plug= plugin_decl(plugin);
154
182
 
155
183
  switch (plug->license) {
156
184
  case PLUGIN_LICENSE_GPL:
157
 
    table->field[7]->store(PLUGIN_LICENSE_GPL_STRING, 
 
185
    table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
158
186
                           strlen(PLUGIN_LICENSE_GPL_STRING), cs);
159
187
    break;
160
188
  case PLUGIN_LICENSE_BSD:
161
 
    table->field[7]->store(PLUGIN_LICENSE_BSD_STRING, 
 
189
    table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
162
190
                           strlen(PLUGIN_LICENSE_BSD_STRING), cs);
163
191
    break;
164
192
  default:
165
 
    table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING, 
 
193
    table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
166
194
                           strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
167
195
    break;
168
196
  }
169
197
  table->field[7]->set_notnull();
170
198
 
171
 
  return schema_table_store_record(thd, table);
 
199
  return schema_table_store_record(session, table);
172
200
}
173
201
 
174
202
 
175
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
203
int fill_plugins(Session *session, TableList *tables, COND *)
176
204
{
177
205
  Table *table= tables->table;
178
206
 
179
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
207
  if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
180
208
                               ~PLUGIN_IS_FREED, table))
181
209
    return(1);
182
210
 
189
217
 
190
218
  SYNOPSIS
191
219
    find_files()
192
 
    thd                 thread handler
 
220
    session                 thread handler
193
221
    files               put found files in this list
194
222
    db                  database name to set in TableList structure
195
223
    path                path to database
205
233
 
206
234
 
207
235
find_files_result
208
 
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
 
236
find_files(Session *session, List<LEX_STRING> *files, const char *db,
209
237
           const char *path, const char *wild, bool dir)
210
238
{
211
239
  uint32_t i;
236
264
    file=dirp->dir_entry+i;
237
265
    if (dir)
238
266
    {                                           /* Return databases */
239
 
      if ((file->name[0] == '.' && 
 
267
      if ((file->name[0] == '.' &&
240
268
          ((file->name[1] == '.' && file->name[2] == '\0') ||
241
269
            file->name[1] == '\0')))
242
270
        continue;                               /* . or .. */
262
290
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
263
291
      if (wild && wild_compare(uname, wild, 0))
264
292
        continue;
265
 
      if (!(file_name= 
266
 
            thd->make_lex_string(file_name, uname, file_name_len, true)))
 
293
      if (!(file_name=
 
294
            session->make_lex_string(file_name, uname, file_name_len, true)))
267
295
      {
268
296
        my_dirend(dirp);
269
297
        return(FIND_FILES_OOM);
273
301
    {
274
302
        // Return only .frm files which aren't temp files.
275
303
      if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),reg_ext) ||
276
 
          is_prefix(file->name, tmp_file_prefix))
 
304
          is_prefix(file->name, TMP_FILE_PREFIX))
277
305
        continue;
278
306
      *ext=0;
279
307
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
280
308
      if (wild)
281
309
      {
282
 
        if (lower_case_table_names)
283
 
        {
284
 
          if (wild_case_compare(files_charset_info, uname, wild))
285
 
            continue;
286
 
        }
287
 
        else if (wild_compare(uname, wild, 0))
288
 
          continue;
 
310
        if (lower_case_table_names)
 
311
        {
 
312
          if (wild_case_compare(files_charset_info, uname, wild))
 
313
            continue;
 
314
        }
 
315
        else if (wild_compare(uname, wild, 0))
 
316
          continue;
289
317
      }
290
318
    }
291
 
    if (!(file_name= 
292
 
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
 
319
    if (!(file_name=
 
320
          session->make_lex_string(file_name, uname, file_name_len, true)) ||
293
321
        files->push_back(file_name))
294
322
    {
295
323
      my_dirend(dirp);
302
330
}
303
331
 
304
332
 
305
 
bool
306
 
mysqld_show_create(THD *thd, TableList *table_list)
 
333
bool drizzled_show_create(Session *session, TableList *table_list)
307
334
{
308
 
  Protocol *protocol= thd->protocol;
 
335
  Protocol *protocol= session->protocol;
309
336
  char buff[2048];
310
337
  String buffer(buff, sizeof(buff), system_charset_info);
311
338
 
312
339
  /* Only one table for now, but VIEW can involve several tables */
313
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
340
  if (open_normal_and_derived_tables(session, table_list, 0))
314
341
  {
315
 
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
 
342
    if (session->is_error())
316
343
      return(true);
317
344
 
318
345
    /*
319
346
      Clear all messages with 'error' level status and
320
 
      issue a warning with 'warning' level status in 
 
347
      issue a warning with 'warning' level status in
321
348
      case of invalid view and last error is ER_VIEW_INVALID
322
349
    */
323
 
    drizzle_reset_errors(thd, true);
324
 
    thd->clear_error();
 
350
    drizzle_reset_errors(session, true);
 
351
    session->clear_error();
325
352
  }
326
353
 
327
354
  buffer.length(0);
328
355
 
329
 
  if (store_create_info(thd, table_list, &buffer, NULL))
 
356
  if (store_create_info(session, table_list, &buffer, NULL))
330
357
    return(true);
331
358
 
332
359
  List<Item> field_list;
339
366
 
340
367
  if (protocol->send_fields(&field_list,
341
368
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
 
369
  {
342
370
    return(true);
 
371
  }
343
372
  protocol->prepare_for_resend();
344
373
  {
345
374
    if (table_list->schema_table)
354
383
  if (protocol->write())
355
384
    return(true);
356
385
 
357
 
  my_eof(thd);
 
386
  session->my_eof();
358
387
  return(false);
359
388
}
360
389
 
361
 
bool mysqld_show_create_db(THD *thd, char *dbname,
 
390
bool mysqld_show_create_db(Session *session, char *dbname,
362
391
                           HA_CREATE_INFO *create_info)
363
392
{
364
393
  char buff[2048];
365
394
  String buffer(buff, sizeof(buff), system_charset_info);
366
 
  Protocol *protocol=thd->protocol;
 
395
  Protocol *protocol=session->protocol;
367
396
 
368
 
  if (store_db_create_info(thd, dbname, &buffer, create_info))
 
397
  if (store_db_create_info(session, dbname, &buffer, create_info))
369
398
  {
370
 
    /* 
 
399
    /*
371
400
      This assumes that the only reason for which store_db_create_info()
372
401
      can fail is incorrect database name (which is the case now).
373
402
    */
374
403
    my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
375
 
    return(true);    
 
404
    return(true);
376
405
  }
377
406
 
378
407
  List<Item> field_list;
389
418
 
390
419
  if (protocol->write())
391
420
    return(true);
392
 
  my_eof(thd);
 
421
  session->my_eof();
393
422
  return(false);
394
423
}
395
424
 
401
430
****************************************************************************/
402
431
 
403
432
void
404
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
433
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
405
434
{
406
435
  Table *table;
407
436
 
408
 
  if (open_normal_and_derived_tables(thd, table_list, 0))
 
437
  if (open_normal_and_derived_tables(session, table_list, 0))
409
438
    return;
410
439
  table= table_list->table;
411
440
 
414
443
  Field **ptr,*field;
415
444
  for (ptr=table->field ; (field= *ptr); ptr++)
416
445
  {
417
 
    if (!wild || !wild[0] || 
 
446
    if (!wild || !wild[0] ||
418
447
        !wild_case_compare(system_charset_info, field->field_name,wild))
419
448
    {
420
449
      field_list.push_back(new Item_field(field));
422
451
  }
423
452
  restore_record(table, s->default_values);              // Get empty record
424
453
  table->use_all_columns();
425
 
  if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
 
454
  if (session->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
426
455
    return;
427
 
  my_eof(thd);
 
456
  session->my_eof();
428
457
  return;
429
458
}
430
459
 
431
460
 
432
461
/*
433
 
  Go through all character combinations and ensure that sql_lex.cc can
434
 
  parse it as an identifier.
435
 
 
436
 
  SYNOPSIS
437
 
  require_quotes()
438
 
  name                  attribute name
439
 
  name_length           length of name
440
 
 
441
 
  RETURN
442
 
    #   Pointer to conflicting character
443
 
    0   No conflicting character
444
 
*/
445
 
 
446
 
static const char *require_quotes(const char *name, uint32_t name_length)
447
 
{
448
 
  uint32_t length;
449
 
  bool pure_digit= true;
450
 
  const char *end= name + name_length;
451
 
 
452
 
  for (; name < end ; name++)
453
 
  {
454
 
    unsigned char chr= (unsigned char) *name;
455
 
    length= my_mbcharlen(system_charset_info, chr);
456
 
    if (length == 1 && !system_charset_info->ident_map[chr])
457
 
      return name;
458
 
    if (length == 1 && (chr < '0' || chr > '9'))
459
 
      pure_digit= false;
460
 
  }
461
 
  if (pure_digit)
462
 
    return name;
463
 
  return 0;
464
 
}
465
 
 
466
 
 
467
 
/*
468
 
  Quote the given identifier if needed and append it to the target string.
469
 
  If the given identifier is empty, it will be quoted.
470
 
 
471
 
  SYNOPSIS
472
 
  append_identifier()
473
 
  thd                   thread handler
474
 
  packet                target string
475
 
  name                  the identifier to be appended
476
 
  name_length           length of the appending identifier
477
 
*/
478
 
 
479
 
void
480
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
481
 
{
482
 
  const char *name_end;
483
 
  char quote_char;
484
 
  int q= get_quote_char_for_identifier(thd, name, length);
485
 
 
486
 
  if (q == EOF)
487
 
  {
488
 
    packet->append(name, length, packet->charset());
489
 
    return;
490
 
  }
491
 
 
492
 
  /*
493
 
    The identifier must be quoted as it includes a quote character or
494
 
   it's a keyword
495
 
  */
496
 
 
497
 
  packet->reserve(length*2 + 2);
498
 
  quote_char= (char) q;
499
 
  packet->append(&quote_char, 1, system_charset_info);
500
 
 
501
 
  for (name_end= name+length ; name < name_end ; name+= length)
502
 
  {
503
 
    unsigned char chr= (unsigned char) *name;
504
 
    length= my_mbcharlen(system_charset_info, chr);
505
 
    /*
506
 
      my_mbcharlen can return 0 on a wrong multibyte
507
 
      sequence. It is possible when upgrading from 4.0,
508
 
      and identifier contains some accented characters.
509
 
      The manual says it does not work. So we'll just
510
 
      change length to 1 not to hang in the endless loop.
511
 
    */
512
 
    if (!length)
513
 
      length= 1;
514
 
    if (length == 1 && chr == (unsigned char) quote_char)
515
 
      packet->append(&quote_char, 1, system_charset_info);
516
 
    packet->append(name, length, system_charset_info);
517
 
  }
518
 
  packet->append(&quote_char, 1, system_charset_info);
519
 
}
520
 
 
521
 
 
522
 
/*
523
462
  Get the quote character for displaying an identifier.
524
463
 
525
464
  SYNOPSIS
526
465
    get_quote_char_for_identifier()
527
 
    thd         Thread handler
 
466
    session             Thread handler
528
467
    name        name to quote
529
468
    length      length of name
530
469
 
542
481
    #     Quote character
543
482
*/
544
483
 
545
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
484
int get_quote_char_for_identifier(Session *, const char *, uint32_t)
546
485
{
547
 
  if (length &&
548
 
      !is_keyword(name,length) &&
549
 
      !require_quotes(name, length) &&
550
 
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
551
 
    return EOF;
552
486
  return '`';
553
487
}
554
488
 
555
489
 
556
490
/* Append directory name (if exists) to CREATE INFO */
557
491
 
558
 
static void append_directory(THD *thd __attribute__((unused)),
 
492
static void append_directory(Session *,
559
493
                             String *packet, const char *dir_type,
560
 
                             const char *filename)
 
494
                             const char *filename)
561
495
{
562
496
  if (filename)
563
497
  {
573
507
 
574
508
#define LIST_PROCESS_HOST_LEN 64
575
509
 
576
 
static bool get_field_default_value(THD *thd __attribute__((unused)),
 
510
static bool get_field_default_value(Session *,
577
511
                                    Field *timestamp_field,
578
512
                                    Field *field, String *def_value,
579
513
                                    bool quoted)
581
515
  bool has_default;
582
516
  bool has_now_default;
583
517
 
584
 
  /* 
 
518
  /*
585
519
     We are using CURRENT_TIMESTAMP instead of NOW because it is
586
520
     more standard
587
521
  */
588
522
  has_now_default= (timestamp_field == field &&
589
523
                    field->unireg_check != Field::TIMESTAMP_UN_FIELD);
590
 
    
 
524
 
591
525
  has_default= (field->type() != DRIZZLE_TYPE_BLOB &&
592
526
                !(field->flags & NO_DEFAULT_VALUE_FLAG) &&
593
 
                field->unireg_check != Field::NEXT_NUMBER
594
 
                  && has_now_default);
 
527
                field->unireg_check != Field::NEXT_NUMBER);
595
528
 
596
529
  def_value->length(0);
597
530
  if (has_default)
622
555
      def_value->append(STRING_WITH_LEN("NULL"));    // Null as default
623
556
    else
624
557
      return 0;
625
 
 
626
558
  }
627
559
  return has_default;
628
560
}
632
564
 
633
565
  SYNOPSIS
634
566
    store_create_info()
635
 
    thd               The thread
 
567
    session               The thread
636
568
    table_list        A list containing one table to write statement
637
569
                      for.
638
570
    packet            Pointer to a string where statement will be
641
573
                      to tailor the format of the statement.  Can be
642
574
                      NULL, in which case only SQL_MODE is considered
643
575
                      when building the statement.
644
 
  
 
576
 
645
577
  NOTE
646
578
    Currently always return 0, but might return error code in the
647
579
    future.
648
 
    
 
580
 
649
581
  RETURN
650
582
    0       OK
651
583
 */
652
584
 
653
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
585
int store_create_info(Session *session, TableList *table_list, String *packet,
654
586
                      HA_CREATE_INFO *create_info_arg)
655
587
{
656
588
  List<Item> field_list;
657
 
  char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
 
589
  char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
658
590
  const char *alias;
 
591
  string buff;
659
592
  String type(tmp, sizeof(tmp), system_charset_info);
660
593
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
594
  Field **ptr,*field;
684
617
    if (lower_case_table_names == 2)
685
618
      alias= table->alias;
686
619
    else
687
 
    {
688
620
      alias= share->table_name.str;
689
 
    }
690
621
  }
691
 
  append_identifier(thd, packet, alias, strlen(alias));
 
622
  packet->append_identifier(alias, strlen(alias));
692
623
  packet->append(STRING_WITH_LEN(" (\n"));
693
624
  /*
694
625
    We need this to get default values from the table
705
636
      packet->append(STRING_WITH_LEN(",\n"));
706
637
 
707
638
    packet->append(STRING_WITH_LEN("  "));
708
 
    append_identifier(thd,packet,field->field_name, strlen(field->field_name));
 
639
    packet->append_identifier(field->field_name, strlen(field->field_name));
709
640
    packet->append(' ');
710
641
    // check for surprises from the previous call to Field::sql_type()
711
642
    if (type.ptr() != tmp)
713
644
    else
714
645
      type.set_charset(system_charset_info);
715
646
 
 
647
    if (field->vcol_info)
 
648
    {
 
649
      packet->append(STRING_WITH_LEN("VIRTUAL "));
 
650
    }
 
651
 
716
652
    field->sql_type(type);
717
653
    packet->append(type.ptr(), type.length(), system_charset_info);
718
654
 
 
655
    if (field->vcol_info)
 
656
    {
 
657
      packet->append(STRING_WITH_LEN(" AS ("));
 
658
      packet->append(field->vcol_info->expr_str.str,
 
659
                     field->vcol_info->expr_str.length,
 
660
                     system_charset_info);
 
661
      packet->append(STRING_WITH_LEN(")"));
 
662
      if (field->is_stored)
 
663
        packet->append(STRING_WITH_LEN(" STORED"));
 
664
    }
 
665
 
719
666
    if (field->has_charset())
720
667
    {
721
668
      if (field->charset() != share->table_charset)
722
669
      {
723
 
        packet->append(STRING_WITH_LEN(" CHARACTER SET "));
724
 
        packet->append(field->charset()->csname);
 
670
        packet->append(STRING_WITH_LEN(" CHARACTER SET "));
 
671
        packet->append(field->charset()->csname);
725
672
      }
726
 
      /* 
727
 
        For string types dump collation name only if 
728
 
        collation is not primary for the given charset
 
673
 
 
674
      /*
 
675
        For string types dump collation name only if
 
676
        collation is not primary for the given charset
729
677
      */
730
678
      if (!(field->charset()->state & MY_CS_PRIMARY))
731
679
      {
732
 
        packet->append(STRING_WITH_LEN(" COLLATE "));
733
 
        packet->append(field->charset()->name);
 
680
        packet->append(STRING_WITH_LEN(" COLLATE "));
 
681
        packet->append(field->charset()->name);
734
682
      }
735
683
    }
736
684
 
762
710
          packet->append(STRING_WITH_LEN(" DYNAMIC */"));
763
711
      }
764
712
    }
765
 
    if (get_field_default_value(thd, table->timestamp_field,
 
713
    if (!field->vcol_info &&
 
714
        get_field_default_value(session, table->timestamp_field,
766
715
                                field, &def_value, 1))
767
716
    {
768
717
      packet->append(STRING_WITH_LEN(" DEFAULT "));
795
744
    bool found_primary=0;
796
745
    packet->append(STRING_WITH_LEN(",\n  "));
797
746
 
798
 
    if (i == primary_key && !strcmp(key_info->name, primary_key_name))
 
747
    if (i == primary_key && is_primary_key(key_info))
799
748
    {
800
749
      found_primary=1;
801
750
      /*
810
759
      packet->append(STRING_WITH_LEN("KEY "));
811
760
 
812
761
    if (!found_primary)
813
 
     append_identifier(thd, packet, key_info->name, strlen(key_info->name));
 
762
     packet->append_identifier(key_info->name, strlen(key_info->name));
814
763
 
815
764
    packet->append(STRING_WITH_LEN(" ("));
816
765
 
820
769
        packet->append(',');
821
770
 
822
771
      if (key_part->field)
823
 
        append_identifier(thd,packet,key_part->field->field_name,
824
 
                          strlen(key_part->field->field_name));
 
772
        packet->append_identifier(key_part->field->field_name,
 
773
                                  strlen(key_part->field->field_name));
825
774
      if (key_part->field &&
826
775
          (key_part->length !=
827
776
           table->field[key_part->fieldnr-1]->key_length()))
828
777
      {
829
 
        char *end;
830
 
        buff[0] = '(';
831
 
        end= int10_to_str((long) key_part->length /
832
 
                          key_part->field->charset()->mbmaxlen,
833
 
                          buff + 1,10);
834
 
        *end++ = ')';
835
 
        packet->append(buff,(uint) (end-buff));
 
778
        buff= "(";
 
779
        buff= to_string(buff, (int32_t) key_part->length /
 
780
                              key_part->field->charset()->mbmaxlen);
 
781
        buff += ")";
 
782
        packet->append(buff.c_str(), buff.length());
836
783
      }
837
784
    }
838
785
    packet->append(')');
839
 
    store_key_options(thd, packet, table, key_info);
 
786
    store_key_options(session, packet, table, key_info);
840
787
  }
841
788
 
842
789
  /*
882
829
 
883
830
    if (create_info.auto_increment_value > 1)
884
831
    {
885
 
      char *end;
886
832
      packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
887
 
      end= int64_t10_to_str(create_info.auto_increment_value, buff,10);
888
 
      packet->append(buff, (uint) (end - buff));
 
833
      buff= to_string(create_info.auto_increment_value);
 
834
      packet->append(buff.c_str(), buff.length());
889
835
    }
890
836
 
891
837
    if (share->min_rows)
892
838
    {
893
 
      char *end;
894
839
      packet->append(STRING_WITH_LEN(" MIN_ROWS="));
895
 
      end= int64_t10_to_str(share->min_rows, buff, 10);
896
 
      packet->append(buff, (uint) (end- buff));
 
840
      buff= to_string(share->min_rows);
 
841
      packet->append(buff.c_str(), buff.length());
897
842
    }
898
843
 
899
844
    if (share->max_rows && !table_list->schema_table)
900
845
    {
901
 
      char *end;
902
846
      packet->append(STRING_WITH_LEN(" MAX_ROWS="));
903
 
      end= int64_t10_to_str(share->max_rows, buff, 10);
904
 
      packet->append(buff, (uint) (end - buff));
 
847
      buff= to_string(share->max_rows);
 
848
      packet->append(buff.c_str(), buff.length());
905
849
    }
906
850
 
907
851
    if (share->avg_row_length)
908
852
    {
909
 
      char *end;
910
853
      packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
911
 
      end= int64_t10_to_str(share->avg_row_length, buff,10);
912
 
      packet->append(buff, (uint) (end - buff));
 
854
      buff= to_string(share->avg_row_length);
 
855
      packet->append(buff.c_str(), buff.length());
913
856
    }
914
857
 
915
858
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
931
874
      packet->append(STRING_WITH_LEN(" ROW_FORMAT="));
932
875
      packet->append(ha_row_type[(uint) create_info.row_type]);
933
876
    }
934
 
    if (share->transactional != HA_CHOICE_UNDEF)
935
 
    {
936
 
      packet->append(STRING_WITH_LEN(" TRANSACTIONAL="));
937
 
      packet->append(ha_choice_values[(uint) share->transactional], 1);
938
 
    }
939
877
    if (table->s->key_block_size)
940
878
    {
941
 
      char *end;
942
879
      packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
943
 
      end= int64_t10_to_str(table->s->key_block_size, buff, 10);
944
 
      packet->append(buff, (uint) (end - buff));
 
880
      buff= to_string(table->s->key_block_size);
 
881
      packet->append(buff.c_str(), buff.length());
945
882
    }
946
883
    if (share->block_size)
947
884
    {
948
 
      char *end;
949
885
      packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
950
 
      end= int64_t10_to_str(share->block_size, buff,10);
951
 
      packet->append(buff, (uint) (end - buff));
 
886
      buff= to_string(share->block_size);
 
887
      packet->append(buff.c_str(), buff.length());
952
888
    }
953
889
    table->file->append_create_info(packet);
954
890
    if (share->comment.length)
961
897
      packet->append(STRING_WITH_LEN(" CONNECTION="));
962
898
      append_unescaped(packet, share->connect_string.str, share->connect_string.length);
963
899
    }
964
 
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
965
 
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
 
900
    append_directory(session, packet, "DATA",  create_info.data_file_name);
 
901
    append_directory(session, packet, "INDEX", create_info.index_file_name);
966
902
  }
967
903
  table->restore_column_map(old_map);
968
904
  return(0);
981
917
  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
982
918
  in @c create_options are ignored.
983
919
 
984
 
  @param  thd           The current thread instance.
 
920
  @param  session           The current thread instance.
985
921
  @param  dbname        The name of the database.
986
922
  @param  buffer        A String instance where the statement is stored.
987
 
  @param  create_info   If not NULL, the options member influences the resulting 
 
923
  @param  create_info   If not NULL, the options member influences the resulting
988
924
                        CRATE statement.
989
925
 
990
926
  @returns true if errors are detected, false otherwise.
991
927
*/
992
928
 
993
 
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
 
929
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
994
930
                          HA_CREATE_INFO *create_info)
995
931
{
996
932
  HA_CREATE_INFO create;
997
933
  uint32_t create_options = create_info ? create_info->options : 0;
998
934
 
999
935
  if (!my_strcasecmp(system_charset_info, dbname,
1000
 
                     INFORMATION_SCHEMA_NAME.str))
 
936
                     INFORMATION_SCHEMA_NAME.c_str()))
1001
937
  {
1002
 
    dbname= INFORMATION_SCHEMA_NAME.str;
 
938
    dbname= INFORMATION_SCHEMA_NAME.c_str();
1003
939
    create.default_table_charset= system_charset_info;
1004
940
  }
1005
941
  else
1007
943
    if (check_db_dir_existence(dbname))
1008
944
      return(true);
1009
945
 
1010
 
    load_db_opt_by_name(thd, dbname, &create);
 
946
    load_db_opt_by_name(session, dbname, &create);
1011
947
  }
1012
948
 
1013
949
  buffer->length(0);
1016
952
  buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
1017
953
 
1018
954
  if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1019
 
    buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1020
 
 
1021
 
  append_identifier(thd, buffer, dbname, strlen(dbname));
1022
 
 
1023
 
  if (create.default_table_charset)
1024
 
  {
1025
 
    buffer->append(STRING_WITH_LEN(" /*!40100"));
1026
 
    buffer->append(STRING_WITH_LEN(" DEFAULT CHARACTER SET "));
1027
 
    buffer->append(create.default_table_charset->csname);
1028
 
    if (!(create.default_table_charset->state & MY_CS_PRIMARY))
1029
 
    {
1030
 
      buffer->append(STRING_WITH_LEN(" COLLATE "));
1031
 
      buffer->append(create.default_table_charset->name);
1032
 
    }
1033
 
    buffer->append(STRING_WITH_LEN(" */"));
1034
 
  }
 
955
    buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
 
956
 
 
957
  buffer->append_identifier(dbname, strlen(dbname));
1035
958
 
1036
959
  return(false);
1037
960
}
1038
961
 
1039
 
static void store_key_options(THD *thd __attribute__((unused)),
 
962
static void store_key_options(Session *,
1040
963
                              String *packet, Table *table,
1041
964
                              KEY *key_info)
1042
965
{
1056
979
    packet->append(buff, (uint) (end - buff));
1057
980
  }
1058
981
 
1059
 
  assert(test(key_info->flags & HA_USES_COMMENT) == 
 
982
  assert(test(key_info->flags & HA_USES_COMMENT) ==
1060
983
              (key_info->comment.length > 0));
1061
984
  if (key_info->flags & HA_USES_COMMENT)
1062
985
  {
1063
986
    packet->append(STRING_WITH_LEN(" COMMENT "));
1064
 
    append_unescaped(packet, key_info->comment.str, 
 
987
    append_unescaped(packet, key_info->comment.str,
1065
988
                     key_info->comment.length);
1066
989
  }
1067
990
}
1078
1001
  {
1079
1002
    return (void*) sql_alloc((uint) size);
1080
1003
  }
1081
 
  static void operator delete(void *ptr __attribute__((unused)),
1082
 
                              size_t size __attribute__((unused)))
 
1004
  static void operator delete(void *, size_t)
1083
1005
  { TRASH(ptr, size); }
1084
1006
 
1085
1007
  ulong thread_id;
1093
1015
template class I_List<thread_info>;
1094
1016
#endif
1095
1017
 
1096
 
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
 
1018
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1097
1019
{
1098
1020
  Item *field;
1099
1021
  List<Item> field_list;
1100
1022
  I_List<thread_info> thread_infos;
1101
 
  ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
 
1023
  ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1102
1024
                           PROCESS_LIST_WIDTH);
1103
 
  Protocol *protocol= thd->protocol;
 
1025
  Protocol *protocol= session->protocol;
1104
1026
 
1105
1027
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1106
1028
  field_list.push_back(new Item_empty_string("User",16));
1118
1040
    return;
1119
1041
 
1120
1042
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1121
 
  if (!thd->killed)
 
1043
  if (!session->killed)
1122
1044
  {
1123
 
    I_List_iterator<THD> it(threads);
1124
 
    THD *tmp;
 
1045
    I_List_iterator<Session> it(threads);
 
1046
    Session *tmp;
1125
1047
    while ((tmp=it++))
1126
1048
    {
1127
 
      Security_context *tmp_sctx= tmp->security_ctx;
 
1049
      Security_context *tmp_sctx= &tmp->security_ctx;
1128
1050
      struct st_my_thread_var *mysys_var;
1129
 
      if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
 
1051
      if ((tmp->drizzleclient_vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user.c_str() && !strcmp(tmp_sctx->user.c_str(), user))))
1130
1052
      {
1131
 
        thread_info *thd_info= new thread_info;
 
1053
        thread_info *session_info= new thread_info;
1132
1054
 
1133
 
        thd_info->thread_id=tmp->thread_id;
1134
 
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
 
1055
        session_info->thread_id=tmp->thread_id;
 
1056
        session_info->user= session->strdup(tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1135
1057
                                    (tmp->system_thread ?
1136
1058
                                     "system user" : "unauthenticated user"));
1137
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
1138
 
        if ((thd_info->db=tmp->db))             // Safe test
1139
 
          thd_info->db=thd->strdup(thd_info->db);
1140
 
        thd_info->command=(int) tmp->command;
 
1059
        session_info->host= session->strdup(tmp_sctx->ip.c_str());
 
1060
        if ((session_info->db=tmp->db))             // Safe test
 
1061
          session_info->db=session->strdup(session_info->db);
 
1062
        session_info->command=(int) tmp->command;
1141
1063
        if ((mysys_var= tmp->mysys_var))
1142
1064
          pthread_mutex_lock(&mysys_var->mutex);
1143
 
        thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
1144
 
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
 
1065
        session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
 
1066
        session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1067
                                       (tmp->net.reading_or_writing == 2 ?
1146
1068
                                        "Writing to net" :
1147
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1069
                                        session_info->command == COM_SLEEP ? NULL :
1148
1070
                                        "Reading from net") :
1149
1071
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
1150
1072
                                       tmp->mysys_var &&
1153
1075
        if (mysys_var)
1154
1076
          pthread_mutex_unlock(&mysys_var->mutex);
1155
1077
 
1156
 
        thd_info->start_time= tmp->start_time;
1157
 
        thd_info->query=0;
 
1078
        session_info->start_time= tmp->start_time;
 
1079
        session_info->query=0;
1158
1080
        if (tmp->query)
1159
1081
        {
1160
 
          /* 
 
1082
          /*
1161
1083
            query_length is always set to 0 when we set query = NULL; see
1162
 
            the comment in sql_class.h why this prevents crashes in possible
 
1084
                  the comment in session.h why this prevents crashes in possible
1163
1085
            races with query_length
1164
1086
          */
1165
1087
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1166
 
          thd_info->query=(char*) thd->strmake(tmp->query,length);
 
1088
          session_info->query=(char*) session->strmake(tmp->query,length);
1167
1089
        }
1168
 
        thread_infos.append(thd_info);
 
1090
        thread_infos.append(session_info);
1169
1091
      }
1170
1092
    }
1171
1093
  }
1172
1094
  pthread_mutex_unlock(&LOCK_thread_count);
1173
1095
 
1174
 
  thread_info *thd_info;
1175
 
  time_t now= my_time(0);
1176
 
  while ((thd_info=thread_infos.get()))
 
1096
  thread_info *session_info;
 
1097
  time_t now= time(NULL);
 
1098
  while ((session_info=thread_infos.get()))
1177
1099
  {
1178
1100
    protocol->prepare_for_resend();
1179
 
    protocol->store((uint64_t) thd_info->thread_id);
1180
 
    protocol->store(thd_info->user, system_charset_info);
1181
 
    protocol->store(thd_info->host, system_charset_info);
1182
 
    protocol->store(thd_info->db, system_charset_info);
1183
 
    if (thd_info->proc_info)
1184
 
      protocol->store(thd_info->proc_info, system_charset_info);
 
1101
    protocol->store((uint64_t) session_info->thread_id);
 
1102
    protocol->store(session_info->user, system_charset_info);
 
1103
    protocol->store(session_info->host, system_charset_info);
 
1104
    protocol->store(session_info->db, system_charset_info);
 
1105
    if (session_info->proc_info)
 
1106
      protocol->store(session_info->proc_info, system_charset_info);
1185
1107
    else
1186
 
      protocol->store(command_name[thd_info->command].str, system_charset_info);
1187
 
    if (thd_info->start_time)
1188
 
      protocol->store((uint32_t) (now - thd_info->start_time));
 
1108
      protocol->store(command_name[session_info->command].str, system_charset_info);
 
1109
    if (session_info->start_time)
 
1110
      protocol->store((uint32_t) (now - session_info->start_time));
1189
1111
    else
1190
1112
      protocol->store_null();
1191
 
    protocol->store(thd_info->state_info, system_charset_info);
1192
 
    protocol->store(thd_info->query, system_charset_info);
 
1113
    protocol->store(session_info->state_info, system_charset_info);
 
1114
    protocol->store(session_info->query, system_charset_info);
1193
1115
    if (protocol->write())
1194
1116
      break; /* purecov: inspected */
1195
1117
  }
1196
 
  my_eof(thd);
 
1118
  session->my_eof();
1197
1119
  return;
1198
1120
}
1199
1121
 
1200
 
int fill_schema_processlist(THD* thd, TableList* tables,
1201
 
                            COND* cond __attribute__((unused)))
 
1122
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1202
1123
{
1203
1124
  Table *table= tables->table;
1204
1125
  const CHARSET_INFO * const cs= system_charset_info;
1205
1126
  char *user;
1206
 
  time_t now= my_time(0);
 
1127
  time_t now= time(NULL);
 
1128
 
 
1129
  if (now == (time_t)-1)
 
1130
    return 1;
1207
1131
 
1208
1132
  user= NULL;
1209
1133
 
1210
1134
  pthread_mutex_lock(&LOCK_thread_count);
1211
1135
 
1212
 
  if (!thd->killed)
 
1136
  if (!session->killed)
1213
1137
  {
1214
 
    I_List_iterator<THD> it(threads);
1215
 
    THD* tmp;
 
1138
    I_List_iterator<Session> it(threads);
 
1139
    Session* tmp;
1216
1140
 
1217
1141
    while ((tmp= it++))
1218
1142
    {
1219
 
      Security_context *tmp_sctx= tmp->security_ctx;
 
1143
      Security_context *tmp_sctx= &tmp->security_ctx;
1220
1144
      struct st_my_thread_var *mysys_var;
1221
1145
      const char *val;
1222
1146
 
1223
 
      if ((!tmp->vio_ok() && !tmp->system_thread))
 
1147
      if ((!tmp->drizzleclient_vio_ok() && !tmp->system_thread))
1224
1148
        continue;
1225
1149
 
1226
1150
      restore_record(table, s->default_values);
1227
1151
      /* ID */
1228
1152
      table->field[0]->store((int64_t) tmp->thread_id, true);
1229
1153
      /* USER */
1230
 
      val= tmp_sctx->user ? tmp_sctx->user :
 
1154
      val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1231
1155
            (tmp->system_thread ? "system user" : "unauthenticated user");
1232
1156
      table->field[1]->store(val, strlen(val), cs);
1233
1157
      /* HOST */
1234
 
      table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
 
1158
      table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
1235
1159
      /* DB */
1236
1160
      if (tmp->db)
1237
1161
      {
1242
1166
      if ((mysys_var= tmp->mysys_var))
1243
1167
        pthread_mutex_lock(&mysys_var->mutex);
1244
1168
      /* COMMAND */
1245
 
      if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
 
1169
      if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
1246
1170
        table->field[4]->store(val, strlen(val), cs);
1247
1171
      else
1248
1172
        table->field[4]->store(command_name[tmp->command].str,
1278
1202
        table->field[7]->set_notnull();
1279
1203
      }
1280
1204
 
1281
 
      if (schema_table_store_record(thd, table))
 
1205
      if (schema_table_store_record(session, table))
1282
1206
      {
1283
1207
        pthread_mutex_unlock(&LOCK_thread_count);
1284
1208
        return(1);
1296
1220
 
1297
1221
static DYNAMIC_ARRAY all_status_vars;
1298
1222
static bool status_vars_inited= 0;
1299
 
static int show_var_cmp(const void *var1, const void *var2)
 
1223
int show_var_cmp(const void *var1, const void *var2)
1300
1224
{
1301
1225
  return strcmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
1302
1226
}
1387
1311
    /* Note that SHOW_LONG_NOFLUSH variables are not reset */
1388
1312
    if (ptr->type == SHOW_LONG)
1389
1313
      *(ulong*) ptr->value= 0;
1390
 
  }  
 
1314
  }
1391
1315
}
1392
1316
 
1393
1317
/*
1469
1393
    *buf= my_toupper(system_charset_info, *buf);
1470
1394
}
1471
1395
 
1472
 
static bool show_status_array(THD *thd, const char *wild,
 
1396
static bool show_status_array(Session *session, const char *wild,
1473
1397
                              SHOW_VAR *variables,
1474
1398
                              enum enum_var_type value_type,
1475
1399
                              struct system_status_var *status_var,
1476
1400
                              const char *prefix, Table *table,
1477
1401
                              bool ucase_names)
1478
1402
{
1479
 
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
 
1403
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1480
1404
  char * const buff= (char *) &buff_data;
1481
1405
  char *prefix_end;
1482
1406
  /* the variable name should not be longer than 64 characters */
1483
1407
  char name_buffer[64];
1484
1408
  int len;
1485
 
  LEX_STRING null_lex_str;
1486
1409
  SHOW_VAR tmp, *var;
1487
1410
 
1488
 
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1489
 
  null_lex_str.length= 0;
 
1411
  prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1412
  prefix_end+= strlen(prefix);
1490
1413
 
1491
 
  prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1492
1414
  if (*prefix)
1493
1415
    *prefix_end++= '_';
1494
1416
  len=name_buffer + sizeof(name_buffer) - prefix_end;
1495
1417
 
1496
1418
  for (; variables->name; variables++)
1497
1419
  {
1498
 
    my_stpncpy(prefix_end, variables->name, len);
 
1420
    strncpy(prefix_end, variables->name, len);
1499
1421
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
1500
1422
    if (ucase_names)
1501
1423
      make_upper(name_buffer);
1505
1427
      Repeat as necessary, if new var is again SHOW_FUNC
1506
1428
    */
1507
1429
    for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1508
 
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
 
1430
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1509
1431
 
1510
1432
    SHOW_TYPE show_type=var->type;
1511
1433
    if (show_type == SHOW_ARRAY)
1512
1434
    {
1513
 
      show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
 
1435
      show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1514
1436
                        status_var, name_buffer, table, ucase_names);
1515
1437
    }
1516
1438
    else
1520
1442
      {
1521
1443
        char *value=var->value;
1522
1444
        const char *pos, *end;                  // We assign a lot of const's
1523
 
 
1524
1445
        pthread_mutex_lock(&LOCK_global_system_variables);
1525
1446
 
1526
1447
        if (show_type == SHOW_SYS)
1527
1448
        {
1528
1449
          show_type= ((sys_var*) value)->show_type();
1529
 
          value=     (char*) ((sys_var*) value)->value_ptr(thd, value_type,
1530
 
                                                           &null_lex_str);
 
1450
          value= (char*) ((sys_var*) value)->value_ptr(session, value_type,
 
1451
                                                       &null_lex_str);
1531
1452
        }
1532
1453
 
1533
1454
        pos= end= buff;
1556
1477
        case SHOW_LONGLONG:
1557
1478
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1558
1479
          break;
 
1480
        case SHOW_SIZE:
 
1481
          {
 
1482
            stringstream ss (stringstream::in);
 
1483
            ss << *(size_t*) value;
 
1484
 
 
1485
            string str= ss.str();
 
1486
            strncpy(buff, str.c_str(), str.length());
 
1487
            end= buff+ str.length();
 
1488
          }
 
1489
          break;
1559
1490
        case SHOW_HA_ROWS:
1560
1491
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1561
1492
          break;
1562
1493
        case SHOW_BOOL:
1563
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1494
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1564
1495
          break;
1565
1496
        case SHOW_MY_BOOL:
1566
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1497
          end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1567
1498
          break;
1568
1499
        case SHOW_INT:
1569
1500
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1570
1501
          break;
1571
1502
        case SHOW_HAVE:
1572
1503
        {
1573
 
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
 
          pos= show_comp_option_name[(int) tmp];
 
1504
          SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
 
1505
          pos= show_comp_option_name[(int) tmp_option];
1575
1506
          end= strchr(pos, '\0');
1576
1507
          break;
1577
1508
        }
1612
1543
 
1613
1544
        pthread_mutex_unlock(&LOCK_global_system_variables);
1614
1545
 
1615
 
        if (schema_table_store_record(thd, table))
 
1546
        if (schema_table_store_record(session, table))
1616
1547
          return(true);
1617
1548
      }
1618
1549
    }
1630
1561
  /* Ensure that thread id not killed during loop */
1631
1562
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1632
1563
 
1633
 
  I_List_iterator<THD> it(threads);
1634
 
  THD *tmp;
1635
 
  
 
1564
  I_List_iterator<Session> it(threads);
 
1565
  Session *tmp;
 
1566
 
1636
1567
  /* Get global values as base */
1637
1568
  *to= global_status_var;
1638
 
  
 
1569
 
1639
1570
  /* Add to this status from existing threads */
1640
1571
  while ((tmp= it++))
1641
1572
    add_to_status(to, &tmp->status_var);
1642
 
  
 
1573
 
1643
1574
  pthread_mutex_unlock(&LOCK_thread_count);
1644
1575
  return;
1645
1576
}
1661
1592
 
1662
1593
  SYNOPSIS
1663
1594
    schema_table_store_record()
1664
 
    thd                   thread handler
 
1595
    session                   thread handler
1665
1596
    table                 Information schema table to be updated
1666
1597
 
1667
1598
  RETURN
1669
1600
    1                     error
1670
1601
*/
1671
1602
 
1672
 
bool schema_table_store_record(THD *thd, Table *table)
 
1603
bool schema_table_store_record(Session *session, Table *table)
1673
1604
{
1674
1605
  int error;
1675
1606
  if ((error= table->file->ha_write_row(table->record[0])))
1676
1607
  {
1677
 
    TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
 
1608
    Tmp_Table_Param *param= table->pos_in_table_list->schema_table_param;
1678
1609
 
1679
 
    if (create_myisam_from_heap(thd, table, param->start_recinfo, 
 
1610
    if (create_myisam_from_heap(session, table, param->start_recinfo,
1680
1611
                                &param->recinfo, error, 0))
1681
1612
      return 1;
1682
1613
  }
1684
1615
}
1685
1616
 
1686
1617
 
1687
 
int make_table_list(THD *thd, SELECT_LEX *sel,
 
1618
int make_table_list(Session *session, Select_Lex *sel,
1688
1619
                    LEX_STRING *db_name, LEX_STRING *table_name)
1689
1620
{
1690
1621
  Table_ident *table_ident;
1691
 
  table_ident= new Table_ident(thd, *db_name, *table_name, 1);
 
1622
  table_ident= new Table_ident(session, *db_name, *table_name, 1);
1692
1623
  sel->init_query();
1693
 
  if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
 
1624
  if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1694
1625
    return 1;
1695
1626
  return 0;
1696
1627
}
1697
1628
 
1698
1629
 
1699
1630
/**
1700
 
  @brief    Get lookup value from the part of 'WHERE' condition 
 
1631
  @brief    Get lookup value from the part of 'WHERE' condition
1701
1632
 
1702
 
  @details This function gets lookup value from 
1703
 
           the part of 'WHERE' condition if it's possible and 
 
1633
  @details This function gets lookup value from
 
1634
           the part of 'WHERE' condition if it's possible and
1704
1635
           fill appropriate lookup_field_vals struct field
1705
1636
           with this value.
1706
1637
 
1707
 
  @param[in]      thd                   thread handler
 
1638
  @param[in]      session                   thread handler
1708
1639
  @param[in]      item_func             part of WHERE condition
1709
1640
  @param[in]      table                 I_S table
1710
 
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
 
1641
  @param[in, out] lookup_field_vals     Struct which holds lookup values
1711
1642
 
1712
1643
  @return
1713
1644
    0             success
1714
1645
    1             error, there can be no matching records for the condition
1715
1646
*/
1716
1647
 
1717
 
bool get_lookup_value(THD *thd, Item_func *item_func,
1718
 
                      TableList *table, 
 
1648
bool get_lookup_value(Session *session, Item_func *item_func,
 
1649
                      TableList *table,
1719
1650
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1720
1651
{
1721
1652
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1763
1694
                               (unsigned char *) item_field->field_name,
1764
1695
                               strlen(item_field->field_name), 0))
1765
1696
    {
1766
 
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
 
1697
      session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1698
                           tmp_str->length(), false);
1768
1699
    }
1769
1700
    /* Lookup value is table name */
1772
1703
                                    (unsigned char *) item_field->field_name,
1773
1704
                                    strlen(item_field->field_name), 0))
1774
1705
    {
1775
 
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
 
1706
      session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1776
1707
                           tmp_str->length(), false);
1777
1708
    }
1778
1709
  }
1781
1712
 
1782
1713
 
1783
1714
/**
1784
 
  @brief    Calculates lookup values from 'WHERE' condition 
 
1715
  @brief    Calculates lookup values from 'WHERE' condition
1785
1716
 
1786
1717
  @details This function calculates lookup value(database name, table name)
1787
 
           from 'WHERE' condition if it's possible and 
 
1718
           from 'WHERE' condition if it's possible and
1788
1719
           fill lookup_field_vals struct fields with these values.
1789
1720
 
1790
 
  @param[in]      thd                   thread handler
 
1721
  @param[in]      session                   thread handler
1791
1722
  @param[in]      cond                  WHERE condition
1792
1723
  @param[in]      table                 I_S table
1793
 
  @param[in, out] lookup_field_vals     Struct which holds lookup values 
 
1724
  @param[in, out] lookup_field_vals     Struct which holds lookup values
1794
1725
 
1795
1726
  @return
1796
1727
    0             success
1797
1728
    1             error, there can be no matching records for the condition
1798
1729
*/
1799
1730
 
1800
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1731
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1801
1732
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1802
1733
{
1803
1734
  if (!cond)
1813
1744
      {
1814
1745
        if (item->type() == Item::FUNC_ITEM)
1815
1746
        {
1816
 
          if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
 
1747
          if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1817
1748
            return 1;
1818
1749
        }
1819
1750
        else
1820
1751
        {
1821
 
          if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
 
1752
          if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1822
1753
            return 1;
1823
1754
        }
1824
1755
      }
1826
1757
    return 0;
1827
1758
  }
1828
1759
  else if (cond->type() == Item::FUNC_ITEM &&
1829
 
           get_lookup_value(thd, (Item_func*) cond, table, lookup_field_vals))
 
1760
           get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals))
1830
1761
    return 1;
1831
1762
  return 0;
1832
1763
}
1936
1867
           from LEX struct and fill lookup_field_vals struct field
1937
1868
           with these values.
1938
1869
 
1939
 
  @param[in]      thd                   thread handler
 
1870
  @param[in]      session                   thread handler
1940
1871
  @param[in]      cond                  WHERE condition
1941
1872
  @param[in]      tables                I_S table
1942
 
  @param[in, out] lookup_field_values   Struct which holds lookup values 
 
1873
  @param[in, out] lookup_field_values   Struct which holds lookup values
1943
1874
 
1944
1875
  @return
1945
1876
    0             success
1946
1877
    1             error, there can be no matching records for the condition
1947
1878
*/
1948
1879
 
1949
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1880
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1950
1881
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1951
1882
{
1952
 
  LEX *lex= thd->lex;
 
1883
  LEX *lex= session->lex;
1953
1884
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
1885
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1886
  switch (lex->sql_command) {
1977
1908
      The "default" is for queries over I_S.
1978
1909
      All previous cases handle SHOW commands.
1979
1910
    */
1980
 
    return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
 
1911
    return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
1981
1912
  }
1982
1913
}
1983
1914
 
1993
1924
 
1994
1925
  SYNOPSIS
1995
1926
    make_db_list()
1996
 
    thd                   thread handler
 
1927
    session                   thread handler
1997
1928
    files                 list of db names
1998
1929
    wild                  wild string
1999
1930
    idx_field_vals        idx_field_vals->db_name contains db name or
2000
1931
                          wild string
2001
1932
    with_i_schema         returns 1 if we added 'IS' name to list
2002
 
                          otherwise returns 0 
 
1933
                          otherwise returns 0
2003
1934
 
2004
1935
  RETURN
2005
1936
    zero                  success
2006
1937
    non-zero              error
2007
1938
*/
2008
1939
 
2009
 
int make_db_list(THD *thd, List<LEX_STRING> *files,
 
1940
int make_db_list(Session *session, List<LEX_STRING> *files,
2010
1941
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
2011
1942
                 bool *with_i_schema)
2012
1943
{
2013
1944
  LEX_STRING *i_s_name_copy= 0;
2014
 
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2015
 
                                      INFORMATION_SCHEMA_NAME.str,
2016
 
                                      INFORMATION_SCHEMA_NAME.length, true);
 
1945
  i_s_name_copy= session->make_lex_string(i_s_name_copy,
 
1946
                                      INFORMATION_SCHEMA_NAME.c_str(),
 
1947
                                      INFORMATION_SCHEMA_NAME.length(), true);
2017
1948
  *with_i_schema= 0;
2018
1949
  if (lookup_field_vals->wild_db_value)
2019
1950
  {
2023
1954
      LIKE clause (see also get_index_field_values() function)
2024
1955
    */
2025
1956
    if (!lookup_field_vals->db_value.str ||
2026
 
        !wild_case_compare(system_charset_info, 
2027
 
                           INFORMATION_SCHEMA_NAME.str,
 
1957
        !wild_case_compare(system_charset_info,
 
1958
                           INFORMATION_SCHEMA_NAME.c_str(),
2028
1959
                           lookup_field_vals->db_value.str))
2029
1960
    {
2030
1961
      *with_i_schema= 1;
2031
1962
      if (files->push_back(i_s_name_copy))
2032
1963
        return 1;
2033
1964
    }
2034
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
1965
    return (find_files(session, files, NULL, drizzle_data_home,
2035
1966
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2036
1967
  }
2037
1968
 
2042
1973
  */
2043
1974
  if (lookup_field_vals->db_value.str)
2044
1975
  {
2045
 
    if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
 
1976
    if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.c_str(),
2046
1977
                       lookup_field_vals->db_value.str))
2047
1978
    {
2048
1979
      *with_i_schema= 1;
2062
1993
  if (files->push_back(i_s_name_copy))
2063
1994
    return 1;
2064
1995
  *with_i_schema= 1;
2065
 
  return (find_files(thd, files, NULL,
2066
 
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
 
1996
  return (find_files(session, files, NULL,
 
1997
                     drizzle_data_home, NULL, 1) != FIND_FILES_OK);
2067
1998
}
2068
1999
 
2069
2000
 
2070
 
struct st_add_schema_table 
 
2001
struct st_add_schema_table
2071
2002
{
2072
2003
  List<LEX_STRING> *files;
2073
2004
  const char *wild;
2074
2005
};
2075
2006
 
2076
2007
 
2077
 
static bool add_schema_table(THD *thd, plugin_ref plugin,
 
2008
static bool add_schema_table(Session *session, plugin_ref plugin,
2078
2009
                                void* p_data)
2079
2010
{
2080
2011
  LEX_STRING *file_name= 0;
2098
2029
      return(0);
2099
2030
  }
2100
2031
 
2101
 
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
 
2032
  if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2102
2033
                                       strlen(schema_table->table_name),
2103
2034
                                       true)) &&
2104
2035
      !file_list->push_back(file_name))
2107
2038
}
2108
2039
 
2109
2040
 
2110
 
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
 
2041
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2111
2042
{
2112
2043
  LEX_STRING *file_name= 0;
2113
2044
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2129
2060
      else if (wild_compare(tmp_schema_table->table_name, wild, 0))
2130
2061
        continue;
2131
2062
    }
2132
 
    if ((file_name= 
2133
 
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
 
2063
    if ((file_name=
 
2064
         session->make_lex_string(file_name, tmp_schema_table->table_name,
2134
2065
                              strlen(tmp_schema_table->table_name), true)) &&
2135
2066
        !files->push_back(file_name))
2136
2067
      continue;
2139
2070
 
2140
2071
  add_data.files= files;
2141
2072
  add_data.wild= wild;
2142
 
  if (plugin_foreach(thd, add_schema_table,
 
2073
  if (plugin_foreach(session, add_schema_table,
2143
2074
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2144
2075
    return(1);
2145
2076
 
2153
2084
  @details        The function creates the list of table names in
2154
2085
                  database
2155
2086
 
2156
 
  @param[in]      thd                   thread handler
 
2087
  @param[in]      session                   thread handler
2157
2088
  @param[in]      table_names           List of table names in database
2158
2089
  @param[in]      lex                   pointer to LEX struct
2159
2090
  @param[in]      lookup_field_vals     pointer to LOOKUP_FIELD_VALUE struct
2167
2098
*/
2168
2099
 
2169
2100
static int
2170
 
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
 
2101
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2171
2102
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
2172
2103
                     bool with_i_schema, LEX_STRING *db_name)
2173
2104
{
2178
2109
  {
2179
2110
    if (with_i_schema)
2180
2111
    {
2181
 
      if (find_schema_table(thd, lookup_field_vals->table_value.str))
 
2112
      if (find_schema_table(session, lookup_field_vals->table_value.str))
2182
2113
      {
2183
2114
        if (table_names->push_back(&lookup_field_vals->table_value))
2184
2115
          return 1;
2185
2116
      }
2186
2117
    }
2187
2118
    else
2188
 
    {    
 
2119
    {
2189
2120
      if (table_names->push_back(&lookup_field_vals->table_value))
2190
2121
        return 1;
2191
2122
    }
2197
2128
    to the list
2198
2129
  */
2199
2130
  if (with_i_schema)
2200
 
    return (schema_tables_add(thd, table_names,
 
2131
    return (schema_tables_add(session, table_names,
2201
2132
                              lookup_field_vals->table_value.str));
2202
2133
 
2203
 
  find_files_result res= find_files(thd, table_names, db_name->str, path,
 
2134
  find_files_result res= find_files(session, table_names, db_name->str, path,
2204
2135
                                    lookup_field_vals->table_value.str, 0);
2205
2136
  if (res != FIND_FILES_OK)
2206
2137
  {
2214
2145
    {
2215
2146
      if (lex->sql_command != SQLCOM_SELECT)
2216
2147
        return 1;
2217
 
      thd->clear_error();
 
2148
      session->clear_error();
2218
2149
      return 2;
2219
2150
    }
2220
2151
    return 1;
2226
2157
/**
2227
2158
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2228
2159
 
2229
 
  @param[in]      thd                      thread handler
 
2160
  @param[in]      session                      thread handler
2230
2161
  @param[in]      tables                   TableList for I_S table
2231
2162
  @param[in]      schema_table             pointer to I_S structure
2232
2163
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2239
2170
    @retval       1           error
2240
2171
*/
2241
2172
 
2242
 
static int 
2243
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2173
static int
 
2174
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2244
2175
                              ST_SCHEMA_TABLE *schema_table,
2245
2176
                              Open_tables_state *open_tables_state_backup)
2246
2177
{
2247
 
  LEX *lex= thd->lex;
 
2178
  LEX *lex= session->lex;
2248
2179
  bool res;
2249
2180
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2181
  enum_sql_command save_sql_command= lex->sql_command;
2255
2186
 
2256
2187
  lex->all_selects_list= tables->schema_select_lex;
2257
2188
  /*
2258
 
    Restore thd->temporary_tables to be able to process
 
2189
    Restore session->temporary_tables to be able to process
2259
2190
    temporary tables(only for 'show index' & 'show columns').
2260
2191
    This should be changed when processing of temporary tables for
2261
2192
    I_S tables will be done.
2262
2193
  */
2263
 
  thd->temporary_tables= open_tables_state_backup->temporary_tables;
 
2194
  session->temporary_tables= open_tables_state_backup->temporary_tables;
2264
2195
  /*
2265
2196
    Let us set fake sql_command so views won't try to merge
2266
2197
    themselves into main statement. If we don't do this,
2267
2198
    SELECT * from information_schema.xxxx will cause problems.
2268
 
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()' 
 
2199
    SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2269
2200
  */
2270
2201
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
 
  res= open_normal_and_derived_tables(thd, show_table_list,
 
2202
  res= open_normal_and_derived_tables(session, show_table_list,
2272
2203
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
2273
2204
  lex->sql_command= save_sql_command;
2274
2205
  /*
2275
2206
    get_all_tables() returns 1 on failure and 0 on success thus
2276
2207
    return only these and not the result code of ::process_table()
2277
2208
 
2278
 
    We should use show_table_list->alias instead of 
 
2209
    We should use show_table_list->alias instead of
2279
2210
    show_table_list->table_name because table_name
2280
2211
    could be changed during opening of I_S tables. It's safe
2281
 
    to use alias because alias contains original table name 
2282
 
    in this case(this part of code is used only for 
 
2212
    to use alias because alias contains original table name
 
2213
    in this case(this part of code is used only for
2283
2214
    'show columns' & 'show statistics' commands).
2284
2215
  */
2285
 
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
 
2216
   table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2286
2217
                                    strlen(show_table_list->alias), false);
2287
 
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
 
2218
   db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2288
2219
                                 show_table_list->db_length, false);
2289
 
      
2290
 
 
2291
 
   error= test(schema_table->process_table(thd, show_table_list,
 
2220
 
 
2221
 
 
2222
   error= test(schema_table->process_table(session, show_table_list,
2292
2223
                                           table, res, db_name,
2293
2224
                                           table_name));
2294
 
   thd->temporary_tables= 0;
2295
 
   close_tables_for_reopen(thd, &show_table_list);
 
2225
   session->temporary_tables= 0;
 
2226
   close_tables_for_reopen(session, &show_table_list);
2296
2227
   return(error);
2297
2228
}
2298
2229
 
2300
2231
/**
2301
2232
  @brief          Fill I_S table for SHOW Table NAMES commands
2302
2233
 
2303
 
  @param[in]      thd                      thread handler
 
2234
  @param[in]      session                      thread handler
2304
2235
  @param[in]      table                    Table struct for I_S table
2305
2236
  @param[in]      db_name                  database name
2306
2237
  @param[in]      table_name               table name
2311
2242
    @retval       1           error
2312
2243
*/
2313
2244
 
2314
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2245
static int fill_schema_table_names(Session *session, Table *table,
2315
2246
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2316
2247
                                   bool with_i_schema)
2317
2248
{
2322
2253
  }
2323
2254
  else
2324
2255
  {
2325
 
    enum legacy_db_type not_used;
2326
2256
    char path[FN_REFLEN];
2327
 
    (void) build_table_filename(path, sizeof(path), db_name->str, 
 
2257
    (void) build_table_filename(path, sizeof(path), db_name->str,
2328
2258
                                table_name->str, reg_ext, 0);
2329
 
    if (mysql_frm_type(thd, path, &not_used)) 
2330
 
    {
 
2259
 
2331
2260
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
2261
                             system_charset_info);
2333
 
    }
2334
 
    else
2335
 
    {
2336
 
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2337
 
                             system_charset_info);
2338
 
    }
2339
2262
 
2340
 
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2263
    if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2341
2264
    {
2342
 
      thd->clear_error();
 
2265
      session->clear_error();
2343
2266
      return 0;
2344
2267
    }
2345
2268
  }
2346
 
  if (schema_table_store_record(thd, table))
 
2269
  if (schema_table_store_record(session, table))
2347
2270
    return 1;
2348
2271
  return 0;
2349
2272
}
2366
2289
*/
2367
2290
 
2368
2291
static uint32_t get_table_open_method(TableList *tables,
2369
 
                                  ST_SCHEMA_TABLE *schema_table,
2370
 
                                  enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2292
                                      ST_SCHEMA_TABLE *schema_table,
 
2293
                                      enum enum_schema_tables)
2371
2294
{
2372
2295
  /*
2373
2296
    determine which method will be used for table opening
2392
2315
/**
2393
2316
  @brief          Fill I_S table with data from FRM file only
2394
2317
 
2395
 
  @param[in]      thd                      thread handler
 
2318
  @param[in]      session                      thread handler
2396
2319
  @param[in]      table                    Table struct for I_S table
2397
2320
  @param[in]      schema_table             I_S table struct
2398
2321
  @param[in]      db_name                  database name
2406
2329
                              open_tables function for this table
2407
2330
*/
2408
2331
 
2409
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
 
2332
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2410
2333
                                      ST_SCHEMA_TABLE *schema_table,
2411
2334
                                      LEX_STRING *db_name,
2412
2335
                                      LEX_STRING *table_name,
2413
 
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2336
                                      enum enum_schema_tables)
2414
2337
{
2415
2338
  Table *table= tables->table;
2416
2339
  TABLE_SHARE *share;
2427
2350
  table_list.table_name= table_name->str;
2428
2351
  table_list.db= db_name->str;
2429
2352
 
2430
 
  key_length= create_table_def_key(thd, key, &table_list, 0);
 
2353
  key_length= create_table_def_key(session, key, &table_list, 0);
2431
2354
  pthread_mutex_lock(&LOCK_open);
2432
 
  share= get_table_share(thd, &table_list, key,
 
2355
  share= get_table_share(session, &table_list, key,
2433
2356
                         key_length, 0, &error);
2434
2357
  if (!share)
2435
2358
  {
2440
2363
  {
2441
2364
    tbl.s= share;
2442
2365
    table_list.table= &tbl;
2443
 
    res= schema_table->process_table(thd, &table_list, table,
 
2366
    res= schema_table->process_table(session, &table_list, table,
2444
2367
                                     res, db_name, table_name);
2445
2368
  }
2446
2369
 
2448
2371
 
2449
2372
err:
2450
2373
  pthread_mutex_unlock(&LOCK_open);
2451
 
  thd->clear_error();
 
2374
  session->clear_error();
2452
2375
  return res;
2453
2376
}
2454
2377
 
2464
2387
                  from frm files and storage engine are filled by the function
2465
2388
                  get_all_tables().
2466
2389
 
2467
 
  @param[in]      thd                      thread handler
 
2390
  @param[in]      session                      thread handler
2468
2391
  @param[in]      tables                   I_S table
2469
2392
  @param[in]      cond                     'WHERE' condition
2470
2393
 
2473
2396
    @retval       1                        error
2474
2397
*/
2475
2398
 
2476
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2399
int get_all_tables(Session *session, TableList *tables, COND *cond)
2477
2400
{
2478
 
  LEX *lex= thd->lex;
 
2401
  LEX *lex= session->lex;
2479
2402
  Table *table= tables->table;
2480
 
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
 
2403
  Select_Lex *old_all_select_lex= lex->all_selects_list;
2481
2404
  enum_sql_command save_sql_command= lex->sql_command;
2482
 
  SELECT_LEX *lsel= tables->schema_select_lex;
 
2405
  Select_Lex *lsel= tables->schema_select_lex;
2483
2406
  ST_SCHEMA_TABLE *schema_table= tables->schema_table;
2484
 
  SELECT_LEX sel;
 
2407
  Select_Lex sel;
2485
2408
  LOOKUP_FIELD_VALUES lookup_field_vals;
2486
2409
  LEX_STRING *db_name, *table_name;
2487
2410
  bool with_i_schema;
2489
2412
  List<LEX_STRING> db_names;
2490
2413
  List_iterator_fast<LEX_STRING> it(db_names);
2491
2414
  COND *partial_cond= 0;
2492
 
  uint32_t derived_tables= lex->derived_tables; 
 
2415
  uint32_t derived_tables= lex->derived_tables;
2493
2416
  int error= 1;
2494
2417
  Open_tables_state open_tables_state_backup;
2495
2418
  Query_tables_list query_tables_list_backup;
2496
2419
  uint32_t table_open_method;
2497
 
  bool old_value= thd->no_warnings_for_error;
2498
 
 
2499
 
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
 
2420
  bool old_value= session->no_warnings_for_error;
2500
2421
 
2501
2422
  /*
2502
2423
    We should not introduce deadlocks even if we already have some
2503
2424
    tables open and locked, since we won't lock tables which we will
2504
2425
    open and will ignore possible name-locks for these tables.
2505
2426
  */
2506
 
  thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
 
2427
  session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2507
2428
 
2508
2429
  schema_table_idx= get_schema_table_idx(schema_table);
2509
2430
  tables->table_open_method= table_open_method=
2510
2431
    get_table_open_method(tables, schema_table, schema_table_idx);
2511
 
  /* 
 
2432
  /*
2512
2433
    this branch processes SHOW FIELDS, SHOW INDEXES commands.
2513
2434
    see sql_parse.cc, prepare_schema_table() function where
2514
2435
    this values are initialized
2515
2436
  */
2516
2437
  if (lsel && lsel->table_list.first)
2517
2438
  {
2518
 
    error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
 
2439
    error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2519
2440
                                         &open_tables_state_backup);
2520
2441
    goto err;
2521
2442
  }
2522
2443
 
2523
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2444
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2524
2445
  {
2525
2446
    error= 0;
2526
2447
    goto err;
2528
2449
 
2529
2450
  if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2530
2451
  {
2531
 
    /* 
 
2452
    /*
2532
2453
      if lookup value is empty string then
2533
2454
      it's impossible table name or db name
2534
2455
    */
2544
2465
      !lookup_field_vals.wild_db_value)
2545
2466
    tables->has_db_lookup_value= true;
2546
2467
  if (lookup_field_vals.table_value.length &&
2547
 
      !lookup_field_vals.wild_table_value) 
 
2468
      !lookup_field_vals.wild_table_value)
2548
2469
    tables->has_table_lookup_value= true;
2549
2470
 
2550
2471
  if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2559
2480
    goto err;
2560
2481
  }
2561
2482
 
2562
 
  if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
 
2483
  if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2563
2484
    goto err;
2564
2485
  it.rewind(); /* To get access to new elements in basis list */
2565
2486
  while ((db_name= it++))
2566
2487
  {
2567
2488
    {
2568
 
      thd->no_warnings_for_error= 1;
 
2489
      session->no_warnings_for_error= 1;
2569
2490
      List<LEX_STRING> table_names;
2570
 
      int res= make_table_name_list(thd, &table_names, lex,
 
2491
      int res= make_table_name_list(session, &table_names, lex,
2571
2492
                                    &lookup_field_vals,
2572
2493
                                    with_i_schema, db_name);
2573
2494
      if (res == 2)   /* Not fatal error, continue */
2578
2499
      List_iterator_fast<LEX_STRING> it_files(table_names);
2579
2500
      while ((table_name= it_files++))
2580
2501
      {
2581
 
        restore_record(table, s->default_values);
 
2502
        restore_record(table, s->default_values);
2582
2503
        table->field[schema_table->idx_field1]->
2583
2504
          store(db_name->str, db_name->length, system_charset_info);
2584
2505
        table->field[schema_table->idx_field2]->
2588
2509
        {
2589
2510
          /*
2590
2511
            If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2591
 
            we can skip table opening and we don't have lookup value for 
 
2512
            we can skip table opening and we don't have lookup value for
2592
2513
            table name or lookup value is wild string(table name list is
2593
2514
            already created by make_table_name_list() function).
2594
2515
          */
2596
2517
              (!lookup_field_vals.table_value.length ||
2597
2518
               lookup_field_vals.wild_table_value))
2598
2519
          {
2599
 
            if (schema_table_store_record(thd, table))
 
2520
            if (schema_table_store_record(session, table))
2600
2521
              goto err;      /* Out of space in temporary table */
2601
2522
            continue;
2602
2523
          }
2604
2525
          /* SHOW Table NAMES command */
2605
2526
          if (schema_table_idx == SCH_TABLE_NAMES)
2606
2527
          {
2607
 
            if (fill_schema_table_names(thd, tables->table, db_name,
 
2528
            if (fill_schema_table_names(session, tables->table, db_name,
2608
2529
                                        table_name, with_i_schema))
2609
2530
              continue;
2610
2531
          }
2613
2534
            if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2614
2535
                !with_i_schema)
2615
2536
            {
2616
 
              if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
 
2537
              if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2617
2538
                                              table_name, schema_table_idx))
2618
2539
                continue;
2619
2540
            }
2620
2541
 
2621
 
            int res;
2622
2542
            LEX_STRING tmp_lex_string, orig_db_name;
2623
2543
            /*
2624
2544
              Set the parent lex of 'sel' because it is needed by
2625
2545
              sel.init_query() which is called inside make_table_list.
2626
2546
            */
2627
 
            thd->no_warnings_for_error= 1;
 
2547
            session->no_warnings_for_error= 1;
2628
2548
            sel.parent_lex= lex;
2629
2549
            /* db_name can be changed in make_table_list() func */
2630
 
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
2631
 
                                      db_name->length, false))
 
2550
            if (!session->make_lex_string(&orig_db_name, db_name->str,
 
2551
                                          db_name->length, false))
2632
2552
              goto err;
2633
 
            if (make_table_list(thd, &sel, db_name, table_name))
 
2553
            if (make_table_list(session, &sel, db_name, table_name))
2634
2554
              goto err;
2635
2555
            TableList *show_table_list= (TableList*) sel.table_list.first;
2636
2556
            lex->all_selects_list= &sel;
2638
2558
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2559
            show_table_list->i_s_requested_object=
2640
2560
              schema_table->i_s_requested_object;
2641
 
            res= open_normal_and_derived_tables(thd, show_table_list,
 
2561
            res= open_normal_and_derived_tables(session, show_table_list,
2642
2562
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
2643
2563
            lex->sql_command= save_sql_command;
2644
2564
            /*
2645
 
              XXX:  show_table_list has a flag i_is_requested,
2646
 
              and when it's set, open_normal_and_derived_tables()
2647
 
              can return an error without setting an error message
2648
 
              in THD, which is a hack. This is why we have to
2649
 
              check for res, then for thd->is_error() only then
2650
 
              for thd->main_da.sql_errno().
 
2565
XXX:  show_table_list has a flag i_is_requested,
 
2566
and when it's set, open_normal_and_derived_tables()
 
2567
can return an error without setting an error message
 
2568
in Session, which is a hack. This is why we have to
 
2569
check for res, then for session->is_error() only then
 
2570
for session->main_da.sql_errno().
2651
2571
            */
2652
 
            if (res && thd->is_error() &&
2653
 
                thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2572
            if (res && session->is_error() &&
 
2573
                session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2654
2574
            {
2655
2575
              /*
2656
2576
                Hide error for not existing table.
2659
2579
                table does not exist.
2660
2580
              */
2661
2581
              res= 0;
2662
 
              thd->clear_error();
 
2582
              session->clear_error();
2663
2583
            }
2664
2584
            else
2665
2585
            {
2666
2586
              /*
2667
 
                We should use show_table_list->alias instead of 
 
2587
                We should use show_table_list->alias instead of
2668
2588
                show_table_list->table_name because table_name
2669
2589
                could be changed during opening of I_S tables. It's safe
2670
 
                to use alias because alias contains original table name 
 
2590
                to use alias because alias contains original table name
2671
2591
                in this case.
2672
2592
              */
2673
 
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2674
 
                                   strlen(show_table_list->alias), false);
2675
 
              res= schema_table->process_table(thd, show_table_list, table,
 
2593
              session->make_lex_string(&tmp_lex_string, show_table_list->alias,
 
2594
                                       strlen(show_table_list->alias), false);
 
2595
              res= schema_table->process_table(session, show_table_list, table,
2676
2596
                                               res, &orig_db_name,
2677
2597
                                               &tmp_lex_string);
2678
 
              close_tables_for_reopen(thd, &show_table_list);
 
2598
              close_tables_for_reopen(session, &show_table_list);
2679
2599
            }
2680
2600
            assert(!lex->query_tables_own_last);
2681
2601
            if (res)
2693
2613
 
2694
2614
  error= 0;
2695
2615
err:
2696
 
  thd->restore_backup_open_tables_state(&open_tables_state_backup);
2697
 
  lex->restore_backup_query_tables_list(&query_tables_list_backup);
 
2616
  session->restore_backup_open_tables_state(&open_tables_state_backup);
2698
2617
  lex->derived_tables= derived_tables;
2699
2618
  lex->all_selects_list= old_all_select_lex;
2700
2619
  lex->sql_command= save_sql_command;
2701
 
  thd->no_warnings_for_error= old_value;
 
2620
  session->no_warnings_for_error= old_value;
2702
2621
  return(error);
2703
2622
}
2704
2623
 
2705
2624
 
2706
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
 
2625
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2707
2626
                          const CHARSET_INFO * const cs)
2708
2627
{
2709
2628
  restore_record(table, s->default_values);
2710
2629
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
2630
  table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
2631
  table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
 
  return schema_table_store_record(thd, table);
 
2632
  return schema_table_store_record(session, table);
2714
2633
}
2715
2634
 
2716
2635
 
2717
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2636
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2718
2637
{
2719
2638
  /*
2720
2639
    TODO: fill_schema_shemata() is called when new client is connected.
2725
2644
  List<LEX_STRING> db_names;
2726
2645
  LEX_STRING *db_name;
2727
2646
  bool with_i_schema;
2728
 
  HA_CREATE_INFO create;
2729
2647
  Table *table= tables->table;
2730
2648
 
2731
 
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
 
2649
  if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2732
2650
    return(0);
2733
 
  if (make_db_list(thd, &db_names, &lookup_field_vals,
 
2651
  if (make_db_list(session, &db_names, &lookup_field_vals,
2734
2652
                   &with_i_schema))
2735
2653
    return(1);
2736
2654
 
2757
2675
  {
2758
2676
    if (with_i_schema)       // information schema name is always first in list
2759
2677
    {
2760
 
      if (store_schema_shemata(thd, table, db_name,
 
2678
      if (store_schema_shemata(session, table, db_name,
2761
2679
                               system_charset_info))
2762
2680
        return(1);
2763
2681
      with_i_schema= 0;
2764
2682
      continue;
2765
2683
    }
2766
2684
    {
2767
 
      load_db_opt_by_name(thd, db_name->str, &create);
2768
 
      if (store_schema_shemata(thd, table, db_name,
 
2685
      HA_CREATE_INFO create;
 
2686
      load_db_opt_by_name(session, db_name->str, &create);
 
2687
 
 
2688
      if (store_schema_shemata(session, table, db_name,
2769
2689
                               create.default_table_charset))
2770
2690
        return(1);
2771
2691
    }
2774
2694
}
2775
2695
 
2776
2696
 
2777
 
static int get_schema_tables_record(THD *thd, TableList *tables,
 
2697
static int get_schema_tables_record(Session *session, TableList *tables,
2778
2698
                                    Table *table, bool res,
2779
2699
                                    LEX_STRING *db_name,
2780
2700
                                    LEX_STRING *table_name)
2791
2711
    /*
2792
2712
      there was errors during opening tables
2793
2713
    */
2794
 
    const char *error= thd->is_error() ? thd->main_da.message() : "";
 
2714
    const char *error= session->is_error() ? session->main_da.message() : "";
2795
2715
    if (tables->schema_table)
2796
2716
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2797
2717
    else
2798
2718
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2799
2719
    table->field[20]->store(error, strlen(error), cs);
2800
 
    thd->clear_error();
 
2720
    session->clear_error();
2801
2721
  }
2802
2722
  else
2803
2723
  {
2821
2741
    }
2822
2742
    tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2823
2743
    table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2824
 
    table->field[5]->store((int64_t) share->frm_version, true);
 
2744
    table->field[5]->store((int64_t) 0, true);
2825
2745
 
2826
2746
    ptr=option_buff;
2827
2747
    if (share->min_rows)
2828
2748
    {
2829
 
      ptr=my_stpcpy(ptr," min_rows=");
2830
 
      ptr=int64_t10_to_str(share->min_rows,ptr,10);
 
2749
      ptr= strcpy(ptr," min_rows=")+10;
 
2750
      ptr= int64_t10_to_str(share->min_rows,ptr,10);
2831
2751
    }
2832
2752
    if (share->max_rows)
2833
2753
    {
2834
 
      ptr=my_stpcpy(ptr," max_rows=");
2835
 
      ptr=int64_t10_to_str(share->max_rows,ptr,10);
 
2754
      ptr= strcpy(ptr," max_rows=")+10;
 
2755
      ptr= int64_t10_to_str(share->max_rows,ptr,10);
2836
2756
    }
2837
2757
    if (share->avg_row_length)
2838
2758
    {
2839
 
      ptr=my_stpcpy(ptr," avg_row_length=");
2840
 
      ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
 
2759
      ptr= strcpy(ptr," avg_row_length=")+16;
 
2760
      ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2841
2761
    }
2842
2762
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
 
      ptr=my_stpcpy(ptr," pack_keys=1");
 
2763
      ptr= strcpy(ptr," pack_keys=1")+12;
2844
2764
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
 
      ptr=my_stpcpy(ptr," pack_keys=0");
 
2765
      ptr= strcpy(ptr," pack_keys=0")+12;
2846
2766
    /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2767
    if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
 
      ptr=my_stpcpy(ptr," checksum=1");
 
2768
      ptr= strcpy(ptr," checksum=1")+11;
2849
2769
    if (share->page_checksum != HA_CHOICE_UNDEF)
2850
 
      ptr= strxmov(ptr, " page_checksum=",
2851
 
                   ha_choice_values[(uint) share->page_checksum], NULL);
 
2770
      ptr+= sprintf(ptr, " page_checksum=%s",
 
2771
                    ha_choice_values[(uint) share->page_checksum]);
2852
2772
    if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
 
      ptr=my_stpcpy(ptr," delay_key_write=1");
 
2773
      ptr= strcpy(ptr," delay_key_write=1")+18;
2854
2774
    if (share->row_type != ROW_TYPE_DEFAULT)
2855
 
      ptr=strxmov(ptr, " row_format=", 
2856
 
                  ha_row_type[(uint) share->row_type],
2857
 
                  NULL);
 
2775
      ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint)share->row_type]);
2858
2776
    if (share->block_size)
2859
2777
    {
2860
 
      ptr= my_stpcpy(ptr, " block_size=");
 
2778
      ptr= strcpy(ptr, " block_size=")+12;
2861
2779
      ptr= int64_t10_to_str(share->block_size, ptr, 10);
2862
2780
    }
2863
 
    
2864
 
    if (share->transactional != HA_CHOICE_UNDEF)
2865
 
    {
2866
 
      ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
 
                   (share->transactional == HA_CHOICE_YES ? "1" : "0"),
2868
 
                   NULL);
2869
 
    }
2870
 
    if (share->transactional != HA_CHOICE_UNDEF)
2871
 
      ptr= strxmov(ptr, " transactional=",
2872
 
                   ha_choice_values[(uint) share->transactional], NULL);
 
2781
 
2873
2782
    table->field[19]->store(option_buff+1,
2874
 
                            (ptr == option_buff ? 0 : 
 
2783
                            (ptr == option_buff ? 0 :
2875
2784
                             (uint) (ptr-option_buff)-1), cs);
2876
2785
 
2877
2786
    tmp_buff= (share->table_charset ?
2936
2845
      }
2937
2846
      if (file->stats.create_time)
2938
2847
      {
2939
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2940
 
                                                  (my_time_t) file->stats.create_time);
 
2848
        session->variables.time_zone->gmt_sec_to_TIME(&time,
 
2849
                                                  (time_t) file->stats.create_time);
2941
2850
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
2851
        table->field[14]->set_notnull();
2943
2852
      }
2944
2853
      if (file->stats.update_time)
2945
2854
      {
2946
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2947
 
                                                  (my_time_t) file->stats.update_time);
 
2855
        session->variables.time_zone->gmt_sec_to_TIME(&time,
 
2856
                                                  (time_t) file->stats.update_time);
2948
2857
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
2858
        table->field[15]->set_notnull();
2950
2859
      }
2951
2860
      if (file->stats.check_time)
2952
2861
      {
2953
 
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2954
 
                                                  (my_time_t) file->stats.check_time);
 
2862
        session->variables.time_zone->gmt_sec_to_TIME(&time,
 
2863
                                                  (time_t) file->stats.check_time);
2955
2864
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
2865
        table->field[16]->set_notnull();
2957
2866
      }
2962
2871
      }
2963
2872
    }
2964
2873
  }
2965
 
  return(schema_table_store_record(thd, table));
 
2874
  return(schema_table_store_record(session, table));
2966
2875
}
2967
2876
 
2968
2877
 
2974
2883
  @param[in]      cs                I_S table charset
2975
2884
  @param[in]      offset            offset from beginning of table
2976
2885
                                    to DATE_TYPE column in I_S table
2977
 
                                    
 
2886
 
2978
2887
  @return         void
2979
2888
*/
2980
2889
 
3003
2912
    uint32_t octet_max_length= field->max_display_length();
3004
2913
    if (is_blob && octet_max_length != (uint32_t) 4294967295U)
3005
2914
      octet_max_length /= field->charset()->mbmaxlen;
3006
 
    int64_t char_max_len= is_blob ? 
 
2915
    int64_t char_max_len= is_blob ?
3007
2916
      (int64_t) octet_max_length / field->charset()->mbminlen :
3008
2917
      (int64_t) octet_max_length / field->charset()->mbmaxlen;
3009
2918
    /* CHARACTER_MAXIMUM_LENGTH column*/
3024
2933
  case DRIZZLE_TYPE_NEWDECIMAL:
3025
2934
    field_length= ((Field_new_decimal*) field)->precision;
3026
2935
    break;
3027
 
  case DRIZZLE_TYPE_TINY:
3028
2936
  case DRIZZLE_TYPE_LONG:
3029
2937
  case DRIZZLE_TYPE_LONGLONG:
3030
2938
    field_length= field->max_display_length() - 1;
3065
2973
}
3066
2974
 
3067
2975
 
3068
 
static int get_schema_column_record(THD *thd, TableList *tables,
 
2976
static int get_schema_column_record(Session *session, TableList *tables,
3069
2977
                                    Table *table, bool res,
3070
2978
                                    LEX_STRING *db_name,
3071
2979
                                    LEX_STRING *table_name)
3072
2980
{
3073
 
  LEX *lex= thd->lex;
 
2981
  LEX *lex= session->lex;
3074
2982
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3075
2983
  const CHARSET_INFO * const cs= system_charset_info;
3076
2984
  Table *show_table;
3085
2993
      /*
3086
2994
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3087
2995
        rather than in SHOW COLUMNS
3088
 
      */ 
3089
 
      if (thd->is_error())
3090
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3091
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3092
 
      thd->clear_error();
 
2996
      */
 
2997
      if (session->is_error())
 
2998
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2999
                     session->main_da.sql_errno(), session->main_da.message());
 
3000
      session->clear_error();
3093
3001
      res= 0;
3094
3002
    }
3095
3003
    return(res);
3118
3026
      /* to satisfy 'field->val_str' ASSERTs */
3119
3027
      unsigned char *bitmaps;
3120
3028
      uint32_t bitmap_size= show_table_share->column_bitmap_size;
3121
 
      if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
 
3029
      if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3122
3030
        return(0);
3123
3031
      bitmap_init(&show_table->def_read_set,
3124
3032
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3137
3045
 
3138
3046
    /* to satisfy 'field->val_str' ASSERTs */
3139
3047
    field->table= show_table;
3140
 
    show_table->in_use= thd;
 
3048
    show_table->in_use= session;
3141
3049
 
3142
3050
    if (wild && wild[0] &&
3143
3051
        wild_case_compare(system_charset_info, field->field_name,wild))
3153
3061
                           cs);
3154
3062
    table->field[4]->store((int64_t) count, true);
3155
3063
 
3156
 
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
 
3064
    if (get_field_default_value(session, timestamp_field, field, &type, 0))
3157
3065
    {
3158
3066
      table->field[5]->store(type.ptr(), type.length(), cs);
3159
3067
      table->field[5]->set_notnull();
3176
3084
        field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3177
3085
      table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3178
3086
                              cs);
3179
 
 
 
3087
    if (field->vcol_info)
 
3088
          table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3180
3089
    table->field[18]->store(field->comment.str, field->comment.length, cs);
3181
3090
    {
3182
3091
      enum column_format_type column_format= (enum column_format_type)
3190
3099
      table->field[20]->store((const char*) pos,
3191
3100
                              strlen((const char*) pos), cs);
3192
3101
    }
3193
 
    if (schema_table_store_record(thd, table))
 
3102
    if (schema_table_store_record(session, table))
3194
3103
      return(1);
3195
3104
  }
3196
3105
  return(0);
3198
3107
 
3199
3108
 
3200
3109
 
3201
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3110
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3202
3111
{
3203
3112
  CHARSET_INFO **cs;
3204
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3113
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
3114
  Table *table= tables->table;
3206
3115
  const CHARSET_INFO * const scs= system_charset_info;
3207
3116
 
3208
3117
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3209
3118
  {
3210
3119
    const CHARSET_INFO * const tmp_cs= cs[0];
3211
 
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) && 
 
3120
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3212
3121
        (tmp_cs->state & MY_CS_AVAILABLE) &&
3213
3122
        !(tmp_cs->state & MY_CS_HIDDEN) &&
3214
3123
        !(wild && wild[0] &&
3221
3130
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3222
3131
      table->field[2]->store(comment, strlen(comment), scs);
3223
3132
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3224
 
      if (schema_table_store_record(thd, table))
 
3133
      if (schema_table_store_record(session, table))
3225
3134
        return 1;
3226
3135
    }
3227
3136
  }
3229
3138
}
3230
3139
 
3231
3140
 
3232
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3141
int fill_schema_collation(Session *session, TableList *tables, COND *)
3233
3142
{
3234
3143
  CHARSET_INFO **cs;
3235
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3144
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3236
3145
  Table *table= tables->table;
3237
3146
  const CHARSET_INFO * const scs= system_charset_info;
3238
3147
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3246
3155
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3247
3156
    {
3248
3157
      const CHARSET_INFO *tmp_cl= cl[0];
3249
 
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
 
3158
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3250
3159
          !my_charset_same(tmp_cs, tmp_cl))
3251
3160
        continue;
3252
3161
      if (!(wild && wild[0] &&
3262
3171
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3263
3172
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3264
3173
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3265
 
        if (schema_table_store_record(thd, table))
 
3174
        if (schema_table_store_record(session, table))
3266
3175
          return 1;
3267
3176
      }
3268
3177
    }
3271
3180
}
3272
3181
 
3273
3182
 
3274
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3183
int fill_schema_coll_charset_app(Session *session, TableList *tables, COND *)
3275
3184
{
3276
3185
  CHARSET_INFO **cs;
3277
3186
  Table *table= tables->table;
3280
3189
  {
3281
3190
    CHARSET_INFO **cl;
3282
3191
    const CHARSET_INFO *tmp_cs= cs[0];
3283
 
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || 
 
3192
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3284
3193
        !(tmp_cs->state & MY_CS_PRIMARY))
3285
3194
      continue;
3286
3195
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3287
3196
    {
3288
3197
      const CHARSET_INFO *tmp_cl= cl[0];
3289
 
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
 
3198
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3290
3199
          !my_charset_same(tmp_cs,tmp_cl))
3291
3200
        continue;
3292
3201
      restore_record(table, s->default_values);
3293
3202
      table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
3203
      table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
 
      if (schema_table_store_record(thd, table))
 
3204
      if (schema_table_store_record(session, table))
3296
3205
        return 1;
3297
3206
    }
3298
3207
  }
3300
3209
}
3301
3210
 
3302
3211
 
3303
 
static int get_schema_stat_record(THD *thd, TableList *tables,
 
3212
static int get_schema_stat_record(Session *session, TableList *tables,
3304
3213
                                  Table *table, bool res,
3305
3214
                                  LEX_STRING *db_name,
3306
3215
                                  LEX_STRING *table_name)
3308
3217
  const CHARSET_INFO * const cs= system_charset_info;
3309
3218
  if (res)
3310
3219
  {
3311
 
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
 
3220
    if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3312
3221
    {
3313
3222
      /*
3314
3223
        I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3315
3224
        rather than in SHOW KEYS
3316
3225
      */
3317
 
      if (thd->is_error())
3318
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3319
 
                     thd->main_da.sql_errno(), thd->main_da.message());
3320
 
      thd->clear_error();
 
3226
      if (session->is_error())
 
3227
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3228
                     session->main_da.sql_errno(), session->main_da.message());
 
3229
      session->clear_error();
3321
3230
      res= 0;
3322
3231
    }
3323
3232
    return(res);
3383
3292
        else
3384
3293
          table->field[14]->store("", 0, cs);
3385
3294
        table->field[14]->set_notnull();
3386
 
        assert(test(key_info->flags & HA_USES_COMMENT) == 
 
3295
        assert(test(key_info->flags & HA_USES_COMMENT) ==
3387
3296
                   (key_info->comment.length > 0));
3388
3297
        if (key_info->flags & HA_USES_COMMENT)
3389
 
          table->field[15]->store(key_info->comment.str, 
 
3298
          table->field[15]->store(key_info->comment.str,
3390
3299
                                  key_info->comment.length, cs);
3391
 
        if (schema_table_store_record(thd, table))
 
3300
        if (schema_table_store_record(session, table))
3392
3301
          return(1);
3393
3302
      }
3394
3303
    }
3397
3306
}
3398
3307
 
3399
3308
 
3400
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3309
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3401
3310
                       LEX_STRING *table_name, const char *key_name,
3402
3311
                       uint32_t key_len, const char *con_type, uint32_t con_len)
3403
3312
{
3408
3317
  table->field[3]->store(db_name->str, db_name->length, cs);
3409
3318
  table->field[4]->store(table_name->str, table_name->length, cs);
3410
3319
  table->field[5]->store(con_type, con_len, cs);
3411
 
  return schema_table_store_record(thd, table);
 
3320
  return schema_table_store_record(session, table);
3412
3321
}
3413
3322
 
3414
3323
 
3415
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
 
3324
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
3325
                                         Table *table, bool res,
3417
3326
                                         LEX_STRING *db_name,
3418
3327
                                         LEX_STRING *table_name)
3419
3328
{
3420
3329
  if (res)
3421
3330
  {
3422
 
    if (thd->is_error())
3423
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3424
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3425
 
    thd->clear_error();
 
3331
    if (session->is_error())
 
3332
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3333
                   session->main_da.sql_errno(), session->main_da.message());
 
3334
    session->clear_error();
3426
3335
    return(0);
3427
3336
  }
3428
3337
  else
3431
3340
    Table *show_table= tables->table;
3432
3341
    KEY *key_info=show_table->key_info;
3433
3342
    uint32_t primary_key= show_table->s->primary_key;
3434
 
    show_table->file->info(HA_STATUS_VARIABLE | 
 
3343
    show_table->file->info(HA_STATUS_VARIABLE |
3435
3344
                           HA_STATUS_NO_LOCK |
3436
3345
                           HA_STATUS_TIME);
3437
3346
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3439
3348
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3440
3349
        continue;
3441
3350
 
3442
 
      if (i == primary_key && !strcmp(key_info->name, primary_key_name))
 
3351
      if (i == primary_key && is_primary_key(key_info))
3443
3352
      {
3444
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3353
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3445
3354
                              strlen(key_info->name),
3446
3355
                              STRING_WITH_LEN("PRIMARY KEY")))
3447
3356
          return(1);
3448
3357
      }
3449
3358
      else if (key_info->flags & HA_NOSAME)
3450
3359
      {
3451
 
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
 
3360
        if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
3361
                              strlen(key_info->name),
3453
3362
                              STRING_WITH_LEN("UNIQUE")))
3454
3363
          return(1);
3455
3364
      }
3456
3365
    }
3457
3366
 
3458
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3367
    show_table->file->get_foreign_key_list(session, &f_key_list);
3459
3368
    FOREIGN_KEY_INFO *f_key_info;
3460
3369
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
3370
    while ((f_key_info=it++))
3462
3371
    {
3463
 
      if (store_constraints(thd, table, db_name, table_name, 
 
3372
      if (store_constraints(session, table, db_name, table_name,
3464
3373
                            f_key_info->forein_id->str,
3465
3374
                            strlen(f_key_info->forein_id->str),
3466
3375
                            "FOREIGN KEY", 11))
3486
3395
}
3487
3396
 
3488
3397
 
3489
 
static int get_schema_key_column_usage_record(THD *thd,
 
3398
static int get_schema_key_column_usage_record(Session *session,
3490
3399
                                              TableList *tables,
3491
3400
                                              Table *table, bool res,
3492
3401
                                              LEX_STRING *db_name,
3494
3403
{
3495
3404
  if (res)
3496
3405
  {
3497
 
    if (thd->is_error())
3498
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3499
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3500
 
    thd->clear_error();
 
3406
    if (session->is_error())
 
3407
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3408
                   session->main_da.sql_errno(), session->main_da.message());
 
3409
    session->clear_error();
3501
3410
    return(0);
3502
3411
  }
3503
3412
  else
3506
3415
    Table *show_table= tables->table;
3507
3416
    KEY *key_info=show_table->key_info;
3508
3417
    uint32_t primary_key= show_table->s->primary_key;
3509
 
    show_table->file->info(HA_STATUS_VARIABLE | 
 
3418
    show_table->file->info(HA_STATUS_VARIABLE |
3510
3419
                           HA_STATUS_NO_LOCK |
3511
3420
                           HA_STATUS_TIME);
3512
3421
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3523
3432
          restore_record(table, s->default_values);
3524
3433
          store_key_column_usage(table, db_name, table_name,
3525
3434
                                 key_info->name,
3526
 
                                 strlen(key_info->name), 
3527
 
                                 key_part->field->field_name, 
 
3435
                                 strlen(key_info->name),
 
3436
                                 key_part->field->field_name,
3528
3437
                                 strlen(key_part->field->field_name),
3529
3438
                                 (int64_t) f_idx);
3530
 
          if (schema_table_store_record(thd, table))
 
3439
          if (schema_table_store_record(session, table))
3531
3440
            return(1);
3532
3441
        }
3533
3442
      }
3534
3443
    }
3535
3444
 
3536
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3445
    show_table->file->get_foreign_key_list(session, &f_key_list);
3537
3446
    FOREIGN_KEY_INFO *f_key_info;
3538
3447
    List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
3448
    while ((f_key_info= fkey_it++))
3560
3469
                               system_charset_info);
3561
3470
        table->field[9]->set_notnull();
3562
3471
        table->field[10]->store(f_key_info->referenced_table->str,
3563
 
                                f_key_info->referenced_table->length, 
 
3472
                                f_key_info->referenced_table->length,
3564
3473
                                system_charset_info);
3565
3474
        table->field[10]->set_notnull();
3566
3475
        table->field[11]->store(r_info->str, r_info->length,
3567
3476
                                system_charset_info);
3568
3477
        table->field[11]->set_notnull();
3569
 
        if (schema_table_store_record(thd, table))
 
3478
        if (schema_table_store_record(session, table))
3570
3479
          return(1);
3571
3480
      }
3572
3481
    }
3575
3484
}
3576
3485
 
3577
3486
 
3578
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3487
int fill_open_tables(Session *session, TableList *tables, COND *)
3579
3488
{
3580
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
 
3489
  const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
3490
  Table *table= tables->table;
3582
3491
  const CHARSET_INFO * const cs= system_charset_info;
3583
3492
  OPEN_TableList *open_list;
3584
 
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
 
            && thd->is_fatal_error)
 
3493
  if (!(open_list=list_open_tables(session->lex->select_lex.db, wild))
 
3494
            && session->is_fatal_error)
3586
3495
    return(1);
3587
3496
 
3588
3497
  for (; open_list ; open_list=open_list->next)
3592
3501
    table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
3502
    table->field[2]->store((int64_t) open_list->in_use, true);
3594
3503
    table->field[3]->store((int64_t) open_list->locked, true);
3595
 
    if (schema_table_store_record(thd, table))
 
3504
    if (schema_table_store_record(session, table))
3596
3505
      return(1);
3597
3506
  }
3598
3507
  return(0);
3599
3508
}
3600
3509
 
3601
3510
 
3602
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3511
int fill_variables(Session *session, TableList *tables, COND *)
3603
3512
{
3604
3513
  int res= 0;
3605
 
  LEX *lex= thd->lex;
 
3514
  LEX *lex= session->lex;
3606
3515
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
3516
  enum enum_schema_tables schema_table_idx=
3608
3517
    get_schema_table_idx(tables->schema_table);
3614
3523
      schema_table_idx == SCH_GLOBAL_VARIABLES)
3615
3524
    option_type= OPT_GLOBAL;
3616
3525
 
3617
 
  rw_rdlock(&LOCK_system_variables_hash);
3618
 
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
 
3526
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
 
3527
  res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
3528
                         option_type, NULL, "", tables->table, upper_case_names);
3620
 
  rw_unlock(&LOCK_system_variables_hash);
 
3529
  pthread_rwlock_unlock(&LOCK_system_variables_hash);
3621
3530
  return(res);
3622
3531
}
3623
3532
 
3624
3533
 
3625
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3534
int fill_status(Session *session, TableList *tables, COND *)
3626
3535
{
3627
 
  LEX *lex= thd->lex;
 
3536
  LEX *lex= session->lex;
3628
3537
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3629
3538
  int res= 0;
3630
3539
  STATUS_VAR *tmp1, tmp;
3639
3548
    if (option_type == OPT_GLOBAL)
3640
3549
      tmp1= &tmp;
3641
3550
    else
3642
 
      tmp1= thd->initial_status_var;
 
3551
      tmp1= session->initial_status_var;
3643
3552
  }
3644
3553
  else if (schema_table_idx == SCH_GLOBAL_STATUS)
3645
3554
  {
3647
3556
    tmp1= &tmp;
3648
3557
  }
3649
3558
  else
3650
 
  { 
 
3559
  {
3651
3560
    option_type= OPT_SESSION;
3652
 
    tmp1= &thd->status_var;
 
3561
    tmp1= &session->status_var;
3653
3562
  }
3654
3563
 
3655
3564
  pthread_mutex_lock(&LOCK_status);
3656
3565
  if (option_type == OPT_GLOBAL)
3657
3566
    calc_sum_of_all_status(&tmp);
3658
 
  res= show_status_array(thd, wild,
 
3567
  res= show_status_array(session, wild,
3659
3568
                         (SHOW_VAR *)all_status_vars.buffer,
3660
3569
                         option_type, tmp1, "", tables->table,
3661
3570
                         upper_case_names);
3669
3578
 
3670
3579
  SYNOPSIS
3671
3580
    get_referential_constraints_record()
3672
 
    thd                 thread handle
 
3581
    session                 thread handle
3673
3582
    tables              table list struct(processed table)
3674
3583
    table               I_S table
3675
3584
    res                 1 means the error during opening of the processed table
3683
3592
*/
3684
3593
 
3685
3594
static int
3686
 
get_referential_constraints_record(THD *thd, TableList *tables,
 
3595
get_referential_constraints_record(Session *session, TableList *tables,
3687
3596
                                   Table *table, bool res,
3688
3597
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3689
3598
{
3691
3600
 
3692
3601
  if (res)
3693
3602
  {
3694
 
    if (thd->is_error())
3695
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3696
 
                   thd->main_da.sql_errno(), thd->main_da.message());
3697
 
    thd->clear_error();
 
3603
    if (session->is_error())
 
3604
      push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3605
                   session->main_da.sql_errno(), session->main_da.message());
 
3606
    session->clear_error();
3698
3607
    return(0);
3699
3608
  }
3700
3609
 
3701
3610
  {
3702
3611
    List<FOREIGN_KEY_INFO> f_key_list;
3703
3612
    Table *show_table= tables->table;
3704
 
    show_table->file->info(HA_STATUS_VARIABLE | 
 
3613
    show_table->file->info(HA_STATUS_VARIABLE |
3705
3614
                           HA_STATUS_NO_LOCK |
3706
3615
                           HA_STATUS_TIME);
3707
3616
 
3708
 
    show_table->file->get_foreign_key_list(thd, &f_key_list);
 
3617
    show_table->file->get_foreign_key_list(session, &f_key_list);
3709
3618
    FOREIGN_KEY_INFO *f_key_info;
3710
3619
    List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
3620
    while ((f_key_info= it++))
3715
3624
      table->field[9]->store(table_name->str, table_name->length, cs);
3716
3625
      table->field[2]->store(f_key_info->forein_id->str,
3717
3626
                             f_key_info->forein_id->length, cs);
3718
 
      table->field[4]->store(f_key_info->referenced_db->str, 
 
3627
      table->field[4]->store(f_key_info->referenced_db->str,
3719
3628
                             f_key_info->referenced_db->length, cs);
3720
 
      table->field[10]->store(f_key_info->referenced_table->str, 
 
3629
      table->field[10]->store(f_key_info->referenced_table->str,
3721
3630
                             f_key_info->referenced_table->length, cs);
3722
3631
      if (f_key_info->referenced_key_name)
3723
3632
      {
3724
 
        table->field[5]->store(f_key_info->referenced_key_name->str, 
 
3633
        table->field[5]->store(f_key_info->referenced_key_name->str,
3725
3634
                               f_key_info->referenced_key_name->length, cs);
3726
3635
        table->field[5]->set_notnull();
3727
3636
      }
3728
3637
      else
3729
3638
        table->field[5]->set_null();
3730
3639
      table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3731
 
      table->field[7]->store(f_key_info->update_method->str, 
 
3640
      table->field[7]->store(f_key_info->update_method->str,
3732
3641
                             f_key_info->update_method->length, cs);
3733
 
      table->field[8]->store(f_key_info->delete_method->str, 
 
3642
      table->field[8]->store(f_key_info->delete_method->str,
3734
3643
                             f_key_info->delete_method->length, cs);
3735
 
      if (schema_table_store_record(thd, table))
 
3644
      if (schema_table_store_record(session, table))
3736
3645
        return(1);
3737
3646
    }
3738
3647
  }
3740
3649
}
3741
3650
 
3742
3651
 
3743
 
struct schema_table_ref 
 
3652
struct schema_table_ref
3744
3653
{
3745
3654
  const char *table_name;
3746
3655
  ST_SCHEMA_TABLE *schema_table;
3752
3661
 
3753
3662
  SYNOPSIS
3754
3663
    find_schema_table_in_plugin()
3755
 
    thd                 thread handler
 
3664
    session                 thread handler
3756
3665
    plugin              plugin
3757
3666
    table_name          table name
3758
3667
 
3760
3669
    0   table not found
3761
3670
    1   found the schema table
3762
3671
*/
3763
 
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
3764
 
                                           plugin_ref plugin,
3765
 
                                           void* p_table)
 
3672
static bool find_schema_table_in_plugin(Session *, plugin_ref plugin,
 
3673
                                        void* p_table)
3766
3674
{
3767
3675
  schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3768
3676
  const char* table_name= p_schema_table->table_name;
3784
3692
 
3785
3693
  SYNOPSIS
3786
3694
    find_schema_table()
3787
 
    thd                 thread handler
 
3695
    session                 thread handler
3788
3696
    table_name          table name
3789
3697
 
3790
3698
  RETURN
3792
3700
    #   pointer to 'schema_tables' element
3793
3701
*/
3794
3702
 
3795
 
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
 
3703
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3796
3704
{
3797
3705
  schema_table_ref schema_table_a;
3798
3706
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3806
3714
  }
3807
3715
 
3808
3716
  schema_table_a.table_name= table_name;
3809
 
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
 
3717
  if (plugin_foreach(session, find_schema_table_in_plugin,
3810
3718
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3811
3719
    return(schema_table_a.schema_table);
3812
3720
 
3826
3734
  @note
3827
3735
 
3828
3736
  @param
3829
 
    thd                   thread handler
 
3737
    session                       thread handler
3830
3738
 
3831
3739
  @param table_list Used to pass I_S table information(fields info, tables
3832
3740
  parameters etc) and table name.
3835
3743
  @retval  NULL           Can't create table
3836
3744
*/
3837
3745
 
3838
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3746
Table *create_schema_table(Session *session, TableList *table_list)
3839
3747
{
3840
3748
  int field_count= 0;
3841
3749
  Item *item;
3848
3756
  for (; fields_info->field_name; fields_info++)
3849
3757
  {
3850
3758
    switch (fields_info->field_type) {
3851
 
    case DRIZZLE_TYPE_TINY:
3852
3759
    case DRIZZLE_TYPE_LONG:
3853
3760
    case DRIZZLE_TYPE_LONGLONG:
3854
3761
      if (!(item= new Item_return_int(fields_info->field_name,
3860
3767
      }
3861
3768
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3862
3769
      break;
3863
 
    case DRIZZLE_TYPE_NEWDATE:
 
3770
    case DRIZZLE_TYPE_DATE:
3864
3771
    case DRIZZLE_TYPE_TIME:
3865
3772
    case DRIZZLE_TYPE_TIMESTAMP:
3866
3773
    case DRIZZLE_TYPE_DATETIME:
3871
3778
      }
3872
3779
      break;
3873
3780
    case DRIZZLE_TYPE_DOUBLE:
3874
 
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC, 
 
3781
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC,
3875
3782
                           fields_info->field_length)) == NULL)
3876
3783
        return(NULL);
3877
3784
      break;
3910
3817
    item->maybe_null= (fields_info->field_flags & MY_I_S_MAYBE_NULL);
3911
3818
    field_count++;
3912
3819
  }
3913
 
  TMP_TABLE_PARAM *tmp_table_param =
3914
 
    (TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
 
3820
  Tmp_Table_Param *tmp_table_param =
 
3821
    (Tmp_Table_Param*) (session->alloc(sizeof(Tmp_Table_Param)));
3915
3822
  tmp_table_param->init();
3916
3823
  tmp_table_param->table_charset= cs;
3917
3824
  tmp_table_param->field_count= field_count;
3918
3825
  tmp_table_param->schema_table= 1;
3919
 
  SELECT_LEX *select_lex= thd->lex->current_select;
3920
 
  if (!(table= create_tmp_table(thd, tmp_table_param,
3921
 
                                field_list, (order_st*) 0, 0, 0, 
3922
 
                                (select_lex->options | thd->options |
 
3826
  Select_Lex *select_lex= session->lex->current_select;
 
3827
  if (!(table= create_tmp_table(session, tmp_table_param,
 
3828
                                field_list, (order_st*) 0, 0, 0,
 
3829
                                (select_lex->options | session->options |
3923
3830
                                 TMP_TABLE_ALL_COLUMNS),
3924
3831
                                HA_POS_ERROR, table_list->alias)))
3925
3832
    return(0);
3926
3833
  my_bitmap_map* bitmaps=
3927
 
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
 
3834
    (my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3928
3835
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3929
3836
              false);
3930
3837
  table->read_set= &table->def_read_set;
3941
3848
 
3942
3849
  SYNOPSIS
3943
3850
    make_old_format()
3944
 
    thd                 thread handler
 
3851
    session                     thread handler
3945
3852
    schema_table        pointer to 'schema_tables' element
3946
3853
 
3947
3854
  RETURN
3949
3856
   0    success
3950
3857
*/
3951
3858
 
3952
 
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3859
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3953
3860
{
3954
3861
  ST_FIELD_INFO *field_info= schema_table->fields_info;
3955
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
3862
  Name_resolution_context *context= &session->lex->select_lex.context;
3956
3863
  for (; field_info->field_name; field_info++)
3957
3864
  {
3958
3865
    if (field_info->old_name)
3964
3871
        field->set_name(field_info->old_name,
3965
3872
                        strlen(field_info->old_name),
3966
3873
                        system_charset_info);
3967
 
        if (add_item_to_list(thd, field))
 
3874
        if (session->add_item_to_list(field))
3968
3875
          return 1;
3969
3876
      }
3970
3877
    }
3973
3880
}
3974
3881
 
3975
3882
 
3976
 
int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3883
int make_schemata_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3977
3884
{
3978
3885
  char tmp[128];
3979
 
  LEX *lex= thd->lex;
3980
 
  SELECT_LEX *sel= lex->current_select;
 
3886
  LEX *lex= session->lex;
 
3887
  Select_Lex *sel= lex->current_select;
3981
3888
  Name_resolution_context *context= &sel->context;
3982
3889
 
3983
3890
  if (!sel->item_list.elements)
3986
3893
    String buffer(tmp,sizeof(tmp), system_charset_info);
3987
3894
    Item_field *field= new Item_field(context,
3988
3895
                                      NULL, NULL, field_info->field_name);
3989
 
    if (!field || add_item_to_list(thd, field))
 
3896
    if (!field || session->add_item_to_list(field))
3990
3897
      return 1;
3991
3898
    buffer.length(0);
3992
3899
    buffer.append(field_info->old_name);
4002
3909
}
4003
3910
 
4004
3911
 
4005
 
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3912
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4006
3913
{
4007
3914
  char tmp[128];
4008
 
  String buffer(tmp,sizeof(tmp), thd->charset());
4009
 
  LEX *lex= thd->lex;
 
3915
  String buffer(tmp,sizeof(tmp), session->charset());
 
3916
  LEX *lex= session->lex;
4010
3917
  Name_resolution_context *context= &lex->select_lex.context;
4011
3918
 
4012
3919
  ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4021
3928
  }
4022
3929
  Item_field *field= new Item_field(context,
4023
3930
                                    NULL, NULL, field_info->field_name);
4024
 
  if (add_item_to_list(thd, field))
 
3931
  if (session->add_item_to_list(field))
4025
3932
    return 1;
4026
3933
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4027
 
  if (thd->lex->verbose)
 
3934
  if (session->lex->verbose)
4028
3935
  {
4029
3936
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
3937
    field_info= &schema_table->fields_info[3];
4031
3938
    field= new Item_field(context, NULL, NULL, field_info->field_name);
4032
 
    if (add_item_to_list(thd, field))
 
3939
    if (session->add_item_to_list(field))
4033
3940
      return 1;
4034
3941
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4035
3942
                    system_charset_info);
4038
3945
}
4039
3946
 
4040
3947
 
4041
 
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3948
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4042
3949
{
4043
3950
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4044
3951
  int *field_num= fields_arr;
4045
3952
  ST_FIELD_INFO *field_info;
4046
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
3953
  Name_resolution_context *context= &session->lex->select_lex.context;
4047
3954
 
4048
3955
  for (; *field_num >= 0; field_num++)
4049
3956
  {
4050
3957
    field_info= &schema_table->fields_info[*field_num];
4051
 
    if (!thd->lex->verbose && (*field_num == 13 ||
 
3958
    if (!session->lex->verbose && (*field_num == 13 ||
4052
3959
                               *field_num == 17 ||
4053
3960
                               *field_num == 18))
4054
3961
      continue;
4059
3966
      field->set_name(field_info->old_name,
4060
3967
                      strlen(field_info->old_name),
4061
3968
                      system_charset_info);
4062
 
      if (add_item_to_list(thd, field))
 
3969
      if (session->add_item_to_list(field))
4063
3970
        return 1;
4064
3971
    }
4065
3972
  }
4067
3974
}
4068
3975
 
4069
3976
 
4070
 
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3977
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4071
3978
{
4072
3979
  int fields_arr[]= {0, 2, 1, 3, -1};
4073
3980
  int *field_num= fields_arr;
4074
3981
  ST_FIELD_INFO *field_info;
4075
 
  Name_resolution_context *context= &thd->lex->select_lex.context;
 
3982
  Name_resolution_context *context= &session->lex->select_lex.context;
4076
3983
 
4077
3984
  for (; *field_num >= 0; field_num++)
4078
3985
  {
4084
3991
      field->set_name(field_info->old_name,
4085
3992
                      strlen(field_info->old_name),
4086
3993
                      system_charset_info);
4087
 
      if (add_item_to_list(thd, field))
 
3994
      if (session->add_item_to_list(field))
4088
3995
        return 1;
4089
3996
    }
4090
3997
  }
4097
4004
 
4098
4005
  SYNOPSIS
4099
4006
  mysql_schema_table()
4100
 
    thd                thread handler
 
4007
    session                thread handler
4101
4008
    lex                pointer to LEX
4102
4009
    table_list         pointer to table_list
4103
4010
 
4106
4013
    1   error
4107
4014
*/
4108
4015
 
4109
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4016
int mysql_schema_table(Session *session, LEX *, TableList *table_list)
4110
4017
{
4111
4018
  Table *table;
4112
 
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
 
4019
  if (!(table= table_list->schema_table->create_table(session, table_list)))
4113
4020
    return(1);
4114
4021
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4115
4022
  /*
4126
4033
  table_list->table_name= table->s->table_name.str;
4127
4034
  table_list->table_name_length= table->s->table_name.length;
4128
4035
  table_list->table= table;
4129
 
  table->next= thd->derived_tables;
4130
 
  thd->derived_tables= table;
 
4036
  table->next= session->derived_tables;
 
4037
  session->derived_tables= table;
4131
4038
  table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4132
4039
 
4133
 
  if (table_list->schema_table_reformed) // show command
4134
 
  {
4135
 
    SELECT_LEX *sel= lex->current_select;
4136
 
    Item *item;
4137
 
    Field_translator *transl, *org_transl;
4138
 
 
4139
 
    if (table_list->field_translation)
4140
 
    {
4141
 
      Field_translator *end= table_list->field_translation_end;
4142
 
      for (transl= table_list->field_translation; transl < end; transl++)
4143
 
      {
4144
 
        if (!transl->item->fixed &&
4145
 
            transl->item->fix_fields(thd, &transl->item))
4146
 
          return(1);
4147
 
      }
4148
 
      return(0);
4149
 
    }
4150
 
    List_iterator_fast<Item> it(sel->item_list);
4151
 
    if (!(transl=
4152
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
4153
 
                                    sizeof(Field_translator)))))
4154
 
    {
4155
 
      return(1);
4156
 
    }
4157
 
    for (org_transl= transl; (item= it++); transl++)
4158
 
    {
4159
 
      transl->item= item;
4160
 
      transl->name= item->name;
4161
 
      if (!item->fixed && item->fix_fields(thd, &transl->item))
4162
 
      {
4163
 
        return(1);
4164
 
      }
4165
 
    }
4166
 
    table_list->field_translation= org_transl;
4167
 
    table_list->field_translation_end= transl;
4168
 
  }
4169
 
 
4170
4040
  return(0);
4171
4041
}
4172
4042
 
4176
4046
 
4177
4047
  SYNOPSIS
4178
4048
    make_schema_select()
4179
 
    thd                  thread handler
4180
 
    sel                  pointer to SELECT_LEX
 
4049
    session                  thread handler
 
4050
    sel                  pointer to Select_Lex
4181
4051
    schema_table_idx     index of 'schema_tables' element
4182
4052
 
4183
4053
  RETURN
4185
4055
    1   error
4186
4056
*/
4187
4057
 
4188
 
int make_schema_select(THD *thd, SELECT_LEX *sel,
 
4058
int make_schema_select(Session *session, Select_Lex *sel,
4189
4059
                       enum enum_schema_tables schema_table_idx)
4190
4060
{
4191
4061
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4194
4064
     We have to make non const db_name & table_name
4195
4065
     because of lower_case_table_names
4196
4066
  */
4197
 
  thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4198
 
                       INFORMATION_SCHEMA_NAME.length, 0);
4199
 
  thd->make_lex_string(&table, schema_table->table_name,
 
4067
  session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
 
4068
                       INFORMATION_SCHEMA_NAME.length(), 0);
 
4069
  session->make_lex_string(&table, schema_table->table_name,
4200
4070
                       strlen(schema_table->table_name), 0);
4201
 
  if (schema_table->old_format(thd, schema_table) ||   /* Handle old syntax */
4202
 
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
 
4071
  if (schema_table->old_format(session, schema_table) ||   /* Handle old syntax */
 
4072
      !sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4203
4073
                              0, 0, TL_READ))
4204
4074
  {
4205
4075
    return(1);
4225
4095
                              enum enum_schema_table_state executed_place)
4226
4096
{
4227
4097
  JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4228
 
  THD *thd= join->thd;
4229
 
  LEX *lex= thd->lex;
 
4098
  Session *session= join->session;
 
4099
  LEX *lex= session->lex;
4230
4100
  bool result= 0;
4231
4101
 
4232
 
  thd->no_warnings_for_error= 1;
 
4102
  session->no_warnings_for_error= 1;
4233
4103
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4234
4104
  {
4235
4105
    if (!tab->table || !tab->table->pos_in_table_list)
4243
4113
 
4244
4114
 
4245
4115
      /* skip I_S optimizations specific to get_all_tables */
4246
 
      if (thd->lex->describe &&
 
4116
      if (session->lex->describe &&
4247
4117
          (table_list->schema_table->fill_table != get_all_tables))
4248
4118
        continue;
4249
4119
 
4277
4147
      else
4278
4148
        table_list->table->file->stats.records= 0;
4279
4149
 
4280
 
      if (table_list->schema_table->fill_table(thd, table_list,
 
4150
      if (table_list->schema_table->fill_table(session, table_list,
4281
4151
                                               tab->select_cond))
4282
4152
      {
4283
4153
        result= 1;
4290
4160
      table_list->schema_table_state= executed_place;
4291
4161
    }
4292
4162
  }
4293
 
  thd->no_warnings_for_error= 0;
 
4163
  session->no_warnings_for_error= 0;
4294
4164
  return(result);
4295
4165
}
4296
4166
 
4320
4190
  {"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4321
4191
  {"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4322
4192
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4323
 
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4193
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4324
4194
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4325
 
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4195
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4326
4196
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4327
4197
  {"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4328
4198
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4329
 
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4199
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4330
4200
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4331
4201
  {"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4332
4202
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4333
 
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0, 
 
4203
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4334
4204
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4335
4205
  {"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4336
4206
  {"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4529
4399
 
4530
4400
ST_FIELD_INFO plugin_fields_info[]=
4531
4401
{
4532
 
  {"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name", 
 
4402
  {"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4533
4403
   SKIP_OPEN_TABLE},
4534
4404
  {"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4535
4405
  {"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4574
4444
 
4575
4445
ST_SCHEMA_TABLE schema_tables[]=
4576
4446
{
4577
 
  {"CHARACTER_SETS", charsets_fields_info, create_schema_table, 
 
4447
  {"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4578
4448
   fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4579
 
  {"COLLATIONS", collation_fields_info, create_schema_table, 
 
4449
  {"COLLATIONS", collation_fields_info, create_schema_table,
4580
4450
   fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4581
4451
  {"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4582
4452
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
 
  {"COLUMNS", columns_fields_info, create_schema_table, 
 
4453
  {"COLUMNS", columns_fields_info, create_schema_table,
4584
4454
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
4455
   OPTIMIZE_I_S_TABLE},
4586
4456
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4605
4475
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4606
4476
  {"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4607
4477
   fill_variables, make_old_format, 0, -1, -1, 0, 0},
4608
 
  {"STATISTICS", stat_fields_info, create_schema_table, 
 
4478
  {"STATISTICS", stat_fields_info, create_schema_table,
4609
4479
   get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4610
4480
   OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4611
 
  {"STATUS", variables_fields_info, create_schema_table, fill_status, 
 
4481
  {"STATUS", variables_fields_info, create_schema_table, fill_status,
4612
4482
   make_old_format, 0, -1, -1, 1, 0},
4613
 
  {"TABLES", tables_fields_info, create_schema_table, 
 
4483
  {"TABLES", tables_fields_info, create_schema_table,
4614
4484
   get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4615
4485
   OPTIMIZE_I_S_TABLE},
4616
4486
  {"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4632
4502
{
4633
4503
  ST_SCHEMA_TABLE *schema_table;
4634
4504
 
4635
 
  if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4636
 
                                MYF(MY_WME | MY_ZEROFILL))))
4637
 
      return(1);
 
4505
  if ((schema_table= new ST_SCHEMA_TABLE) == NULL)
 
4506
    return(1);
 
4507
  memset(schema_table, 0, sizeof(ST_SCHEMA_TABLE));
 
4508
 
4638
4509
  /* Historical Requirement */
4639
4510
  plugin->data= schema_table; // shortcut for the future
4640
4511
  if (plugin->plugin->init)
4641
4512
  {
4642
4513
    schema_table->create_table= create_schema_table;
4643
4514
    schema_table->old_format= make_old_format;
4644
 
    schema_table->idx_field1= -1, 
4645
 
    schema_table->idx_field2= -1; 
 
4515
    schema_table->idx_field1= -1,
 
4516
    schema_table->idx_field2= -1;
4646
4517
 
4647
4518
    /* Make the name available to the init() function. */
4648
4519
    schema_table->table_name= plugin->name.str;
4649
4520
 
4650
4521
    if (plugin->plugin->init(schema_table))
4651
4522
    {
4652
 
      sql_print_error(_("Plugin '%s' init function returned error."),
4653
 
                      plugin->name.str);
 
4523
      errmsg_printf(ERRMSG_LVL_ERROR,
 
4524
                    _("Plugin '%s' init function returned error."),
 
4525
                    plugin->name.str);
4654
4526
      goto err;
4655
4527
    }
4656
 
    
 
4528
 
4657
4529
    /* Make sure the plugin name is not set inside the init() function. */
4658
4530
    schema_table->table_name= plugin->name.str;
4659
4531
  }
4660
4532
 
4661
 
  return(0);
 
4533
  plugin->state= PLUGIN_IS_READY;
 
4534
 
 
4535
  return 0;
4662
4536
err:
4663
 
  free(schema_table);
4664
 
  return(1);
 
4537
  delete schema_table;
 
4538
 
 
4539
  return 1;
4665
4540
}
4666
4541
 
4667
4542
int finalize_schema_table(st_plugin_int *plugin)
4669
4544
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4670
4545
 
4671
4546
  if (schema_table && plugin->plugin->deinit)
4672
 
    free(schema_table);
 
4547
    delete schema_table;
4673
4548
 
4674
4549
  return(0);
4675
4550
}