~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_show.cc

MergingĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
 
17
17
/* Function with list databases, tables or fields */
18
 
#include <drizzled/server_includes.h>
19
 
#include <drizzled/sql_select.h>
20
 
#include <drizzled/sql_show.h>
21
 
#include <mysys/my_dir.h>
22
 
#include <libdrizzle/gettext.h>
23
 
#include <drizzled/util/convert.h>
24
 
#include <string>
25
 
 
26
 
inline const char *
27
 
str_or_nil(const char *str)
28
 
{
29
 
  return str ? str : "<nil>";
30
 
}
 
18
 
 
19
#include "mysql_priv.h"
 
20
#include "sql_select.h"                         // For select_describe
 
21
#include "sql_show.h"
 
22
#include "repl_failsafe.h"
 
23
#include <my_dir.h>
 
24
 
 
25
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
31
26
 
32
27
/* Match the values of enum ha_choice */
33
28
static const char *ha_choice_values[] = {"", "0", "1"};
34
29
 
35
 
static void store_key_options(THD *thd, String *packet, Table *table,
 
30
static void store_key_options(THD *thd, String *packet, TABLE *table,
36
31
                              KEY *key_info);
37
32
 
38
33
 
39
34
 
40
 
int wild_case_compare(const CHARSET_INFO * const cs, const char *str,const char *wildstr)
 
35
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr)
41
36
{
42
37
  register int flag;
43
38
  while (*wildstr)
87
82
** List all table types supported
88
83
***************************************************************************/
89
84
 
90
 
static bool show_plugins(THD *thd, plugin_ref plugin,
 
85
static int make_version_string(char *buf, int buf_length, uint version)
 
86
{
 
87
  return snprintf(buf, buf_length, "%d.%d", version>>8,version&0xff);
 
88
}
 
89
 
 
90
static my_bool show_plugins(THD *thd, plugin_ref plugin,
91
91
                            void *arg)
92
92
{
93
 
  Table *table= (Table*) arg;
 
93
  TABLE *table= (TABLE*) arg;
94
94
  struct st_mysql_plugin *plug= plugin_decl(plugin);
95
95
  struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
96
 
  const CHARSET_INFO * const cs= system_charset_info;
 
96
  CHARSET_INFO *cs= system_charset_info;
 
97
  char version_buf[20];
97
98
 
98
99
  restore_record(table, s->default_values);
99
100
 
100
101
  table->field[0]->store(plugin_name(plugin)->str,
101
102
                         plugin_name(plugin)->length, cs);
102
103
 
103
 
  if (plug->version)
104
 
  {
105
 
    table->field[1]->store(plug->version, strlen(plug->version), cs);
106
 
    table->field[1]->set_notnull();
107
 
  }
108
 
  else
109
 
    table->field[1]->set_null();
 
104
  table->field[1]->store(version_buf,
 
105
        make_version_string(version_buf, sizeof(version_buf), plug->version),
 
106
        cs);
 
107
 
110
108
 
111
109
  switch (plugin_state(plugin)) {
112
110
  /* case PLUGIN_IS_FREED: does not happen */
120
118
    table->field[2]->store(STRING_WITH_LEN("ACTIVE"), cs);
121
119
    break;
122
120
  default:
123
 
    assert(0);
 
121
    DBUG_ASSERT(0);
124
122
  }
125
123
 
126
124
  table->field[3]->store(plugin_type_names[plug->type].str,
127
125
                         plugin_type_names[plug->type].length,
128
126
                         cs);
 
127
  table->field[4]->store(version_buf,
 
128
        make_version_string(version_buf, sizeof(version_buf),
 
129
                            *(uint *)plug->info), cs);
129
130
 
130
131
  if (plugin_dl)
131
132
  {
132
 
    table->field[4]->store(plugin_dl->dl.str, plugin_dl->dl.length, cs);
133
 
    table->field[4]->set_notnull();
134
 
  }
135
 
  else
136
 
  {
137
 
    table->field[4]->set_null();
138
 
  }
139
 
 
140
 
  if (plug->author)
141
 
  {
142
 
    table->field[5]->store(plug->author, strlen(plug->author), cs);
 
133
    table->field[5]->store(plugin_dl->dl.str, plugin_dl->dl.length, cs);
143
134
    table->field[5]->set_notnull();
 
135
    table->field[6]->store(version_buf,
 
136
          make_version_string(version_buf, sizeof(version_buf),
 
137
                              plugin_dl->version),
 
138
          cs);
 
139
    table->field[6]->set_notnull();
144
140
  }
145
141
  else
 
142
  {
146
143
    table->field[5]->set_null();
 
144
    table->field[6]->set_null();
 
145
  }
 
146
 
 
147
 
 
148
  if (plug->author)
 
149
  {
 
150
    table->field[7]->store(plug->author, strlen(plug->author), cs);
 
151
    table->field[7]->set_notnull();
 
152
  }
 
153
  else
 
154
    table->field[7]->set_null();
147
155
 
148
156
  if (plug->descr)
149
157
  {
150
 
    table->field[6]->store(plug->descr, strlen(plug->descr), cs);
151
 
    table->field[6]->set_notnull();
 
158
    table->field[8]->store(plug->descr, strlen(plug->descr), cs);
 
159
    table->field[8]->set_notnull();
152
160
  }
153
161
  else
154
 
    table->field[6]->set_null();
 
162
    table->field[8]->set_null();
155
163
 
156
164
  switch (plug->license) {
157
165
  case PLUGIN_LICENSE_GPL:
158
 
    table->field[7]->store(PLUGIN_LICENSE_GPL_STRING, 
 
166
    table->field[9]->store(PLUGIN_LICENSE_GPL_STRING, 
159
167
                           strlen(PLUGIN_LICENSE_GPL_STRING), cs);
160
168
    break;
161
169
  case PLUGIN_LICENSE_BSD:
162
 
    table->field[7]->store(PLUGIN_LICENSE_BSD_STRING, 
 
170
    table->field[9]->store(PLUGIN_LICENSE_BSD_STRING, 
163
171
                           strlen(PLUGIN_LICENSE_BSD_STRING), cs);
164
172
    break;
165
173
  default:
166
 
    table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING, 
 
174
    table->field[9]->store(PLUGIN_LICENSE_PROPRIETARY_STRING, 
167
175
                           strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
168
176
    break;
169
177
  }
170
 
  table->field[7]->set_notnull();
 
178
  table->field[9]->set_notnull();
171
179
 
172
180
  return schema_table_store_record(thd, table);
173
181
}
174
182
 
175
183
 
176
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
184
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
177
185
{
178
 
  Table *table= tables->table;
 
186
  TABLE *table= tables->table;
179
187
 
180
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
188
  if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
181
189
                               ~PLUGIN_IS_FREED, table))
182
190
    return(1);
183
191
 
192
200
    find_files()
193
201
    thd                 thread handler
194
202
    files               put found files in this list
195
 
    db                  database name to set in TableList structure
 
203
    db                  database name to set in TABLE_LIST structure
196
204
    path                path to database
197
205
    wild                filter for found files
198
 
    dir                 read databases in path if true, read .frm files in
 
206
    dir                 read databases in path if TRUE, read .frm files in
199
207
                        database otherwise
200
208
 
201
209
  RETURN
209
217
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
210
218
           const char *path, const char *wild, bool dir)
211
219
{
212
 
  uint32_t i;
 
220
  uint i;
213
221
  char *ext;
214
222
  MY_DIR *dirp;
215
223
  FILEINFO *file;
216
224
  LEX_STRING *file_name= 0;
217
 
  uint32_t file_name_len;
218
 
  TableList table_list;
 
225
  uint file_name_len;
 
226
  TABLE_LIST table_list;
219
227
 
220
228
  if (wild && !wild[0])
221
229
    wild=0;
222
230
 
223
 
  memset(&table_list, 0, sizeof(table_list));
 
231
  bzero((char*) &table_list,sizeof(table_list));
224
232
 
225
233
  if (!(dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0))))
226
234
  {
250
258
        char *end;
251
259
        *ext=0;                                 /* Remove extension */
252
260
        unpack_dirname(buff, file->name);
253
 
        end= strchr(buff, '\0');
 
261
        end= strend(buff);
254
262
        if (end != buff && end[-1] == FN_LIBCHAR)
255
263
          end[-1]= 0;                           // Remove end FN_LIBCHAR
256
264
        if (stat(buff, file->mystat))
257
265
               continue;
258
266
       }
259
267
#endif
260
 
      if (!S_ISDIR(file->mystat->st_mode))
 
268
      if (!MY_S_ISDIR(file->mystat->st_mode))
261
269
        continue;
262
270
 
263
271
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
264
272
      if (wild && wild_compare(uname, wild, 0))
265
273
        continue;
266
274
      if (!(file_name= 
267
 
            thd->make_lex_string(file_name, uname, file_name_len, true)))
 
275
            thd->make_lex_string(file_name, uname, file_name_len, TRUE)))
268
276
      {
269
277
        my_dirend(dirp);
270
278
        return(FIND_FILES_OOM);
290
298
      }
291
299
    }
292
300
    if (!(file_name= 
293
 
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
 
301
          thd->make_lex_string(file_name, uname, file_name_len, TRUE)) ||
294
302
        files->push_back(file_name))
295
303
    {
296
304
      my_dirend(dirp);
304
312
 
305
313
 
306
314
bool
307
 
mysqld_show_create(THD *thd, TableList *table_list)
 
315
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
308
316
{
309
317
  Protocol *protocol= thd->protocol;
310
318
  char buff[2048];
314
322
  if (open_normal_and_derived_tables(thd, table_list, 0))
315
323
  {
316
324
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
317
 
      return(true);
 
325
      return(TRUE);
318
326
 
319
327
    /*
320
328
      Clear all messages with 'error' level status and
321
329
      issue a warning with 'warning' level status in 
322
330
      case of invalid view and last error is ER_VIEW_INVALID
323
331
    */
324
 
    drizzle_reset_errors(thd, true);
 
332
    mysql_reset_errors(thd, true);
325
333
    thd->clear_error();
326
334
  }
327
335
 
328
336
  buffer.length(0);
329
337
 
330
338
  if (store_create_info(thd, table_list, &buffer, NULL))
331
 
    return(true);
 
339
    return(TRUE);
332
340
 
333
341
  List<Item> field_list;
334
342
  {
335
343
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
336
344
    // 1024 is for not to confuse old clients
337
345
    field_list.push_back(new Item_empty_string("Create Table",
338
 
                                               cmax(buffer.length(),(uint32_t)1024)));
 
346
                                               max(buffer.length(),1024)));
339
347
  }
340
348
 
341
349
  if (protocol->send_fields(&field_list,
342
350
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
343
 
    return(true);
 
351
    return(TRUE);
344
352
  protocol->prepare_for_resend();
345
353
  {
346
354
    if (table_list->schema_table)
353
361
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
354
362
 
355
363
  if (protocol->write())
356
 
    return(true);
 
364
    return(TRUE);
357
365
 
358
366
  my_eof(thd);
359
 
  return(false);
 
367
  return(FALSE);
360
368
}
361
369
 
362
370
bool mysqld_show_create_db(THD *thd, char *dbname,
373
381
      can fail is incorrect database name (which is the case now).
374
382
    */
375
383
    my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
376
 
    return(true);    
 
384
    return(TRUE);    
377
385
  }
378
386
 
379
387
  List<Item> field_list;
382
390
 
383
391
  if (protocol->send_fields(&field_list,
384
392
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
385
 
    return(true);
 
393
    return(TRUE);
386
394
 
387
395
  protocol->prepare_for_resend();
388
396
  protocol->store(dbname, strlen(dbname), system_charset_info);
389
397
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
390
398
 
391
399
  if (protocol->write())
392
 
    return(true);
 
400
    return(TRUE);
393
401
  my_eof(thd);
394
 
  return(false);
 
402
  return(FALSE);
395
403
}
396
404
 
397
405
 
402
410
****************************************************************************/
403
411
 
404
412
void
405
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
413
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
406
414
{
407
 
  Table *table;
 
415
  TABLE *table;
408
416
 
409
417
  if (open_normal_and_derived_tables(thd, table_list, 0))
410
418
    return;
444
452
    0   No conflicting character
445
453
*/
446
454
 
447
 
static const char *require_quotes(const char *name, uint32_t name_length)
 
455
static const char *require_quotes(const char *name, uint name_length)
448
456
{
449
 
  uint32_t length;
450
 
  bool pure_digit= true;
 
457
  uint length;
 
458
  bool pure_digit= TRUE;
451
459
  const char *end= name + name_length;
452
460
 
453
461
  for (; name < end ; name++)
454
462
  {
455
 
    unsigned char chr= (unsigned char) *name;
 
463
    uchar chr= (uchar) *name;
456
464
    length= my_mbcharlen(system_charset_info, chr);
457
465
    if (length == 1 && !system_charset_info->ident_map[chr])
458
466
      return name;
459
467
    if (length == 1 && (chr < '0' || chr > '9'))
460
 
      pure_digit= false;
 
468
      pure_digit= FALSE;
461
469
  }
462
470
  if (pure_digit)
463
471
    return name;
478
486
*/
479
487
 
480
488
void
481
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
 
489
append_identifier(THD *thd, String *packet, const char *name, uint length)
482
490
{
483
491
  const char *name_end;
484
492
  char quote_char;
495
503
   it's a keyword
496
504
  */
497
505
 
498
 
  packet->reserve(length*2 + 2);
 
506
  VOID(packet->reserve(length*2 + 2));
499
507
  quote_char= (char) q;
500
508
  packet->append(&quote_char, 1, system_charset_info);
501
509
 
502
510
  for (name_end= name+length ; name < name_end ; name+= length)
503
511
  {
504
 
    unsigned char chr= (unsigned char) *name;
 
512
    uchar chr= (uchar) *name;
505
513
    length= my_mbcharlen(system_charset_info, chr);
506
514
    /*
507
515
      my_mbcharlen can return 0 on a wrong multibyte
512
520
    */
513
521
    if (!length)
514
522
      length= 1;
515
 
    if (length == 1 && chr == (unsigned char) quote_char)
 
523
    if (length == 1 && chr == (uchar) quote_char)
516
524
      packet->append(&quote_char, 1, system_charset_info);
517
525
    packet->append(name, length, system_charset_info);
518
526
  }
543
551
    #     Quote character
544
552
*/
545
553
 
546
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
554
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
547
555
{
548
556
  if (length &&
549
557
      !is_keyword(name,length) &&
550
558
      !require_quotes(name, length) &&
551
559
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
552
560
    return EOF;
553
 
  return '`';
 
561
  return '"';
554
562
}
555
563
 
556
564
 
557
565
/* Append directory name (if exists) to CREATE INFO */
558
566
 
559
 
static void append_directory(THD *thd __attribute__((unused)),
 
567
static void append_directory(THD *thd __attribute__((__unused__)),
560
568
                             String *packet, const char *dir_type,
561
569
                             const char *filename)
562
570
{
563
571
  if (filename)
564
572
  {
565
 
    uint32_t length= dirname_length(filename);
 
573
    uint length= dirname_length(filename);
566
574
    packet->append(' ');
567
575
    packet->append(dir_type);
568
576
    packet->append(STRING_WITH_LEN(" DIRECTORY='"));
574
582
 
575
583
#define LIST_PROCESS_HOST_LEN 64
576
584
 
577
 
static bool get_field_default_value(THD *thd __attribute__((unused)),
 
585
static bool get_field_default_value(THD *thd __attribute__((__unused__)),
578
586
                                    Field *timestamp_field,
579
587
                                    Field *field, String *def_value,
580
588
                                    bool quoted)
589
597
  has_now_default= (timestamp_field == field &&
590
598
                    field->unireg_check != Field::TIMESTAMP_UN_FIELD);
591
599
    
592
 
  has_default= (field->type() != DRIZZLE_TYPE_BLOB &&
 
600
  has_default= (field->type() != FIELD_TYPE_BLOB &&
593
601
                !(field->flags & NO_DEFAULT_VALUE_FLAG) &&
594
602
                field->unireg_check != Field::NEXT_NUMBER
595
603
                  && has_now_default);
607
615
      if (type.length())
608
616
      {
609
617
        String def_val;
610
 
        uint32_t dummy_errors;
 
618
        uint dummy_errors;
611
619
        /* convert to system_charset_info == utf8 */
612
620
        def_val.copy(type.ptr(), type.length(), field->charset(),
613
621
                     system_charset_info, &dummy_errors);
651
659
    0       OK
652
660
 */
653
661
 
654
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
662
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
655
663
                      HA_CREATE_INFO *create_info_arg)
656
664
{
657
665
  List<Item> field_list;
658
 
  char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
 
666
  char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
659
667
  const char *alias;
660
 
  std::string buff;
661
668
  String type(tmp, sizeof(tmp), system_charset_info);
662
669
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
663
670
  Field **ptr,*field;
664
 
  uint32_t primary_key;
 
671
  uint primary_key;
665
672
  KEY *key_info;
666
 
  Table *table= table_list->table;
 
673
  TABLE *table= table_list->table;
667
674
  handler *file= table->file;
668
675
  TABLE_SHARE *share= table->s;
669
676
  HA_CREATE_INFO create_info;
670
 
  bool show_table_options= false;
 
677
  bool show_table_options= FALSE;
671
678
  my_bitmap_map *old_map;
672
679
 
673
680
  restore_record(table, s->default_values); // Get empty record
697
704
    We have to restore the read_set if we are called from insert in case
698
705
    of row based replication.
699
706
  */
700
 
  old_map= table->use_all_columns(table->read_set);
 
707
  old_map= tmp_use_all_columns(table, table->read_set);
701
708
 
702
709
  for (ptr=table->field ; (field= *ptr); ptr++)
703
710
  {
704
 
    uint32_t flags = field->flags;
 
711
    uint flags = field->flags;
705
712
 
706
713
    if (ptr != table->field)
707
714
      packet->append(STRING_WITH_LEN(",\n"));
715
722
    else
716
723
      type.set_charset(system_charset_info);
717
724
 
718
 
    if (field->vcol_info)
719
 
    {
720
 
      packet->append(STRING_WITH_LEN("VIRTUAL "));
721
 
    }
722
 
 
723
725
    field->sql_type(type);
724
726
    packet->append(type.ptr(), type.length(), system_charset_info);
725
727
 
726
 
    if (field->vcol_info)
727
 
    {
728
 
      packet->append(STRING_WITH_LEN(" AS ("));
729
 
      packet->append(field->vcol_info->expr_str.str,
730
 
                     field->vcol_info->expr_str.length,
731
 
                     system_charset_info);
732
 
      packet->append(STRING_WITH_LEN(")"));
733
 
      if (field->is_stored)
734
 
        packet->append(STRING_WITH_LEN(" STORED"));
735
 
    }
736
 
    
737
728
    if (field->has_charset())
738
729
    {
739
730
      if (field->charset() != share->table_charset)
754
745
 
755
746
    if (flags & NOT_NULL_FLAG)
756
747
      packet->append(STRING_WITH_LEN(" NOT NULL"));
757
 
    else if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
748
    else if (field->type() == MYSQL_TYPE_TIMESTAMP)
758
749
    {
759
750
      /*
760
751
        TIMESTAMP field require explicit NULL flag, because unlike
772
763
      if (column_format)
773
764
      {
774
765
        packet->append(STRING_WITH_LEN(" /*!"));
775
 
        packet->append(STRING_WITH_LEN(DRIZZLE_VERSION_TABLESPACE_IN_FRM_STR));
 
766
        packet->append(STRING_WITH_LEN(MYSQL_VERSION_TABLESPACE_IN_FRM_STR));
776
767
        packet->append(STRING_WITH_LEN(" COLUMN_FORMAT"));
777
768
        if (column_format == COLUMN_FORMAT_TYPE_FIXED)
778
769
          packet->append(STRING_WITH_LEN(" FIXED */"));
780
771
          packet->append(STRING_WITH_LEN(" DYNAMIC */"));
781
772
      }
782
773
    }
783
 
    if (!field->vcol_info &&
784
 
        get_field_default_value(thd, table->timestamp_field,
 
774
    if (get_field_default_value(thd, table->timestamp_field,
785
775
                                field, &def_value, 1))
786
776
    {
787
777
      packet->append(STRING_WITH_LEN(" DEFAULT "));
802
792
  }
803
793
 
804
794
  key_info= table->key_info;
805
 
  memset(&create_info, 0, sizeof(create_info));
 
795
  bzero((char*) &create_info, sizeof(create_info));
806
796
  /* Allow update_create_info to update row type */
807
797
  create_info.row_type= share->row_type;
808
798
  file->update_create_info(&create_info);
809
799
  primary_key= share->primary_key;
810
800
 
811
 
  for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
 
801
  for (uint i=0 ; i < share->keys ; i++,key_info++)
812
802
  {
813
803
    KEY_PART_INFO *key_part= key_info->key_part;
814
804
    bool found_primary=0;
833
823
 
834
824
    packet->append(STRING_WITH_LEN(" ("));
835
825
 
836
 
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
826
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
837
827
    {
838
828
      if (j)
839
829
        packet->append(',');
845
835
          (key_part->length !=
846
836
           table->field[key_part->fieldnr-1]->key_length()))
847
837
      {
848
 
        buff= "(";
849
 
        buff= to_string(buff, (int32_t) key_part->length /
850
 
                              key_part->field->charset()->mbmaxlen);
851
 
        buff += ")";
852
 
        packet->append(buff.c_str(), buff.length());
 
838
        char *end;
 
839
        buff[0] = '(';
 
840
        end= int10_to_str((long) key_part->length /
 
841
                          key_part->field->charset()->mbmaxlen,
 
842
                          buff + 1,10);
 
843
        *end++ = ')';
 
844
        packet->append(buff,(uint) (end-buff));
853
845
      }
854
846
    }
855
847
    packet->append(')');
869
861
 
870
862
  packet->append(STRING_WITH_LEN("\n)"));
871
863
  {
872
 
    show_table_options= true;
 
864
    show_table_options= TRUE;
873
865
    /*
874
866
      Get possible table space definitions and append them
875
867
      to the CREATE TABLE statement
899
891
 
900
892
    if (create_info.auto_increment_value > 1)
901
893
    {
 
894
      char *end;
902
895
      packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
903
 
      buff= to_string(create_info.auto_increment_value);
904
 
      packet->append(buff.c_str(), buff.length());
 
896
      end= longlong10_to_str(create_info.auto_increment_value, buff,10);
 
897
      packet->append(buff, (uint) (end - buff));
 
898
    }
 
899
 
 
900
    
 
901
    if (share->table_charset)
 
902
    {
 
903
      /*
 
904
        IF   check_create_info
 
905
        THEN add DEFAULT CHARSET only if it was used when creating the table
 
906
      */
 
907
      if (!create_info_arg ||
 
908
          (create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
 
909
      {
 
910
        packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
 
911
        packet->append(share->table_charset->csname);
 
912
        if (!(share->table_charset->state & MY_CS_PRIMARY))
 
913
        {
 
914
          packet->append(STRING_WITH_LEN(" COLLATE="));
 
915
          packet->append(table->s->table_charset->name);
 
916
        }
 
917
      }
905
918
    }
906
919
 
907
920
    if (share->min_rows)
908
921
    {
 
922
      char *end;
909
923
      packet->append(STRING_WITH_LEN(" MIN_ROWS="));
910
 
      buff= to_string(share->min_rows);
911
 
      packet->append(buff.c_str(), buff.length());
 
924
      end= longlong10_to_str(share->min_rows, buff, 10);
 
925
      packet->append(buff, (uint) (end- buff));
912
926
    }
913
927
 
914
928
    if (share->max_rows && !table_list->schema_table)
915
929
    {
 
930
      char *end;
916
931
      packet->append(STRING_WITH_LEN(" MAX_ROWS="));
917
 
      buff= to_string(share->max_rows);
918
 
      packet->append(buff.c_str(), buff.length());
 
932
      end= longlong10_to_str(share->max_rows, buff, 10);
 
933
      packet->append(buff, (uint) (end - buff));
919
934
    }
920
935
 
921
936
    if (share->avg_row_length)
922
937
    {
 
938
      char *end;
923
939
      packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
924
 
      buff= to_string(share->avg_row_length);
925
 
      packet->append(buff.c_str(), buff.length());
 
940
      end= longlong10_to_str(share->avg_row_length, buff,10);
 
941
      packet->append(buff, (uint) (end - buff));
926
942
    }
927
943
 
928
944
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
951
967
    }
952
968
    if (table->s->key_block_size)
953
969
    {
 
970
      char *end;
954
971
      packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
955
 
      buff= to_string(table->s->key_block_size);
956
 
      packet->append(buff.c_str(), buff.length());
957
 
    }
958
 
    if (share->block_size)
959
 
    {
960
 
      packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
961
 
      buff= to_string(share->block_size);
962
 
      packet->append(buff.c_str(), buff.length());
 
972
      end= longlong10_to_str(table->s->key_block_size, buff, 10);
 
973
      packet->append(buff, (uint) (end - buff));
963
974
    }
964
975
    table->file->append_create_info(packet);
965
976
    if (share->comment.length)
975
986
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
976
987
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
977
988
  }
978
 
  table->restore_column_map(old_map);
 
989
  tmp_restore_column_map(table->read_set, old_map);
979
990
  return(0);
980
991
}
981
992
 
998
1009
  @param  create_info   If not NULL, the options member influences the resulting 
999
1010
                        CRATE statement.
1000
1011
 
1001
 
  @returns true if errors are detected, false otherwise.
 
1012
  @returns TRUE if errors are detected, FALSE otherwise.
1002
1013
*/
1003
1014
 
1004
1015
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
1005
1016
                          HA_CREATE_INFO *create_info)
1006
1017
{
1007
1018
  HA_CREATE_INFO create;
1008
 
  uint32_t create_options = create_info ? create_info->options : 0;
 
1019
  uint create_options = create_info ? create_info->options : 0;
1009
1020
 
1010
1021
  if (!my_strcasecmp(system_charset_info, dbname,
1011
1022
                     INFORMATION_SCHEMA_NAME.str))
1016
1027
  else
1017
1028
  {
1018
1029
    if (check_db_dir_existence(dbname))
1019
 
      return(true);
 
1030
      return(TRUE);
1020
1031
 
1021
1032
    load_db_opt_by_name(thd, dbname, &create);
1022
1033
  }
1044
1055
    buffer->append(STRING_WITH_LEN(" */"));
1045
1056
  }
1046
1057
 
1047
 
  return(false);
 
1058
  return(FALSE);
1048
1059
}
1049
1060
 
1050
 
static void store_key_options(THD *thd __attribute__((unused)),
1051
 
                              String *packet, Table *table,
 
1061
static void store_key_options(THD *thd __attribute__((__unused__)),
 
1062
                              String *packet, TABLE *table,
1052
1063
                              KEY *key_info)
1053
1064
{
1054
1065
  char *end, buff[32];
1063
1074
      table->s->key_block_size != key_info->block_size)
1064
1075
  {
1065
1076
    packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
1066
 
    end= int64_t10_to_str(key_info->block_size, buff, 10);
 
1077
    end= longlong10_to_str(key_info->block_size, buff, 10);
1067
1078
    packet->append(buff, (uint) (end - buff));
1068
1079
  }
1069
1080
 
1070
 
  assert(test(key_info->flags & HA_USES_COMMENT) == 
 
1081
  DBUG_ASSERT(test(key_info->flags & HA_USES_COMMENT) == 
1071
1082
              (key_info->comment.length > 0));
1072
1083
  if (key_info->flags & HA_USES_COMMENT)
1073
1084
  {
1095
1106
 
1096
1107
  ulong thread_id;
1097
1108
  time_t start_time;
1098
 
  uint32_t   command;
 
1109
  uint   command;
1099
1110
  const char *user,*host,*db,*proc_info,*state_info;
1100
1111
  char *query;
1101
1112
};
1119
1130
  field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN));
1120
1131
  field->maybe_null=1;
1121
1132
  field_list.push_back(new Item_empty_string("Command",16));
1122
 
  field_list.push_back(new Item_return_int("Time",7, DRIZZLE_TYPE_LONG));
 
1133
  field_list.push_back(new Item_return_int("Time",7, MYSQL_TYPE_LONG));
1123
1134
  field_list.push_back(field=new Item_empty_string("State",30));
1124
1135
  field->maybe_null=1;
1125
1136
  field_list.push_back(field=new Item_empty_string("Info",max_query_length));
1128
1139
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1129
1140
    return;
1130
1141
 
1131
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1142
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1132
1143
  if (!thd->killed)
1133
1144
  {
1134
1145
    I_List_iterator<THD> it(threads);
1145
1156
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1146
1157
                                    (tmp->system_thread ?
1147
1158
                                     "system user" : "unauthenticated user"));
1148
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
 
1159
        thd_info->host= thd->strdup(tmp_sctx->host_or_ip[0] ? 
 
1160
                                    tmp_sctx->host_or_ip : 
 
1161
                                    tmp_sctx->host ? tmp_sctx->host : "");
1149
1162
        if ((thd_info->db=tmp->db))             // Safe test
1150
1163
          thd_info->db=thd->strdup(thd_info->db);
1151
1164
        thd_info->command=(int) tmp->command;
1155
1168
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1156
1169
                                       (tmp->net.reading_or_writing == 2 ?
1157
1170
                                        "Writing to net" :
1158
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1171
                                        thd_info->command == COM_SLEEP ? NullS :
1159
1172
                                        "Reading from net") :
1160
 
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
 
1173
                                       tmp->proc_info ? tmp->proc_info :
1161
1174
                                       tmp->mysys_var &&
1162
1175
                                       tmp->mysys_var->current_cond ?
1163
 
                                       "Waiting on cond" : NULL);
 
1176
                                       "Waiting on cond" : NullS);
1164
1177
        if (mysys_var)
1165
1178
          pthread_mutex_unlock(&mysys_var->mutex);
1166
1179
 
1173
1186
            the comment in sql_class.h why this prevents crashes in possible
1174
1187
            races with query_length
1175
1188
          */
1176
 
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
 
1189
          uint length= min(max_query_length, tmp->query_length);
1177
1190
          thd_info->query=(char*) thd->strmake(tmp->query,length);
1178
1191
        }
1179
1192
        thread_infos.append(thd_info);
1180
1193
      }
1181
1194
    }
1182
1195
  }
1183
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1196
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1184
1197
 
1185
1198
  thread_info *thd_info;
1186
1199
  time_t now= my_time(0);
1187
1200
  while ((thd_info=thread_infos.get()))
1188
1201
  {
1189
1202
    protocol->prepare_for_resend();
1190
 
    protocol->store((uint64_t) thd_info->thread_id);
 
1203
    protocol->store((ulonglong) thd_info->thread_id);
1191
1204
    protocol->store(thd_info->user, system_charset_info);
1192
1205
    protocol->store(thd_info->host, system_charset_info);
1193
1206
    protocol->store(thd_info->db, system_charset_info);
1196
1209
    else
1197
1210
      protocol->store(command_name[thd_info->command].str, system_charset_info);
1198
1211
    if (thd_info->start_time)
1199
 
      protocol->store((uint32_t) (now - thd_info->start_time));
 
1212
      protocol->store((uint32) (now - thd_info->start_time));
1200
1213
    else
1201
1214
      protocol->store_null();
1202
1215
    protocol->store(thd_info->state_info, system_charset_info);
1208
1221
  return;
1209
1222
}
1210
1223
 
1211
 
int fill_schema_processlist(THD* thd, TableList* tables,
1212
 
                            COND* cond __attribute__((unused)))
 
1224
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
 
1225
                            COND* cond __attribute__((__unused__)))
1213
1226
{
1214
 
  Table *table= tables->table;
1215
 
  const CHARSET_INFO * const cs= system_charset_info;
 
1227
  TABLE *table= tables->table;
 
1228
  CHARSET_INFO *cs= system_charset_info;
1216
1229
  char *user;
1217
1230
  time_t now= my_time(0);
1218
1231
 
1219
 
  user= NULL;
 
1232
  user= NullS;
1220
1233
 
1221
 
  pthread_mutex_lock(&LOCK_thread_count);
 
1234
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1222
1235
 
1223
1236
  if (!thd->killed)
1224
1237
  {
1236
1249
 
1237
1250
      restore_record(table, s->default_values);
1238
1251
      /* ID */
1239
 
      table->field[0]->store((int64_t) tmp->thread_id, true);
 
1252
      table->field[0]->store((longlong) tmp->thread_id, TRUE);
1240
1253
      /* USER */
1241
1254
      val= tmp_sctx->user ? tmp_sctx->user :
1242
1255
            (tmp->system_thread ? "system user" : "unauthenticated user");
1243
1256
      table->field[1]->store(val, strlen(val), cs);
1244
1257
      /* HOST */
1245
 
      table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
 
1258
      table->field[2]->store(tmp_sctx->host_or_ip,
 
1259
                             strlen(tmp_sctx->host_or_ip), cs);
1246
1260
      /* DB */
1247
1261
      if (tmp->db)
1248
1262
      {
1258
1272
      else
1259
1273
        table->field[4]->store(command_name[tmp->command].str,
1260
1274
                               command_name[tmp->command].length, cs);
1261
 
      /* DRIZZLE_TIME */
1262
 
      table->field[5]->store((uint32_t)(tmp->start_time ?
1263
 
                                      now - tmp->start_time : 0), true);
 
1275
      /* MYSQL_TIME */
 
1276
      table->field[5]->store((uint32)(tmp->start_time ?
 
1277
                                      now - tmp->start_time : 0), TRUE);
1264
1278
      /* STATE */
1265
1279
      val= (char*) (tmp->net.reading_or_writing ?
1266
1280
                    (tmp->net.reading_or_writing == 2 ?
1267
1281
                     "Writing to net" :
1268
 
                     tmp->command == COM_SLEEP ? NULL :
 
1282
                     tmp->command == COM_SLEEP ? NullS :
1269
1283
                     "Reading from net") :
1270
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
 
1284
                    tmp->proc_info ? tmp->proc_info :
1271
1285
                    tmp->mysys_var &&
1272
1286
                    tmp->mysys_var->current_cond ?
1273
 
                    "Waiting on cond" : NULL);
 
1287
                    "Waiting on cond" : NullS);
1274
1288
      if (val)
1275
1289
      {
1276
1290
        table->field[6]->store(val, strlen(val), cs);
1284
1298
      if (tmp->query)
1285
1299
      {
1286
1300
        table->field[7]->store(tmp->query,
1287
 
                               cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
 
1301
                               min(PROCESS_LIST_INFO_WIDTH,
1288
1302
                                   tmp->query_length), cs);
1289
1303
        table->field[7]->set_notnull();
1290
1304
      }
1291
1305
 
1292
1306
      if (schema_table_store_record(thd, table))
1293
1307
      {
1294
 
        pthread_mutex_unlock(&LOCK_thread_count);
 
1308
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
1295
1309
        return(1);
1296
1310
      }
1297
1311
    }
1298
1312
  }
1299
1313
 
1300
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1314
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1301
1315
  return(0);
1302
1316
}
1303
1317
 
1318
1332
*/
1319
1333
static void shrink_var_array(DYNAMIC_ARRAY *array)
1320
1334
{
1321
 
  uint32_t a,b;
 
1335
  uint a,b;
1322
1336
  SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1323
1337
 
1324
1338
  for (a= b= 0; b < array->elements; b++)
1326
1340
      all[a++]= all[b];
1327
1341
  if (a)
1328
1342
  {
1329
 
    memset(all+a, 0, sizeof(SHOW_VAR)); // writing NULL-element to the end
 
1343
    bzero(all+a, sizeof(SHOW_VAR)); // writing NULL-element to the end
1330
1344
    array->elements= a;
1331
1345
  }
1332
1346
  else // array is completely empty - delete it
1364
1378
    goto err;
1365
1379
  }
1366
1380
  while (list->name)
1367
 
    res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
1368
 
  res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
 
1381
    res|= insert_dynamic(&all_status_vars, (uchar*)list++);
 
1382
  res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1369
1383
  all_status_vars.elements--; // but next insert_dynamic should overwite it
1370
1384
  if (status_vars_inited)
1371
1385
    sort_dynamic(&all_status_vars, show_var_cmp);
1459
1473
  else
1460
1474
  {
1461
1475
    SHOW_VAR *all= dynamic_element(&all_status_vars, 0, SHOW_VAR *);
1462
 
    uint32_t i;
 
1476
    uint i;
1463
1477
    for (; list->name; list++)
1464
1478
    {
1465
1479
      for (i= 0; i < all_status_vars.elements; i++)
1484
1498
                              SHOW_VAR *variables,
1485
1499
                              enum enum_var_type value_type,
1486
1500
                              struct system_status_var *status_var,
1487
 
                              const char *prefix, Table *table,
 
1501
                              const char *prefix, TABLE *table,
1488
1502
                              bool ucase_names)
1489
1503
{
1490
1504
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1499
1513
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1500
1514
  null_lex_str.length= 0;
1501
1515
 
1502
 
  prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1516
  prefix_end=strnmov(name_buffer, prefix, sizeof(name_buffer)-1);
1503
1517
  if (*prefix)
1504
1518
    *prefix_end++= '_';
1505
1519
  len=name_buffer + sizeof(name_buffer) - prefix_end;
1506
1520
 
1507
1521
  for (; variables->name; variables++)
1508
1522
  {
1509
 
    my_stpncpy(prefix_end, variables->name, len);
 
1523
    strnmov(prefix_end, variables->name, len);
1510
1524
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
1511
1525
    if (ucase_names)
1512
1526
      make_upper(name_buffer);
1562
1576
          end= int10_to_str(*(long*) value, buff, 10);
1563
1577
          break;
1564
1578
        case SHOW_LONGLONG_STATUS:
1565
 
          value= ((char *) status_var + (uint64_t) value);
 
1579
          value= ((char *) status_var + (ulonglong) value);
1566
1580
          /* fall through */
1567
1581
        case SHOW_LONGLONG:
1568
 
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
1582
          end= longlong10_to_str(*(longlong*) value, buff, 10);
1569
1583
          break;
1570
1584
        case SHOW_HA_ROWS:
1571
 
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
 
1585
          end= longlong10_to_str((longlong) *(ha_rows*) value, buff, 10);
1572
1586
          break;
1573
1587
        case SHOW_BOOL:
1574
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1588
          end= strmov(buff, *(bool*) value ? "ON" : "OFF");
1575
1589
          break;
1576
1590
        case SHOW_MY_BOOL:
1577
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1591
          end= strmov(buff, *(my_bool*) value ? "ON" : "OFF");
1578
1592
          break;
1579
1593
        case SHOW_INT:
1580
 
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
 
1594
          end= int10_to_str((long) *(uint32*) value, buff, 10);
1581
1595
          break;
1582
1596
        case SHOW_HAVE:
1583
1597
        {
1584
1598
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1585
1599
          pos= show_comp_option_name[(int) tmp];
1586
 
          end= strchr(pos, '\0');
 
1600
          end= strend(pos);
1587
1601
          break;
1588
1602
        }
1589
1603
        case SHOW_CHAR:
1590
1604
        {
1591
1605
          if (!(pos= value))
1592
1606
            pos= "";
1593
 
          end= strchr(pos, '\0');
 
1607
          end= strend(pos);
1594
1608
          break;
1595
1609
        }
1596
1610
       case SHOW_CHAR_PTR:
1597
1611
        {
1598
1612
          if (!(pos= *(char**) value))
1599
1613
            pos= "";
1600
 
          end= strchr(pos, '\0');
 
1614
          end= strend(pos);
1601
1615
          break;
1602
1616
        }
1603
1617
        case SHOW_KEY_CACHE_LONG:
1606
1620
          break;
1607
1621
        case SHOW_KEY_CACHE_LONGLONG:
1608
1622
          value= (char*) dflt_key_cache + (ulong)value;
1609
 
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
1623
          end= longlong10_to_str(*(longlong*) value, buff, 10);
1610
1624
          break;
1611
1625
        case SHOW_UNDEF:
1612
1626
          break;                                        // Return empty string
1613
1627
        case SHOW_SYS:                                  // Cannot happen
1614
1628
        default:
1615
 
          assert(0);
 
1629
          DBUG_ASSERT(0);
1616
1630
          break;
1617
1631
        }
1618
1632
        restore_record(table, s->default_values);
1619
1633
        table->field[0]->store(name_buffer, strlen(name_buffer),
1620
1634
                               system_charset_info);
1621
 
        table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
 
1635
        table->field[1]->store(pos, (uint32) (end - pos), system_charset_info);
1622
1636
        table->field[1]->set_notnull();
1623
1637
 
1624
1638
        pthread_mutex_unlock(&LOCK_global_system_variables);
1625
1639
 
1626
1640
        if (schema_table_store_record(thd, table))
1627
 
          return(true);
 
1641
          return(TRUE);
1628
1642
      }
1629
1643
    }
1630
1644
  }
1631
1645
 
1632
 
  return(false);
 
1646
  return(FALSE);
1633
1647
}
1634
1648
 
1635
1649
 
1639
1653
{
1640
1654
 
1641
1655
  /* Ensure that thread id not killed during loop */
1642
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1656
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1643
1657
 
1644
1658
  I_List_iterator<THD> it(threads);
1645
1659
  THD *tmp;
1651
1665
  while ((tmp= it++))
1652
1666
    add_to_status(to, &tmp->status_var);
1653
1667
  
1654
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1668
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1655
1669
  return;
1656
1670
}
1657
1671
 
1680
1694
    1                     error
1681
1695
*/
1682
1696
 
1683
 
bool schema_table_store_record(THD *thd, Table *table)
 
1697
bool schema_table_store_record(THD *thd, TABLE *table)
1684
1698
{
1685
1699
  int error;
1686
1700
  if ((error= table->file->ha_write_row(table->record[0])))
1726
1740
*/
1727
1741
 
1728
1742
bool get_lookup_value(THD *thd, Item_func *item_func,
1729
 
                      TableList *table, 
 
1743
                      TABLE_LIST *table, 
1730
1744
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1731
1745
{
1732
1746
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1743
1757
    char tmp[MAX_FIELD_WIDTH];
1744
1758
    String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1745
1759
    Item_field *item_field;
1746
 
    const CHARSET_INFO * const cs= system_charset_info;
 
1760
    CHARSET_INFO *cs= system_charset_info;
1747
1761
 
1748
1762
    if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1749
1763
        item_func->arguments()[1]->const_item())
1770
1784
      return 1;
1771
1785
 
1772
1786
    /* Lookup value is database name */
1773
 
    if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1774
 
                               (unsigned char *) item_field->field_name,
 
1787
    if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1788
                               (uchar *) item_field->field_name,
1775
1789
                               strlen(item_field->field_name), 0))
1776
1790
    {
1777
1791
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1778
 
                           tmp_str->length(), false);
 
1792
                           tmp_str->length(), FALSE);
1779
1793
    }
1780
1794
    /* Lookup value is table name */
1781
 
    else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
 
1795
    else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1782
1796
                                    strlen(field_name2),
1783
 
                                    (unsigned char *) item_field->field_name,
 
1797
                                    (uchar *) item_field->field_name,
1784
1798
                                    strlen(item_field->field_name), 0))
1785
1799
    {
1786
1800
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1787
 
                           tmp_str->length(), false);
 
1801
                           tmp_str->length(), FALSE);
1788
1802
    }
1789
1803
  }
1790
1804
  return 0;
1808
1822
    1             error, there can be no matching records for the condition
1809
1823
*/
1810
1824
 
1811
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1825
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1812
1826
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1813
1827
{
1814
1828
  if (!cond)
1843
1857
}
1844
1858
 
1845
1859
 
1846
 
bool uses_only_table_name_fields(Item *item, TableList *table)
 
1860
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1847
1861
{
1848
1862
  if (item->type() == Item::FUNC_ITEM)
1849
1863
  {
1850
1864
    Item_func *item_func= (Item_func*)item;
1851
 
    for (uint32_t i=0; i<item_func->argument_count(); i++)
 
1865
    for (uint i=0; i<item_func->argument_count(); i++)
1852
1866
    {
1853
1867
      if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1854
1868
        return 0;
1857
1871
  else if (item->type() == Item::FIELD_ITEM)
1858
1872
  {
1859
1873
    Item_field *item_field= (Item_field*)item;
1860
 
    const CHARSET_INFO * const cs= system_charset_info;
 
1874
    CHARSET_INFO *cs= system_charset_info;
1861
1875
    ST_SCHEMA_TABLE *schema_table= table->schema_table;
1862
1876
    ST_FIELD_INFO *field_info= schema_table->fields_info;
1863
1877
    const char *field_name1= schema_table->idx_field1 >= 0 ?
1865
1879
    const char *field_name2= schema_table->idx_field2 >= 0 ?
1866
1880
      field_info[schema_table->idx_field2].field_name : "";
1867
1881
    if (table->table != item_field->field->table ||
1868
 
        (cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1869
 
                               (unsigned char *) item_field->field_name,
 
1882
        (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1883
                               (uchar *) item_field->field_name,
1870
1884
                               strlen(item_field->field_name), 0) &&
1871
 
         cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1872
 
                               (unsigned char *) item_field->field_name,
 
1885
         cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
 
1886
                               (uchar *) item_field->field_name,
1873
1887
                               strlen(item_field->field_name), 0)))
1874
1888
      return 0;
1875
1889
  }
1883
1897
}
1884
1898
 
1885
1899
 
1886
 
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
 
1900
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
1887
1901
{
1888
1902
  if (!cond)
1889
1903
    return (COND*) 0;
1957
1971
    1             error, there can be no matching records for the condition
1958
1972
*/
1959
1973
 
1960
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1974
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1961
1975
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1962
1976
{
1963
1977
  LEX *lex= thd->lex;
1964
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1965
 
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
 
1978
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
1979
  bzero((char*) lookup_field_values, sizeof(LOOKUP_FIELD_VALUES));
1966
1980
  switch (lex->sql_command) {
1967
1981
  case SQLCOM_SHOW_DATABASES:
1968
1982
    if (wild)
2024
2038
  LEX_STRING *i_s_name_copy= 0;
2025
2039
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2026
2040
                                      INFORMATION_SCHEMA_NAME.str,
2027
 
                                      INFORMATION_SCHEMA_NAME.length, true);
 
2041
                                      INFORMATION_SCHEMA_NAME.length, TRUE);
2028
2042
  *with_i_schema= 0;
2029
2043
  if (lookup_field_vals->wild_db_value)
2030
2044
  {
2042
2056
      if (files->push_back(i_s_name_copy))
2043
2057
        return 1;
2044
2058
    }
2045
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
2059
    return (find_files(thd, files, NullS, mysql_data_home,
2046
2060
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2047
2061
  }
2048
2062
 
2073
2087
  if (files->push_back(i_s_name_copy))
2074
2088
    return 1;
2075
2089
  *with_i_schema= 1;
2076
 
  return (find_files(thd, files, NULL,
2077
 
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
 
2090
  return (find_files(thd, files, NullS,
 
2091
                     mysql_data_home, NullS, 1) != FIND_FILES_OK);
2078
2092
}
2079
2093
 
2080
2094
 
2085
2099
};
2086
2100
 
2087
2101
 
2088
 
static bool add_schema_table(THD *thd, plugin_ref plugin,
 
2102
static my_bool add_schema_table(THD *thd, plugin_ref plugin,
2089
2103
                                void* p_data)
2090
2104
{
2091
2105
  LEX_STRING *file_name= 0;
2111
2125
 
2112
2126
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2113
2127
                                       strlen(schema_table->table_name),
2114
 
                                       true)) &&
 
2128
                                       TRUE)) &&
2115
2129
      !file_list->push_back(file_name))
2116
2130
    return(0);
2117
2131
  return(1);
2142
2156
    }
2143
2157
    if ((file_name= 
2144
2158
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
2145
 
                              strlen(tmp_schema_table->table_name), true)) &&
 
2159
                              strlen(tmp_schema_table->table_name), TRUE)) &&
2146
2160
        !files->push_back(file_name))
2147
2161
      continue;
2148
2162
    return(1);
2151
2165
  add_data.files= files;
2152
2166
  add_data.wild= wild;
2153
2167
  if (plugin_foreach(thd, add_schema_table,
2154
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2155
 
    return(1);
 
2168
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data))
 
2169
      return(1);
2156
2170
 
2157
2171
  return(0);
2158
2172
}
2168
2182
  @param[in]      table_names           List of table names in database
2169
2183
  @param[in]      lex                   pointer to LEX struct
2170
2184
  @param[in]      lookup_field_vals     pointer to LOOKUP_FIELD_VALUE struct
2171
 
  @param[in]      with_i_schema         true means that we add I_S tables to list
 
2185
  @param[in]      with_i_schema         TRUE means that we add I_S tables to list
2172
2186
  @param[in]      db_name               database name
2173
2187
 
2174
2188
  @return         Operation status
2238
2252
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2239
2253
 
2240
2254
  @param[in]      thd                      thread handler
2241
 
  @param[in]      tables                   TableList for I_S table
 
2255
  @param[in]      tables                   TABLE_LIST for I_S table
2242
2256
  @param[in]      schema_table             pointer to I_S structure
2243
2257
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2244
2258
                                           which is used to save|restore original
2251
2265
*/
2252
2266
 
2253
2267
static int 
2254
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2268
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2255
2269
                              ST_SCHEMA_TABLE *schema_table,
2256
2270
                              Open_tables_state *open_tables_state_backup)
2257
2271
{
2259
2273
  bool res;
2260
2274
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2261
2275
  enum_sql_command save_sql_command= lex->sql_command;
2262
 
  TableList *show_table_list= (TableList*) tables->schema_select_lex->
 
2276
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2263
2277
    table_list.first;
2264
 
  Table *table= tables->table;
 
2278
  TABLE *table= tables->table;
2265
2279
  int error= 1;
2266
2280
 
2267
2281
  lex->all_selects_list= tables->schema_select_lex;
2280
2294
  */
2281
2295
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2282
2296
  res= open_normal_and_derived_tables(thd, show_table_list,
2283
 
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
 
2297
                                      MYSQL_LOCK_IGNORE_FLUSH);
2284
2298
  lex->sql_command= save_sql_command;
2285
2299
  /*
2286
2300
    get_all_tables() returns 1 on failure and 0 on success thus
2294
2308
    'show columns' & 'show statistics' commands).
2295
2309
  */
2296
2310
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2297
 
                                    strlen(show_table_list->alias), false);
 
2311
                                    strlen(show_table_list->alias), FALSE);
2298
2312
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2299
 
                                 show_table_list->db_length, false);
 
2313
                                 show_table_list->db_length, FALSE);
2300
2314
      
2301
2315
 
2302
2316
   error= test(schema_table->process_table(thd, show_table_list,
2309
2323
 
2310
2324
 
2311
2325
/**
2312
 
  @brief          Fill I_S table for SHOW Table NAMES commands
 
2326
  @brief          Fill I_S table for SHOW TABLE NAMES commands
2313
2327
 
2314
2328
  @param[in]      thd                      thread handler
2315
 
  @param[in]      table                    Table struct for I_S table
 
2329
  @param[in]      table                    TABLE struct for I_S table
2316
2330
  @param[in]      db_name                  database name
2317
2331
  @param[in]      table_name               table name
2318
 
  @param[in]      with_i_schema            I_S table if true
 
2332
  @param[in]      with_i_schema            I_S table if TRUE
2319
2333
 
2320
2334
  @return         Operation status
2321
2335
    @retval       0           success
2322
2336
    @retval       1           error
2323
2337
*/
2324
2338
 
2325
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2339
static int fill_schema_table_names(THD *thd, TABLE *table,
2326
2340
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2327
2341
                                   bool with_i_schema)
2328
2342
{
2337
2351
    char path[FN_REFLEN];
2338
2352
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2339
2353
                                table_name->str, reg_ext, 0);
2340
 
    if (mysql_frm_type(thd, path, &not_used)) 
2341
 
    {
2342
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2343
 
                             system_charset_info);
2344
 
    }
2345
 
    else
2346
 
    {
 
2354
    switch (mysql_frm_type(thd, path, &not_used)) {
 
2355
    case FRMTYPE_ERROR:
2347
2356
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2348
2357
                             system_charset_info);
 
2358
      break;
 
2359
    case FRMTYPE_TABLE:
 
2360
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
 
2361
                             system_charset_info);
 
2362
      break;
 
2363
    default:
 
2364
      DBUG_ASSERT(0);
2349
2365
    }
2350
 
 
2351
2366
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2352
2367
    {
2353
2368
      thd->clear_error();
2376
2391
    @retval       SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2377
2392
*/
2378
2393
 
2379
 
static uint32_t get_table_open_method(TableList *tables,
 
2394
static uint get_table_open_method(TABLE_LIST *tables,
2380
2395
                                  ST_SCHEMA_TABLE *schema_table,
2381
 
                                  enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2396
                                  enum enum_schema_tables schema_table_idx __attribute__((__unused__)))
2382
2397
{
2383
2398
  /*
2384
2399
    determine which method will be used for table opening
2404
2419
  @brief          Fill I_S table with data from FRM file only
2405
2420
 
2406
2421
  @param[in]      thd                      thread handler
2407
 
  @param[in]      table                    Table struct for I_S table
 
2422
  @param[in]      table                    TABLE struct for I_S table
2408
2423
  @param[in]      schema_table             I_S table struct
2409
2424
  @param[in]      db_name                  database name
2410
2425
  @param[in]      table_name               table name
2417
2432
                              open_tables function for this table
2418
2433
*/
2419
2434
 
2420
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
 
2435
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2421
2436
                                      ST_SCHEMA_TABLE *schema_table,
2422
2437
                                      LEX_STRING *db_name,
2423
2438
                                      LEX_STRING *table_name,
2424
 
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2439
                                      enum enum_schema_tables schema_table_idx __attribute__((__unused__)))
2425
2440
{
2426
 
  Table *table= tables->table;
 
2441
  TABLE *table= tables->table;
2427
2442
  TABLE_SHARE *share;
2428
 
  Table tbl;
2429
 
  TableList table_list;
2430
 
  uint32_t res= 0;
 
2443
  TABLE tbl;
 
2444
  TABLE_LIST table_list;
 
2445
  uint res= 0;
2431
2446
  int error;
2432
2447
  char key[MAX_DBKEY_LENGTH];
2433
 
  uint32_t key_length;
 
2448
  uint key_length;
2434
2449
 
2435
 
  memset(&table_list, 0, sizeof(TableList));
2436
 
  memset(&tbl, 0, sizeof(Table));
 
2450
  bzero((char*) &table_list, sizeof(TABLE_LIST));
 
2451
  bzero((char*) &tbl, sizeof(TABLE));
2437
2452
 
2438
2453
  table_list.table_name= table_name->str;
2439
2454
  table_list.db= db_name->str;
2441
2456
  key_length= create_table_def_key(thd, key, &table_list, 0);
2442
2457
  pthread_mutex_lock(&LOCK_open);
2443
2458
  share= get_table_share(thd, &table_list, key,
2444
 
                         key_length, 0, &error);
 
2459
                         key_length, OPEN_VIEW, &error);
2445
2460
  if (!share)
2446
2461
  {
2447
2462
    res= 0;
2484
2499
    @retval       1                        error
2485
2500
*/
2486
2501
 
2487
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2502
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2488
2503
{
2489
2504
  LEX *lex= thd->lex;
2490
 
  Table *table= tables->table;
 
2505
  TABLE *table= tables->table;
2491
2506
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2492
2507
  enum_sql_command save_sql_command= lex->sql_command;
2493
2508
  SELECT_LEX *lsel= tables->schema_select_lex;
2500
2515
  List<LEX_STRING> db_names;
2501
2516
  List_iterator_fast<LEX_STRING> it(db_names);
2502
2517
  COND *partial_cond= 0;
2503
 
  uint32_t derived_tables= lex->derived_tables; 
 
2518
  uint derived_tables= lex->derived_tables; 
2504
2519
  int error= 1;
2505
2520
  Open_tables_state open_tables_state_backup;
2506
2521
  Query_tables_list query_tables_list_backup;
2507
 
  uint32_t table_open_method;
 
2522
  uint table_open_method;
2508
2523
  bool old_value= thd->no_warnings_for_error;
2509
2524
 
2510
2525
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2543
2558
      if lookup value is empty string then
2544
2559
      it's impossible table name or db name
2545
2560
    */
2546
 
    if ((lookup_field_vals.db_value.str && !lookup_field_vals.db_value.str[0]) ||
2547
 
        (lookup_field_vals.table_value.str && !lookup_field_vals.table_value.str[0]))
 
2561
    if (lookup_field_vals.db_value.str &&
 
2562
        !lookup_field_vals.db_value.str[0] ||
 
2563
        lookup_field_vals.table_value.str &&
 
2564
        !lookup_field_vals.table_value.str[0])
2548
2565
    {
2549
2566
      error= 0;
2550
2567
      goto err;
2553
2570
 
2554
2571
  if (lookup_field_vals.db_value.length &&
2555
2572
      !lookup_field_vals.wild_db_value)
2556
 
    tables->has_db_lookup_value= true;
 
2573
    tables->has_db_lookup_value= TRUE;
2557
2574
  if (lookup_field_vals.table_value.length &&
2558
2575
      !lookup_field_vals.wild_table_value) 
2559
 
    tables->has_table_lookup_value= true;
 
2576
    tables->has_table_lookup_value= TRUE;
2560
2577
 
2561
2578
  if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2562
2579
    partial_cond= 0;
2612
2629
            continue;
2613
2630
          }
2614
2631
 
2615
 
          /* SHOW Table NAMES command */
 
2632
          /* SHOW TABLE NAMES command */
2616
2633
          if (schema_table_idx == SCH_TABLE_NAMES)
2617
2634
          {
2618
2635
            if (fill_schema_table_names(thd, tables->table, db_name,
2639
2656
            sel.parent_lex= lex;
2640
2657
            /* db_name can be changed in make_table_list() func */
2641
2658
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
2642
 
                                      db_name->length, false))
 
2659
                                      db_name->length, FALSE))
2643
2660
              goto err;
2644
2661
            if (make_table_list(thd, &sel, db_name, table_name))
2645
2662
              goto err;
2646
 
            TableList *show_table_list= (TableList*) sel.table_list.first;
 
2663
            TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2647
2664
            lex->all_selects_list= &sel;
2648
2665
            lex->derived_tables= 0;
2649
2666
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2650
2667
            show_table_list->i_s_requested_object=
2651
2668
              schema_table->i_s_requested_object;
2652
2669
            res= open_normal_and_derived_tables(thd, show_table_list,
2653
 
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
 
2670
                                                MYSQL_LOCK_IGNORE_FLUSH);
2654
2671
            lex->sql_command= save_sql_command;
2655
2672
            /*
2656
2673
              XXX:  show_table_list has a flag i_is_requested,
2682
2699
                in this case.
2683
2700
              */
2684
2701
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2685
 
                                   strlen(show_table_list->alias), false);
 
2702
                                   strlen(show_table_list->alias), FALSE);
2686
2703
              res= schema_table->process_table(thd, show_table_list, table,
2687
2704
                                               res, &orig_db_name,
2688
2705
                                               &tmp_lex_string);
2689
2706
              close_tables_for_reopen(thd, &show_table_list);
2690
2707
            }
2691
 
            assert(!lex->query_tables_own_last);
 
2708
            DBUG_ASSERT(!lex->query_tables_own_last);
2692
2709
            if (res)
2693
2710
              goto err;
2694
2711
          }
2714
2731
}
2715
2732
 
2716
2733
 
2717
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2718
 
                          const CHARSET_INFO * const cs)
 
2734
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
 
2735
                          CHARSET_INFO *cs)
2719
2736
{
2720
2737
  restore_record(table, s->default_values);
2721
2738
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2725
2742
}
2726
2743
 
2727
2744
 
2728
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2745
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
2729
2746
{
2730
2747
  /*
2731
2748
    TODO: fill_schema_shemata() is called when new client is connected.
2737
2754
  LEX_STRING *db_name;
2738
2755
  bool with_i_schema;
2739
2756
  HA_CREATE_INFO create;
2740
 
  Table *table= tables->table;
 
2757
  TABLE *table= tables->table;
2741
2758
 
2742
2759
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2743
2760
    return(0);
2752
2769
     !with_i_schema)
2753
2770
  {
2754
2771
    char path[FN_REFLEN+16];
2755
 
    uint32_t path_len;
 
2772
    uint path_len;
2756
2773
    struct stat stat_info;
2757
2774
    if (!lookup_field_vals.db_value.str[0])
2758
2775
      return(0);
2785
2802
}
2786
2803
 
2787
2804
 
2788
 
static int get_schema_tables_record(THD *thd, TableList *tables,
2789
 
                                    Table *table, bool res,
 
2805
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
 
2806
                                    TABLE *table, bool res,
2790
2807
                                    LEX_STRING *db_name,
2791
2808
                                    LEX_STRING *table_name)
2792
2809
{
2793
2810
  const char *tmp_buff;
2794
 
  DRIZZLE_TIME time;
2795
 
  const CHARSET_INFO * const cs= system_charset_info;
 
2811
  MYSQL_TIME time;
 
2812
  CHARSET_INFO *cs= system_charset_info;
2796
2813
 
2797
2814
  restore_record(table, s->default_values);
2798
2815
  table->field[1]->store(db_name->str, db_name->length, cs);
2806
2823
    if (tables->schema_table)
2807
2824
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2808
2825
    else
2809
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2826
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2810
2827
    table->field[20]->store(error, strlen(error), cs);
2811
2828
    thd->clear_error();
2812
2829
  }
2813
2830
  else
2814
2831
  {
2815
 
    char option_buff[400],*ptr;
2816
 
    Table *show_table= tables->table;
 
2832
    char option_buff[350],*ptr;
 
2833
    TABLE *show_table= tables->table;
2817
2834
    TABLE_SHARE *share= show_table->s;
2818
2835
    handler *file= show_table->file;
2819
2836
    handlerton *tmp_db_type= share->db_type();
2822
2839
    else if (share->tmp_table)
2823
2840
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2824
2841
    else
2825
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2842
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2826
2843
 
2827
2844
    for (int i= 4; i < 20; i++)
2828
2845
    {
2832
2849
    }
2833
2850
    tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2834
2851
    table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2835
 
    table->field[5]->store((int64_t) share->frm_version, true);
 
2852
    table->field[5]->store((longlong) share->frm_version, TRUE);
2836
2853
 
2837
2854
    ptr=option_buff;
2838
2855
    if (share->min_rows)
2839
2856
    {
2840
 
      ptr=my_stpcpy(ptr," min_rows=");
2841
 
      ptr=int64_t10_to_str(share->min_rows,ptr,10);
 
2857
      ptr=strmov(ptr," min_rows=");
 
2858
      ptr=longlong10_to_str(share->min_rows,ptr,10);
2842
2859
    }
2843
2860
    if (share->max_rows)
2844
2861
    {
2845
 
      ptr=my_stpcpy(ptr," max_rows=");
2846
 
      ptr=int64_t10_to_str(share->max_rows,ptr,10);
 
2862
      ptr=strmov(ptr," max_rows=");
 
2863
      ptr=longlong10_to_str(share->max_rows,ptr,10);
2847
2864
    }
2848
2865
    if (share->avg_row_length)
2849
2866
    {
2850
 
      ptr=my_stpcpy(ptr," avg_row_length=");
2851
 
      ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
 
2867
      ptr=strmov(ptr," avg_row_length=");
 
2868
      ptr=longlong10_to_str(share->avg_row_length,ptr,10);
2852
2869
    }
2853
2870
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
2854
 
      ptr=my_stpcpy(ptr," pack_keys=1");
 
2871
      ptr=strmov(ptr," pack_keys=1");
2855
2872
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2856
 
      ptr=my_stpcpy(ptr," pack_keys=0");
 
2873
      ptr=strmov(ptr," pack_keys=0");
2857
2874
    /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2858
2875
    if (share->db_create_options & HA_OPTION_CHECKSUM)
2859
 
      ptr=my_stpcpy(ptr," checksum=1");
 
2876
      ptr=strmov(ptr," checksum=1");
2860
2877
    if (share->page_checksum != HA_CHOICE_UNDEF)
2861
2878
      ptr= strxmov(ptr, " page_checksum=",
2862
 
                   ha_choice_values[(uint) share->page_checksum], NULL);
 
2879
                   ha_choice_values[(uint) share->page_checksum], NullS);
2863
2880
    if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2864
 
      ptr=my_stpcpy(ptr," delay_key_write=1");
 
2881
      ptr=strmov(ptr," delay_key_write=1");
2865
2882
    if (share->row_type != ROW_TYPE_DEFAULT)
2866
2883
      ptr=strxmov(ptr, " row_format=", 
2867
2884
                  ha_row_type[(uint) share->row_type],
2868
 
                  NULL);
2869
 
    if (share->block_size)
2870
 
    {
2871
 
      ptr= my_stpcpy(ptr, " block_size=");
2872
 
      ptr= int64_t10_to_str(share->block_size, ptr, 10);
2873
 
    }
2874
 
    
 
2885
                  NullS);
2875
2886
    if (share->transactional != HA_CHOICE_UNDEF)
2876
2887
    {
2877
2888
      ptr= strxmov(ptr, " TRANSACTIONAL=",
2878
2889
                   (share->transactional == HA_CHOICE_YES ? "1" : "0"),
2879
 
                   NULL);
 
2890
                   NullS);
2880
2891
    }
2881
2892
    if (share->transactional != HA_CHOICE_UNDEF)
2882
2893
      ptr= strxmov(ptr, " transactional=",
2883
 
                   ha_choice_values[(uint) share->transactional], NULL);
 
2894
                   ha_choice_values[(uint) share->transactional], NullS);
2884
2895
    table->field[19]->store(option_buff+1,
2885
2896
                            (ptr == option_buff ? 0 : 
2886
2897
                             (uint) (ptr-option_buff)-1), cs);
2927
2938
      table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2928
2939
      if (!tables->schema_table)
2929
2940
      {
2930
 
        table->field[7]->store((int64_t) file->stats.records, true);
 
2941
        table->field[7]->store((longlong) file->stats.records, TRUE);
2931
2942
        table->field[7]->set_notnull();
2932
2943
      }
2933
 
      table->field[8]->store((int64_t) file->stats.mean_rec_length, true);
2934
 
      table->field[9]->store((int64_t) file->stats.data_file_length, true);
 
2944
      table->field[8]->store((longlong) file->stats.mean_rec_length, TRUE);
 
2945
      table->field[9]->store((longlong) file->stats.data_file_length, TRUE);
2935
2946
      if (file->stats.max_data_file_length)
2936
2947
      {
2937
 
        table->field[10]->store((int64_t) file->stats.max_data_file_length,
2938
 
                                true);
 
2948
        table->field[10]->store((longlong) file->stats.max_data_file_length,
 
2949
                                TRUE);
2939
2950
      }
2940
 
      table->field[11]->store((int64_t) file->stats.index_file_length, true);
2941
 
      table->field[12]->store((int64_t) file->stats.delete_length, true);
 
2951
      table->field[11]->store((longlong) file->stats.index_file_length, TRUE);
 
2952
      table->field[12]->store((longlong) file->stats.delete_length, TRUE);
2942
2953
      if (show_table->found_next_number_field)
2943
2954
      {
2944
 
        table->field[13]->store((int64_t) file->stats.auto_increment_value,
2945
 
                                true);
 
2955
        table->field[13]->store((longlong) file->stats.auto_increment_value,
 
2956
                                TRUE);
2946
2957
        table->field[13]->set_notnull();
2947
2958
      }
2948
2959
      if (file->stats.create_time)
2949
2960
      {
2950
2961
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2951
2962
                                                  (my_time_t) file->stats.create_time);
2952
 
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
 
2963
        table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
2953
2964
        table->field[14]->set_notnull();
2954
2965
      }
2955
2966
      if (file->stats.update_time)
2956
2967
      {
2957
2968
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2958
2969
                                                  (my_time_t) file->stats.update_time);
2959
 
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
 
2970
        table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
2960
2971
        table->field[15]->set_notnull();
2961
2972
      }
2962
2973
      if (file->stats.check_time)
2963
2974
      {
2964
2975
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2965
2976
                                                  (my_time_t) file->stats.check_time);
2966
 
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
 
2977
        table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
2967
2978
        table->field[16]->set_notnull();
2968
2979
      }
2969
2980
      if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2970
2981
      {
2971
 
        table->field[18]->store((int64_t) file->checksum(), true);
 
2982
        table->field[18]->store((longlong) file->checksum(), TRUE);
2972
2983
        table->field[18]->set_notnull();
2973
2984
      }
2974
2985
    }
2989
3000
  @return         void
2990
3001
*/
2991
3002
 
2992
 
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2993
 
                       uint32_t offset)
 
3003
void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
 
3004
                       uint offset)
2994
3005
{
2995
3006
  bool is_blob;
2996
3007
  int decimals, field_length;
3007
3018
  table->field[offset]->store(column_type.ptr(),
3008
3019
                         (tmp_buff ? tmp_buff - column_type.ptr() :
3009
3020
                          column_type.length()), cs);
3010
 
  is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
 
3021
  is_blob= (field->type() == MYSQL_TYPE_BLOB);
3011
3022
  if (field->has_charset() || is_blob ||
3012
 
      field->real_type() == DRIZZLE_TYPE_VARCHAR)  // For varbinary type
 
3023
      field->real_type() == MYSQL_TYPE_VARCHAR ||  // For varbinary type
 
3024
      field->real_type() == MYSQL_TYPE_STRING)     // For binary type
3013
3025
  {
3014
 
    uint32_t octet_max_length= field->max_display_length();
3015
 
    if (is_blob && octet_max_length != (uint32_t) 4294967295U)
 
3026
    uint32 octet_max_length= field->max_display_length();
 
3027
    if (is_blob && octet_max_length != (uint32) 4294967295U)
3016
3028
      octet_max_length /= field->charset()->mbmaxlen;
3017
 
    int64_t char_max_len= is_blob ? 
3018
 
      (int64_t) octet_max_length / field->charset()->mbminlen :
3019
 
      (int64_t) octet_max_length / field->charset()->mbmaxlen;
 
3029
    longlong char_max_len= is_blob ? 
 
3030
      (longlong) octet_max_length / field->charset()->mbminlen :
 
3031
      (longlong) octet_max_length / field->charset()->mbmaxlen;
3020
3032
    /* CHARACTER_MAXIMUM_LENGTH column*/
3021
 
    table->field[offset + 1]->store(char_max_len, true);
 
3033
    table->field[offset + 1]->store(char_max_len, TRUE);
3022
3034
    table->field[offset + 1]->set_notnull();
3023
3035
    /* CHARACTER_OCTET_LENGTH column */
3024
 
    table->field[offset + 2]->store((int64_t) octet_max_length, true);
 
3036
    table->field[offset + 2]->store((longlong) octet_max_length, TRUE);
3025
3037
    table->field[offset + 2]->set_notnull();
3026
3038
  }
3027
3039
 
3032
3044
 
3033
3045
  decimals= field->decimals();
3034
3046
  switch (field->type()) {
3035
 
  case DRIZZLE_TYPE_NEWDECIMAL:
 
3047
  case MYSQL_TYPE_NEWDECIMAL:
3036
3048
    field_length= ((Field_new_decimal*) field)->precision;
3037
3049
    break;
3038
 
  case DRIZZLE_TYPE_TINY:
3039
 
  case DRIZZLE_TYPE_LONG:
3040
 
  case DRIZZLE_TYPE_LONGLONG:
 
3050
  case MYSQL_TYPE_TINY:
 
3051
  case MYSQL_TYPE_SHORT:
 
3052
  case MYSQL_TYPE_LONG:
 
3053
  case MYSQL_TYPE_LONGLONG:
3041
3054
    field_length= field->max_display_length() - 1;
3042
3055
    break;
3043
 
  case DRIZZLE_TYPE_DOUBLE:
 
3056
  case MYSQL_TYPE_FLOAT:  
 
3057
  case MYSQL_TYPE_DOUBLE:
3044
3058
    field_length= field->field_length;
3045
3059
    if (decimals == NOT_FIXED_DEC)
3046
3060
      decimals= -1;                           // return NULL
3053
3067
  /* NUMERIC_PRECISION column */
3054
3068
  if (field_length >= 0)
3055
3069
  {
3056
 
    table->field[offset + 3]->store((int64_t) field_length, true);
 
3070
    table->field[offset + 3]->store((longlong) field_length, TRUE);
3057
3071
    table->field[offset + 3]->set_notnull();
3058
3072
  }
3059
3073
  /* NUMERIC_SCALE column */
3060
3074
  if (decimals >= 0)
3061
3075
  {
3062
 
    table->field[offset + 4]->store((int64_t) decimals, true);
 
3076
    table->field[offset + 4]->store((longlong) decimals, TRUE);
3063
3077
    table->field[offset + 4]->set_notnull();
3064
3078
  }
3065
3079
  if (field->has_charset())
3076
3090
}
3077
3091
 
3078
3092
 
3079
 
static int get_schema_column_record(THD *thd, TableList *tables,
3080
 
                                    Table *table, bool res,
 
3093
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
 
3094
                                    TABLE *table, bool res,
3081
3095
                                    LEX_STRING *db_name,
3082
3096
                                    LEX_STRING *table_name)
3083
3097
{
3084
3098
  LEX *lex= thd->lex;
3085
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3086
 
  const CHARSET_INFO * const cs= system_charset_info;
3087
 
  Table *show_table;
 
3099
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
3100
  CHARSET_INFO *cs= system_charset_info;
 
3101
  TABLE *show_table;
3088
3102
  TABLE_SHARE *show_table_share;
3089
3103
  Field **ptr, *field, *timestamp_field;
3090
3104
  int count;
3098
3112
        rather than in SHOW COLUMNS
3099
3113
      */ 
3100
3114
      if (thd->is_error())
3101
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3115
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3102
3116
                     thd->main_da.sql_errno(), thd->main_da.message());
3103
3117
      thd->clear_error();
3104
3118
      res= 0;
3127
3141
    if (!show_table->read_set)
3128
3142
    {
3129
3143
      /* to satisfy 'field->val_str' ASSERTs */
3130
 
      unsigned char *bitmaps;
3131
 
      uint32_t bitmap_size= show_table_share->column_bitmap_size;
3132
 
      if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
 
3144
      uchar *bitmaps;
 
3145
      uint bitmap_size= show_table_share->column_bitmap_size;
 
3146
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3133
3147
        return(0);
3134
3148
      bitmap_init(&show_table->def_read_set,
3135
 
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
 
3149
                  (my_bitmap_map*) bitmaps, show_table_share->fields, FALSE);
3136
3150
      bitmap_set_all(&show_table->def_read_set);
3137
3151
      show_table->read_set= &show_table->def_read_set;
3138
3152
    }
3141
3155
 
3142
3156
  for (; (field= *ptr) ; ptr++)
3143
3157
  {
3144
 
    unsigned char *pos;
 
3158
    uchar *pos;
3145
3159
    char tmp[MAX_FIELD_WIDTH];
3146
3160
    String type(tmp,sizeof(tmp), system_charset_info);
3147
3161
    char *end;
3162
3176
    table->field[2]->store(table_name->str, table_name->length, cs);
3163
3177
    table->field[3]->store(field->field_name, strlen(field->field_name),
3164
3178
                           cs);
3165
 
    table->field[4]->store((int64_t) count, true);
 
3179
    table->field[4]->store((longlong) count, TRUE);
3166
3180
 
3167
3181
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3168
3182
    {
3169
3183
      table->field[5]->store(type.ptr(), type.length(), cs);
3170
3184
      table->field[5]->set_notnull();
3171
3185
    }
3172
 
    pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
 
3186
    pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
3173
3187
    table->field[6]->store((const char*) pos,
3174
3188
                           strlen((const char*) pos), cs);
3175
3189
    store_column_type(table, field, cs, 7);
3176
3190
 
3177
 
    pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
 
3191
    pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3178
3192
                 (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3179
3193
                 (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3180
3194
    table->field[15]->store((const char*) pos,
3187
3201
        field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3188
3202
      table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3189
3203
                              cs);
3190
 
    if (field->vcol_info)
3191
 
          table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
 
3204
 
3192
3205
    table->field[18]->store(field->comment.str, field->comment.length, cs);
3193
3206
    {
3194
3207
      enum column_format_type column_format= (enum column_format_type)
3195
3208
        ((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3196
 
      pos=(unsigned char*)"Default";
 
3209
      pos=(uchar*)"Default";
3197
3210
      table->field[19]->store((const char*) pos,
3198
3211
                              strlen((const char*) pos), cs);
3199
 
      pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
 
3212
      pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3200
3213
                   column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3201
3214
                                                             "Dynamic");
3202
3215
      table->field[20]->store((const char*) pos,
3210
3223
 
3211
3224
 
3212
3225
 
3213
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3226
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
3214
3227
{
3215
3228
  CHARSET_INFO **cs;
3216
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3217
 
  Table *table= tables->table;
3218
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3229
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3230
  TABLE *table= tables->table;
 
3231
  CHARSET_INFO *scs= system_charset_info;
3219
3232
 
3220
3233
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3221
3234
  {
3222
 
    const CHARSET_INFO * const tmp_cs= cs[0];
 
3235
    CHARSET_INFO *tmp_cs= cs[0];
3223
3236
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) && 
3224
3237
        (tmp_cs->state & MY_CS_AVAILABLE) &&
3225
3238
        !(tmp_cs->state & MY_CS_HIDDEN) &&
3226
3239
        !(wild && wild[0] &&
3227
 
          wild_case_compare(scs, tmp_cs->csname,wild)))
 
3240
          wild_case_compare(scs, tmp_cs->csname,wild)))
3228
3241
    {
3229
3242
      const char *comment;
3230
3243
      restore_record(table, s->default_values);
3232
3245
      table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3233
3246
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3234
3247
      table->field[2]->store(comment, strlen(comment), scs);
3235
 
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
 
3248
      table->field[3]->store((longlong) tmp_cs->mbmaxlen, TRUE);
3236
3249
      if (schema_table_store_record(thd, table))
3237
3250
        return 1;
3238
3251
    }
3241
3254
}
3242
3255
 
3243
3256
 
3244
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3257
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
3245
3258
{
3246
3259
  CHARSET_INFO **cs;
3247
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3248
 
  Table *table= tables->table;
3249
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3260
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3261
  TABLE *table= tables->table;
 
3262
  CHARSET_INFO *scs= system_charset_info;
3250
3263
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3251
3264
  {
3252
3265
    CHARSET_INFO **cl;
3253
 
    const CHARSET_INFO *tmp_cs= cs[0];
 
3266
    CHARSET_INFO *tmp_cs= cs[0];
3254
3267
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3255
3268
         (tmp_cs->state & MY_CS_HIDDEN) ||
3256
3269
        !(tmp_cs->state & MY_CS_PRIMARY))
3257
3270
      continue;
3258
3271
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3259
3272
    {
3260
 
      const CHARSET_INFO *tmp_cl= cl[0];
 
3273
      CHARSET_INFO *tmp_cl= cl[0];
3261
3274
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
3262
3275
          !my_charset_same(tmp_cs, tmp_cl))
3263
 
        continue;
 
3276
        continue;
3264
3277
      if (!(wild && wild[0] &&
3265
 
          wild_case_compare(scs, tmp_cl->name,wild)))
 
3278
          wild_case_compare(scs, tmp_cl->name,wild)))
3266
3279
      {
3267
 
        const char *tmp_buff;
3268
 
        restore_record(table, s->default_values);
3269
 
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
 
3280
        const char *tmp_buff;
 
3281
        restore_record(table, s->default_values);
 
3282
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3270
3283
        table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3271
 
        table->field[2]->store((int64_t) tmp_cl->number, true);
 
3284
        table->field[2]->store((longlong) tmp_cl->number, TRUE);
3272
3285
        tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3273
 
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
 
3286
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3274
3287
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3275
 
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3276
 
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
 
3288
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
 
3289
        table->field[5]->store((longlong) tmp_cl->strxfrm_multiply, TRUE);
3277
3290
        if (schema_table_store_record(thd, table))
3278
3291
          return 1;
3279
3292
      }
3283
3296
}
3284
3297
 
3285
3298
 
3286
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3299
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
3287
3300
{
3288
3301
  CHARSET_INFO **cs;
3289
 
  Table *table= tables->table;
3290
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3302
  TABLE *table= tables->table;
 
3303
  CHARSET_INFO *scs= system_charset_info;
3291
3304
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3292
3305
  {
3293
3306
    CHARSET_INFO **cl;
3294
 
    const CHARSET_INFO *tmp_cs= cs[0];
 
3307
    CHARSET_INFO *tmp_cs= cs[0];
3295
3308
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || 
3296
3309
        !(tmp_cs->state & MY_CS_PRIMARY))
3297
3310
      continue;
3298
3311
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3299
3312
    {
3300
 
      const CHARSET_INFO *tmp_cl= cl[0];
 
3313
      CHARSET_INFO *tmp_cl= cl[0];
3301
3314
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
3302
3315
          !my_charset_same(tmp_cs,tmp_cl))
3303
3316
        continue;
3312
3325
}
3313
3326
 
3314
3327
 
3315
 
static int get_schema_stat_record(THD *thd, TableList *tables,
3316
 
                                  Table *table, bool res,
 
3328
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
 
3329
                                  TABLE *table, bool res,
3317
3330
                                  LEX_STRING *db_name,
3318
3331
                                  LEX_STRING *table_name)
3319
3332
{
3320
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3333
  CHARSET_INFO *cs= system_charset_info;
3321
3334
  if (res)
3322
3335
  {
3323
3336
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3327
3340
        rather than in SHOW KEYS
3328
3341
      */
3329
3342
      if (thd->is_error())
3330
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3343
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3331
3344
                     thd->main_da.sql_errno(), thd->main_da.message());
3332
3345
      thd->clear_error();
3333
3346
      res= 0;
3336
3349
  }
3337
3350
  else
3338
3351
  {
3339
 
    Table *show_table= tables->table;
 
3352
    TABLE *show_table= tables->table;
3340
3353
    KEY *key_info=show_table->s->key_info;
3341
3354
    if (show_table->file)
3342
3355
      show_table->file->info(HA_STATUS_VARIABLE |
3343
3356
                             HA_STATUS_NO_LOCK |
3344
3357
                             HA_STATUS_TIME);
3345
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
 
3358
    for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3346
3359
    {
3347
3360
      KEY_PART_INFO *key_part= key_info->key_part;
3348
3361
      const char *str;
3349
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3362
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3350
3363
      {
3351
3364
        restore_record(table, s->default_values);
3352
3365
        table->field[1]->store(db_name->str, db_name->length, cs);
3353
3366
        table->field[2]->store(table_name->str, table_name->length, cs);
3354
 
        table->field[3]->store((int64_t) ((key_info->flags &
3355
 
                                            HA_NOSAME) ? 0 : 1), true);
 
3367
        table->field[3]->store((longlong) ((key_info->flags &
 
3368
                                            HA_NOSAME) ? 0 : 1), TRUE);
3356
3369
        table->field[4]->store(db_name->str, db_name->length, cs);
3357
3370
        table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3358
 
        table->field[6]->store((int64_t) (j+1), true);
 
3371
        table->field[6]->store((longlong) (j+1), TRUE);
3359
3372
        str=(key_part->field ? key_part->field->field_name :
3360
3373
             "?unknown field?");
3361
3374
        table->field[7]->store(str, strlen(str), cs);
3373
3386
          {
3374
3387
            ha_rows records=(show_table->file->stats.records /
3375
3388
                             key->rec_per_key[j]);
3376
 
            table->field[9]->store((int64_t) records, true);
 
3389
            table->field[9]->store((longlong) records, TRUE);
3377
3390
            table->field[9]->set_notnull();
3378
3391
          }
3379
3392
          str= show_table->file->index_type(i);
3383
3396
             key_part->length !=
3384
3397
             show_table->s->field[key_part->fieldnr-1]->key_length()))
3385
3398
        {
3386
 
          table->field[10]->store((int64_t) key_part->length /
3387
 
                                  key_part->field->charset()->mbmaxlen, true);
 
3399
          table->field[10]->store((longlong) key_part->length /
 
3400
                                  key_part->field->charset()->mbmaxlen, TRUE);
3388
3401
          table->field[10]->set_notnull();
3389
3402
        }
3390
 
        uint32_t flags= key_part->field ? key_part->field->flags : 0;
 
3403
        uint flags= key_part->field ? key_part->field->flags : 0;
3391
3404
        const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3392
3405
        table->field[12]->store(pos, strlen(pos), cs);
3393
3406
        if (!show_table->s->keys_in_use.is_set(i))
3395
3408
        else
3396
3409
          table->field[14]->store("", 0, cs);
3397
3410
        table->field[14]->set_notnull();
3398
 
        assert(test(key_info->flags & HA_USES_COMMENT) == 
 
3411
        DBUG_ASSERT(test(key_info->flags & HA_USES_COMMENT) == 
3399
3412
                   (key_info->comment.length > 0));
3400
3413
        if (key_info->flags & HA_USES_COMMENT)
3401
3414
          table->field[15]->store(key_info->comment.str, 
3409
3422
}
3410
3423
 
3411
3424
 
3412
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3425
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3413
3426
                       LEX_STRING *table_name, const char *key_name,
3414
 
                       uint32_t key_len, const char *con_type, uint32_t con_len)
 
3427
                       uint key_len, const char *con_type, uint con_len)
3415
3428
{
3416
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3429
  CHARSET_INFO *cs= system_charset_info;
3417
3430
  restore_record(table, s->default_values);
3418
3431
  table->field[1]->store(db_name->str, db_name->length, cs);
3419
3432
  table->field[2]->store(key_name, key_len, cs);
3424
3437
}
3425
3438
 
3426
3439
 
3427
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
3428
 
                                         Table *table, bool res,
 
3440
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
 
3441
                                         TABLE *table, bool res,
3429
3442
                                         LEX_STRING *db_name,
3430
3443
                                         LEX_STRING *table_name)
3431
3444
{
3432
3445
  if (res)
3433
3446
  {
3434
3447
    if (thd->is_error())
3435
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3448
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3436
3449
                   thd->main_da.sql_errno(), thd->main_da.message());
3437
3450
    thd->clear_error();
3438
3451
    return(0);
3440
3453
  else
3441
3454
  {
3442
3455
    List<FOREIGN_KEY_INFO> f_key_list;
3443
 
    Table *show_table= tables->table;
 
3456
    TABLE *show_table= tables->table;
3444
3457
    KEY *key_info=show_table->key_info;
3445
 
    uint32_t primary_key= show_table->s->primary_key;
 
3458
    uint primary_key= show_table->s->primary_key;
3446
3459
    show_table->file->info(HA_STATUS_VARIABLE | 
3447
3460
                           HA_STATUS_NO_LOCK |
3448
3461
                           HA_STATUS_TIME);
3449
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3462
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3450
3463
    {
3451
3464
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3452
3465
        continue;
3483
3496
}
3484
3497
 
3485
3498
 
3486
 
void store_key_column_usage(Table *table, LEX_STRING *db_name,
 
3499
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3487
3500
                            LEX_STRING *table_name, const char *key_name,
3488
 
                            uint32_t key_len, const char *con_type, uint32_t con_len,
3489
 
                            int64_t idx)
 
3501
                            uint key_len, const char *con_type, uint con_len,
 
3502
                            longlong idx)
3490
3503
{
3491
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3504
  CHARSET_INFO *cs= system_charset_info;
3492
3505
  table->field[1]->store(db_name->str, db_name->length, cs);
3493
3506
  table->field[2]->store(key_name, key_len, cs);
3494
3507
  table->field[4]->store(db_name->str, db_name->length, cs);
3495
3508
  table->field[5]->store(table_name->str, table_name->length, cs);
3496
3509
  table->field[6]->store(con_type, con_len, cs);
3497
 
  table->field[7]->store((int64_t) idx, true);
 
3510
  table->field[7]->store((longlong) idx, TRUE);
3498
3511
}
3499
3512
 
3500
3513
 
3501
3514
static int get_schema_key_column_usage_record(THD *thd,
3502
 
                                              TableList *tables,
3503
 
                                              Table *table, bool res,
 
3515
                                              TABLE_LIST *tables,
 
3516
                                              TABLE *table, bool res,
3504
3517
                                              LEX_STRING *db_name,
3505
3518
                                              LEX_STRING *table_name)
3506
3519
{
3507
3520
  if (res)
3508
3521
  {
3509
3522
    if (thd->is_error())
3510
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3523
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3511
3524
                   thd->main_da.sql_errno(), thd->main_da.message());
3512
3525
    thd->clear_error();
3513
3526
    return(0);
3515
3528
  else
3516
3529
  {
3517
3530
    List<FOREIGN_KEY_INFO> f_key_list;
3518
 
    Table *show_table= tables->table;
 
3531
    TABLE *show_table= tables->table;
3519
3532
    KEY *key_info=show_table->key_info;
3520
 
    uint32_t primary_key= show_table->s->primary_key;
 
3533
    uint primary_key= show_table->s->primary_key;
3521
3534
    show_table->file->info(HA_STATUS_VARIABLE | 
3522
3535
                           HA_STATUS_NO_LOCK |
3523
3536
                           HA_STATUS_TIME);
3524
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3537
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3525
3538
    {
3526
3539
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3527
3540
        continue;
3528
 
      uint32_t f_idx= 0;
 
3541
      uint f_idx= 0;
3529
3542
      KEY_PART_INFO *key_part= key_info->key_part;
3530
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3543
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3531
3544
      {
3532
3545
        if (key_part->field)
3533
3546
        {
3538
3551
                                 strlen(key_info->name), 
3539
3552
                                 key_part->field->field_name, 
3540
3553
                                 strlen(key_part->field->field_name),
3541
 
                                 (int64_t) f_idx);
 
3554
                                 (longlong) f_idx);
3542
3555
          if (schema_table_store_record(thd, table))
3543
3556
            return(1);
3544
3557
        }
3554
3567
      LEX_STRING *r_info;
3555
3568
      List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3556
3569
        it1(f_key_info->referenced_fields);
3557
 
      uint32_t f_idx= 0;
 
3570
      uint f_idx= 0;
3558
3571
      while ((f_info= it++))
3559
3572
      {
3560
3573
        r_info= it1++;
3564
3577
                               f_key_info->forein_id->str,
3565
3578
                               f_key_info->forein_id->length,
3566
3579
                               f_info->str, f_info->length,
3567
 
                               (int64_t) f_idx);
3568
 
        table->field[8]->store((int64_t) f_idx, true);
 
3580
                               (longlong) f_idx);
 
3581
        table->field[8]->store((longlong) f_idx, TRUE);
3569
3582
        table->field[8]->set_notnull();
3570
3583
        table->field[9]->store(f_key_info->referenced_db->str,
3571
3584
                               f_key_info->referenced_db->length,
3587
3600
}
3588
3601
 
3589
3602
 
3590
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3603
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
3591
3604
{
3592
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3593
 
  Table *table= tables->table;
3594
 
  const CHARSET_INFO * const cs= system_charset_info;
3595
 
  OPEN_TableList *open_list;
 
3605
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3606
  TABLE *table= tables->table;
 
3607
  CHARSET_INFO *cs= system_charset_info;
 
3608
  OPEN_TABLE_LIST *open_list;
3596
3609
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3597
3610
            && thd->is_fatal_error)
3598
3611
    return(1);
3602
3615
    restore_record(table, s->default_values);
3603
3616
    table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3604
3617
    table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3605
 
    table->field[2]->store((int64_t) open_list->in_use, true);
3606
 
    table->field[3]->store((int64_t) open_list->locked, true);
 
3618
    table->field[2]->store((longlong) open_list->in_use, TRUE);
 
3619
    table->field[3]->store((longlong) open_list->locked, TRUE);
3607
3620
    if (schema_table_store_record(thd, table))
3608
3621
      return(1);
3609
3622
  }
3611
3624
}
3612
3625
 
3613
3626
 
3614
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3627
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
3615
3628
{
3616
3629
  int res= 0;
3617
3630
  LEX *lex= thd->lex;
3618
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3631
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3619
3632
  enum enum_schema_tables schema_table_idx=
3620
3633
    get_schema_table_idx(tables->schema_table);
3621
3634
  enum enum_var_type option_type= OPT_SESSION;
3634
3647
}
3635
3648
 
3636
3649
 
3637
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3650
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((__unused__)))
3638
3651
{
3639
3652
  LEX *lex= thd->lex;
3640
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3653
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3641
3654
  int res= 0;
3642
3655
  STATUS_VAR *tmp1, tmp;
3643
3656
  enum enum_schema_tables schema_table_idx=
3695
3708
*/
3696
3709
 
3697
3710
static int
3698
 
get_referential_constraints_record(THD *thd, TableList *tables,
3699
 
                                   Table *table, bool res,
 
3711
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
 
3712
                                   TABLE *table, bool res,
3700
3713
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3701
3714
{
3702
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3715
  CHARSET_INFO *cs= system_charset_info;
3703
3716
 
3704
3717
  if (res)
3705
3718
  {
3706
3719
    if (thd->is_error())
3707
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3720
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3708
3721
                   thd->main_da.sql_errno(), thd->main_da.message());
3709
3722
    thd->clear_error();
3710
3723
    return(0);
3712
3725
 
3713
3726
  {
3714
3727
    List<FOREIGN_KEY_INFO> f_key_list;
3715
 
    Table *show_table= tables->table;
 
3728
    TABLE *show_table= tables->table;
3716
3729
    show_table->file->info(HA_STATUS_VARIABLE | 
3717
3730
                           HA_STATUS_NO_LOCK |
3718
3731
                           HA_STATUS_TIME);
3772
3785
    0   table not found
3773
3786
    1   found the schema table
3774
3787
*/
3775
 
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
 
3788
static my_bool find_schema_table_in_plugin(THD *thd __attribute__((__unused__)),
3776
3789
                                           plugin_ref plugin,
3777
3790
                                           void* p_table)
3778
3791
{
3819
3832
 
3820
3833
  schema_table_a.table_name= table_name;
3821
3834
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
3822
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
 
3835
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3823
3836
    return(schema_table_a.schema_table);
3824
3837
 
3825
3838
  return(NULL);
3847
3860
  @retval  NULL           Can't create table
3848
3861
*/
3849
3862
 
3850
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3863
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3851
3864
{
3852
3865
  int field_count= 0;
3853
3866
  Item *item;
3854
 
  Table *table;
 
3867
  TABLE *table;
3855
3868
  List<Item> field_list;
3856
3869
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3857
3870
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3858
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3871
  CHARSET_INFO *cs= system_charset_info;
3859
3872
 
3860
3873
  for (; fields_info->field_name; fields_info++)
3861
3874
  {
3862
3875
    switch (fields_info->field_type) {
3863
 
    case DRIZZLE_TYPE_TINY:
3864
 
    case DRIZZLE_TYPE_LONG:
3865
 
    case DRIZZLE_TYPE_LONGLONG:
 
3876
    case MYSQL_TYPE_TINY:
 
3877
    case MYSQL_TYPE_LONG:
 
3878
    case MYSQL_TYPE_SHORT:
 
3879
    case MYSQL_TYPE_LONGLONG:
3866
3880
      if (!(item= new Item_return_int(fields_info->field_name,
3867
3881
                                      fields_info->field_length,
3868
3882
                                      fields_info->field_type,
3872
3886
      }
3873
3887
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3874
3888
      break;
3875
 
    case DRIZZLE_TYPE_NEWDATE:
3876
 
    case DRIZZLE_TYPE_TIME:
3877
 
    case DRIZZLE_TYPE_TIMESTAMP:
3878
 
    case DRIZZLE_TYPE_DATETIME:
 
3889
    case MYSQL_TYPE_NEWDATE:
 
3890
    case MYSQL_TYPE_TIME:
 
3891
    case MYSQL_TYPE_TIMESTAMP:
 
3892
    case MYSQL_TYPE_DATETIME:
3879
3893
      if (!(item=new Item_return_date_time(fields_info->field_name,
3880
3894
                                           fields_info->field_type)))
3881
3895
      {
3882
3896
        return(0);
3883
3897
      }
3884
3898
      break;
3885
 
    case DRIZZLE_TYPE_DOUBLE:
 
3899
    case MYSQL_TYPE_FLOAT:
 
3900
    case MYSQL_TYPE_DOUBLE:
3886
3901
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC, 
3887
3902
                           fields_info->field_length)) == NULL)
3888
3903
        return(NULL);
3889
3904
      break;
3890
 
    case DRIZZLE_TYPE_NEWDECIMAL:
3891
 
      if (!(item= new Item_decimal((int64_t) fields_info->value, false)))
 
3905
    case MYSQL_TYPE_NEWDECIMAL:
 
3906
      if (!(item= new Item_decimal((longlong) fields_info->value, false)))
3892
3907
      {
3893
3908
        return(0);
3894
3909
      }
3902
3917
      item->set_name(fields_info->field_name,
3903
3918
                     strlen(fields_info->field_name), cs);
3904
3919
      break;
3905
 
    case DRIZZLE_TYPE_BLOB:
 
3920
    case MYSQL_TYPE_BLOB:
3906
3921
      if (!(item= new Item_blob(fields_info->field_name,
3907
3922
                                fields_info->field_length)))
3908
3923
      {
3910
3925
      }
3911
3926
      break;
3912
3927
    default:
 
3928
      /* Don't let unimplemented types pass through. Could be a grave error. */
 
3929
      DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
 
3930
 
3913
3931
      if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
3914
3932
      {
3915
3933
        return(0);
3930
3948
  tmp_table_param->schema_table= 1;
3931
3949
  SELECT_LEX *select_lex= thd->lex->current_select;
3932
3950
  if (!(table= create_tmp_table(thd, tmp_table_param,
3933
 
                                field_list, (order_st*) 0, 0, 0, 
 
3951
                                field_list, (ORDER*) 0, 0, 0, 
3934
3952
                                (select_lex->options | thd->options |
3935
3953
                                 TMP_TABLE_ALL_COLUMNS),
3936
3954
                                HA_POS_ERROR, table_list->alias)))
3938
3956
  my_bitmap_map* bitmaps=
3939
3957
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3940
3958
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3941
 
              false);
 
3959
              FALSE);
3942
3960
  table->read_set= &table->def_read_set;
3943
3961
  bitmap_clear_all(table->read_set);
3944
3962
  table_list->schema_table_param= tmp_table_param;
3970
3988
    if (field_info->old_name)
3971
3989
    {
3972
3990
      Item_field *field= new Item_field(context,
3973
 
                                        NULL, NULL, field_info->field_name);
 
3991
                                        NullS, NullS, field_info->field_name);
3974
3992
      if (field)
3975
3993
      {
3976
3994
        field->set_name(field_info->old_name,
3997
4015
    ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3998
4016
    String buffer(tmp,sizeof(tmp), system_charset_info);
3999
4017
    Item_field *field= new Item_field(context,
4000
 
                                      NULL, NULL, field_info->field_name);
 
4018
                                      NullS, NullS, field_info->field_name);
4001
4019
    if (!field || add_item_to_list(thd, field))
4002
4020
      return 1;
4003
4021
    buffer.length(0);
4032
4050
    buffer.append(')');
4033
4051
  }
4034
4052
  Item_field *field= new Item_field(context,
4035
 
                                    NULL, NULL, field_info->field_name);
 
4053
                                    NullS, NullS, field_info->field_name);
4036
4054
  if (add_item_to_list(thd, field))
4037
4055
    return 1;
4038
4056
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4040
4058
  {
4041
4059
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4042
4060
    field_info= &schema_table->fields_info[3];
4043
 
    field= new Item_field(context, NULL, NULL, field_info->field_name);
 
4061
    field= new Item_field(context, NullS, NullS, field_info->field_name);
4044
4062
    if (add_item_to_list(thd, field))
4045
4063
      return 1;
4046
4064
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4065
4083
                               *field_num == 18))
4066
4084
      continue;
4067
4085
    Item_field *field= new Item_field(context,
4068
 
                                      NULL, NULL, field_info->field_name);
 
4086
                                      NullS, NullS, field_info->field_name);
4069
4087
    if (field)
4070
4088
    {
4071
4089
      field->set_name(field_info->old_name,
4090
4108
  {
4091
4109
    field_info= &schema_table->fields_info[*field_num];
4092
4110
    Item_field *field= new Item_field(context,
4093
 
                                      NULL, NULL, field_info->field_name);
 
4111
                                      NullS, NullS, field_info->field_name);
4094
4112
    if (field)
4095
4113
    {
4096
4114
      field->set_name(field_info->old_name,
4118
4136
    1   error
4119
4137
*/
4120
4138
 
4121
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4139
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4122
4140
{
4123
 
  Table *table;
 
4141
  TABLE *table;
4124
4142
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4125
4143
    return(1);
4126
4144
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4161
4179
    }
4162
4180
    List_iterator_fast<Item> it(sel->item_list);
4163
4181
    if (!(transl=
4164
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
 
4182
          (Field_translator*)(thd->stmt_arena->
 
4183
                              alloc(sel->item_list.elements *
4165
4184
                                    sizeof(Field_translator)))))
4166
4185
    {
4167
4186
      return(1);
4229
4248
    executed_place place where I_S table processed
4230
4249
 
4231
4250
  RETURN
4232
 
    false success
4233
 
    true  error
 
4251
    FALSE success
 
4252
    TRUE  error
4234
4253
*/
4235
4254
 
4236
4255
bool get_schema_tables_result(JOIN *join,
4247
4266
    if (!tab->table || !tab->table->pos_in_table_list)
4248
4267
      break;
4249
4268
 
4250
 
    TableList *table_list= tab->table->pos_in_table_list;
 
4269
    TABLE_LIST *table_list= tab->table->pos_in_table_list;
4251
4270
    if (table_list->schema_table)
4252
4271
    {
4253
4272
      bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4308
4327
 
4309
4328
ST_FIELD_INFO schema_fields_info[]=
4310
4329
{
4311
 
  {"CATALOG_NAME", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4312
 
  {"SCHEMA_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4313
 
   SKIP_OPEN_TABLE},
4314
 
  {"DEFAULT_CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4315
 
   SKIP_OPEN_TABLE},
4316
 
  {"DEFAULT_COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4317
 
  {"SQL_PATH", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4318
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4330
  {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4331
  {"SCHEMA_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Database",
 
4332
   SKIP_OPEN_TABLE},
 
4333
  {"DEFAULT_CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0,
 
4334
   SKIP_OPEN_TABLE},
 
4335
  {"DEFAULT_COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4336
  {"SQL_PATH", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4337
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4319
4338
};
4320
4339
 
4321
4340
 
4322
4341
ST_FIELD_INFO tables_fields_info[]=
4323
4342
{
4324
 
  {"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4325
 
  {"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4326
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
 
4343
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4344
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4345
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
4327
4346
   SKIP_OPEN_TABLE},
4328
 
  {"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4329
 
  {"ENGINE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Engine", OPEN_FRM_ONLY},
4330
 
  {"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4347
  {"TABLE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4348
  {"ENGINE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Engine", OPEN_FRM_ONLY},
 
4349
  {"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4331
4350
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Version", OPEN_FRM_ONLY},
4332
 
  {"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4333
 
  {"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4351
  {"ROW_FORMAT", 10, MYSQL_TYPE_STRING, 0, 1, "Row_format", OPEN_FULL_TABLE},
 
4352
  {"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4334
4353
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4335
 
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4354
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 
4336
4355
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4337
 
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4356
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 
4338
4357
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4339
 
  {"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4358
  {"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4340
4359
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4341
 
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 
 
4360
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 
4342
4361
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4343
 
  {"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4362
  {"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4344
4363
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4345
 
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0, 
 
4364
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONGLONG, 0, 
4346
4365
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4347
 
  {"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4348
 
  {"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4349
 
  {"CHECK_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
4350
 
  {"TABLE_COLLATION", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4351
 
  {"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4366
  {"CREATE_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
 
4367
  {"UPDATE_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
 
4368
  {"CHECK_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
 
4369
  {"TABLE_COLLATION", 64, MYSQL_TYPE_STRING, 0, 1, "Collation", OPEN_FRM_ONLY},
 
4370
  {"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4352
4371
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Checksum", OPEN_FULL_TABLE},
4353
 
  {"CREATE_OPTIONS", 255, DRIZZLE_TYPE_VARCHAR, 0, 1, "Create_options",
 
4372
  {"CREATE_OPTIONS", 255, MYSQL_TYPE_STRING, 0, 1, "Create_options",
4354
4373
   OPEN_FRM_ONLY},
4355
 
  {"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4356
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4374
  {"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Comment", OPEN_FRM_ONLY},
 
4375
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4357
4376
};
4358
4377
 
4359
4378
 
4360
4379
ST_FIELD_INFO columns_fields_info[]=
4361
4380
{
4362
 
  {"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4363
 
  {"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4364
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4365
 
  {"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Field",
 
4381
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FRM_ONLY},
 
4382
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4383
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4384
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Field",
4366
4385
   OPEN_FRM_ONLY},
4367
 
  {"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4386
  {"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4368
4387
   MY_I_S_UNSIGNED, 0, OPEN_FRM_ONLY},
4369
 
  {"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, DRIZZLE_TYPE_VARCHAR, 0,
 
4388
  {"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, MYSQL_TYPE_STRING, 0,
4370
4389
   1, "Default", OPEN_FRM_ONLY},
4371
 
  {"IS_NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4372
 
  {"DATA_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4373
 
  {"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4374
 
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4375
 
  {"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4376
 
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4377
 
  {"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4378
 
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4379
 
  {"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4380
 
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4381
 
  {"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4382
 
  {"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4383
 
  {"COLUMN_TYPE", 65535, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", OPEN_FRM_ONLY},
4384
 
  {"COLUMN_KEY", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key", OPEN_FRM_ONLY},
4385
 
  {"EXTRA", 27, DRIZZLE_TYPE_VARCHAR, 0, 0, "Extra", OPEN_FRM_ONLY},
4386
 
  {"PRIVILEGES", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Privileges", OPEN_FRM_ONLY},
4387
 
  {"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4388
 
  {"STORAGE", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Storage", OPEN_FRM_ONLY},
4389
 
  {"FORMAT", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Format", OPEN_FRM_ONLY},
4390
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4390
  {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null", OPEN_FRM_ONLY},
 
4391
  {"DATA_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4392
  {"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG,
 
4393
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4394
  {"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONGLONG,
 
4395
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4396
  {"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG,
 
4397
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4398
  {"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONGLONG,
 
4399
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4400
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FRM_ONLY},
 
4401
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 1, "Collation", OPEN_FRM_ONLY},
 
4402
  {"COLUMN_TYPE", 65535, MYSQL_TYPE_STRING, 0, 0, "Type", OPEN_FRM_ONLY},
 
4403
  {"COLUMN_KEY", 3, MYSQL_TYPE_STRING, 0, 0, "Key", OPEN_FRM_ONLY},
 
4404
  {"EXTRA", 27, MYSQL_TYPE_STRING, 0, 0, "Extra", OPEN_FRM_ONLY},
 
4405
  {"PRIVILEGES", 80, MYSQL_TYPE_STRING, 0, 0, "Privileges", OPEN_FRM_ONLY},
 
4406
  {"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Comment", OPEN_FRM_ONLY},
 
4407
  {"STORAGE", 8, MYSQL_TYPE_STRING, 0, 0, "Storage", OPEN_FRM_ONLY},
 
4408
  {"FORMAT", 8, MYSQL_TYPE_STRING, 0, 0, "Format", OPEN_FRM_ONLY},
 
4409
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4391
4410
};
4392
4411
 
4393
4412
 
4394
4413
ST_FIELD_INFO charsets_fields_info[]=
4395
4414
{
4396
 
  {"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4397
 
   SKIP_OPEN_TABLE},
4398
 
  {"DEFAULT_COLLATE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default collation",
4399
 
   SKIP_OPEN_TABLE},
4400
 
  {"DESCRIPTION", 60, DRIZZLE_TYPE_VARCHAR, 0, 0, "Description",
4401
 
   SKIP_OPEN_TABLE},
4402
 
  {"MAXLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
4403
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4415
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Charset",
 
4416
   SKIP_OPEN_TABLE},
 
4417
  {"DEFAULT_COLLATE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Default collation",
 
4418
   SKIP_OPEN_TABLE},
 
4419
  {"DESCRIPTION", 60, MYSQL_TYPE_STRING, 0, 0, "Description",
 
4420
   SKIP_OPEN_TABLE},
 
4421
  {"MAXLEN", 3, MYSQL_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
 
4422
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4404
4423
};
4405
4424
 
4406
4425
 
4407
4426
ST_FIELD_INFO collation_fields_info[]=
4408
4427
{
4409
 
  {"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Collation", SKIP_OPEN_TABLE},
4410
 
  {"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4411
 
   SKIP_OPEN_TABLE},
4412
 
  {"ID", MY_INT32_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id",
4413
 
   SKIP_OPEN_TABLE},
4414
 
  {"IS_DEFAULT", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default", SKIP_OPEN_TABLE},
4415
 
  {"IS_COMPILED", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Compiled", SKIP_OPEN_TABLE},
4416
 
  {"SORTLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
4417
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4428
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Collation", SKIP_OPEN_TABLE},
 
4429
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Charset",
 
4430
   SKIP_OPEN_TABLE},
 
4431
  {"ID", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Id",
 
4432
   SKIP_OPEN_TABLE},
 
4433
  {"IS_DEFAULT", 3, MYSQL_TYPE_STRING, 0, 0, "Default", SKIP_OPEN_TABLE},
 
4434
  {"IS_COMPILED", 3, MYSQL_TYPE_STRING, 0, 0, "Compiled", SKIP_OPEN_TABLE},
 
4435
  {"SORTLEN", 3, MYSQL_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
 
4436
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4437
};
 
4438
 
 
4439
 
 
4440
ST_FIELD_INFO events_fields_info[]=
 
4441
{
 
4442
  {"EVENT_CATALOG", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4443
  {"EVENT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Db",
 
4444
   SKIP_OPEN_TABLE},
 
4445
  {"EVENT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
 
4446
   SKIP_OPEN_TABLE},
 
4447
  {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, "Definer", SKIP_OPEN_TABLE},
 
4448
  {"TIME_ZONE", 64, MYSQL_TYPE_STRING, 0, 0, "Time zone", SKIP_OPEN_TABLE},
 
4449
  {"EVENT_BODY", 8, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4450
  {"EVENT_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4451
  {"EVENT_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, "Type", SKIP_OPEN_TABLE},
 
4452
  {"EXECUTE_AT", 0, MYSQL_TYPE_DATETIME, 0, 1, "Execute at", SKIP_OPEN_TABLE},
 
4453
  {"INTERVAL_VALUE", 256, MYSQL_TYPE_STRING, 0, 1, "Interval value",
 
4454
   SKIP_OPEN_TABLE},
 
4455
  {"INTERVAL_FIELD", 18, MYSQL_TYPE_STRING, 0, 1, "Interval field",
 
4456
   SKIP_OPEN_TABLE},
 
4457
  {"SQL_MODE", 65535, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4458
  {"STARTS", 0, MYSQL_TYPE_DATETIME, 0, 1, "Starts", SKIP_OPEN_TABLE},
 
4459
  {"ENDS", 0, MYSQL_TYPE_DATETIME, 0, 1, "Ends", SKIP_OPEN_TABLE},
 
4460
  {"STATUS", 18, MYSQL_TYPE_STRING, 0, 0, "Status", SKIP_OPEN_TABLE},
 
4461
  {"ON_COMPLETION", 12, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4462
  {"CREATED", 0, MYSQL_TYPE_DATETIME, 0, 0, 0, SKIP_OPEN_TABLE},
 
4463
  {"LAST_ALTERED", 0, MYSQL_TYPE_DATETIME, 0, 0, 0, SKIP_OPEN_TABLE},
 
4464
  {"LAST_EXECUTED", 0, MYSQL_TYPE_DATETIME, 0, 1, 0, SKIP_OPEN_TABLE},
 
4465
  {"EVENT_COMMENT", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4466
  {"ORIGINATOR", 10, MYSQL_TYPE_LONGLONG, 0, 0, "Originator", SKIP_OPEN_TABLE},
 
4467
  {"CHARACTER_SET_CLIENT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
 
4468
   "character_set_client", SKIP_OPEN_TABLE},
 
4469
  {"COLLATION_CONNECTION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
 
4470
   "collation_connection", SKIP_OPEN_TABLE},
 
4471
  {"DATABASE_COLLATION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
 
4472
   "Database Collation", SKIP_OPEN_TABLE},
 
4473
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4418
4474
};
4419
4475
 
4420
4476
 
4421
4477
 
4422
4478
ST_FIELD_INFO coll_charset_app_fields_info[]=
4423
4479
{
4424
 
  {"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4425
 
  {"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4426
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4480
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4481
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4482
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4427
4483
};
4428
4484
 
4429
4485
 
4430
4486
ST_FIELD_INFO stat_fields_info[]=
4431
4487
{
4432
 
  {"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4433
 
  {"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4434
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", OPEN_FRM_ONLY},
4435
 
  {"NON_UNIQUE", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
4436
 
  {"INDEX_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4437
 
  {"INDEX_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key_name",
4438
 
   OPEN_FRM_ONLY},
4439
 
  {"SEQ_IN_INDEX", 2, DRIZZLE_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
4440
 
  {"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Column_name",
4441
 
   OPEN_FRM_ONLY},
4442
 
  {"COLLATION", 1, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4443
 
  {"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 1,
 
4488
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FRM_ONLY},
 
4489
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4490
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Table", OPEN_FRM_ONLY},
 
4491
  {"NON_UNIQUE", 1, MYSQL_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
 
4492
  {"INDEX_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4493
  {"INDEX_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Key_name",
 
4494
   OPEN_FRM_ONLY},
 
4495
  {"SEQ_IN_INDEX", 2, MYSQL_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
 
4496
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Column_name",
 
4497
   OPEN_FRM_ONLY},
 
4498
  {"COLLATION", 1, MYSQL_TYPE_STRING, 0, 1, "Collation", OPEN_FRM_ONLY},
 
4499
  {"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 1,
4444
4500
   "Cardinality", OPEN_FULL_TABLE},
4445
 
  {"SUB_PART", 3, DRIZZLE_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
4446
 
  {"PACKED", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Packed", OPEN_FRM_ONLY},
4447
 
  {"NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4448
 
  {"INDEX_TYPE", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_type", OPEN_FULL_TABLE},
4449
 
  {"COMMENT", 16, DRIZZLE_TYPE_VARCHAR, 0, 1, "Comment", OPEN_FRM_ONLY},
4450
 
  {"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
4451
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4501
  {"SUB_PART", 3, MYSQL_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
 
4502
  {"PACKED", 10, MYSQL_TYPE_STRING, 0, 1, "Packed", OPEN_FRM_ONLY},
 
4503
  {"NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null", OPEN_FRM_ONLY},
 
4504
  {"INDEX_TYPE", 16, MYSQL_TYPE_STRING, 0, 0, "Index_type", OPEN_FULL_TABLE},
 
4505
  {"COMMENT", 16, MYSQL_TYPE_STRING, 0, 1, "Comment", OPEN_FRM_ONLY},
 
4506
  {"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
 
4507
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4508
};
 
4509
 
 
4510
 
 
4511
ST_FIELD_INFO user_privileges_fields_info[]=
 
4512
{
 
4513
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4514
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4515
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4516
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4517
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4518
};
 
4519
 
 
4520
 
 
4521
ST_FIELD_INFO schema_privileges_fields_info[]=
 
4522
{
 
4523
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4524
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4525
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4526
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4527
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4528
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4529
};
 
4530
 
 
4531
 
 
4532
ST_FIELD_INFO table_privileges_fields_info[]=
 
4533
{
 
4534
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4535
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4536
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4537
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4538
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4539
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4540
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4541
};
 
4542
 
 
4543
 
 
4544
ST_FIELD_INFO column_privileges_fields_info[]=
 
4545
{
 
4546
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4547
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4548
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4549
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4550
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4551
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4552
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4553
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4452
4554
};
4453
4555
 
4454
4556
 
4455
4557
ST_FIELD_INFO table_constraints_fields_info[]=
4456
4558
{
4457
 
  {"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4458
 
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4459
 
   OPEN_FULL_TABLE},
4460
 
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4461
 
   OPEN_FULL_TABLE},
4462
 
  {"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4463
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4464
 
  {"CONSTRAINT_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4465
 
   OPEN_FULL_TABLE},
4466
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4559
  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4560
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4561
   OPEN_FULL_TABLE},
 
4562
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4563
   OPEN_FULL_TABLE},
 
4564
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4565
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4566
  {"CONSTRAINT_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4567
   OPEN_FULL_TABLE},
 
4568
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4467
4569
};
4468
4570
 
4469
4571
 
4470
4572
ST_FIELD_INFO key_column_usage_fields_info[]=
4471
4573
{
4472
 
  {"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4473
 
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4474
 
   OPEN_FULL_TABLE},
4475
 
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4476
 
   OPEN_FULL_TABLE},
4477
 
  {"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4478
 
  {"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4479
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4480
 
  {"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4481
 
  {"ORDINAL_POSITION", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
4482
 
  {"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 1, 0,
4483
 
   OPEN_FULL_TABLE},
4484
 
  {"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4485
 
   OPEN_FULL_TABLE},
4486
 
  {"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4487
 
   OPEN_FULL_TABLE},
4488
 
  {"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4489
 
   OPEN_FULL_TABLE},
4490
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4574
  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4575
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4576
   OPEN_FULL_TABLE},
 
4577
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4578
   OPEN_FULL_TABLE},
 
4579
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4580
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4581
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4582
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4583
  {"ORDINAL_POSITION", 10 ,MYSQL_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
 
4584
  {"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,MYSQL_TYPE_LONGLONG, 0, 1, 0,
 
4585
   OPEN_FULL_TABLE},
 
4586
  {"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4587
   OPEN_FULL_TABLE},
 
4588
  {"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4589
   OPEN_FULL_TABLE},
 
4590
  {"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4591
   OPEN_FULL_TABLE},
 
4592
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4491
4593
};
4492
4594
 
4493
4595
 
4494
4596
ST_FIELD_INFO table_names_fields_info[]=
4495
4597
{
4496
 
  {"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4497
 
  {"TABLE_SCHEMA",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4498
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Tables_in_",
 
4598
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4599
  {"TABLE_SCHEMA",NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4600
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Tables_in_",
4499
4601
   SKIP_OPEN_TABLE},
4500
 
  {"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table_type",
 
4602
  {"TABLE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_type",
4501
4603
   OPEN_FRM_ONLY},
4502
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4604
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4503
4605
};
4504
4606
 
4505
4607
 
4506
4608
ST_FIELD_INFO open_tables_fields_info[]=
4507
4609
{
4508
 
  {"Database", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
 
4610
  {"Database", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Database",
4509
4611
   SKIP_OPEN_TABLE},
4510
 
  {"Table",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", SKIP_OPEN_TABLE},
4511
 
  {"In_use", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
4512
 
  {"Name_locked", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
4513
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4612
  {"Table",NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Table", SKIP_OPEN_TABLE},
 
4613
  {"In_use", 1, MYSQL_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
 
4614
  {"Name_locked", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
 
4615
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4514
4616
};
4515
4617
 
4516
4618
 
4517
4619
ST_FIELD_INFO variables_fields_info[]=
4518
4620
{
4519
 
  {"VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
 
4621
  {"VARIABLE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Variable_name",
4520
4622
   SKIP_OPEN_TABLE},
4521
 
  {"VARIABLE_VALUE", 16300, DRIZZLE_TYPE_VARCHAR, 0, 1, "Value", SKIP_OPEN_TABLE},
4522
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4623
  {"VARIABLE_VALUE", 16300, MYSQL_TYPE_STRING, 0, 1, "Value", SKIP_OPEN_TABLE},
 
4624
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4523
4625
};
4524
4626
 
4525
4627
 
4526
4628
ST_FIELD_INFO processlist_fields_info[]=
4527
4629
{
4528
 
  {"ID", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
4529
 
  {"USER", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "User", SKIP_OPEN_TABLE},
4530
 
  {"HOST", LIST_PROCESS_HOST_LEN,  DRIZZLE_TYPE_VARCHAR, 0, 0, "Host",
4531
 
   SKIP_OPEN_TABLE},
4532
 
  {"DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Db", SKIP_OPEN_TABLE},
4533
 
  {"COMMAND", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Command", SKIP_OPEN_TABLE},
4534
 
  {"TIME", 7, DRIZZLE_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
4535
 
  {"STATE", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "State", SKIP_OPEN_TABLE},
4536
 
  {"INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR, 0, 1, "Info",
4537
 
   SKIP_OPEN_TABLE},
4538
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4630
  {"ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
 
4631
  {"USER", 16, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE},
 
4632
  {"HOST", LIST_PROCESS_HOST_LEN,  MYSQL_TYPE_STRING, 0, 0, "Host",
 
4633
   SKIP_OPEN_TABLE},
 
4634
  {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Db", SKIP_OPEN_TABLE},
 
4635
  {"COMMAND", 16, MYSQL_TYPE_STRING, 0, 0, "Command", SKIP_OPEN_TABLE},
 
4636
  {"TIME", 7, MYSQL_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
 
4637
  {"STATE", 64, MYSQL_TYPE_STRING, 0, 1, "State", SKIP_OPEN_TABLE},
 
4638
  {"INFO", PROCESS_LIST_INFO_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info",
 
4639
   SKIP_OPEN_TABLE},
 
4640
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4539
4641
};
4540
4642
 
4541
4643
 
4542
4644
ST_FIELD_INFO plugin_fields_info[]=
4543
4645
{
4544
 
  {"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name", 
4545
 
   SKIP_OPEN_TABLE},
4546
 
  {"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4547
 
  {"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4548
 
  {"PLUGIN_TYPE", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", SKIP_OPEN_TABLE},
4549
 
  {"PLUGIN_LIBRARY", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Library",
4550
 
   SKIP_OPEN_TABLE},
4551
 
  {"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4552
 
  {"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4553
 
  {"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4554
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4646
  {"PLUGIN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
 
4647
   SKIP_OPEN_TABLE},
 
4648
  {"PLUGIN_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4649
  {"PLUGIN_STATUS", 10, MYSQL_TYPE_STRING, 0, 0, "Status", SKIP_OPEN_TABLE},
 
4650
  {"PLUGIN_TYPE", 80, MYSQL_TYPE_STRING, 0, 0, "Type", SKIP_OPEN_TABLE},
 
4651
  {"PLUGIN_TYPE_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4652
  {"PLUGIN_LIBRARY", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Library",
 
4653
   SKIP_OPEN_TABLE},
 
4654
  {"PLUGIN_LIBRARY_VERSION", 20, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4655
  {"PLUGIN_AUTHOR", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4656
  {"PLUGIN_DESCRIPTION", 65535, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4657
  {"PLUGIN_LICENSE", 80, MYSQL_TYPE_STRING, 0, 1, "License", SKIP_OPEN_TABLE},
 
4658
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4555
4659
};
4556
4660
 
4557
4661
ST_FIELD_INFO referential_constraints_fields_info[]=
4558
4662
{
4559
 
  {"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4560
 
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4561
 
   OPEN_FULL_TABLE},
4562
 
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4563
 
   OPEN_FULL_TABLE},
4564
 
  {"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4565
 
   OPEN_FULL_TABLE},
4566
 
  {"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4567
 
   OPEN_FULL_TABLE},
4568
 
  {"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0,
 
4663
  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4664
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4665
   OPEN_FULL_TABLE},
 
4666
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4667
   OPEN_FULL_TABLE},
 
4668
  {"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4669
   OPEN_FULL_TABLE},
 
4670
  {"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4671
   OPEN_FULL_TABLE},
 
4672
  {"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0,
4569
4673
   MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE},
4570
 
  {"MATCH_OPTION", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4571
 
  {"UPDATE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4572
 
  {"DELETE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4573
 
  {"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4574
 
  {"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
 
4674
  {"MATCH_OPTION", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4675
  {"UPDATE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4676
  {"DELETE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4677
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4678
  {"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
4575
4679
   OPEN_FULL_TABLE},
4576
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4680
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4681
};
 
4682
 
 
4683
 
 
4684
ST_FIELD_INFO parameters_fields_info[]=
 
4685
{
 
4686
  {"SPECIFIC_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4687
  {"SPECIFIC_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4688
  {"SPECIFIC_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4689
  {"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0, OPEN_FULL_TABLE},
 
4690
  {"PARAMETER_MODE", 5, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4691
  {"PARAMETER_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4692
  {"DATA_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4693
  {"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4694
  {"CHARACTER_OCTET_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4695
  {"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4696
  {"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4697
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4698
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4699
  {"DTD_IDENTIFIER", 65535, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4700
  {"ROUTINE_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4701
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}
4577
4702
};
4578
4703
 
4579
4704
 
4594
4719
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4595
4720
  {"COLUMNS", columns_fields_info, create_schema_table, 
4596
4721
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4597
 
   OPTIMIZE_I_S_TABLE},
 
4722
   OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4598
4723
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4599
4724
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4600
4725
  {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4661
4786
 
4662
4787
    if (plugin->plugin->init(schema_table))
4663
4788
    {
4664
 
      sql_print_error(_("Plugin '%s' init function returned error."),
 
4789
      sql_print_error("Plugin '%s' init function returned error.",
4665
4790
                      plugin->name.str);
4666
4791
      goto err;
4667
4792
    }
4672
4797
 
4673
4798
  return(0);
4674
4799
err:
4675
 
  free(schema_table);
 
4800
  my_free(schema_table, MYF(0));
4676
4801
  return(1);
4677
4802
}
4678
4803
 
4681
4806
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4682
4807
 
4683
4808
  if (schema_table && plugin->plugin->deinit)
4684
 
    free(schema_table);
 
4809
    my_free(schema_table, MYF(0));
4685
4810
 
4686
4811
  return(0);
4687
4812
}