~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

  • Committer: Monty Taylor
  • Date: 2008-07-05 18:10:38 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705181038-0ih0nnamu5qrut0y
Fixed prototypes. Cleaned define a little bit.

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;
 
38
  DBUG_ENTER("wild_case_compare");
 
39
  DBUG_PRINT("enter",("str: '%s'  wildstr: '%s'",str,wildstr));
43
40
  while (*wildstr)
44
41
  {
45
42
    while (*wildstr && *wildstr != wild_many && *wildstr != wild_one)
46
43
    {
47
44
      if (*wildstr == wild_prefix && wildstr[1])
48
 
        wildstr++;
49
 
      if (my_toupper(cs, *wildstr++) != my_toupper(cs, *str++))
50
 
        return(1);
 
45
        wildstr++;
 
46
      if (my_toupper(cs, *wildstr++) !=
 
47
          my_toupper(cs, *str++)) DBUG_RETURN(1);
51
48
    }
52
 
    if (! *wildstr )
53
 
      return (*str != 0);
 
49
    if (! *wildstr ) DBUG_RETURN (*str != 0);
54
50
    if (*wildstr++ == wild_one)
55
51
    {
56
 
      if (! *str++)
57
 
        return (1);     /* One char; skip */
 
52
      if (! *str++) DBUG_RETURN (1);    /* One char; skip */
58
53
    }
59
54
    else
60
55
    {                                           /* Found '*' */
61
 
      if (!*wildstr)
62
 
        return(0);              /* '*' as last char: OK */
 
56
      if (!*wildstr) DBUG_RETURN(0);            /* '*' as last char: OK */
63
57
      flag=(*wildstr != wild_many && *wildstr != wild_one);
64
58
      do
65
59
      {
71
65
          cmp=my_toupper(cs, cmp);
72
66
          while (*str && my_toupper(cs, *str) != cmp)
73
67
            str++;
74
 
    if (!*str)
75
 
      return (1);
 
68
          if (!*str) DBUG_RETURN (1);
76
69
        }
77
 
  if (wild_case_compare(cs, str,wildstr) == 0)
78
 
      return (0);
 
70
        if (wild_case_compare(cs, str,wildstr) == 0) DBUG_RETURN (0);
79
71
      } while (*str++);
80
 
      return(1);
 
72
      DBUG_RETURN(1);
81
73
    }
82
74
  }
83
 
  return (*str != '\0');
 
75
  DBUG_RETURN (*str != '\0');
84
76
}
85
77
 
86
78
/***************************************************************************
87
79
** List all table types supported
88
80
***************************************************************************/
89
81
 
90
 
static bool show_plugins(THD *thd, plugin_ref plugin,
 
82
static int make_version_string(char *buf, int buf_length, uint version)
 
83
{
 
84
  return my_snprintf(buf, buf_length, "%d.%d", version>>8,version&0xff);
 
85
}
 
86
 
 
87
static my_bool show_plugins(THD *thd, plugin_ref plugin,
91
88
                            void *arg)
92
89
{
93
 
  Table *table= (Table*) arg;
 
90
  TABLE *table= (TABLE*) arg;
94
91
  struct st_mysql_plugin *plug= plugin_decl(plugin);
95
92
  struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
96
 
  const CHARSET_INFO * const cs= system_charset_info;
 
93
  CHARSET_INFO *cs= system_charset_info;
 
94
  char version_buf[20];
97
95
 
98
96
  restore_record(table, s->default_values);
99
97
 
100
98
  table->field[0]->store(plugin_name(plugin)->str,
101
99
                         plugin_name(plugin)->length, cs);
102
100
 
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();
 
101
  table->field[1]->store(version_buf,
 
102
        make_version_string(version_buf, sizeof(version_buf), plug->version),
 
103
        cs);
 
104
 
110
105
 
111
106
  switch (plugin_state(plugin)) {
112
107
  /* case PLUGIN_IS_FREED: does not happen */
120
115
    table->field[2]->store(STRING_WITH_LEN("ACTIVE"), cs);
121
116
    break;
122
117
  default:
123
 
    assert(0);
 
118
    DBUG_ASSERT(0);
124
119
  }
125
120
 
126
121
  table->field[3]->store(plugin_type_names[plug->type].str,
127
122
                         plugin_type_names[plug->type].length,
128
123
                         cs);
 
124
  table->field[4]->store(version_buf,
 
125
        make_version_string(version_buf, sizeof(version_buf),
 
126
                            *(uint *)plug->info), cs);
129
127
 
130
128
  if (plugin_dl)
131
129
  {
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);
 
130
    table->field[5]->store(plugin_dl->dl.str, plugin_dl->dl.length, cs);
143
131
    table->field[5]->set_notnull();
 
132
    table->field[6]->store(version_buf,
 
133
          make_version_string(version_buf, sizeof(version_buf),
 
134
                              plugin_dl->version),
 
135
          cs);
 
136
    table->field[6]->set_notnull();
144
137
  }
145
138
  else
 
139
  {
146
140
    table->field[5]->set_null();
 
141
    table->field[6]->set_null();
 
142
  }
 
143
 
 
144
 
 
145
  if (plug->author)
 
146
  {
 
147
    table->field[7]->store(plug->author, strlen(plug->author), cs);
 
148
    table->field[7]->set_notnull();
 
149
  }
 
150
  else
 
151
    table->field[7]->set_null();
147
152
 
148
153
  if (plug->descr)
149
154
  {
150
 
    table->field[6]->store(plug->descr, strlen(plug->descr), cs);
151
 
    table->field[6]->set_notnull();
 
155
    table->field[8]->store(plug->descr, strlen(plug->descr), cs);
 
156
    table->field[8]->set_notnull();
152
157
  }
153
158
  else
154
 
    table->field[6]->set_null();
 
159
    table->field[8]->set_null();
155
160
 
156
161
  switch (plug->license) {
157
162
  case PLUGIN_LICENSE_GPL:
158
 
    table->field[7]->store(PLUGIN_LICENSE_GPL_STRING, 
 
163
    table->field[9]->store(PLUGIN_LICENSE_GPL_STRING, 
159
164
                           strlen(PLUGIN_LICENSE_GPL_STRING), cs);
160
165
    break;
161
166
  case PLUGIN_LICENSE_BSD:
162
 
    table->field[7]->store(PLUGIN_LICENSE_BSD_STRING, 
 
167
    table->field[9]->store(PLUGIN_LICENSE_BSD_STRING, 
163
168
                           strlen(PLUGIN_LICENSE_BSD_STRING), cs);
164
169
    break;
165
170
  default:
166
 
    table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING, 
 
171
    table->field[9]->store(PLUGIN_LICENSE_PROPRIETARY_STRING, 
167
172
                           strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
168
173
    break;
169
174
  }
170
 
  table->field[7]->set_notnull();
 
175
  table->field[9]->set_notnull();
171
176
 
172
177
  return schema_table_store_record(thd, table);
173
178
}
174
179
 
175
180
 
176
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
181
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond)
177
182
{
178
 
  Table *table= tables->table;
 
183
  DBUG_ENTER("fill_plugins");
 
184
  TABLE *table= tables->table;
179
185
 
180
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
186
  if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
181
187
                               ~PLUGIN_IS_FREED, table))
182
 
    return(1);
 
188
    DBUG_RETURN(1);
183
189
 
184
 
  return(0);
 
190
  DBUG_RETURN(0);
185
191
}
186
192
 
187
193
 
192
198
    find_files()
193
199
    thd                 thread handler
194
200
    files               put found files in this list
195
 
    db                  database name to set in TableList structure
 
201
    db                  database name to set in TABLE_LIST structure
196
202
    path                path to database
197
203
    wild                filter for found files
198
 
    dir                 read databases in path if true, read .frm files in
 
204
    dir                 read databases in path if TRUE, read .frm files in
199
205
                        database otherwise
200
206
 
201
207
  RETURN
209
215
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
210
216
           const char *path, const char *wild, bool dir)
211
217
{
212
 
  uint32_t i;
 
218
  uint i;
213
219
  char *ext;
214
220
  MY_DIR *dirp;
215
221
  FILEINFO *file;
216
222
  LEX_STRING *file_name= 0;
217
 
  uint32_t file_name_len;
218
 
  TableList table_list;
 
223
  uint file_name_len;
 
224
  TABLE_LIST table_list;
 
225
  DBUG_ENTER("find_files");
219
226
 
220
227
  if (wild && !wild[0])
221
228
    wild=0;
222
229
 
223
 
  memset(&table_list, 0, sizeof(table_list));
 
230
  bzero((char*) &table_list,sizeof(table_list));
224
231
 
225
232
  if (!(dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0))))
226
233
  {
228
235
      my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db);
229
236
    else
230
237
      my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
231
 
    return(FIND_FILES_DIR);
 
238
    DBUG_RETURN(FIND_FILES_DIR);
232
239
  }
233
240
 
234
241
  for (i=0 ; i < (uint) dirp->number_off_files  ; i++)
250
257
        char *end;
251
258
        *ext=0;                                 /* Remove extension */
252
259
        unpack_dirname(buff, file->name);
253
 
        end= strchr(buff, '\0');
 
260
        end= strend(buff);
254
261
        if (end != buff && end[-1] == FN_LIBCHAR)
255
262
          end[-1]= 0;                           // Remove end FN_LIBCHAR
256
263
        if (stat(buff, file->mystat))
257
264
               continue;
258
265
       }
259
266
#endif
260
 
      if (!S_ISDIR(file->mystat->st_mode))
 
267
      if (!MY_S_ISDIR(file->mystat->st_mode))
261
268
        continue;
262
269
 
263
270
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
264
271
      if (wild && wild_compare(uname, wild, 0))
265
272
        continue;
266
273
      if (!(file_name= 
267
 
            thd->make_lex_string(file_name, uname, file_name_len, true)))
 
274
            thd->make_lex_string(file_name, uname, file_name_len, TRUE)))
268
275
      {
269
276
        my_dirend(dirp);
270
 
        return(FIND_FILES_OOM);
 
277
        DBUG_RETURN(FIND_FILES_OOM);
271
278
      }
272
279
    }
273
280
    else
290
297
      }
291
298
    }
292
299
    if (!(file_name= 
293
 
          thd->make_lex_string(file_name, uname, file_name_len, true)) ||
 
300
          thd->make_lex_string(file_name, uname, file_name_len, TRUE)) ||
294
301
        files->push_back(file_name))
295
302
    {
296
303
      my_dirend(dirp);
297
 
      return(FIND_FILES_OOM);
 
304
      DBUG_RETURN(FIND_FILES_OOM);
298
305
    }
299
306
  }
 
307
  DBUG_PRINT("info",("found: %d files", files->elements));
300
308
  my_dirend(dirp);
301
309
 
302
 
  return(FIND_FILES_OK);
 
310
  DBUG_RETURN(FIND_FILES_OK);
303
311
}
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];
311
319
  String buffer(buff, sizeof(buff), system_charset_info);
 
320
  DBUG_ENTER("mysqld_show_create");
 
321
  DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
 
322
                      table_list->table_name));
312
323
 
313
324
  /* Only one table for now, but VIEW can involve several tables */
314
325
  if (open_normal_and_derived_tables(thd, table_list, 0))
315
326
  {
316
327
    if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
317
 
      return(true);
 
328
      DBUG_RETURN(TRUE);
318
329
 
319
330
    /*
320
331
      Clear all messages with 'error' level status and
321
332
      issue a warning with 'warning' level status in 
322
333
      case of invalid view and last error is ER_VIEW_INVALID
323
334
    */
324
 
    drizzle_reset_errors(thd, true);
 
335
    mysql_reset_errors(thd, true);
325
336
    thd->clear_error();
326
337
  }
327
338
 
328
339
  buffer.length(0);
329
340
 
330
341
  if (store_create_info(thd, table_list, &buffer, NULL))
331
 
    return(true);
 
342
    DBUG_RETURN(TRUE);
332
343
 
333
344
  List<Item> field_list;
334
345
  {
335
346
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
336
347
    // 1024 is for not to confuse old clients
337
348
    field_list.push_back(new Item_empty_string("Create Table",
338
 
                                               cmax(buffer.length(),(uint32_t)1024)));
 
349
                                               max(buffer.length(),1024)));
339
350
  }
340
351
 
341
352
  if (protocol->send_fields(&field_list,
342
353
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
343
 
    return(true);
 
354
    DBUG_RETURN(TRUE);
344
355
  protocol->prepare_for_resend();
345
356
  {
346
357
    if (table_list->schema_table)
353
364
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
354
365
 
355
366
  if (protocol->write())
356
 
    return(true);
 
367
    DBUG_RETURN(TRUE);
357
368
 
358
369
  my_eof(thd);
359
 
  return(false);
 
370
  DBUG_RETURN(FALSE);
360
371
}
361
372
 
362
373
bool mysqld_show_create_db(THD *thd, char *dbname,
365
376
  char buff[2048];
366
377
  String buffer(buff, sizeof(buff), system_charset_info);
367
378
  Protocol *protocol=thd->protocol;
 
379
  DBUG_ENTER("mysql_show_create_db");
368
380
 
369
381
  if (store_db_create_info(thd, dbname, &buffer, create_info))
370
382
  {
373
385
      can fail is incorrect database name (which is the case now).
374
386
    */
375
387
    my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
376
 
    return(true);    
 
388
    DBUG_RETURN(TRUE);    
377
389
  }
378
390
 
379
391
  List<Item> field_list;
382
394
 
383
395
  if (protocol->send_fields(&field_list,
384
396
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
385
 
    return(true);
 
397
    DBUG_RETURN(TRUE);
386
398
 
387
399
  protocol->prepare_for_resend();
388
400
  protocol->store(dbname, strlen(dbname), system_charset_info);
389
401
  protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
390
402
 
391
403
  if (protocol->write())
392
 
    return(true);
 
404
    DBUG_RETURN(TRUE);
393
405
  my_eof(thd);
394
 
  return(false);
 
406
  DBUG_RETURN(FALSE);
395
407
}
396
408
 
397
409
 
402
414
****************************************************************************/
403
415
 
404
416
void
405
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
417
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
406
418
{
407
 
  Table *table;
 
419
  TABLE *table;
 
420
  DBUG_ENTER("mysqld_list_fields");
 
421
  DBUG_PRINT("enter",("table: %s",table_list->table_name));
408
422
 
409
423
  if (open_normal_and_derived_tables(thd, table_list, 0))
410
 
    return;
 
424
    DBUG_VOID_RETURN;
411
425
  table= table_list->table;
412
426
 
413
427
  List<Item> field_list;
424
438
  restore_record(table, s->default_values);              // Get empty record
425
439
  table->use_all_columns();
426
440
  if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
427
 
    return;
 
441
    DBUG_VOID_RETURN;
428
442
  my_eof(thd);
429
 
  return;
 
443
  DBUG_VOID_RETURN;
430
444
}
431
445
 
432
446
 
444
458
    0   No conflicting character
445
459
*/
446
460
 
447
 
static const char *require_quotes(const char *name, uint32_t name_length)
 
461
static const char *require_quotes(const char *name, uint name_length)
448
462
{
449
 
  uint32_t length;
450
 
  bool pure_digit= true;
 
463
  uint length;
 
464
  bool pure_digit= TRUE;
451
465
  const char *end= name + name_length;
452
466
 
453
467
  for (; name < end ; name++)
454
468
  {
455
 
    unsigned char chr= (unsigned char) *name;
 
469
    uchar chr= (uchar) *name;
456
470
    length= my_mbcharlen(system_charset_info, chr);
457
471
    if (length == 1 && !system_charset_info->ident_map[chr])
458
472
      return name;
459
473
    if (length == 1 && (chr < '0' || chr > '9'))
460
 
      pure_digit= false;
 
474
      pure_digit= FALSE;
461
475
  }
462
476
  if (pure_digit)
463
477
    return name;
478
492
*/
479
493
 
480
494
void
481
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
 
495
append_identifier(THD *thd, String *packet, const char *name, uint length)
482
496
{
483
497
  const char *name_end;
484
498
  char quote_char;
495
509
   it's a keyword
496
510
  */
497
511
 
498
 
  packet->reserve(length*2 + 2);
 
512
  VOID(packet->reserve(length*2 + 2));
499
513
  quote_char= (char) q;
500
514
  packet->append(&quote_char, 1, system_charset_info);
501
515
 
502
516
  for (name_end= name+length ; name < name_end ; name+= length)
503
517
  {
504
 
    unsigned char chr= (unsigned char) *name;
 
518
    uchar chr= (uchar) *name;
505
519
    length= my_mbcharlen(system_charset_info, chr);
506
520
    /*
507
521
      my_mbcharlen can return 0 on a wrong multibyte
512
526
    */
513
527
    if (!length)
514
528
      length= 1;
515
 
    if (length == 1 && chr == (unsigned char) quote_char)
 
529
    if (length == 1 && chr == (uchar) quote_char)
516
530
      packet->append(&quote_char, 1, system_charset_info);
517
531
    packet->append(name, length, system_charset_info);
518
532
  }
543
557
    #     Quote character
544
558
*/
545
559
 
546
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
560
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
547
561
{
548
562
  if (length &&
549
563
      !is_keyword(name,length) &&
550
564
      !require_quotes(name, length) &&
551
565
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
552
566
    return EOF;
553
 
  return '`';
 
567
  return '"';
554
568
}
555
569
 
556
570
 
557
571
/* Append directory name (if exists) to CREATE INFO */
558
572
 
559
 
static void append_directory(THD *thd __attribute__((unused)),
560
 
                             String *packet, const char *dir_type,
 
573
static void append_directory(THD *thd, String *packet, const char *dir_type,
561
574
                             const char *filename)
562
575
{
563
576
  if (filename)
564
577
  {
565
 
    uint32_t length= dirname_length(filename);
 
578
    uint length= dirname_length(filename);
566
579
    packet->append(' ');
567
580
    packet->append(dir_type);
568
581
    packet->append(STRING_WITH_LEN(" DIRECTORY='"));
574
587
 
575
588
#define LIST_PROCESS_HOST_LEN 64
576
589
 
577
 
static bool get_field_default_value(THD *thd __attribute__((unused)),
578
 
                                    Field *timestamp_field,
 
590
static bool get_field_default_value(THD *thd, Field *timestamp_field,
579
591
                                    Field *field, String *def_value,
580
592
                                    bool quoted)
581
593
{
589
601
  has_now_default= (timestamp_field == field &&
590
602
                    field->unireg_check != Field::TIMESTAMP_UN_FIELD);
591
603
    
592
 
  has_default= (field->type() != DRIZZLE_TYPE_BLOB &&
 
604
  has_default= (field->type() != FIELD_TYPE_BLOB &&
593
605
                !(field->flags & NO_DEFAULT_VALUE_FLAG) &&
594
606
                field->unireg_check != Field::NEXT_NUMBER
595
607
                  && has_now_default);
607
619
      if (type.length())
608
620
      {
609
621
        String def_val;
610
 
        uint32_t dummy_errors;
 
622
        uint dummy_errors;
611
623
        /* convert to system_charset_info == utf8 */
612
624
        def_val.copy(type.ptr(), type.length(), field->charset(),
613
625
                     system_charset_info, &dummy_errors);
651
663
    0       OK
652
664
 */
653
665
 
654
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
666
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
655
667
                      HA_CREATE_INFO *create_info_arg)
656
668
{
657
669
  List<Item> field_list;
658
 
  char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
 
670
  char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
659
671
  const char *alias;
660
 
  std::string buff;
661
672
  String type(tmp, sizeof(tmp), system_charset_info);
662
673
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
663
674
  Field **ptr,*field;
664
 
  uint32_t primary_key;
 
675
  uint primary_key;
665
676
  KEY *key_info;
666
 
  Table *table= table_list->table;
 
677
  TABLE *table= table_list->table;
667
678
  handler *file= table->file;
668
679
  TABLE_SHARE *share= table->s;
669
680
  HA_CREATE_INFO create_info;
670
 
  bool show_table_options= false;
 
681
  bool show_table_options= FALSE;
671
682
  my_bitmap_map *old_map;
 
683
  DBUG_ENTER("store_create_info");
 
684
  DBUG_PRINT("enter",("table: %s", table->s->table_name.str));
672
685
 
673
686
  restore_record(table, s->default_values); // Get empty record
674
687
 
697
710
    We have to restore the read_set if we are called from insert in case
698
711
    of row based replication.
699
712
  */
700
 
  old_map= table->use_all_columns(table->read_set);
 
713
  old_map= tmp_use_all_columns(table, table->read_set);
701
714
 
702
715
  for (ptr=table->field ; (field= *ptr); ptr++)
703
716
  {
704
 
    uint32_t flags = field->flags;
 
717
    uint flags = field->flags;
705
718
 
706
719
    if (ptr != table->field)
707
720
      packet->append(STRING_WITH_LEN(",\n"));
715
728
    else
716
729
      type.set_charset(system_charset_info);
717
730
 
718
 
    if (field->vcol_info)
719
 
    {
720
 
      packet->append(STRING_WITH_LEN("VIRTUAL "));
721
 
    }
722
 
 
723
731
    field->sql_type(type);
724
732
    packet->append(type.ptr(), type.length(), system_charset_info);
725
733
 
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
734
    if (field->has_charset())
738
735
    {
739
736
      if (field->charset() != share->table_charset)
754
751
 
755
752
    if (flags & NOT_NULL_FLAG)
756
753
      packet->append(STRING_WITH_LEN(" NOT NULL"));
757
 
    else if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
 
754
    else if (field->type() == MYSQL_TYPE_TIMESTAMP)
758
755
    {
759
756
      /*
760
757
        TIMESTAMP field require explicit NULL flag, because unlike
767
764
        Add field flags about FIELD FORMAT (FIXED or DYNAMIC)
768
765
        and about STORAGE (DISK or MEMORY).
769
766
      */
 
767
      enum ha_storage_media storage_type= (enum ha_storage_media)
 
768
        ((flags >> FIELD_STORAGE_FLAGS) & STORAGE_TYPE_MASK);
770
769
      enum column_format_type column_format= (enum column_format_type)
771
770
        ((flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
 
771
      if (storage_type)
 
772
      {
 
773
        packet->append(STRING_WITH_LEN(" /*!"));
 
774
        packet->append(STRING_WITH_LEN(MYSQL_VERSION_TABLESPACE_IN_FRM_STR));
 
775
        packet->append(STRING_WITH_LEN(" STORAGE"));
 
776
        if (storage_type == HA_SM_DISK)
 
777
          packet->append(STRING_WITH_LEN(" DISK */"));
 
778
        else
 
779
          packet->append(STRING_WITH_LEN(" MEMORY */"));
 
780
      }
772
781
      if (column_format)
773
782
      {
774
783
        packet->append(STRING_WITH_LEN(" /*!"));
775
 
        packet->append(STRING_WITH_LEN(DRIZZLE_VERSION_TABLESPACE_IN_FRM_STR));
 
784
        packet->append(STRING_WITH_LEN(MYSQL_VERSION_TABLESPACE_IN_FRM_STR));
776
785
        packet->append(STRING_WITH_LEN(" COLUMN_FORMAT"));
777
786
        if (column_format == COLUMN_FORMAT_TYPE_FIXED)
778
787
          packet->append(STRING_WITH_LEN(" FIXED */"));
780
789
          packet->append(STRING_WITH_LEN(" DYNAMIC */"));
781
790
      }
782
791
    }
783
 
    if (!field->vcol_info &&
784
 
        get_field_default_value(thd, table->timestamp_field,
 
792
    if (get_field_default_value(thd, table->timestamp_field,
785
793
                                field, &def_value, 1))
786
794
    {
787
795
      packet->append(STRING_WITH_LEN(" DEFAULT "));
802
810
  }
803
811
 
804
812
  key_info= table->key_info;
805
 
  memset(&create_info, 0, sizeof(create_info));
 
813
  bzero((char*) &create_info, sizeof(create_info));
806
814
  /* Allow update_create_info to update row type */
807
815
  create_info.row_type= share->row_type;
808
816
  file->update_create_info(&create_info);
809
817
  primary_key= share->primary_key;
810
818
 
811
 
  for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
 
819
  for (uint i=0 ; i < share->keys ; i++,key_info++)
812
820
  {
813
821
    KEY_PART_INFO *key_part= key_info->key_part;
814
822
    bool found_primary=0;
833
841
 
834
842
    packet->append(STRING_WITH_LEN(" ("));
835
843
 
836
 
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
844
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
837
845
    {
838
846
      if (j)
839
847
        packet->append(',');
845
853
          (key_part->length !=
846
854
           table->field[key_part->fieldnr-1]->key_length()))
847
855
      {
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());
 
856
        char *end;
 
857
        buff[0] = '(';
 
858
        end= int10_to_str((long) key_part->length /
 
859
                          key_part->field->charset()->mbmaxlen,
 
860
                          buff + 1,10);
 
861
        *end++ = ')';
 
862
        packet->append(buff,(uint) (end-buff));
853
863
      }
854
864
    }
855
865
    packet->append(')');
869
879
 
870
880
  packet->append(STRING_WITH_LEN("\n)"));
871
881
  {
872
 
    show_table_options= true;
 
882
    show_table_options= TRUE;
873
883
    /*
874
884
      Get possible table space definitions and append them
875
885
      to the CREATE TABLE statement
876
886
    */
877
887
 
 
888
    switch (table->s->default_storage_media) {
 
889
    case(HA_SM_DEFAULT):
 
890
      if ((for_str= (char *)file->get_tablespace_name()))
 
891
      {
 
892
        packet->append(STRING_WITH_LEN(" /*!50100 TABLESPACE "));
 
893
        append_identifier(thd, packet, for_str, strlen(for_str));
 
894
        packet->append(STRING_WITH_LEN(" */"));
 
895
      }
 
896
      break;
 
897
    case(HA_SM_DISK):
 
898
      packet->append(STRING_WITH_LEN(" /*!50100"));
 
899
      if ((for_str= (char *)file->get_tablespace_name()))
 
900
      {
 
901
        packet->append(STRING_WITH_LEN(" TABLESPACE "));
 
902
        append_identifier(thd, packet, for_str, strlen(for_str));
 
903
      }
 
904
      packet->append(STRING_WITH_LEN(" STORAGE DISK */"));
 
905
      break;
 
906
    case(HA_SM_MEMORY):
 
907
      packet->append(STRING_WITH_LEN(" /*!50100"));
 
908
      if ((for_str= (char *)file->get_tablespace_name()))
 
909
      {
 
910
        packet->append(STRING_WITH_LEN(" TABLESPACE "));
 
911
        append_identifier(thd, packet, for_str, strlen(for_str));
 
912
      }
 
913
      packet->append(STRING_WITH_LEN(" STORAGE MEMORY */"));
 
914
      break;
 
915
    };
 
916
 
878
917
    /*
879
918
      IF   check_create_info
880
919
      THEN add ENGINE only if it was used when creating the table
899
938
 
900
939
    if (create_info.auto_increment_value > 1)
901
940
    {
 
941
      char *end;
902
942
      packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
903
 
      buff= to_string(create_info.auto_increment_value);
904
 
      packet->append(buff.c_str(), buff.length());
 
943
      end= longlong10_to_str(create_info.auto_increment_value, buff,10);
 
944
      packet->append(buff, (uint) (end - buff));
 
945
    }
 
946
 
 
947
    
 
948
    if (share->table_charset)
 
949
    {
 
950
      /*
 
951
        IF   check_create_info
 
952
        THEN add DEFAULT CHARSET only if it was used when creating the table
 
953
      */
 
954
      if (!create_info_arg ||
 
955
          (create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
 
956
      {
 
957
        packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
 
958
        packet->append(share->table_charset->csname);
 
959
        if (!(share->table_charset->state & MY_CS_PRIMARY))
 
960
        {
 
961
          packet->append(STRING_WITH_LEN(" COLLATE="));
 
962
          packet->append(table->s->table_charset->name);
 
963
        }
 
964
      }
905
965
    }
906
966
 
907
967
    if (share->min_rows)
908
968
    {
 
969
      char *end;
909
970
      packet->append(STRING_WITH_LEN(" MIN_ROWS="));
910
 
      buff= to_string(share->min_rows);
911
 
      packet->append(buff.c_str(), buff.length());
 
971
      end= longlong10_to_str(share->min_rows, buff, 10);
 
972
      packet->append(buff, (uint) (end- buff));
912
973
    }
913
974
 
914
975
    if (share->max_rows && !table_list->schema_table)
915
976
    {
 
977
      char *end;
916
978
      packet->append(STRING_WITH_LEN(" MAX_ROWS="));
917
 
      buff= to_string(share->max_rows);
918
 
      packet->append(buff.c_str(), buff.length());
 
979
      end= longlong10_to_str(share->max_rows, buff, 10);
 
980
      packet->append(buff, (uint) (end - buff));
919
981
    }
920
982
 
921
983
    if (share->avg_row_length)
922
984
    {
 
985
      char *end;
923
986
      packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
924
 
      buff= to_string(share->avg_row_length);
925
 
      packet->append(buff.c_str(), buff.length());
 
987
      end= longlong10_to_str(share->avg_row_length, buff,10);
 
988
      packet->append(buff, (uint) (end - buff));
926
989
    }
927
990
 
928
991
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
951
1014
    }
952
1015
    if (table->s->key_block_size)
953
1016
    {
 
1017
      char *end;
954
1018
      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());
 
1019
      end= longlong10_to_str(table->s->key_block_size, buff, 10);
 
1020
      packet->append(buff, (uint) (end - buff));
963
1021
    }
964
1022
    table->file->append_create_info(packet);
965
1023
    if (share->comment.length)
975
1033
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
976
1034
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
977
1035
  }
978
 
  table->restore_column_map(old_map);
979
 
  return(0);
 
1036
  tmp_restore_column_map(table->read_set, old_map);
 
1037
  DBUG_RETURN(0);
980
1038
}
981
1039
 
982
1040
/**
998
1056
  @param  create_info   If not NULL, the options member influences the resulting 
999
1057
                        CRATE statement.
1000
1058
 
1001
 
  @returns true if errors are detected, false otherwise.
 
1059
  @returns TRUE if errors are detected, FALSE otherwise.
1002
1060
*/
1003
1061
 
1004
1062
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
1005
1063
                          HA_CREATE_INFO *create_info)
1006
1064
{
1007
1065
  HA_CREATE_INFO create;
1008
 
  uint32_t create_options = create_info ? create_info->options : 0;
 
1066
  uint create_options = create_info ? create_info->options : 0;
 
1067
  DBUG_ENTER("store_db_create_info");
1009
1068
 
1010
1069
  if (!my_strcasecmp(system_charset_info, dbname,
1011
1070
                     INFORMATION_SCHEMA_NAME.str))
1016
1075
  else
1017
1076
  {
1018
1077
    if (check_db_dir_existence(dbname))
1019
 
      return(true);
 
1078
      DBUG_RETURN(TRUE);
1020
1079
 
1021
1080
    load_db_opt_by_name(thd, dbname, &create);
1022
1081
  }
1044
1103
    buffer->append(STRING_WITH_LEN(" */"));
1045
1104
  }
1046
1105
 
1047
 
  return(false);
 
1106
  DBUG_RETURN(FALSE);
1048
1107
}
1049
1108
 
1050
 
static void store_key_options(THD *thd __attribute__((unused)),
1051
 
                              String *packet, Table *table,
 
1109
static void store_key_options(THD *thd, String *packet, TABLE *table,
1052
1110
                              KEY *key_info)
1053
1111
{
1054
1112
  char *end, buff[32];
1063
1121
      table->s->key_block_size != key_info->block_size)
1064
1122
  {
1065
1123
    packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
1066
 
    end= int64_t10_to_str(key_info->block_size, buff, 10);
 
1124
    end= longlong10_to_str(key_info->block_size, buff, 10);
1067
1125
    packet->append(buff, (uint) (end - buff));
1068
1126
  }
1069
1127
 
1070
 
  assert(test(key_info->flags & HA_USES_COMMENT) == 
 
1128
  DBUG_ASSERT(test(key_info->flags & HA_USES_COMMENT) == 
1071
1129
              (key_info->comment.length > 0));
1072
1130
  if (key_info->flags & HA_USES_COMMENT)
1073
1131
  {
1095
1153
 
1096
1154
  ulong thread_id;
1097
1155
  time_t start_time;
1098
 
  uint32_t   command;
 
1156
  uint   command;
1099
1157
  const char *user,*host,*db,*proc_info,*state_info;
1100
1158
  char *query;
1101
1159
};
1112
1170
  ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
1113
1171
                           PROCESS_LIST_WIDTH);
1114
1172
  Protocol *protocol= thd->protocol;
 
1173
  DBUG_ENTER("mysqld_list_processes");
1115
1174
 
1116
1175
  field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1117
1176
  field_list.push_back(new Item_empty_string("User",16));
1119
1178
  field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN));
1120
1179
  field->maybe_null=1;
1121
1180
  field_list.push_back(new Item_empty_string("Command",16));
1122
 
  field_list.push_back(new Item_return_int("Time",7, DRIZZLE_TYPE_LONG));
 
1181
  field_list.push_back(new Item_return_int("Time",7, MYSQL_TYPE_LONG));
1123
1182
  field_list.push_back(field=new Item_empty_string("State",30));
1124
1183
  field->maybe_null=1;
1125
1184
  field_list.push_back(field=new Item_empty_string("Info",max_query_length));
1126
1185
  field->maybe_null=1;
1127
1186
  if (protocol->send_fields(&field_list,
1128
1187
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1129
 
    return;
 
1188
    DBUG_VOID_RETURN;
1130
1189
 
1131
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1190
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1132
1191
  if (!thd->killed)
1133
1192
  {
1134
1193
    I_List_iterator<THD> it(threads);
1145
1204
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1146
1205
                                    (tmp->system_thread ?
1147
1206
                                     "system user" : "unauthenticated user"));
1148
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
 
1207
        thd_info->host= thd->strdup(tmp_sctx->host_or_ip[0] ? 
 
1208
                                    tmp_sctx->host_or_ip : 
 
1209
                                    tmp_sctx->host ? tmp_sctx->host : "");
1149
1210
        if ((thd_info->db=tmp->db))             // Safe test
1150
1211
          thd_info->db=thd->strdup(thd_info->db);
1151
1212
        thd_info->command=(int) tmp->command;
1155
1216
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1156
1217
                                       (tmp->net.reading_or_writing == 2 ?
1157
1218
                                        "Writing to net" :
1158
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1219
                                        thd_info->command == COM_SLEEP ? NullS :
1159
1220
                                        "Reading from net") :
1160
 
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
 
1221
                                       tmp->proc_info ? tmp->proc_info :
1161
1222
                                       tmp->mysys_var &&
1162
1223
                                       tmp->mysys_var->current_cond ?
1163
 
                                       "Waiting on cond" : NULL);
 
1224
                                       "Waiting on cond" : NullS);
1164
1225
        if (mysys_var)
1165
1226
          pthread_mutex_unlock(&mysys_var->mutex);
1166
1227
 
1173
1234
            the comment in sql_class.h why this prevents crashes in possible
1174
1235
            races with query_length
1175
1236
          */
1176
 
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
 
1237
          uint length= min(max_query_length, tmp->query_length);
1177
1238
          thd_info->query=(char*) thd->strmake(tmp->query,length);
1178
1239
        }
1179
1240
        thread_infos.append(thd_info);
1180
1241
      }
1181
1242
    }
1182
1243
  }
1183
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1244
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1184
1245
 
1185
1246
  thread_info *thd_info;
1186
1247
  time_t now= my_time(0);
1187
1248
  while ((thd_info=thread_infos.get()))
1188
1249
  {
1189
1250
    protocol->prepare_for_resend();
1190
 
    protocol->store((uint64_t) thd_info->thread_id);
 
1251
    protocol->store((ulonglong) thd_info->thread_id);
1191
1252
    protocol->store(thd_info->user, system_charset_info);
1192
1253
    protocol->store(thd_info->host, system_charset_info);
1193
1254
    protocol->store(thd_info->db, system_charset_info);
1196
1257
    else
1197
1258
      protocol->store(command_name[thd_info->command].str, system_charset_info);
1198
1259
    if (thd_info->start_time)
1199
 
      protocol->store((uint32_t) (now - thd_info->start_time));
 
1260
      protocol->store((uint32) (now - thd_info->start_time));
1200
1261
    else
1201
1262
      protocol->store_null();
1202
1263
    protocol->store(thd_info->state_info, system_charset_info);
1205
1266
      break; /* purecov: inspected */
1206
1267
  }
1207
1268
  my_eof(thd);
1208
 
  return;
 
1269
  DBUG_VOID_RETURN;
1209
1270
}
1210
1271
 
1211
 
int fill_schema_processlist(THD* thd, TableList* tables,
1212
 
                            COND* cond __attribute__((unused)))
 
1272
int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
1213
1273
{
1214
 
  Table *table= tables->table;
1215
 
  const CHARSET_INFO * const cs= system_charset_info;
 
1274
  TABLE *table= tables->table;
 
1275
  CHARSET_INFO *cs= system_charset_info;
1216
1276
  char *user;
1217
1277
  time_t now= my_time(0);
1218
 
 
1219
 
  user= NULL;
1220
 
 
1221
 
  pthread_mutex_lock(&LOCK_thread_count);
 
1278
  DBUG_ENTER("fill_process_list");
 
1279
 
 
1280
  user= NullS;
 
1281
 
 
1282
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1222
1283
 
1223
1284
  if (!thd->killed)
1224
1285
  {
1236
1297
 
1237
1298
      restore_record(table, s->default_values);
1238
1299
      /* ID */
1239
 
      table->field[0]->store((int64_t) tmp->thread_id, true);
 
1300
      table->field[0]->store((longlong) tmp->thread_id, TRUE);
1240
1301
      /* USER */
1241
1302
      val= tmp_sctx->user ? tmp_sctx->user :
1242
1303
            (tmp->system_thread ? "system user" : "unauthenticated user");
1243
1304
      table->field[1]->store(val, strlen(val), cs);
1244
1305
      /* HOST */
1245
 
      table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
 
1306
      table->field[2]->store(tmp_sctx->host_or_ip,
 
1307
                             strlen(tmp_sctx->host_or_ip), cs);
1246
1308
      /* DB */
1247
1309
      if (tmp->db)
1248
1310
      {
1258
1320
      else
1259
1321
        table->field[4]->store(command_name[tmp->command].str,
1260
1322
                               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);
 
1323
      /* MYSQL_TIME */
 
1324
      table->field[5]->store((uint32)(tmp->start_time ?
 
1325
                                      now - tmp->start_time : 0), TRUE);
1264
1326
      /* STATE */
1265
1327
      val= (char*) (tmp->net.reading_or_writing ?
1266
1328
                    (tmp->net.reading_or_writing == 2 ?
1267
1329
                     "Writing to net" :
1268
 
                     tmp->command == COM_SLEEP ? NULL :
 
1330
                     tmp->command == COM_SLEEP ? NullS :
1269
1331
                     "Reading from net") :
1270
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
 
1332
                    tmp->proc_info ? tmp->proc_info :
1271
1333
                    tmp->mysys_var &&
1272
1334
                    tmp->mysys_var->current_cond ?
1273
 
                    "Waiting on cond" : NULL);
 
1335
                    "Waiting on cond" : NullS);
1274
1336
      if (val)
1275
1337
      {
1276
1338
        table->field[6]->store(val, strlen(val), cs);
1284
1346
      if (tmp->query)
1285
1347
      {
1286
1348
        table->field[7]->store(tmp->query,
1287
 
                               cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
 
1349
                               min(PROCESS_LIST_INFO_WIDTH,
1288
1350
                                   tmp->query_length), cs);
1289
1351
        table->field[7]->set_notnull();
1290
1352
      }
1291
1353
 
1292
1354
      if (schema_table_store_record(thd, table))
1293
1355
      {
1294
 
        pthread_mutex_unlock(&LOCK_thread_count);
1295
 
        return(1);
 
1356
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1357
        DBUG_RETURN(1);
1296
1358
      }
1297
1359
    }
1298
1360
  }
1299
1361
 
1300
 
  pthread_mutex_unlock(&LOCK_thread_count);
1301
 
  return(0);
 
1362
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1363
  DBUG_RETURN(0);
1302
1364
}
1303
1365
 
1304
1366
/*****************************************************************************
1318
1380
*/
1319
1381
static void shrink_var_array(DYNAMIC_ARRAY *array)
1320
1382
{
1321
 
  uint32_t a,b;
 
1383
  uint a,b;
1322
1384
  SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1323
1385
 
1324
1386
  for (a= b= 0; b < array->elements; b++)
1326
1388
      all[a++]= all[b];
1327
1389
  if (a)
1328
1390
  {
1329
 
    memset(all+a, 0, sizeof(SHOW_VAR)); // writing NULL-element to the end
 
1391
    bzero(all+a, sizeof(SHOW_VAR)); // writing NULL-element to the end
1330
1392
    array->elements= a;
1331
1393
  }
1332
1394
  else // array is completely empty - delete it
1364
1426
    goto err;
1365
1427
  }
1366
1428
  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
 
1429
    res|= insert_dynamic(&all_status_vars, (uchar*)list++);
 
1430
  res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1369
1431
  all_status_vars.elements--; // but next insert_dynamic should overwite it
1370
1432
  if (status_vars_inited)
1371
1433
    sort_dynamic(&all_status_vars, show_var_cmp);
1459
1521
  else
1460
1522
  {
1461
1523
    SHOW_VAR *all= dynamic_element(&all_status_vars, 0, SHOW_VAR *);
1462
 
    uint32_t i;
 
1524
    uint i;
1463
1525
    for (; list->name; list++)
1464
1526
    {
1465
1527
      for (i= 0; i < all_status_vars.elements; i++)
1484
1546
                              SHOW_VAR *variables,
1485
1547
                              enum enum_var_type value_type,
1486
1548
                              struct system_status_var *status_var,
1487
 
                              const char *prefix, Table *table,
 
1549
                              const char *prefix, TABLE *table,
1488
1550
                              bool ucase_names)
1489
1551
{
1490
1552
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1495
1557
  int len;
1496
1558
  LEX_STRING null_lex_str;
1497
1559
  SHOW_VAR tmp, *var;
 
1560
  DBUG_ENTER("show_status_array");
1498
1561
 
1499
1562
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1500
1563
  null_lex_str.length= 0;
1501
1564
 
1502
 
  prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1565
  prefix_end=strnmov(name_buffer, prefix, sizeof(name_buffer)-1);
1503
1566
  if (*prefix)
1504
1567
    *prefix_end++= '_';
1505
1568
  len=name_buffer + sizeof(name_buffer) - prefix_end;
1506
1569
 
1507
1570
  for (; variables->name; variables++)
1508
1571
  {
1509
 
    my_stpncpy(prefix_end, variables->name, len);
 
1572
    strnmov(prefix_end, variables->name, len);
1510
1573
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
1511
1574
    if (ucase_names)
1512
1575
      make_upper(name_buffer);
1516
1579
      Repeat as necessary, if new var is again SHOW_FUNC
1517
1580
    */
1518
1581
    for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1519
 
      ((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
 
1582
      ((mysql_show_var_func)(var->value))(thd, &tmp, buff);
1520
1583
 
1521
1584
    SHOW_TYPE show_type=var->type;
1522
1585
    if (show_type == SHOW_ARRAY)
1562
1625
          end= int10_to_str(*(long*) value, buff, 10);
1563
1626
          break;
1564
1627
        case SHOW_LONGLONG_STATUS:
1565
 
          value= ((char *) status_var + (uint64_t) value);
 
1628
          value= ((char *) status_var + (ulonglong) value);
1566
1629
          /* fall through */
1567
1630
        case SHOW_LONGLONG:
1568
 
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
1631
          end= longlong10_to_str(*(longlong*) value, buff, 10);
1569
1632
          break;
1570
1633
        case SHOW_HA_ROWS:
1571
 
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
 
1634
          end= longlong10_to_str((longlong) *(ha_rows*) value, buff, 10);
1572
1635
          break;
1573
1636
        case SHOW_BOOL:
1574
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1637
          end= strmov(buff, *(bool*) value ? "ON" : "OFF");
1575
1638
          break;
1576
1639
        case SHOW_MY_BOOL:
1577
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1640
          end= strmov(buff, *(my_bool*) value ? "ON" : "OFF");
1578
1641
          break;
1579
1642
        case SHOW_INT:
1580
 
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
 
1643
          end= int10_to_str((long) *(uint32*) value, buff, 10);
1581
1644
          break;
1582
1645
        case SHOW_HAVE:
1583
1646
        {
1584
1647
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1585
1648
          pos= show_comp_option_name[(int) tmp];
1586
 
          end= strchr(pos, '\0');
 
1649
          end= strend(pos);
1587
1650
          break;
1588
1651
        }
1589
1652
        case SHOW_CHAR:
1590
1653
        {
1591
1654
          if (!(pos= value))
1592
1655
            pos= "";
1593
 
          end= strchr(pos, '\0');
 
1656
          end= strend(pos);
1594
1657
          break;
1595
1658
        }
1596
1659
       case SHOW_CHAR_PTR:
1597
1660
        {
1598
1661
          if (!(pos= *(char**) value))
1599
1662
            pos= "";
1600
 
          end= strchr(pos, '\0');
 
1663
          end= strend(pos);
1601
1664
          break;
1602
1665
        }
1603
1666
        case SHOW_KEY_CACHE_LONG:
1606
1669
          break;
1607
1670
        case SHOW_KEY_CACHE_LONGLONG:
1608
1671
          value= (char*) dflt_key_cache + (ulong)value;
1609
 
          end= int64_t10_to_str(*(int64_t*) value, buff, 10);
 
1672
          end= longlong10_to_str(*(longlong*) value, buff, 10);
1610
1673
          break;
1611
1674
        case SHOW_UNDEF:
1612
1675
          break;                                        // Return empty string
1613
1676
        case SHOW_SYS:                                  // Cannot happen
1614
1677
        default:
1615
 
          assert(0);
 
1678
          DBUG_ASSERT(0);
1616
1679
          break;
1617
1680
        }
1618
1681
        restore_record(table, s->default_values);
1619
1682
        table->field[0]->store(name_buffer, strlen(name_buffer),
1620
1683
                               system_charset_info);
1621
 
        table->field[1]->store(pos, (uint32_t) (end - pos), system_charset_info);
 
1684
        table->field[1]->store(pos, (uint32) (end - pos), system_charset_info);
1622
1685
        table->field[1]->set_notnull();
1623
1686
 
1624
1687
        pthread_mutex_unlock(&LOCK_global_system_variables);
1625
1688
 
1626
1689
        if (schema_table_store_record(thd, table))
1627
 
          return(true);
 
1690
          DBUG_RETURN(TRUE);
1628
1691
      }
1629
1692
    }
1630
1693
  }
1631
1694
 
1632
 
  return(false);
 
1695
  DBUG_RETURN(FALSE);
1633
1696
}
1634
1697
 
1635
1698
 
1637
1700
 
1638
1701
void calc_sum_of_all_status(STATUS_VAR *to)
1639
1702
{
 
1703
  DBUG_ENTER("calc_sum_of_all_status");
1640
1704
 
1641
1705
  /* Ensure that thread id not killed during loop */
1642
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1706
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1643
1707
 
1644
1708
  I_List_iterator<THD> it(threads);
1645
1709
  THD *tmp;
1651
1715
  while ((tmp= it++))
1652
1716
    add_to_status(to, &tmp->status_var);
1653
1717
  
1654
 
  pthread_mutex_unlock(&LOCK_thread_count);
1655
 
  return;
 
1718
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
 
1719
  DBUG_VOID_RETURN;
1656
1720
}
1657
1721
 
1658
1722
 
1680
1744
    1                     error
1681
1745
*/
1682
1746
 
1683
 
bool schema_table_store_record(THD *thd, Table *table)
 
1747
bool schema_table_store_record(THD *thd, TABLE *table)
1684
1748
{
1685
1749
  int error;
1686
1750
  if ((error= table->file->ha_write_row(table->record[0])))
1726
1790
*/
1727
1791
 
1728
1792
bool get_lookup_value(THD *thd, Item_func *item_func,
1729
 
                      TableList *table, 
 
1793
                      TABLE_LIST *table, 
1730
1794
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1731
1795
{
1732
1796
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1743
1807
    char tmp[MAX_FIELD_WIDTH];
1744
1808
    String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1745
1809
    Item_field *item_field;
1746
 
    const CHARSET_INFO * const cs= system_charset_info;
 
1810
    CHARSET_INFO *cs= system_charset_info;
1747
1811
 
1748
1812
    if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1749
1813
        item_func->arguments()[1]->const_item())
1770
1834
      return 1;
1771
1835
 
1772
1836
    /* 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,
 
1837
    if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1838
                               (uchar *) item_field->field_name,
1775
1839
                               strlen(item_field->field_name), 0))
1776
1840
    {
1777
1841
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1778
 
                           tmp_str->length(), false);
 
1842
                           tmp_str->length(), FALSE);
1779
1843
    }
1780
1844
    /* Lookup value is table name */
1781
 
    else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
 
1845
    else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1782
1846
                                    strlen(field_name2),
1783
 
                                    (unsigned char *) item_field->field_name,
 
1847
                                    (uchar *) item_field->field_name,
1784
1848
                                    strlen(item_field->field_name), 0))
1785
1849
    {
1786
1850
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1787
 
                           tmp_str->length(), false);
 
1851
                           tmp_str->length(), FALSE);
1788
1852
    }
1789
1853
  }
1790
1854
  return 0;
1808
1872
    1             error, there can be no matching records for the condition
1809
1873
*/
1810
1874
 
1811
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1875
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1812
1876
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1813
1877
{
1814
1878
  if (!cond)
1843
1907
}
1844
1908
 
1845
1909
 
1846
 
bool uses_only_table_name_fields(Item *item, TableList *table)
 
1910
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1847
1911
{
1848
1912
  if (item->type() == Item::FUNC_ITEM)
1849
1913
  {
1850
1914
    Item_func *item_func= (Item_func*)item;
1851
 
    for (uint32_t i=0; i<item_func->argument_count(); i++)
 
1915
    for (uint i=0; i<item_func->argument_count(); i++)
1852
1916
    {
1853
1917
      if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1854
1918
        return 0;
1857
1921
  else if (item->type() == Item::FIELD_ITEM)
1858
1922
  {
1859
1923
    Item_field *item_field= (Item_field*)item;
1860
 
    const CHARSET_INFO * const cs= system_charset_info;
 
1924
    CHARSET_INFO *cs= system_charset_info;
1861
1925
    ST_SCHEMA_TABLE *schema_table= table->schema_table;
1862
1926
    ST_FIELD_INFO *field_info= schema_table->fields_info;
1863
1927
    const char *field_name1= schema_table->idx_field1 >= 0 ?
1865
1929
    const char *field_name2= schema_table->idx_field2 >= 0 ?
1866
1930
      field_info[schema_table->idx_field2].field_name : "";
1867
1931
    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,
 
1932
        (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1933
                               (uchar *) item_field->field_name,
1870
1934
                               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,
 
1935
         cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
 
1936
                               (uchar *) item_field->field_name,
1873
1937
                               strlen(item_field->field_name), 0)))
1874
1938
      return 0;
1875
1939
  }
1883
1947
}
1884
1948
 
1885
1949
 
1886
 
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
 
1950
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
1887
1951
{
1888
1952
  if (!cond)
1889
1953
    return (COND*) 0;
1957
2021
    1             error, there can be no matching records for the condition
1958
2022
*/
1959
2023
 
1960
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
2024
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1961
2025
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1962
2026
{
1963
2027
  LEX *lex= thd->lex;
1964
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1965
 
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
 
2028
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
2029
  bzero((char*) lookup_field_values, sizeof(LOOKUP_FIELD_VALUES));
1966
2030
  switch (lex->sql_command) {
1967
2031
  case SQLCOM_SHOW_DATABASES:
1968
2032
    if (wild)
2024
2088
  LEX_STRING *i_s_name_copy= 0;
2025
2089
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2026
2090
                                      INFORMATION_SCHEMA_NAME.str,
2027
 
                                      INFORMATION_SCHEMA_NAME.length, true);
 
2091
                                      INFORMATION_SCHEMA_NAME.length, TRUE);
2028
2092
  *with_i_schema= 0;
2029
2093
  if (lookup_field_vals->wild_db_value)
2030
2094
  {
2042
2106
      if (files->push_back(i_s_name_copy))
2043
2107
        return 1;
2044
2108
    }
2045
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
2109
    return (find_files(thd, files, NullS, mysql_data_home,
2046
2110
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2047
2111
  }
2048
2112
 
2073
2137
  if (files->push_back(i_s_name_copy))
2074
2138
    return 1;
2075
2139
  *with_i_schema= 1;
2076
 
  return (find_files(thd, files, NULL,
2077
 
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
 
2140
  return (find_files(thd, files, NullS,
 
2141
                     mysql_data_home, NullS, 1) != FIND_FILES_OK);
2078
2142
}
2079
2143
 
2080
2144
 
2085
2149
};
2086
2150
 
2087
2151
 
2088
 
static bool add_schema_table(THD *thd, plugin_ref plugin,
 
2152
static my_bool add_schema_table(THD *thd, plugin_ref plugin,
2089
2153
                                void* p_data)
2090
2154
{
2091
2155
  LEX_STRING *file_name= 0;
2093
2157
  List<LEX_STRING> *file_list= data->files;
2094
2158
  const char *wild= data->wild;
2095
2159
  ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
 
2160
  DBUG_ENTER("add_schema_table");
2096
2161
 
2097
2162
  if (schema_table->hidden)
2098
 
      return(0);
 
2163
      DBUG_RETURN(0);
2099
2164
  if (wild)
2100
2165
  {
2101
2166
    if (lower_case_table_names)
2103
2168
      if (wild_case_compare(files_charset_info,
2104
2169
                            schema_table->table_name,
2105
2170
                            wild))
2106
 
        return(0);
 
2171
        DBUG_RETURN(0);
2107
2172
    }
2108
2173
    else if (wild_compare(schema_table->table_name, wild, 0))
2109
 
      return(0);
 
2174
      DBUG_RETURN(0);
2110
2175
  }
2111
2176
 
2112
2177
  if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2113
2178
                                       strlen(schema_table->table_name),
2114
 
                                       true)) &&
 
2179
                                       TRUE)) &&
2115
2180
      !file_list->push_back(file_name))
2116
 
    return(0);
2117
 
  return(1);
 
2181
    DBUG_RETURN(0);
 
2182
  DBUG_RETURN(1);
2118
2183
}
2119
2184
 
2120
2185
 
2123
2188
  LEX_STRING *file_name= 0;
2124
2189
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2125
2190
  st_add_schema_table add_data;
 
2191
  DBUG_ENTER("schema_tables_add");
2126
2192
 
2127
2193
  for (; tmp_schema_table->table_name; tmp_schema_table++)
2128
2194
  {
2142
2208
    }
2143
2209
    if ((file_name= 
2144
2210
         thd->make_lex_string(file_name, tmp_schema_table->table_name,
2145
 
                              strlen(tmp_schema_table->table_name), true)) &&
 
2211
                              strlen(tmp_schema_table->table_name), TRUE)) &&
2146
2212
        !files->push_back(file_name))
2147
2213
      continue;
2148
 
    return(1);
 
2214
    DBUG_RETURN(1);
2149
2215
  }
2150
2216
 
2151
2217
  add_data.files= files;
2152
2218
  add_data.wild= wild;
2153
2219
  if (plugin_foreach(thd, add_schema_table,
2154
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
2155
 
    return(1);
 
2220
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data))
 
2221
      DBUG_RETURN(1);
2156
2222
 
2157
 
  return(0);
 
2223
  DBUG_RETURN(0);
2158
2224
}
2159
2225
 
2160
2226
 
2168
2234
  @param[in]      table_names           List of table names in database
2169
2235
  @param[in]      lex                   pointer to LEX struct
2170
2236
  @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
 
2237
  @param[in]      with_i_schema         TRUE means that we add I_S tables to list
2172
2238
  @param[in]      db_name               database name
2173
2239
 
2174
2240
  @return         Operation status
2238
2304
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2239
2305
 
2240
2306
  @param[in]      thd                      thread handler
2241
 
  @param[in]      tables                   TableList for I_S table
 
2307
  @param[in]      tables                   TABLE_LIST for I_S table
2242
2308
  @param[in]      schema_table             pointer to I_S structure
2243
2309
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2244
2310
                                           which is used to save|restore original
2251
2317
*/
2252
2318
 
2253
2319
static int 
2254
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2320
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2255
2321
                              ST_SCHEMA_TABLE *schema_table,
2256
2322
                              Open_tables_state *open_tables_state_backup)
2257
2323
{
2259
2325
  bool res;
2260
2326
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2261
2327
  enum_sql_command save_sql_command= lex->sql_command;
2262
 
  TableList *show_table_list= (TableList*) tables->schema_select_lex->
 
2328
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2263
2329
    table_list.first;
2264
 
  Table *table= tables->table;
 
2330
  TABLE *table= tables->table;
2265
2331
  int error= 1;
 
2332
  DBUG_ENTER("fill_schema_show");
2266
2333
 
2267
2334
  lex->all_selects_list= tables->schema_select_lex;
2268
2335
  /*
2280
2347
  */
2281
2348
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2282
2349
  res= open_normal_and_derived_tables(thd, show_table_list,
2283
 
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
 
2350
                                      MYSQL_LOCK_IGNORE_FLUSH);
2284
2351
  lex->sql_command= save_sql_command;
2285
2352
  /*
2286
2353
    get_all_tables() returns 1 on failure and 0 on success thus
2294
2361
    'show columns' & 'show statistics' commands).
2295
2362
  */
2296
2363
   table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2297
 
                                    strlen(show_table_list->alias), false);
 
2364
                                    strlen(show_table_list->alias), FALSE);
2298
2365
   db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2299
 
                                 show_table_list->db_length, false);
 
2366
                                 show_table_list->db_length, FALSE);
2300
2367
      
2301
2368
 
2302
2369
   error= test(schema_table->process_table(thd, show_table_list,
2304
2371
                                           table_name));
2305
2372
   thd->temporary_tables= 0;
2306
2373
   close_tables_for_reopen(thd, &show_table_list);
2307
 
   return(error);
 
2374
   DBUG_RETURN(error);
2308
2375
}
2309
2376
 
2310
2377
 
2311
2378
/**
2312
 
  @brief          Fill I_S table for SHOW Table NAMES commands
 
2379
  @brief          Fill I_S table for SHOW TABLE NAMES commands
2313
2380
 
2314
2381
  @param[in]      thd                      thread handler
2315
 
  @param[in]      table                    Table struct for I_S table
 
2382
  @param[in]      table                    TABLE struct for I_S table
2316
2383
  @param[in]      db_name                  database name
2317
2384
  @param[in]      table_name               table name
2318
 
  @param[in]      with_i_schema            I_S table if true
 
2385
  @param[in]      with_i_schema            I_S table if TRUE
2319
2386
 
2320
2387
  @return         Operation status
2321
2388
    @retval       0           success
2322
2389
    @retval       1           error
2323
2390
*/
2324
2391
 
2325
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2392
static int fill_schema_table_names(THD *thd, TABLE *table,
2326
2393
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2327
2394
                                   bool with_i_schema)
2328
2395
{
2337
2404
    char path[FN_REFLEN];
2338
2405
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2339
2406
                                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
 
    {
 
2407
    switch (mysql_frm_type(thd, path, &not_used)) {
 
2408
    case FRMTYPE_ERROR:
2347
2409
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2348
2410
                             system_charset_info);
 
2411
      break;
 
2412
    case FRMTYPE_TABLE:
 
2413
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
 
2414
                             system_charset_info);
 
2415
      break;
 
2416
    default:
 
2417
      DBUG_ASSERT(0);
2349
2418
    }
2350
 
 
2351
2419
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2352
2420
    {
2353
2421
      thd->clear_error();
2376
2444
    @retval       SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2377
2445
*/
2378
2446
 
2379
 
static uint32_t get_table_open_method(TableList *tables,
 
2447
static uint get_table_open_method(TABLE_LIST *tables,
2380
2448
                                  ST_SCHEMA_TABLE *schema_table,
2381
 
                                  enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2449
                                  enum enum_schema_tables schema_table_idx)
2382
2450
{
2383
2451
  /*
2384
2452
    determine which method will be used for table opening
2404
2472
  @brief          Fill I_S table with data from FRM file only
2405
2473
 
2406
2474
  @param[in]      thd                      thread handler
2407
 
  @param[in]      table                    Table struct for I_S table
 
2475
  @param[in]      table                    TABLE struct for I_S table
2408
2476
  @param[in]      schema_table             I_S table struct
2409
2477
  @param[in]      db_name                  database name
2410
2478
  @param[in]      table_name               table name
2417
2485
                              open_tables function for this table
2418
2486
*/
2419
2487
 
2420
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
2421
 
                                      ST_SCHEMA_TABLE *schema_table,
 
2488
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
 
2489
                                      ST_SCHEMA_TABLE *schema_table, 
2422
2490
                                      LEX_STRING *db_name,
2423
2491
                                      LEX_STRING *table_name,
2424
 
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
 
2492
                                      enum enum_schema_tables schema_table_idx)
2425
2493
{
2426
 
  Table *table= tables->table;
 
2494
  TABLE *table= tables->table;
2427
2495
  TABLE_SHARE *share;
2428
 
  Table tbl;
2429
 
  TableList table_list;
2430
 
  uint32_t res= 0;
 
2496
  TABLE tbl;
 
2497
  TABLE_LIST table_list;
 
2498
  uint res= 0;
2431
2499
  int error;
2432
2500
  char key[MAX_DBKEY_LENGTH];
2433
 
  uint32_t key_length;
 
2501
  uint key_length;
2434
2502
 
2435
 
  memset(&table_list, 0, sizeof(TableList));
2436
 
  memset(&tbl, 0, sizeof(Table));
 
2503
  bzero((char*) &table_list, sizeof(TABLE_LIST));
 
2504
  bzero((char*) &tbl, sizeof(TABLE));
2437
2505
 
2438
2506
  table_list.table_name= table_name->str;
2439
2507
  table_list.db= db_name->str;
2441
2509
  key_length= create_table_def_key(thd, key, &table_list, 0);
2442
2510
  pthread_mutex_lock(&LOCK_open);
2443
2511
  share= get_table_share(thd, &table_list, key,
2444
 
                         key_length, 0, &error);
 
2512
                         key_length, OPEN_VIEW, &error);
2445
2513
  if (!share)
2446
2514
  {
2447
2515
    res= 0;
2484
2552
    @retval       1                        error
2485
2553
*/
2486
2554
 
2487
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2555
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2488
2556
{
2489
2557
  LEX *lex= thd->lex;
2490
 
  Table *table= tables->table;
 
2558
  TABLE *table= tables->table;
2491
2559
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2492
2560
  enum_sql_command save_sql_command= lex->sql_command;
2493
2561
  SELECT_LEX *lsel= tables->schema_select_lex;
2500
2568
  List<LEX_STRING> db_names;
2501
2569
  List_iterator_fast<LEX_STRING> it(db_names);
2502
2570
  COND *partial_cond= 0;
2503
 
  uint32_t derived_tables= lex->derived_tables; 
 
2571
  uint derived_tables= lex->derived_tables; 
2504
2572
  int error= 1;
2505
2573
  Open_tables_state open_tables_state_backup;
2506
2574
  Query_tables_list query_tables_list_backup;
2507
 
  uint32_t table_open_method;
 
2575
  uint table_open_method;
2508
2576
  bool old_value= thd->no_warnings_for_error;
 
2577
  DBUG_ENTER("get_all_tables");
2509
2578
 
2510
2579
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2511
2580
 
2519
2588
  schema_table_idx= get_schema_table_idx(schema_table);
2520
2589
  tables->table_open_method= table_open_method=
2521
2590
    get_table_open_method(tables, schema_table, schema_table_idx);
 
2591
  DBUG_PRINT("open_method", ("%d", tables->table_open_method));
2522
2592
  /* 
2523
2593
    this branch processes SHOW FIELDS, SHOW INDEXES commands.
2524
2594
    see sql_parse.cc, prepare_schema_table() function where
2536
2606
    error= 0;
2537
2607
    goto err;
2538
2608
  }
 
2609
  DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
 
2610
                             STR_OR_NIL(lookup_field_vals.db_value.str),
 
2611
                             STR_OR_NIL(lookup_field_vals.table_value.str)));
2539
2612
 
2540
2613
  if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
2541
2614
  {
2543
2616
      if lookup value is empty string then
2544
2617
      it's impossible table name or db name
2545
2618
    */
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]))
 
2619
    if (lookup_field_vals.db_value.str &&
 
2620
        !lookup_field_vals.db_value.str[0] ||
 
2621
        lookup_field_vals.table_value.str &&
 
2622
        !lookup_field_vals.table_value.str[0])
2548
2623
    {
2549
2624
      error= 0;
2550
2625
      goto err;
2553
2628
 
2554
2629
  if (lookup_field_vals.db_value.length &&
2555
2630
      !lookup_field_vals.wild_db_value)
2556
 
    tables->has_db_lookup_value= true;
 
2631
    tables->has_db_lookup_value= TRUE;
2557
2632
  if (lookup_field_vals.table_value.length &&
2558
2633
      !lookup_field_vals.wild_table_value) 
2559
 
    tables->has_table_lookup_value= true;
 
2634
    tables->has_table_lookup_value= TRUE;
2560
2635
 
2561
2636
  if (tables->has_db_lookup_value && tables->has_table_lookup_value)
2562
2637
    partial_cond= 0;
2612
2687
            continue;
2613
2688
          }
2614
2689
 
2615
 
          /* SHOW Table NAMES command */
 
2690
          /* SHOW TABLE NAMES command */
2616
2691
          if (schema_table_idx == SCH_TABLE_NAMES)
2617
2692
          {
2618
2693
            if (fill_schema_table_names(thd, tables->table, db_name,
2639
2714
            sel.parent_lex= lex;
2640
2715
            /* db_name can be changed in make_table_list() func */
2641
2716
            if (!thd->make_lex_string(&orig_db_name, db_name->str,
2642
 
                                      db_name->length, false))
 
2717
                                      db_name->length, FALSE))
2643
2718
              goto err;
2644
2719
            if (make_table_list(thd, &sel, db_name, table_name))
2645
2720
              goto err;
2646
 
            TableList *show_table_list= (TableList*) sel.table_list.first;
 
2721
            TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2647
2722
            lex->all_selects_list= &sel;
2648
2723
            lex->derived_tables= 0;
2649
2724
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2650
2725
            show_table_list->i_s_requested_object=
2651
2726
              schema_table->i_s_requested_object;
2652
2727
            res= open_normal_and_derived_tables(thd, show_table_list,
2653
 
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
 
2728
                                                MYSQL_LOCK_IGNORE_FLUSH);
2654
2729
            lex->sql_command= save_sql_command;
2655
2730
            /*
2656
2731
              XXX:  show_table_list has a flag i_is_requested,
2682
2757
                in this case.
2683
2758
              */
2684
2759
              thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2685
 
                                   strlen(show_table_list->alias), false);
 
2760
                                   strlen(show_table_list->alias), FALSE);
2686
2761
              res= schema_table->process_table(thd, show_table_list, table,
2687
2762
                                               res, &orig_db_name,
2688
2763
                                               &tmp_lex_string);
2689
2764
              close_tables_for_reopen(thd, &show_table_list);
2690
2765
            }
2691
 
            assert(!lex->query_tables_own_last);
 
2766
            DBUG_ASSERT(!lex->query_tables_own_last);
2692
2767
            if (res)
2693
2768
              goto err;
2694
2769
          }
2710
2785
  lex->all_selects_list= old_all_select_lex;
2711
2786
  lex->sql_command= save_sql_command;
2712
2787
  thd->no_warnings_for_error= old_value;
2713
 
  return(error);
 
2788
  DBUG_RETURN(error);
2714
2789
}
2715
2790
 
2716
2791
 
2717
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2718
 
                          const CHARSET_INFO * const cs)
 
2792
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
 
2793
                          CHARSET_INFO *cs)
2719
2794
{
2720
2795
  restore_record(table, s->default_values);
2721
2796
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2725
2800
}
2726
2801
 
2727
2802
 
2728
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2803
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
2729
2804
{
2730
2805
  /*
2731
2806
    TODO: fill_schema_shemata() is called when new client is connected.
2737
2812
  LEX_STRING *db_name;
2738
2813
  bool with_i_schema;
2739
2814
  HA_CREATE_INFO create;
2740
 
  Table *table= tables->table;
 
2815
  TABLE *table= tables->table;
 
2816
  DBUG_ENTER("fill_schema_shemata");
2741
2817
 
2742
2818
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2743
 
    return(0);
 
2819
    DBUG_RETURN(0);
 
2820
  DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
 
2821
                             lookup_field_vals.db_value.str,
 
2822
                             lookup_field_vals.table_value.str));
2744
2823
  if (make_db_list(thd, &db_names, &lookup_field_vals,
2745
2824
                   &with_i_schema))
2746
 
    return(1);
 
2825
    DBUG_RETURN(1);
2747
2826
 
2748
2827
  /*
2749
2828
    If we have lookup db value we should check that the database exists
2752
2831
     !with_i_schema)
2753
2832
  {
2754
2833
    char path[FN_REFLEN+16];
2755
 
    uint32_t path_len;
 
2834
    uint path_len;
2756
2835
    struct stat stat_info;
2757
2836
    if (!lookup_field_vals.db_value.str[0])
2758
 
      return(0);
 
2837
      DBUG_RETURN(0);
2759
2838
    path_len= build_table_filename(path, sizeof(path),
2760
2839
                                   lookup_field_vals.db_value.str, "", "", 0);
2761
2840
    path[path_len-1]= 0;
2762
2841
    if (stat(path,&stat_info))
2763
 
      return(0);
 
2842
      DBUG_RETURN(0);
2764
2843
  }
2765
2844
 
2766
2845
  List_iterator_fast<LEX_STRING> it(db_names);
2770
2849
    {
2771
2850
      if (store_schema_shemata(thd, table, db_name,
2772
2851
                               system_charset_info))
2773
 
        return(1);
 
2852
        DBUG_RETURN(1);
2774
2853
      with_i_schema= 0;
2775
2854
      continue;
2776
2855
    }
2778
2857
      load_db_opt_by_name(thd, db_name->str, &create);
2779
2858
      if (store_schema_shemata(thd, table, db_name,
2780
2859
                               create.default_table_charset))
2781
 
        return(1);
 
2860
        DBUG_RETURN(1);
2782
2861
    }
2783
2862
  }
2784
 
  return(0);
 
2863
  DBUG_RETURN(0);
2785
2864
}
2786
2865
 
2787
2866
 
2788
 
static int get_schema_tables_record(THD *thd, TableList *tables,
2789
 
                                    Table *table, bool res,
 
2867
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
 
2868
                                    TABLE *table, bool res,
2790
2869
                                    LEX_STRING *db_name,
2791
2870
                                    LEX_STRING *table_name)
2792
2871
{
2793
2872
  const char *tmp_buff;
2794
 
  DRIZZLE_TIME time;
2795
 
  const CHARSET_INFO * const cs= system_charset_info;
 
2873
  MYSQL_TIME time;
 
2874
  CHARSET_INFO *cs= system_charset_info;
 
2875
  DBUG_ENTER("get_schema_tables_record");
2796
2876
 
2797
2877
  restore_record(table, s->default_values);
2798
2878
  table->field[1]->store(db_name->str, db_name->length, cs);
2806
2886
    if (tables->schema_table)
2807
2887
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2808
2888
    else
2809
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2889
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2810
2890
    table->field[20]->store(error, strlen(error), cs);
2811
2891
    thd->clear_error();
2812
2892
  }
2813
2893
  else
2814
2894
  {
2815
 
    char option_buff[400],*ptr;
2816
 
    Table *show_table= tables->table;
 
2895
    char option_buff[350],*ptr;
 
2896
    TABLE *show_table= tables->table;
2817
2897
    TABLE_SHARE *share= show_table->s;
2818
2898
    handler *file= show_table->file;
2819
2899
    handlerton *tmp_db_type= share->db_type();
2822
2902
    else if (share->tmp_table)
2823
2903
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2824
2904
    else
2825
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2905
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2826
2906
 
2827
2907
    for (int i= 4; i < 20; i++)
2828
2908
    {
2832
2912
    }
2833
2913
    tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2834
2914
    table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2835
 
    table->field[5]->store((int64_t) share->frm_version, true);
 
2915
    table->field[5]->store((longlong) share->frm_version, TRUE);
2836
2916
 
2837
2917
    ptr=option_buff;
2838
2918
    if (share->min_rows)
2839
2919
    {
2840
 
      ptr=my_stpcpy(ptr," min_rows=");
2841
 
      ptr=int64_t10_to_str(share->min_rows,ptr,10);
 
2920
      ptr=strmov(ptr," min_rows=");
 
2921
      ptr=longlong10_to_str(share->min_rows,ptr,10);
2842
2922
    }
2843
2923
    if (share->max_rows)
2844
2924
    {
2845
 
      ptr=my_stpcpy(ptr," max_rows=");
2846
 
      ptr=int64_t10_to_str(share->max_rows,ptr,10);
 
2925
      ptr=strmov(ptr," max_rows=");
 
2926
      ptr=longlong10_to_str(share->max_rows,ptr,10);
2847
2927
    }
2848
2928
    if (share->avg_row_length)
2849
2929
    {
2850
 
      ptr=my_stpcpy(ptr," avg_row_length=");
2851
 
      ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
 
2930
      ptr=strmov(ptr," avg_row_length=");
 
2931
      ptr=longlong10_to_str(share->avg_row_length,ptr,10);
2852
2932
    }
2853
2933
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
2854
 
      ptr=my_stpcpy(ptr," pack_keys=1");
 
2934
      ptr=strmov(ptr," pack_keys=1");
2855
2935
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2856
 
      ptr=my_stpcpy(ptr," pack_keys=0");
 
2936
      ptr=strmov(ptr," pack_keys=0");
2857
2937
    /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2858
2938
    if (share->db_create_options & HA_OPTION_CHECKSUM)
2859
 
      ptr=my_stpcpy(ptr," checksum=1");
 
2939
      ptr=strmov(ptr," checksum=1");
2860
2940
    if (share->page_checksum != HA_CHOICE_UNDEF)
2861
2941
      ptr= strxmov(ptr, " page_checksum=",
2862
 
                   ha_choice_values[(uint) share->page_checksum], NULL);
 
2942
                   ha_choice_values[(uint) share->page_checksum], NullS);
2863
2943
    if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2864
 
      ptr=my_stpcpy(ptr," delay_key_write=1");
 
2944
      ptr=strmov(ptr," delay_key_write=1");
2865
2945
    if (share->row_type != ROW_TYPE_DEFAULT)
2866
2946
      ptr=strxmov(ptr, " row_format=", 
2867
2947
                  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
 
    
 
2948
                  NullS);
2875
2949
    if (share->transactional != HA_CHOICE_UNDEF)
2876
2950
    {
2877
2951
      ptr= strxmov(ptr, " TRANSACTIONAL=",
2878
2952
                   (share->transactional == HA_CHOICE_YES ? "1" : "0"),
2879
 
                   NULL);
 
2953
                   NullS);
2880
2954
    }
2881
2955
    if (share->transactional != HA_CHOICE_UNDEF)
2882
2956
      ptr= strxmov(ptr, " transactional=",
2883
 
                   ha_choice_values[(uint) share->transactional], NULL);
 
2957
                   ha_choice_values[(uint) share->transactional], NullS);
2884
2958
    table->field[19]->store(option_buff+1,
2885
2959
                            (ptr == option_buff ? 0 : 
2886
2960
                             (uint) (ptr-option_buff)-1), cs);
2927
3001
      table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2928
3002
      if (!tables->schema_table)
2929
3003
      {
2930
 
        table->field[7]->store((int64_t) file->stats.records, true);
 
3004
        table->field[7]->store((longlong) file->stats.records, TRUE);
2931
3005
        table->field[7]->set_notnull();
2932
3006
      }
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);
 
3007
      table->field[8]->store((longlong) file->stats.mean_rec_length, TRUE);
 
3008
      table->field[9]->store((longlong) file->stats.data_file_length, TRUE);
2935
3009
      if (file->stats.max_data_file_length)
2936
3010
      {
2937
 
        table->field[10]->store((int64_t) file->stats.max_data_file_length,
2938
 
                                true);
 
3011
        table->field[10]->store((longlong) file->stats.max_data_file_length,
 
3012
                                TRUE);
2939
3013
      }
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);
 
3014
      table->field[11]->store((longlong) file->stats.index_file_length, TRUE);
 
3015
      table->field[12]->store((longlong) file->stats.delete_length, TRUE);
2942
3016
      if (show_table->found_next_number_field)
2943
3017
      {
2944
 
        table->field[13]->store((int64_t) file->stats.auto_increment_value,
2945
 
                                true);
 
3018
        table->field[13]->store((longlong) file->stats.auto_increment_value,
 
3019
                                TRUE);
2946
3020
        table->field[13]->set_notnull();
2947
3021
      }
2948
3022
      if (file->stats.create_time)
2949
3023
      {
2950
3024
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2951
3025
                                                  (my_time_t) file->stats.create_time);
2952
 
        table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
 
3026
        table->field[14]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
2953
3027
        table->field[14]->set_notnull();
2954
3028
      }
2955
3029
      if (file->stats.update_time)
2956
3030
      {
2957
3031
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2958
3032
                                                  (my_time_t) file->stats.update_time);
2959
 
        table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
 
3033
        table->field[15]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
2960
3034
        table->field[15]->set_notnull();
2961
3035
      }
2962
3036
      if (file->stats.check_time)
2963
3037
      {
2964
3038
        thd->variables.time_zone->gmt_sec_to_TIME(&time,
2965
3039
                                                  (my_time_t) file->stats.check_time);
2966
 
        table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
 
3040
        table->field[16]->store_time(&time, MYSQL_TIMESTAMP_DATETIME);
2967
3041
        table->field[16]->set_notnull();
2968
3042
      }
2969
3043
      if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2970
3044
      {
2971
 
        table->field[18]->store((int64_t) file->checksum(), true);
 
3045
        table->field[18]->store((longlong) file->checksum(), TRUE);
2972
3046
        table->field[18]->set_notnull();
2973
3047
      }
2974
3048
    }
2975
3049
  }
2976
 
  return(schema_table_store_record(thd, table));
 
3050
  DBUG_RETURN(schema_table_store_record(thd, table));
2977
3051
}
2978
3052
 
2979
3053
 
2989
3063
  @return         void
2990
3064
*/
2991
3065
 
2992
 
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2993
 
                       uint32_t offset)
 
3066
void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
 
3067
                       uint offset)
2994
3068
{
2995
3069
  bool is_blob;
2996
3070
  int decimals, field_length;
3007
3081
  table->field[offset]->store(column_type.ptr(),
3008
3082
                         (tmp_buff ? tmp_buff - column_type.ptr() :
3009
3083
                          column_type.length()), cs);
3010
 
  is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
 
3084
  is_blob= (field->type() == MYSQL_TYPE_BLOB);
3011
3085
  if (field->has_charset() || is_blob ||
3012
 
      field->real_type() == DRIZZLE_TYPE_VARCHAR)  // For varbinary type
 
3086
      field->real_type() == MYSQL_TYPE_VARCHAR ||  // For varbinary type
 
3087
      field->real_type() == MYSQL_TYPE_STRING)     // For binary type
3013
3088
  {
3014
 
    uint32_t octet_max_length= field->max_display_length();
3015
 
    if (is_blob && octet_max_length != (uint32_t) 4294967295U)
 
3089
    uint32 octet_max_length= field->max_display_length();
 
3090
    if (is_blob && octet_max_length != (uint32) 4294967295U)
3016
3091
      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;
 
3092
    longlong char_max_len= is_blob ? 
 
3093
      (longlong) octet_max_length / field->charset()->mbminlen :
 
3094
      (longlong) octet_max_length / field->charset()->mbmaxlen;
3020
3095
    /* CHARACTER_MAXIMUM_LENGTH column*/
3021
 
    table->field[offset + 1]->store(char_max_len, true);
 
3096
    table->field[offset + 1]->store(char_max_len, TRUE);
3022
3097
    table->field[offset + 1]->set_notnull();
3023
3098
    /* CHARACTER_OCTET_LENGTH column */
3024
 
    table->field[offset + 2]->store((int64_t) octet_max_length, true);
 
3099
    table->field[offset + 2]->store((longlong) octet_max_length, TRUE);
3025
3100
    table->field[offset + 2]->set_notnull();
3026
3101
  }
3027
3102
 
3032
3107
 
3033
3108
  decimals= field->decimals();
3034
3109
  switch (field->type()) {
3035
 
  case DRIZZLE_TYPE_NEWDECIMAL:
 
3110
  case MYSQL_TYPE_NEWDECIMAL:
3036
3111
    field_length= ((Field_new_decimal*) field)->precision;
3037
3112
    break;
3038
 
  case DRIZZLE_TYPE_TINY:
3039
 
  case DRIZZLE_TYPE_LONG:
3040
 
  case DRIZZLE_TYPE_LONGLONG:
 
3113
  case MYSQL_TYPE_DECIMAL:
 
3114
    field_length= field->field_length - (decimals  ? 2 : 1);
 
3115
    break;
 
3116
  case MYSQL_TYPE_TINY:
 
3117
  case MYSQL_TYPE_SHORT:
 
3118
  case MYSQL_TYPE_LONG:
 
3119
  case MYSQL_TYPE_LONGLONG:
 
3120
  case MYSQL_TYPE_INT24:
3041
3121
    field_length= field->max_display_length() - 1;
3042
3122
    break;
3043
 
  case DRIZZLE_TYPE_DOUBLE:
 
3123
  case MYSQL_TYPE_BIT:
 
3124
    field_length= field->max_display_length();
 
3125
    decimals= -1;                             // return NULL
 
3126
    break;
 
3127
  case MYSQL_TYPE_FLOAT:  
 
3128
  case MYSQL_TYPE_DOUBLE:
3044
3129
    field_length= field->field_length;
3045
3130
    if (decimals == NOT_FIXED_DEC)
3046
3131
      decimals= -1;                           // return NULL
3053
3138
  /* NUMERIC_PRECISION column */
3054
3139
  if (field_length >= 0)
3055
3140
  {
3056
 
    table->field[offset + 3]->store((int64_t) field_length, true);
 
3141
    table->field[offset + 3]->store((longlong) field_length, TRUE);
3057
3142
    table->field[offset + 3]->set_notnull();
3058
3143
  }
3059
3144
  /* NUMERIC_SCALE column */
3060
3145
  if (decimals >= 0)
3061
3146
  {
3062
 
    table->field[offset + 4]->store((int64_t) decimals, true);
 
3147
    table->field[offset + 4]->store((longlong) decimals, TRUE);
3063
3148
    table->field[offset + 4]->set_notnull();
3064
3149
  }
3065
3150
  if (field->has_charset())
3076
3161
}
3077
3162
 
3078
3163
 
3079
 
static int get_schema_column_record(THD *thd, TableList *tables,
3080
 
                                    Table *table, bool res,
 
3164
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
 
3165
                                    TABLE *table, bool res,
3081
3166
                                    LEX_STRING *db_name,
3082
3167
                                    LEX_STRING *table_name)
3083
3168
{
3084
3169
  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;
 
3170
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
3171
  CHARSET_INFO *cs= system_charset_info;
 
3172
  TABLE *show_table;
3088
3173
  TABLE_SHARE *show_table_share;
3089
3174
  Field **ptr, *field, *timestamp_field;
3090
3175
  int count;
 
3176
  DBUG_ENTER("get_schema_column_record");
3091
3177
 
3092
3178
  if (res)
3093
3179
  {
3098
3184
        rather than in SHOW COLUMNS
3099
3185
      */ 
3100
3186
      if (thd->is_error())
3101
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3187
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3102
3188
                     thd->main_da.sql_errno(), thd->main_da.message());
3103
3189
      thd->clear_error();
3104
3190
      res= 0;
3105
3191
    }
3106
 
    return(res);
 
3192
    DBUG_RETURN(res);
3107
3193
  }
3108
3194
 
3109
3195
  show_table= tables->table;
3127
3213
    if (!show_table->read_set)
3128
3214
    {
3129
3215
      /* 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)))
3133
 
        return(0);
 
3216
      uchar *bitmaps;
 
3217
      uint bitmap_size= show_table_share->column_bitmap_size;
 
3218
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
 
3219
        DBUG_RETURN(0);
3134
3220
      bitmap_init(&show_table->def_read_set,
3135
 
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
 
3221
                  (my_bitmap_map*) bitmaps, show_table_share->fields, FALSE);
3136
3222
      bitmap_set_all(&show_table->def_read_set);
3137
3223
      show_table->read_set= &show_table->def_read_set;
3138
3224
    }
3141
3227
 
3142
3228
  for (; (field= *ptr) ; ptr++)
3143
3229
  {
3144
 
    unsigned char *pos;
 
3230
    uchar *pos;
3145
3231
    char tmp[MAX_FIELD_WIDTH];
3146
3232
    String type(tmp,sizeof(tmp), system_charset_info);
3147
3233
    char *end;
3162
3248
    table->field[2]->store(table_name->str, table_name->length, cs);
3163
3249
    table->field[3]->store(field->field_name, strlen(field->field_name),
3164
3250
                           cs);
3165
 
    table->field[4]->store((int64_t) count, true);
 
3251
    table->field[4]->store((longlong) count, TRUE);
3166
3252
 
3167
3253
    if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3168
3254
    {
3169
3255
      table->field[5]->store(type.ptr(), type.length(), cs);
3170
3256
      table->field[5]->set_notnull();
3171
3257
    }
3172
 
    pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
 
3258
    pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
3173
3259
    table->field[6]->store((const char*) pos,
3174
3260
                           strlen((const char*) pos), cs);
3175
3261
    store_column_type(table, field, cs, 7);
3176
3262
 
3177
 
    pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
 
3263
    pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3178
3264
                 (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3179
3265
                 (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3180
3266
    table->field[15]->store((const char*) pos,
3187
3273
        field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3188
3274
      table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3189
3275
                              cs);
3190
 
    if (field->vcol_info)
3191
 
          table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
 
3276
 
3192
3277
    table->field[18]->store(field->comment.str, field->comment.length, cs);
3193
3278
    {
 
3279
      enum ha_storage_media storage_type= (enum ha_storage_media)
 
3280
        ((field->flags >> FIELD_STORAGE_FLAGS) & STORAGE_TYPE_MASK);
3194
3281
      enum column_format_type column_format= (enum column_format_type)
3195
3282
        ((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3196
 
      pos=(unsigned char*)"Default";
 
3283
      pos=(uchar*)(storage_type == HA_SM_DEFAULT ? "Default" :
 
3284
                   storage_type == HA_SM_DISK ? "Disk" : "Memory");
3197
3285
      table->field[19]->store((const char*) pos,
3198
3286
                              strlen((const char*) pos), cs);
3199
 
      pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
 
3287
      pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3200
3288
                   column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3201
3289
                                                             "Dynamic");
3202
3290
      table->field[20]->store((const char*) pos,
3203
3291
                              strlen((const char*) pos), cs);
3204
3292
    }
3205
3293
    if (schema_table_store_record(thd, table))
3206
 
      return(1);
 
3294
      DBUG_RETURN(1);
3207
3295
  }
3208
 
  return(0);
 
3296
  DBUG_RETURN(0);
3209
3297
}
3210
3298
 
3211
3299
 
3212
3300
 
3213
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3301
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond)
3214
3302
{
3215
3303
  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;
 
3304
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3305
  TABLE *table= tables->table;
 
3306
  CHARSET_INFO *scs= system_charset_info;
3219
3307
 
3220
3308
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3221
3309
  {
3222
 
    const CHARSET_INFO * const tmp_cs= cs[0];
 
3310
    CHARSET_INFO *tmp_cs= cs[0];
3223
3311
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) && 
3224
3312
        (tmp_cs->state & MY_CS_AVAILABLE) &&
3225
3313
        !(tmp_cs->state & MY_CS_HIDDEN) &&
3226
3314
        !(wild && wild[0] &&
3227
 
          wild_case_compare(scs, tmp_cs->csname,wild)))
 
3315
          wild_case_compare(scs, tmp_cs->csname,wild)))
3228
3316
    {
3229
3317
      const char *comment;
3230
3318
      restore_record(table, s->default_values);
3232
3320
      table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3233
3321
      comment= tmp_cs->comment ? tmp_cs->comment : "";
3234
3322
      table->field[2]->store(comment, strlen(comment), scs);
3235
 
      table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
 
3323
      table->field[3]->store((longlong) tmp_cs->mbmaxlen, TRUE);
3236
3324
      if (schema_table_store_record(thd, table))
3237
3325
        return 1;
3238
3326
    }
3241
3329
}
3242
3330
 
3243
3331
 
3244
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3332
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond)
3245
3333
{
3246
3334
  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;
 
3335
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3336
  TABLE *table= tables->table;
 
3337
  CHARSET_INFO *scs= system_charset_info;
3250
3338
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3251
3339
  {
3252
3340
    CHARSET_INFO **cl;
3253
 
    const CHARSET_INFO *tmp_cs= cs[0];
 
3341
    CHARSET_INFO *tmp_cs= cs[0];
3254
3342
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3255
3343
         (tmp_cs->state & MY_CS_HIDDEN) ||
3256
3344
        !(tmp_cs->state & MY_CS_PRIMARY))
3257
3345
      continue;
3258
3346
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3259
3347
    {
3260
 
      const CHARSET_INFO *tmp_cl= cl[0];
 
3348
      CHARSET_INFO *tmp_cl= cl[0];
3261
3349
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
3262
3350
          !my_charset_same(tmp_cs, tmp_cl))
3263
 
        continue;
 
3351
        continue;
3264
3352
      if (!(wild && wild[0] &&
3265
 
          wild_case_compare(scs, tmp_cl->name,wild)))
 
3353
          wild_case_compare(scs, tmp_cl->name,wild)))
3266
3354
      {
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);
 
3355
        const char *tmp_buff;
 
3356
        restore_record(table, s->default_values);
 
3357
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3270
3358
        table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3271
 
        table->field[2]->store((int64_t) tmp_cl->number, true);
 
3359
        table->field[2]->store((longlong) tmp_cl->number, TRUE);
3272
3360
        tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3273
 
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
 
3361
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3274
3362
        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);
 
3363
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
 
3364
        table->field[5]->store((longlong) tmp_cl->strxfrm_multiply, TRUE);
3277
3365
        if (schema_table_store_record(thd, table))
3278
3366
          return 1;
3279
3367
      }
3283
3371
}
3284
3372
 
3285
3373
 
3286
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3374
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond)
3287
3375
{
3288
3376
  CHARSET_INFO **cs;
3289
 
  Table *table= tables->table;
3290
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3377
  TABLE *table= tables->table;
 
3378
  CHARSET_INFO *scs= system_charset_info;
3291
3379
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3292
3380
  {
3293
3381
    CHARSET_INFO **cl;
3294
 
    const CHARSET_INFO *tmp_cs= cs[0];
 
3382
    CHARSET_INFO *tmp_cs= cs[0];
3295
3383
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || 
3296
3384
        !(tmp_cs->state & MY_CS_PRIMARY))
3297
3385
      continue;
3298
3386
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3299
3387
    {
3300
 
      const CHARSET_INFO *tmp_cl= cl[0];
 
3388
      CHARSET_INFO *tmp_cl= cl[0];
3301
3389
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
3302
3390
          !my_charset_same(tmp_cs,tmp_cl))
3303
3391
        continue;
3312
3400
}
3313
3401
 
3314
3402
 
3315
 
static int get_schema_stat_record(THD *thd, TableList *tables,
3316
 
                                  Table *table, bool res,
 
3403
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
 
3404
                                  TABLE *table, bool res,
3317
3405
                                  LEX_STRING *db_name,
3318
3406
                                  LEX_STRING *table_name)
3319
3407
{
3320
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3408
  CHARSET_INFO *cs= system_charset_info;
 
3409
  DBUG_ENTER("get_schema_stat_record");
3321
3410
  if (res)
3322
3411
  {
3323
3412
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3327
3416
        rather than in SHOW KEYS
3328
3417
      */
3329
3418
      if (thd->is_error())
3330
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3419
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3331
3420
                     thd->main_da.sql_errno(), thd->main_da.message());
3332
3421
      thd->clear_error();
3333
3422
      res= 0;
3334
3423
    }
3335
 
    return(res);
 
3424
    DBUG_RETURN(res);
3336
3425
  }
3337
3426
  else
3338
3427
  {
3339
 
    Table *show_table= tables->table;
 
3428
    TABLE *show_table= tables->table;
3340
3429
    KEY *key_info=show_table->s->key_info;
3341
3430
    if (show_table->file)
3342
3431
      show_table->file->info(HA_STATUS_VARIABLE |
3343
3432
                             HA_STATUS_NO_LOCK |
3344
3433
                             HA_STATUS_TIME);
3345
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
 
3434
    for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3346
3435
    {
3347
3436
      KEY_PART_INFO *key_part= key_info->key_part;
3348
3437
      const char *str;
3349
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3438
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3350
3439
      {
3351
3440
        restore_record(table, s->default_values);
3352
3441
        table->field[1]->store(db_name->str, db_name->length, cs);
3353
3442
        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);
 
3443
        table->field[3]->store((longlong) ((key_info->flags &
 
3444
                                            HA_NOSAME) ? 0 : 1), TRUE);
3356
3445
        table->field[4]->store(db_name->str, db_name->length, cs);
3357
3446
        table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3358
 
        table->field[6]->store((int64_t) (j+1), true);
 
3447
        table->field[6]->store((longlong) (j+1), TRUE);
3359
3448
        str=(key_part->field ? key_part->field->field_name :
3360
3449
             "?unknown field?");
3361
3450
        table->field[7]->store(str, strlen(str), cs);
3373
3462
          {
3374
3463
            ha_rows records=(show_table->file->stats.records /
3375
3464
                             key->rec_per_key[j]);
3376
 
            table->field[9]->store((int64_t) records, true);
 
3465
            table->field[9]->store((longlong) records, TRUE);
3377
3466
            table->field[9]->set_notnull();
3378
3467
          }
3379
3468
          str= show_table->file->index_type(i);
3383
3472
             key_part->length !=
3384
3473
             show_table->s->field[key_part->fieldnr-1]->key_length()))
3385
3474
        {
3386
 
          table->field[10]->store((int64_t) key_part->length /
3387
 
                                  key_part->field->charset()->mbmaxlen, true);
 
3475
          table->field[10]->store((longlong) key_part->length /
 
3476
                                  key_part->field->charset()->mbmaxlen, TRUE);
3388
3477
          table->field[10]->set_notnull();
3389
3478
        }
3390
 
        uint32_t flags= key_part->field ? key_part->field->flags : 0;
 
3479
        uint flags= key_part->field ? key_part->field->flags : 0;
3391
3480
        const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3392
3481
        table->field[12]->store(pos, strlen(pos), cs);
3393
3482
        if (!show_table->s->keys_in_use.is_set(i))
3395
3484
        else
3396
3485
          table->field[14]->store("", 0, cs);
3397
3486
        table->field[14]->set_notnull();
3398
 
        assert(test(key_info->flags & HA_USES_COMMENT) == 
 
3487
        DBUG_ASSERT(test(key_info->flags & HA_USES_COMMENT) == 
3399
3488
                   (key_info->comment.length > 0));
3400
3489
        if (key_info->flags & HA_USES_COMMENT)
3401
3490
          table->field[15]->store(key_info->comment.str, 
3402
3491
                                  key_info->comment.length, cs);
3403
3492
        if (schema_table_store_record(thd, table))
3404
 
          return(1);
 
3493
          DBUG_RETURN(1);
3405
3494
      }
3406
3495
    }
3407
3496
  }
3408
 
  return(res);
 
3497
  DBUG_RETURN(res);
3409
3498
}
3410
3499
 
3411
3500
 
3412
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3501
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3413
3502
                       LEX_STRING *table_name, const char *key_name,
3414
 
                       uint32_t key_len, const char *con_type, uint32_t con_len)
 
3503
                       uint key_len, const char *con_type, uint con_len)
3415
3504
{
3416
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3505
  CHARSET_INFO *cs= system_charset_info;
3417
3506
  restore_record(table, s->default_values);
3418
3507
  table->field[1]->store(db_name->str, db_name->length, cs);
3419
3508
  table->field[2]->store(key_name, key_len, cs);
3424
3513
}
3425
3514
 
3426
3515
 
3427
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
3428
 
                                         Table *table, bool res,
 
3516
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
 
3517
                                         TABLE *table, bool res,
3429
3518
                                         LEX_STRING *db_name,
3430
3519
                                         LEX_STRING *table_name)
3431
3520
{
 
3521
  DBUG_ENTER("get_schema_constraints_record");
3432
3522
  if (res)
3433
3523
  {
3434
3524
    if (thd->is_error())
3435
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3525
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3436
3526
                   thd->main_da.sql_errno(), thd->main_da.message());
3437
3527
    thd->clear_error();
3438
 
    return(0);
 
3528
    DBUG_RETURN(0);
3439
3529
  }
3440
3530
  else
3441
3531
  {
3442
3532
    List<FOREIGN_KEY_INFO> f_key_list;
3443
 
    Table *show_table= tables->table;
 
3533
    TABLE *show_table= tables->table;
3444
3534
    KEY *key_info=show_table->key_info;
3445
 
    uint32_t primary_key= show_table->s->primary_key;
 
3535
    uint primary_key= show_table->s->primary_key;
3446
3536
    show_table->file->info(HA_STATUS_VARIABLE | 
3447
3537
                           HA_STATUS_NO_LOCK |
3448
3538
                           HA_STATUS_TIME);
3449
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3539
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3450
3540
    {
3451
3541
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3452
3542
        continue;
3456
3546
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
3457
3547
                              strlen(key_info->name),
3458
3548
                              STRING_WITH_LEN("PRIMARY KEY")))
3459
 
          return(1);
 
3549
          DBUG_RETURN(1);
3460
3550
      }
3461
3551
      else if (key_info->flags & HA_NOSAME)
3462
3552
      {
3463
3553
        if (store_constraints(thd, table, db_name, table_name, key_info->name,
3464
3554
                              strlen(key_info->name),
3465
3555
                              STRING_WITH_LEN("UNIQUE")))
3466
 
          return(1);
 
3556
          DBUG_RETURN(1);
3467
3557
      }
3468
3558
    }
3469
3559
 
3476
3566
                            f_key_info->forein_id->str,
3477
3567
                            strlen(f_key_info->forein_id->str),
3478
3568
                            "FOREIGN KEY", 11))
3479
 
        return(1);
 
3569
        DBUG_RETURN(1);
3480
3570
    }
3481
3571
  }
3482
 
  return(res);
 
3572
  DBUG_RETURN(res);
3483
3573
}
3484
3574
 
3485
3575
 
3486
 
void store_key_column_usage(Table *table, LEX_STRING *db_name,
 
3576
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3487
3577
                            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)
 
3578
                            uint key_len, const char *con_type, uint con_len,
 
3579
                            longlong idx)
3490
3580
{
3491
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3581
  CHARSET_INFO *cs= system_charset_info;
3492
3582
  table->field[1]->store(db_name->str, db_name->length, cs);
3493
3583
  table->field[2]->store(key_name, key_len, cs);
3494
3584
  table->field[4]->store(db_name->str, db_name->length, cs);
3495
3585
  table->field[5]->store(table_name->str, table_name->length, cs);
3496
3586
  table->field[6]->store(con_type, con_len, cs);
3497
 
  table->field[7]->store((int64_t) idx, true);
 
3587
  table->field[7]->store((longlong) idx, TRUE);
3498
3588
}
3499
3589
 
3500
3590
 
3501
3591
static int get_schema_key_column_usage_record(THD *thd,
3502
 
                                              TableList *tables,
3503
 
                                              Table *table, bool res,
 
3592
                                              TABLE_LIST *tables,
 
3593
                                              TABLE *table, bool res,
3504
3594
                                              LEX_STRING *db_name,
3505
3595
                                              LEX_STRING *table_name)
3506
3596
{
 
3597
  DBUG_ENTER("get_schema_key_column_usage_record");
3507
3598
  if (res)
3508
3599
  {
3509
3600
    if (thd->is_error())
3510
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3601
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3511
3602
                   thd->main_da.sql_errno(), thd->main_da.message());
3512
3603
    thd->clear_error();
3513
 
    return(0);
 
3604
    DBUG_RETURN(0);
3514
3605
  }
3515
3606
  else
3516
3607
  {
3517
3608
    List<FOREIGN_KEY_INFO> f_key_list;
3518
 
    Table *show_table= tables->table;
 
3609
    TABLE *show_table= tables->table;
3519
3610
    KEY *key_info=show_table->key_info;
3520
 
    uint32_t primary_key= show_table->s->primary_key;
 
3611
    uint primary_key= show_table->s->primary_key;
3521
3612
    show_table->file->info(HA_STATUS_VARIABLE | 
3522
3613
                           HA_STATUS_NO_LOCK |
3523
3614
                           HA_STATUS_TIME);
3524
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3615
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3525
3616
    {
3526
3617
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3527
3618
        continue;
3528
 
      uint32_t f_idx= 0;
 
3619
      uint f_idx= 0;
3529
3620
      KEY_PART_INFO *key_part= key_info->key_part;
3530
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3621
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3531
3622
      {
3532
3623
        if (key_part->field)
3533
3624
        {
3538
3629
                                 strlen(key_info->name), 
3539
3630
                                 key_part->field->field_name, 
3540
3631
                                 strlen(key_part->field->field_name),
3541
 
                                 (int64_t) f_idx);
 
3632
                                 (longlong) f_idx);
3542
3633
          if (schema_table_store_record(thd, table))
3543
 
            return(1);
 
3634
            DBUG_RETURN(1);
3544
3635
        }
3545
3636
      }
3546
3637
    }
3554
3645
      LEX_STRING *r_info;
3555
3646
      List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3556
3647
        it1(f_key_info->referenced_fields);
3557
 
      uint32_t f_idx= 0;
 
3648
      uint f_idx= 0;
3558
3649
      while ((f_info= it++))
3559
3650
      {
3560
3651
        r_info= it1++;
3564
3655
                               f_key_info->forein_id->str,
3565
3656
                               f_key_info->forein_id->length,
3566
3657
                               f_info->str, f_info->length,
3567
 
                               (int64_t) f_idx);
3568
 
        table->field[8]->store((int64_t) f_idx, true);
 
3658
                               (longlong) f_idx);
 
3659
        table->field[8]->store((longlong) f_idx, TRUE);
3569
3660
        table->field[8]->set_notnull();
3570
3661
        table->field[9]->store(f_key_info->referenced_db->str,
3571
3662
                               f_key_info->referenced_db->length,
3579
3670
                                system_charset_info);
3580
3671
        table->field[11]->set_notnull();
3581
3672
        if (schema_table_store_record(thd, table))
3582
 
          return(1);
 
3673
          DBUG_RETURN(1);
3583
3674
      }
3584
3675
    }
3585
3676
  }
3586
 
  return(res);
 
3677
  DBUG_RETURN(res);
3587
3678
}
3588
3679
 
3589
3680
 
3590
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3681
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond)
3591
3682
{
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;
 
3683
  DBUG_ENTER("fill_open_tables");
 
3684
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3685
  TABLE *table= tables->table;
 
3686
  CHARSET_INFO *cs= system_charset_info;
 
3687
  OPEN_TABLE_LIST *open_list;
3596
3688
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3597
3689
            && thd->is_fatal_error)
3598
 
    return(1);
 
3690
    DBUG_RETURN(1);
3599
3691
 
3600
3692
  for (; open_list ; open_list=open_list->next)
3601
3693
  {
3602
3694
    restore_record(table, s->default_values);
3603
3695
    table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3604
3696
    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);
 
3697
    table->field[2]->store((longlong) open_list->in_use, TRUE);
 
3698
    table->field[3]->store((longlong) open_list->locked, TRUE);
3607
3699
    if (schema_table_store_record(thd, table))
3608
 
      return(1);
 
3700
      DBUG_RETURN(1);
3609
3701
  }
3610
 
  return(0);
 
3702
  DBUG_RETURN(0);
3611
3703
}
3612
3704
 
3613
3705
 
3614
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3706
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond)
3615
3707
{
 
3708
  DBUG_ENTER("fill_variables");
3616
3709
  int res= 0;
3617
3710
  LEX *lex= thd->lex;
3618
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3711
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3619
3712
  enum enum_schema_tables schema_table_idx=
3620
3713
    get_schema_table_idx(tables->schema_table);
3621
3714
  enum enum_var_type option_type= OPT_SESSION;
3630
3723
  res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3631
3724
                         option_type, NULL, "", tables->table, upper_case_names);
3632
3725
  rw_unlock(&LOCK_system_variables_hash);
3633
 
  return(res);
 
3726
  DBUG_RETURN(res);
3634
3727
}
3635
3728
 
3636
3729
 
3637
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3730
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
3638
3731
{
 
3732
  DBUG_ENTER("fill_status");
3639
3733
  LEX *lex= thd->lex;
3640
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3734
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3641
3735
  int res= 0;
3642
3736
  STATUS_VAR *tmp1, tmp;
3643
3737
  enum enum_schema_tables schema_table_idx=
3672
3766
                         option_type, tmp1, "", tables->table,
3673
3767
                         upper_case_names);
3674
3768
  pthread_mutex_unlock(&LOCK_status);
3675
 
  return(res);
 
3769
  DBUG_RETURN(res);
3676
3770
}
3677
3771
 
3678
3772
 
3695
3789
*/
3696
3790
 
3697
3791
static int
3698
 
get_referential_constraints_record(THD *thd, TableList *tables,
3699
 
                                   Table *table, bool res,
 
3792
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
 
3793
                                   TABLE *table, bool res,
3700
3794
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3701
3795
{
3702
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3796
  CHARSET_INFO *cs= system_charset_info;
 
3797
  DBUG_ENTER("get_referential_constraints_record");
3703
3798
 
3704
3799
  if (res)
3705
3800
  {
3706
3801
    if (thd->is_error())
3707
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3802
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3708
3803
                   thd->main_da.sql_errno(), thd->main_da.message());
3709
3804
    thd->clear_error();
3710
 
    return(0);
 
3805
    DBUG_RETURN(0);
3711
3806
  }
3712
3807
 
3713
3808
  {
3714
3809
    List<FOREIGN_KEY_INFO> f_key_list;
3715
 
    Table *show_table= tables->table;
 
3810
    TABLE *show_table= tables->table;
3716
3811
    show_table->file->info(HA_STATUS_VARIABLE | 
3717
3812
                           HA_STATUS_NO_LOCK |
3718
3813
                           HA_STATUS_TIME);
3745
3840
      table->field[8]->store(f_key_info->delete_method->str, 
3746
3841
                             f_key_info->delete_method->length, cs);
3747
3842
      if (schema_table_store_record(thd, table))
3748
 
        return(1);
 
3843
        DBUG_RETURN(1);
3749
3844
    }
3750
3845
  }
3751
 
  return(0);
 
3846
  DBUG_RETURN(0);
3752
3847
}
3753
3848
 
3754
3849
 
3772
3867
    0   table not found
3773
3868
    1   found the schema table
3774
3869
*/
3775
 
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
3776
 
                                           plugin_ref plugin,
 
3870
static my_bool find_schema_table_in_plugin(THD *thd, plugin_ref plugin,
3777
3871
                                           void* p_table)
3778
3872
{
3779
3873
  schema_table_ref *p_schema_table= (schema_table_ref *)p_table;
3780
3874
  const char* table_name= p_schema_table->table_name;
3781
3875
  ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
 
3876
  DBUG_ENTER("find_schema_table_in_plugin");
3782
3877
 
3783
3878
  if (!my_strcasecmp(system_charset_info,
3784
3879
                     schema_table->table_name,
3785
3880
                     table_name)) {
3786
3881
    p_schema_table->schema_table= schema_table;
3787
 
    return(1);
 
3882
    DBUG_RETURN(1);
3788
3883
  }
3789
3884
 
3790
 
  return(0);
 
3885
  DBUG_RETURN(0);
3791
3886
}
3792
3887
 
3793
3888
 
3808
3903
{
3809
3904
  schema_table_ref schema_table_a;
3810
3905
  ST_SCHEMA_TABLE *schema_table= schema_tables;
 
3906
  DBUG_ENTER("find_schema_table");
3811
3907
 
3812
3908
  for (; schema_table->table_name; schema_table++)
3813
3909
  {
3814
3910
    if (!my_strcasecmp(system_charset_info,
3815
3911
                       schema_table->table_name,
3816
3912
                       table_name))
3817
 
      return(schema_table);
 
3913
      DBUG_RETURN(schema_table);
3818
3914
  }
3819
3915
 
3820
3916
  schema_table_a.table_name= table_name;
3821
3917
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
3822
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3823
 
    return(schema_table_a.schema_table);
 
3918
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
 
3919
    DBUG_RETURN(schema_table_a.schema_table);
3824
3920
 
3825
 
  return(NULL);
 
3921
  DBUG_RETURN(NULL);
3826
3922
}
3827
3923
 
3828
3924
 
3836
3932
  Create information_schema table using schema_table data.
3837
3933
 
3838
3934
  @note
 
3935
    For MYSQL_TYPE_DECIMAL fields only, the field_length member has encoded
 
3936
    into it two numbers, based on modulus of base-10 numbers.  In the ones
 
3937
    position is the number of decimals.  Tens position is unused.  In the
 
3938
    hundreds and thousands position is a two-digit decimal number representing
 
3939
    length.  Encode this value with  (decimals*100)+length  , where
 
3940
    0<decimals<10 and 0<=length<100 .
3839
3941
 
3840
3942
  @param
3841
3943
    thd                   thread handler
3847
3949
  @retval  NULL           Can't create table
3848
3950
*/
3849
3951
 
3850
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3952
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3851
3953
{
3852
3954
  int field_count= 0;
3853
3955
  Item *item;
3854
 
  Table *table;
 
3956
  TABLE *table;
3855
3957
  List<Item> field_list;
3856
3958
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3857
3959
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3858
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3960
  CHARSET_INFO *cs= system_charset_info;
 
3961
  DBUG_ENTER("create_schema_table");
3859
3962
 
3860
3963
  for (; fields_info->field_name; fields_info++)
3861
3964
  {
3862
3965
    switch (fields_info->field_type) {
3863
 
    case DRIZZLE_TYPE_TINY:
3864
 
    case DRIZZLE_TYPE_LONG:
3865
 
    case DRIZZLE_TYPE_LONGLONG:
 
3966
    case MYSQL_TYPE_TINY:
 
3967
    case MYSQL_TYPE_LONG:
 
3968
    case MYSQL_TYPE_SHORT:
 
3969
    case MYSQL_TYPE_LONGLONG:
 
3970
    case MYSQL_TYPE_INT24:
3866
3971
      if (!(item= new Item_return_int(fields_info->field_name,
3867
3972
                                      fields_info->field_length,
3868
3973
                                      fields_info->field_type,
3869
3974
                                      fields_info->value)))
3870
3975
      {
3871
 
        return(0);
 
3976
        DBUG_RETURN(0);
3872
3977
      }
3873
3978
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3874
3979
      break;
3875
 
    case DRIZZLE_TYPE_NEWDATE:
3876
 
    case DRIZZLE_TYPE_TIME:
3877
 
    case DRIZZLE_TYPE_TIMESTAMP:
3878
 
    case DRIZZLE_TYPE_DATETIME:
 
3980
    case MYSQL_TYPE_DATE:
 
3981
    case MYSQL_TYPE_TIME:
 
3982
    case MYSQL_TYPE_TIMESTAMP:
 
3983
    case MYSQL_TYPE_DATETIME:
3879
3984
      if (!(item=new Item_return_date_time(fields_info->field_name,
3880
3985
                                           fields_info->field_type)))
3881
3986
      {
3882
 
        return(0);
 
3987
        DBUG_RETURN(0);
3883
3988
      }
3884
3989
      break;
3885
 
    case DRIZZLE_TYPE_DOUBLE:
 
3990
    case MYSQL_TYPE_FLOAT:
 
3991
    case MYSQL_TYPE_DOUBLE:
3886
3992
      if ((item= new Item_float(fields_info->field_name, 0.0, NOT_FIXED_DEC, 
3887
3993
                           fields_info->field_length)) == NULL)
3888
 
        return(NULL);
 
3994
        DBUG_RETURN(NULL);
3889
3995
      break;
3890
 
    case DRIZZLE_TYPE_NEWDECIMAL:
3891
 
      if (!(item= new Item_decimal((int64_t) fields_info->value, false)))
 
3996
    case MYSQL_TYPE_DECIMAL:
 
3997
    case MYSQL_TYPE_NEWDECIMAL:
 
3998
      if (!(item= new Item_decimal((longlong) fields_info->value, false)))
3892
3999
      {
3893
 
        return(0);
 
4000
        DBUG_RETURN(0);
3894
4001
      }
3895
4002
      item->unsigned_flag= (fields_info->field_flags & MY_I_S_UNSIGNED);
3896
4003
      item->decimals= fields_info->field_length%10;
3902
4009
      item->set_name(fields_info->field_name,
3903
4010
                     strlen(fields_info->field_name), cs);
3904
4011
      break;
3905
 
    case DRIZZLE_TYPE_BLOB:
 
4012
    case MYSQL_TYPE_TINY_BLOB:
 
4013
    case MYSQL_TYPE_MEDIUM_BLOB:
 
4014
    case MYSQL_TYPE_LONG_BLOB:
 
4015
    case MYSQL_TYPE_BLOB:
3906
4016
      if (!(item= new Item_blob(fields_info->field_name,
3907
4017
                                fields_info->field_length)))
3908
4018
      {
3909
 
        return(0);
 
4019
        DBUG_RETURN(0);
3910
4020
      }
3911
4021
      break;
3912
4022
    default:
 
4023
      /* Don't let unimplemented types pass through. Could be a grave error. */
 
4024
      DBUG_ASSERT(fields_info->field_type == MYSQL_TYPE_STRING);
 
4025
 
3913
4026
      if (!(item= new Item_empty_string("", fields_info->field_length, cs)))
3914
4027
      {
3915
 
        return(0);
 
4028
        DBUG_RETURN(0);
3916
4029
      }
3917
4030
      item->set_name(fields_info->field_name,
3918
4031
                     strlen(fields_info->field_name), cs);
3930
4043
  tmp_table_param->schema_table= 1;
3931
4044
  SELECT_LEX *select_lex= thd->lex->current_select;
3932
4045
  if (!(table= create_tmp_table(thd, tmp_table_param,
3933
 
                                field_list, (order_st*) 0, 0, 0, 
 
4046
                                field_list, (ORDER*) 0, 0, 0, 
3934
4047
                                (select_lex->options | thd->options |
3935
4048
                                 TMP_TABLE_ALL_COLUMNS),
3936
4049
                                HA_POS_ERROR, table_list->alias)))
3937
 
    return(0);
 
4050
    DBUG_RETURN(0);
3938
4051
  my_bitmap_map* bitmaps=
3939
4052
    (my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3940
4053
  bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3941
 
              false);
 
4054
              FALSE);
3942
4055
  table->read_set= &table->def_read_set;
3943
4056
  bitmap_clear_all(table->read_set);
3944
4057
  table_list->schema_table_param= tmp_table_param;
3945
 
  return(table);
 
4058
  DBUG_RETURN(table);
3946
4059
}
3947
4060
 
3948
4061
 
3970
4083
    if (field_info->old_name)
3971
4084
    {
3972
4085
      Item_field *field= new Item_field(context,
3973
 
                                        NULL, NULL, field_info->field_name);
 
4086
                                        NullS, NullS, field_info->field_name);
3974
4087
      if (field)
3975
4088
      {
3976
4089
        field->set_name(field_info->old_name,
3997
4110
    ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3998
4111
    String buffer(tmp,sizeof(tmp), system_charset_info);
3999
4112
    Item_field *field= new Item_field(context,
4000
 
                                      NULL, NULL, field_info->field_name);
 
4113
                                      NullS, NullS, field_info->field_name);
4001
4114
    if (!field || add_item_to_list(thd, field))
4002
4115
      return 1;
4003
4116
    buffer.length(0);
4032
4145
    buffer.append(')');
4033
4146
  }
4034
4147
  Item_field *field= new Item_field(context,
4035
 
                                    NULL, NULL, field_info->field_name);
 
4148
                                    NullS, NullS, field_info->field_name);
4036
4149
  if (add_item_to_list(thd, field))
4037
4150
    return 1;
4038
4151
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4040
4153
  {
4041
4154
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4042
4155
    field_info= &schema_table->fields_info[3];
4043
 
    field= new Item_field(context, NULL, NULL, field_info->field_name);
 
4156
    field= new Item_field(context, NullS, NullS, field_info->field_name);
4044
4157
    if (add_item_to_list(thd, field))
4045
4158
      return 1;
4046
4159
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4065
4178
                               *field_num == 18))
4066
4179
      continue;
4067
4180
    Item_field *field= new Item_field(context,
4068
 
                                      NULL, NULL, field_info->field_name);
 
4181
                                      NullS, NullS, field_info->field_name);
4069
4182
    if (field)
4070
4183
    {
4071
4184
      field->set_name(field_info->old_name,
4090
4203
  {
4091
4204
    field_info= &schema_table->fields_info[*field_num];
4092
4205
    Item_field *field= new Item_field(context,
4093
 
                                      NULL, NULL, field_info->field_name);
 
4206
                                      NullS, NullS, field_info->field_name);
4094
4207
    if (field)
4095
4208
    {
4096
4209
      field->set_name(field_info->old_name,
4118
4231
    1   error
4119
4232
*/
4120
4233
 
4121
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4234
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4122
4235
{
4123
 
  Table *table;
 
4236
  TABLE *table;
 
4237
  DBUG_ENTER("mysql_schema_table");
4124
4238
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4125
 
    return(1);
 
4239
    DBUG_RETURN(1);
4126
4240
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4127
4241
  /*
4128
4242
    This test is necessary to make
4155
4269
      {
4156
4270
        if (!transl->item->fixed &&
4157
4271
            transl->item->fix_fields(thd, &transl->item))
4158
 
          return(1);
 
4272
          DBUG_RETURN(1);
4159
4273
      }
4160
 
      return(0);
 
4274
      DBUG_RETURN(0);
4161
4275
    }
4162
4276
    List_iterator_fast<Item> it(sel->item_list);
4163
4277
    if (!(transl=
4164
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
 
4278
          (Field_translator*)(thd->stmt_arena->
 
4279
                              alloc(sel->item_list.elements *
4165
4280
                                    sizeof(Field_translator)))))
4166
4281
    {
4167
 
      return(1);
 
4282
      DBUG_RETURN(1);
4168
4283
    }
4169
4284
    for (org_transl= transl; (item= it++); transl++)
4170
4285
    {
4172
4287
      transl->name= item->name;
4173
4288
      if (!item->fixed && item->fix_fields(thd, &transl->item))
4174
4289
      {
4175
 
        return(1);
 
4290
        DBUG_RETURN(1);
4176
4291
      }
4177
4292
    }
4178
4293
    table_list->field_translation= org_transl;
4179
4294
    table_list->field_translation_end= transl;
4180
4295
  }
4181
4296
 
4182
 
  return(0);
 
4297
  DBUG_RETURN(0);
4183
4298
}
4184
4299
 
4185
4300
 
4202
4317
{
4203
4318
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4204
4319
  LEX_STRING db, table;
 
4320
  DBUG_ENTER("make_schema_select");
 
4321
  DBUG_PRINT("enter", ("mysql_schema_select: %s", schema_table->table_name));
4205
4322
  /*
4206
4323
     We have to make non const db_name & table_name
4207
4324
     because of lower_case_table_names
4214
4331
      !sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4215
4332
                              0, 0, TL_READ))
4216
4333
  {
4217
 
    return(1);
 
4334
    DBUG_RETURN(1);
4218
4335
  }
4219
 
  return(0);
 
4336
  DBUG_RETURN(0);
4220
4337
}
4221
4338
 
4222
4339
 
4229
4346
    executed_place place where I_S table processed
4230
4347
 
4231
4348
  RETURN
4232
 
    false success
4233
 
    true  error
 
4349
    FALSE success
 
4350
    TRUE  error
4234
4351
*/
4235
4352
 
4236
4353
bool get_schema_tables_result(JOIN *join,
4240
4357
  THD *thd= join->thd;
4241
4358
  LEX *lex= thd->lex;
4242
4359
  bool result= 0;
 
4360
  DBUG_ENTER("get_schema_tables_result");
4243
4361
 
4244
4362
  thd->no_warnings_for_error= 1;
4245
4363
  for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4247
4365
    if (!tab->table || !tab->table->pos_in_table_list)
4248
4366
      break;
4249
4367
 
4250
 
    TableList *table_list= tab->table->pos_in_table_list;
 
4368
    TABLE_LIST *table_list= tab->table->pos_in_table_list;
4251
4369
    if (table_list->schema_table)
4252
4370
    {
4253
4371
      bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4303
4421
    }
4304
4422
  }
4305
4423
  thd->no_warnings_for_error= 0;
4306
 
  return(result);
 
4424
  DBUG_RETURN(result);
4307
4425
}
4308
4426
 
4309
4427
ST_FIELD_INFO schema_fields_info[]=
4310
4428
{
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}
 
4429
  {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4430
  {"SCHEMA_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Database",
 
4431
   SKIP_OPEN_TABLE},
 
4432
  {"DEFAULT_CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0,
 
4433
   SKIP_OPEN_TABLE},
 
4434
  {"DEFAULT_COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4435
  {"SQL_PATH", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4436
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4319
4437
};
4320
4438
 
4321
4439
 
4322
4440
ST_FIELD_INFO tables_fields_info[]=
4323
4441
{
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",
 
4442
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4443
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4444
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
4327
4445
   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,
 
4446
  {"TABLE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4447
  {"ENGINE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Engine", OPEN_FRM_ONLY},
 
4448
  {"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4331
4449
   (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,
 
4450
  {"ROW_FORMAT", 10, MYSQL_TYPE_STRING, 0, 1, "Row_format", OPEN_FULL_TABLE},
 
4451
  {"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4334
4452
   (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, 
 
4453
  {"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 
4336
4454
   (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, 
 
4455
  {"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 
4338
4456
   (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,
 
4457
  {"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4340
4458
   (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, 
 
4459
  {"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 
4342
4460
   (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,
 
4461
  {"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4344
4462
   (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, 
 
4463
  {"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONGLONG, 0, 
4346
4464
   (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,
 
4465
  {"CREATE_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
 
4466
  {"UPDATE_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
 
4467
  {"CHECK_TIME", 0, MYSQL_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
 
4468
  {"TABLE_COLLATION", 64, MYSQL_TYPE_STRING, 0, 1, "Collation", OPEN_FRM_ONLY},
 
4469
  {"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4352
4470
   (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Checksum", OPEN_FULL_TABLE},
4353
 
  {"CREATE_OPTIONS", 255, DRIZZLE_TYPE_VARCHAR, 0, 1, "Create_options",
 
4471
  {"CREATE_OPTIONS", 255, MYSQL_TYPE_STRING, 0, 1, "Create_options",
4354
4472
   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}
 
4473
  {"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Comment", OPEN_FRM_ONLY},
 
4474
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4357
4475
};
4358
4476
 
4359
4477
 
4360
4478
ST_FIELD_INFO columns_fields_info[]=
4361
4479
{
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",
 
4480
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FRM_ONLY},
 
4481
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4482
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4483
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Field",
4366
4484
   OPEN_FRM_ONLY},
4367
 
  {"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
 
4485
  {"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
4368
4486
   MY_I_S_UNSIGNED, 0, OPEN_FRM_ONLY},
4369
 
  {"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, DRIZZLE_TYPE_VARCHAR, 0,
 
4487
  {"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, MYSQL_TYPE_STRING, 0,
4370
4488
   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}
 
4489
  {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null", OPEN_FRM_ONLY},
 
4490
  {"DATA_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4491
  {"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG,
 
4492
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4493
  {"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONGLONG,
 
4494
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4495
  {"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG,
 
4496
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4497
  {"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONGLONG,
 
4498
   0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
 
4499
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FRM_ONLY},
 
4500
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 1, "Collation", OPEN_FRM_ONLY},
 
4501
  {"COLUMN_TYPE", 65535, MYSQL_TYPE_STRING, 0, 0, "Type", OPEN_FRM_ONLY},
 
4502
  {"COLUMN_KEY", 3, MYSQL_TYPE_STRING, 0, 0, "Key", OPEN_FRM_ONLY},
 
4503
  {"EXTRA", 27, MYSQL_TYPE_STRING, 0, 0, "Extra", OPEN_FRM_ONLY},
 
4504
  {"PRIVILEGES", 80, MYSQL_TYPE_STRING, 0, 0, "Privileges", OPEN_FRM_ONLY},
 
4505
  {"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Comment", OPEN_FRM_ONLY},
 
4506
  {"STORAGE", 8, MYSQL_TYPE_STRING, 0, 0, "Storage", OPEN_FRM_ONLY},
 
4507
  {"FORMAT", 8, MYSQL_TYPE_STRING, 0, 0, "Format", OPEN_FRM_ONLY},
 
4508
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4391
4509
};
4392
4510
 
4393
4511
 
4394
4512
ST_FIELD_INFO charsets_fields_info[]=
4395
4513
{
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}
 
4514
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Charset",
 
4515
   SKIP_OPEN_TABLE},
 
4516
  {"DEFAULT_COLLATE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Default collation",
 
4517
   SKIP_OPEN_TABLE},
 
4518
  {"DESCRIPTION", 60, MYSQL_TYPE_STRING, 0, 0, "Description",
 
4519
   SKIP_OPEN_TABLE},
 
4520
  {"MAXLEN", 3, MYSQL_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
 
4521
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4404
4522
};
4405
4523
 
4406
4524
 
4407
4525
ST_FIELD_INFO collation_fields_info[]=
4408
4526
{
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}
 
4527
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Collation", SKIP_OPEN_TABLE},
 
4528
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Charset",
 
4529
   SKIP_OPEN_TABLE},
 
4530
  {"ID", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Id",
 
4531
   SKIP_OPEN_TABLE},
 
4532
  {"IS_DEFAULT", 3, MYSQL_TYPE_STRING, 0, 0, "Default", SKIP_OPEN_TABLE},
 
4533
  {"IS_COMPILED", 3, MYSQL_TYPE_STRING, 0, 0, "Compiled", SKIP_OPEN_TABLE},
 
4534
  {"SORTLEN", 3, MYSQL_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
 
4535
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4536
};
 
4537
 
 
4538
 
 
4539
ST_FIELD_INFO events_fields_info[]=
 
4540
{
 
4541
  {"EVENT_CATALOG", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4542
  {"EVENT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Db",
 
4543
   SKIP_OPEN_TABLE},
 
4544
  {"EVENT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
 
4545
   SKIP_OPEN_TABLE},
 
4546
  {"DEFINER", 77, MYSQL_TYPE_STRING, 0, 0, "Definer", SKIP_OPEN_TABLE},
 
4547
  {"TIME_ZONE", 64, MYSQL_TYPE_STRING, 0, 0, "Time zone", SKIP_OPEN_TABLE},
 
4548
  {"EVENT_BODY", 8, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4549
  {"EVENT_DEFINITION", 65535, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4550
  {"EVENT_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, "Type", SKIP_OPEN_TABLE},
 
4551
  {"EXECUTE_AT", 0, MYSQL_TYPE_DATETIME, 0, 1, "Execute at", SKIP_OPEN_TABLE},
 
4552
  {"INTERVAL_VALUE", 256, MYSQL_TYPE_STRING, 0, 1, "Interval value",
 
4553
   SKIP_OPEN_TABLE},
 
4554
  {"INTERVAL_FIELD", 18, MYSQL_TYPE_STRING, 0, 1, "Interval field",
 
4555
   SKIP_OPEN_TABLE},
 
4556
  {"SQL_MODE", 65535, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4557
  {"STARTS", 0, MYSQL_TYPE_DATETIME, 0, 1, "Starts", SKIP_OPEN_TABLE},
 
4558
  {"ENDS", 0, MYSQL_TYPE_DATETIME, 0, 1, "Ends", SKIP_OPEN_TABLE},
 
4559
  {"STATUS", 18, MYSQL_TYPE_STRING, 0, 0, "Status", SKIP_OPEN_TABLE},
 
4560
  {"ON_COMPLETION", 12, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4561
  {"CREATED", 0, MYSQL_TYPE_DATETIME, 0, 0, 0, SKIP_OPEN_TABLE},
 
4562
  {"LAST_ALTERED", 0, MYSQL_TYPE_DATETIME, 0, 0, 0, SKIP_OPEN_TABLE},
 
4563
  {"LAST_EXECUTED", 0, MYSQL_TYPE_DATETIME, 0, 1, 0, SKIP_OPEN_TABLE},
 
4564
  {"EVENT_COMMENT", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4565
  {"ORIGINATOR", 10, MYSQL_TYPE_LONGLONG, 0, 0, "Originator", SKIP_OPEN_TABLE},
 
4566
  {"CHARACTER_SET_CLIENT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
 
4567
   "character_set_client", SKIP_OPEN_TABLE},
 
4568
  {"COLLATION_CONNECTION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
 
4569
   "collation_connection", SKIP_OPEN_TABLE},
 
4570
  {"DATABASE_COLLATION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0,
 
4571
   "Database Collation", SKIP_OPEN_TABLE},
 
4572
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4418
4573
};
4419
4574
 
4420
4575
 
4421
4576
 
4422
4577
ST_FIELD_INFO coll_charset_app_fields_info[]=
4423
4578
{
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}
 
4579
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4580
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4581
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4427
4582
};
4428
4583
 
4429
4584
 
4430
4585
ST_FIELD_INFO stat_fields_info[]=
4431
4586
{
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,
 
4587
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FRM_ONLY},
 
4588
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4589
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Table", OPEN_FRM_ONLY},
 
4590
  {"NON_UNIQUE", 1, MYSQL_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
 
4591
  {"INDEX_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FRM_ONLY},
 
4592
  {"INDEX_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Key_name",
 
4593
   OPEN_FRM_ONLY},
 
4594
  {"SEQ_IN_INDEX", 2, MYSQL_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
 
4595
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Column_name",
 
4596
   OPEN_FRM_ONLY},
 
4597
  {"COLLATION", 1, MYSQL_TYPE_STRING, 0, 1, "Collation", OPEN_FRM_ONLY},
 
4598
  {"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 1,
4444
4599
   "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}
 
4600
  {"SUB_PART", 3, MYSQL_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
 
4601
  {"PACKED", 10, MYSQL_TYPE_STRING, 0, 1, "Packed", OPEN_FRM_ONLY},
 
4602
  {"NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null", OPEN_FRM_ONLY},
 
4603
  {"INDEX_TYPE", 16, MYSQL_TYPE_STRING, 0, 0, "Index_type", OPEN_FULL_TABLE},
 
4604
  {"COMMENT", 16, MYSQL_TYPE_STRING, 0, 1, "Comment", OPEN_FRM_ONLY},
 
4605
  {"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
 
4606
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4607
};
 
4608
 
 
4609
 
 
4610
ST_FIELD_INFO user_privileges_fields_info[]=
 
4611
{
 
4612
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4613
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4614
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4615
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4616
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4617
};
 
4618
 
 
4619
 
 
4620
ST_FIELD_INFO schema_privileges_fields_info[]=
 
4621
{
 
4622
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4623
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4624
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4625
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4626
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4627
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4628
};
 
4629
 
 
4630
 
 
4631
ST_FIELD_INFO table_privileges_fields_info[]=
 
4632
{
 
4633
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4634
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4635
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4636
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4637
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4638
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4639
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4640
};
 
4641
 
 
4642
 
 
4643
ST_FIELD_INFO column_privileges_fields_info[]=
 
4644
{
 
4645
  {"GRANTEE", 81, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4646
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4647
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4648
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4649
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4650
  {"PRIVILEGE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4651
  {"IS_GRANTABLE", 3, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4652
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4452
4653
};
4453
4654
 
4454
4655
 
4455
4656
ST_FIELD_INFO table_constraints_fields_info[]=
4456
4657
{
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}
 
4658
  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4659
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4660
   OPEN_FULL_TABLE},
 
4661
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4662
   OPEN_FULL_TABLE},
 
4663
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4664
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4665
  {"CONSTRAINT_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4666
   OPEN_FULL_TABLE},
 
4667
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4467
4668
};
4468
4669
 
4469
4670
 
4470
4671
ST_FIELD_INFO key_column_usage_fields_info[]=
4471
4672
{
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}
 
4673
  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4674
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4675
   OPEN_FULL_TABLE},
 
4676
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4677
   OPEN_FULL_TABLE},
 
4678
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4679
  {"TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4680
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4681
  {"COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4682
  {"ORDINAL_POSITION", 10 ,MYSQL_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
 
4683
  {"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,MYSQL_TYPE_LONGLONG, 0, 1, 0,
 
4684
   OPEN_FULL_TABLE},
 
4685
  {"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4686
   OPEN_FULL_TABLE},
 
4687
  {"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4688
   OPEN_FULL_TABLE},
 
4689
  {"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4690
   OPEN_FULL_TABLE},
 
4691
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4491
4692
};
4492
4693
 
4493
4694
 
4494
4695
ST_FIELD_INFO table_names_fields_info[]=
4495
4696
{
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_",
 
4697
  {"TABLE_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4698
  {"TABLE_SCHEMA",NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4699
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Tables_in_",
4499
4700
   SKIP_OPEN_TABLE},
4500
 
  {"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table_type",
 
4701
  {"TABLE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_type",
4501
4702
   OPEN_FRM_ONLY},
4502
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4703
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4503
4704
};
4504
4705
 
4505
4706
 
4506
4707
ST_FIELD_INFO open_tables_fields_info[]=
4507
4708
{
4508
 
  {"Database", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
 
4709
  {"Database", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Database",
4509
4710
   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}
 
4711
  {"Table",NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Table", SKIP_OPEN_TABLE},
 
4712
  {"In_use", 1, MYSQL_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
 
4713
  {"Name_locked", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
 
4714
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4514
4715
};
4515
4716
 
4516
4717
 
4517
4718
ST_FIELD_INFO variables_fields_info[]=
4518
4719
{
4519
 
  {"VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
 
4720
  {"VARIABLE_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Variable_name",
4520
4721
   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}
 
4722
  {"VARIABLE_VALUE", 16300, MYSQL_TYPE_STRING, 0, 1, "Value", SKIP_OPEN_TABLE},
 
4723
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4523
4724
};
4524
4725
 
4525
4726
 
4526
4727
ST_FIELD_INFO processlist_fields_info[]=
4527
4728
{
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}
 
4729
  {"ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
 
4730
  {"USER", 16, MYSQL_TYPE_STRING, 0, 0, "User", SKIP_OPEN_TABLE},
 
4731
  {"HOST", LIST_PROCESS_HOST_LEN,  MYSQL_TYPE_STRING, 0, 0, "Host",
 
4732
   SKIP_OPEN_TABLE},
 
4733
  {"DB", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Db", SKIP_OPEN_TABLE},
 
4734
  {"COMMAND", 16, MYSQL_TYPE_STRING, 0, 0, "Command", SKIP_OPEN_TABLE},
 
4735
  {"TIME", 7, MYSQL_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
 
4736
  {"STATE", 64, MYSQL_TYPE_STRING, 0, 1, "State", SKIP_OPEN_TABLE},
 
4737
  {"INFO", PROCESS_LIST_INFO_WIDTH, MYSQL_TYPE_STRING, 0, 1, "Info",
 
4738
   SKIP_OPEN_TABLE},
 
4739
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4539
4740
};
4540
4741
 
4541
4742
 
4542
4743
ST_FIELD_INFO plugin_fields_info[]=
4543
4744
{
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}
 
4745
  {"PLUGIN_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
 
4746
   SKIP_OPEN_TABLE},
 
4747
  {"PLUGIN_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4748
  {"PLUGIN_STATUS", 10, MYSQL_TYPE_STRING, 0, 0, "Status", SKIP_OPEN_TABLE},
 
4749
  {"PLUGIN_TYPE", 80, MYSQL_TYPE_STRING, 0, 0, "Type", SKIP_OPEN_TABLE},
 
4750
  {"PLUGIN_TYPE_VERSION", 20, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
 
4751
  {"PLUGIN_LIBRARY", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, "Library",
 
4752
   SKIP_OPEN_TABLE},
 
4753
  {"PLUGIN_LIBRARY_VERSION", 20, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4754
  {"PLUGIN_AUTHOR", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4755
  {"PLUGIN_DESCRIPTION", 65535, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
 
4756
  {"PLUGIN_LICENSE", 80, MYSQL_TYPE_STRING, 0, 1, "License", SKIP_OPEN_TABLE},
 
4757
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
4555
4758
};
4556
4759
 
4557
4760
ST_FIELD_INFO referential_constraints_fields_info[]=
4558
4761
{
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,
 
4762
  {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4763
  {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4764
   OPEN_FULL_TABLE},
 
4765
  {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4766
   OPEN_FULL_TABLE},
 
4767
  {"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0,
 
4768
   OPEN_FULL_TABLE},
 
4769
  {"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
 
4770
   OPEN_FULL_TABLE},
 
4771
  {"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0,
4569
4772
   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,
 
4773
  {"MATCH_OPTION", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4774
  {"UPDATE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4775
  {"DELETE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4776
  {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4777
  {"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
4575
4778
   OPEN_FULL_TABLE},
4576
 
  {0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
 
4779
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
 
4780
};
 
4781
 
 
4782
 
 
4783
ST_FIELD_INFO parameters_fields_info[]=
 
4784
{
 
4785
  {"SPECIFIC_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4786
  {"SPECIFIC_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4787
  {"SPECIFIC_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4788
  {"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0, OPEN_FULL_TABLE},
 
4789
  {"PARAMETER_MODE", 5, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4790
  {"PARAMETER_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4791
  {"DATA_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4792
  {"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4793
  {"CHARACTER_OCTET_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4794
  {"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4795
  {"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 1, 0, OPEN_FULL_TABLE},
 
4796
  {"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4797
  {"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0, OPEN_FULL_TABLE},
 
4798
  {"DTD_IDENTIFIER", 65535, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4799
  {"ROUTINE_TYPE", 9, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
 
4800
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE}
4577
4801
};
4578
4802
 
4579
4803
 
4594
4818
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4595
4819
  {"COLUMNS", columns_fields_info, create_schema_table, 
4596
4820
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4597
 
   OPTIMIZE_I_S_TABLE},
 
4821
   OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4598
4822
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4599
4823
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4600
4824
  {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4643
4867
int initialize_schema_table(st_plugin_int *plugin)
4644
4868
{
4645
4869
  ST_SCHEMA_TABLE *schema_table;
 
4870
  DBUG_ENTER("initialize_schema_table");
4646
4871
 
4647
4872
  if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4648
4873
                                MYF(MY_WME | MY_ZEROFILL))))
4649
 
      return(1);
 
4874
      DBUG_RETURN(1);
4650
4875
  /* Historical Requirement */
4651
4876
  plugin->data= schema_table; // shortcut for the future
4652
4877
  if (plugin->plugin->init)
4661
4886
 
4662
4887
    if (plugin->plugin->init(schema_table))
4663
4888
    {
4664
 
      sql_print_error(_("Plugin '%s' init function returned error."),
 
4889
      sql_print_error("Plugin '%s' init function returned error.",
4665
4890
                      plugin->name.str);
4666
4891
      goto err;
4667
4892
    }
4670
4895
    schema_table->table_name= plugin->name.str;
4671
4896
  }
4672
4897
 
4673
 
  return(0);
 
4898
  DBUG_RETURN(0);
4674
4899
err:
4675
 
  free(schema_table);
4676
 
  return(1);
 
4900
  my_free(schema_table, MYF(0));
 
4901
  DBUG_RETURN(1);
4677
4902
}
4678
4903
 
4679
4904
int finalize_schema_table(st_plugin_int *plugin)
4680
4905
{
4681
4906
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
 
4907
  DBUG_ENTER("finalize_schema_table");
4682
4908
 
4683
4909
  if (schema_table && plugin->plugin->deinit)
4684
 
    free(schema_table);
4685
 
 
4686
 
  return(0);
 
4910
  {
 
4911
    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
 
4912
    if (plugin->plugin->deinit(NULL))
 
4913
    {
 
4914
      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
 
4915
                             plugin->name.str));
 
4916
    }
 
4917
    my_free(schema_table, MYF(0));
 
4918
  }
 
4919
  DBUG_RETURN(0);
4687
4920
}