~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Monty Taylor
  • Date: 2008-08-04 22:01:39 UTC
  • mto: (261.1.4 drizzle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804220139-fy862jc9lykayvka
Moved libdrizzle.ver.in to libdrizzle.ver.

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>
 
18
 
 
19
#include "mysql_priv.h"
 
20
#include "sql_select.h"                         // For select_describe
 
21
#include "sql_show.h"
21
22
#include "repl_failsafe.h"
22
23
#include <mysys/my_dir.h>
23
 
#include <libdrizzle/gettext.h>
24
24
 
25
 
inline const char *
26
 
str_or_nil(const char *str)
27
 
{
28
 
  return str ? str : "<nil>";
29
 
}
 
25
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
30
26
 
31
27
/* Match the values of enum ha_choice */
32
28
static const char *ha_choice_values[] = {"", "0", "1"};
33
29
 
34
 
static void store_key_options(THD *thd, String *packet, Table *table,
 
30
static void store_key_options(THD *thd, String *packet, TABLE *table,
35
31
                              KEY *key_info);
36
32
 
37
33
 
38
34
 
39
 
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)
40
36
{
41
37
  register int flag;
42
38
  while (*wildstr)
89
85
static bool show_plugins(THD *thd, plugin_ref plugin,
90
86
                            void *arg)
91
87
{
92
 
  Table *table= (Table*) arg;
 
88
  TABLE *table= (TABLE*) arg;
93
89
  struct st_mysql_plugin *plug= plugin_decl(plugin);
94
90
  struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
95
 
  const CHARSET_INFO * const cs= system_charset_info;
 
91
  CHARSET_INFO *cs= system_charset_info;
96
92
 
97
93
  restore_record(table, s->default_values);
98
94
 
172
168
}
173
169
 
174
170
 
175
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
171
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
176
172
{
177
 
  Table *table= tables->table;
 
173
  TABLE *table= tables->table;
178
174
 
179
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
175
  if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
180
176
                               ~PLUGIN_IS_FREED, table))
181
177
    return(1);
182
178
 
191
187
    find_files()
192
188
    thd                 thread handler
193
189
    files               put found files in this list
194
 
    db                  database name to set in TableList structure
 
190
    db                  database name to set in TABLE_LIST structure
195
191
    path                path to database
196
192
    wild                filter for found files
197
193
    dir                 read databases in path if true, read .frm files in
208
204
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
209
205
           const char *path, const char *wild, bool dir)
210
206
{
211
 
  uint32_t i;
 
207
  uint i;
212
208
  char *ext;
213
209
  MY_DIR *dirp;
214
210
  FILEINFO *file;
215
211
  LEX_STRING *file_name= 0;
216
 
  uint32_t file_name_len;
217
 
  TableList table_list;
 
212
  uint file_name_len;
 
213
  TABLE_LIST table_list;
218
214
 
219
215
  if (wild && !wild[0])
220
216
    wild=0;
249
245
        char *end;
250
246
        *ext=0;                                 /* Remove extension */
251
247
        unpack_dirname(buff, file->name);
252
 
        end= strchr(buff, '\0');
 
248
        end= strend(buff);
253
249
        if (end != buff && end[-1] == FN_LIBCHAR)
254
250
          end[-1]= 0;                           // Remove end FN_LIBCHAR
255
251
        if (stat(buff, file->mystat))
303
299
 
304
300
 
305
301
bool
306
 
mysqld_show_create(THD *thd, TableList *table_list)
 
302
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
307
303
{
308
304
  Protocol *protocol= thd->protocol;
309
305
  char buff[2048];
320
316
      issue a warning with 'warning' level status in 
321
317
      case of invalid view and last error is ER_VIEW_INVALID
322
318
    */
323
 
    drizzle_reset_errors(thd, true);
 
319
    mysql_reset_errors(thd, true);
324
320
    thd->clear_error();
325
321
  }
326
322
 
334
330
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
335
331
    // 1024 is for not to confuse old clients
336
332
    field_list.push_back(new Item_empty_string("Create Table",
337
 
                                               cmax(buffer.length(),(uint32_t)1024)));
 
333
                                               max(buffer.length(),1024)));
338
334
  }
339
335
 
340
336
  if (protocol->send_fields(&field_list,
401
397
****************************************************************************/
402
398
 
403
399
void
404
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
400
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
405
401
{
406
 
  Table *table;
 
402
  TABLE *table;
407
403
 
408
404
  if (open_normal_and_derived_tables(thd, table_list, 0))
409
405
    return;
443
439
    0   No conflicting character
444
440
*/
445
441
 
446
 
static const char *require_quotes(const char *name, uint32_t name_length)
 
442
static const char *require_quotes(const char *name, uint name_length)
447
443
{
448
 
  uint32_t length;
 
444
  uint length;
449
445
  bool pure_digit= true;
450
446
  const char *end= name + name_length;
451
447
 
452
448
  for (; name < end ; name++)
453
449
  {
454
 
    unsigned char chr= (unsigned char) *name;
 
450
    uchar chr= (uchar) *name;
455
451
    length= my_mbcharlen(system_charset_info, chr);
456
452
    if (length == 1 && !system_charset_info->ident_map[chr])
457
453
      return name;
477
473
*/
478
474
 
479
475
void
480
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
 
476
append_identifier(THD *thd, String *packet, const char *name, uint length)
481
477
{
482
478
  const char *name_end;
483
479
  char quote_char;
494
490
   it's a keyword
495
491
  */
496
492
 
497
 
  packet->reserve(length*2 + 2);
 
493
  VOID(packet->reserve(length*2 + 2));
498
494
  quote_char= (char) q;
499
495
  packet->append(&quote_char, 1, system_charset_info);
500
496
 
501
497
  for (name_end= name+length ; name < name_end ; name+= length)
502
498
  {
503
 
    unsigned char chr= (unsigned char) *name;
 
499
    uchar chr= (uchar) *name;
504
500
    length= my_mbcharlen(system_charset_info, chr);
505
501
    /*
506
502
      my_mbcharlen can return 0 on a wrong multibyte
511
507
    */
512
508
    if (!length)
513
509
      length= 1;
514
 
    if (length == 1 && chr == (unsigned char) quote_char)
 
510
    if (length == 1 && chr == (uchar) quote_char)
515
511
      packet->append(&quote_char, 1, system_charset_info);
516
512
    packet->append(name, length, system_charset_info);
517
513
  }
542
538
    #     Quote character
543
539
*/
544
540
 
545
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
541
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
546
542
{
547
543
  if (length &&
548
544
      !is_keyword(name,length) &&
549
545
      !require_quotes(name, length) &&
550
546
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
551
547
    return EOF;
552
 
  return '`';
 
548
  return '"';
553
549
}
554
550
 
555
551
 
561
557
{
562
558
  if (filename)
563
559
  {
564
 
    uint32_t length= dirname_length(filename);
 
560
    uint length= dirname_length(filename);
565
561
    packet->append(' ');
566
562
    packet->append(dir_type);
567
563
    packet->append(STRING_WITH_LEN(" DIRECTORY='"));
606
602
      if (type.length())
607
603
      {
608
604
        String def_val;
609
 
        uint32_t dummy_errors;
 
605
        uint dummy_errors;
610
606
        /* convert to system_charset_info == utf8 */
611
607
        def_val.copy(type.ptr(), type.length(), field->charset(),
612
608
                     system_charset_info, &dummy_errors);
650
646
    0       OK
651
647
 */
652
648
 
653
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
649
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
654
650
                      HA_CREATE_INFO *create_info_arg)
655
651
{
656
652
  List<Item> field_list;
659
655
  String type(tmp, sizeof(tmp), system_charset_info);
660
656
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
657
  Field **ptr,*field;
662
 
  uint32_t primary_key;
 
658
  uint primary_key;
663
659
  KEY *key_info;
664
 
  Table *table= table_list->table;
 
660
  TABLE *table= table_list->table;
665
661
  handler *file= table->file;
666
662
  TABLE_SHARE *share= table->s;
667
663
  HA_CREATE_INFO create_info;
695
691
    We have to restore the read_set if we are called from insert in case
696
692
    of row based replication.
697
693
  */
698
 
  old_map= table->use_all_columns(table->read_set);
 
694
  old_map= tmp_use_all_columns(table, table->read_set);
699
695
 
700
696
  for (ptr=table->field ; (field= *ptr); ptr++)
701
697
  {
702
 
    uint32_t flags = field->flags;
 
698
    uint flags = field->flags;
703
699
 
704
700
    if (ptr != table->field)
705
701
      packet->append(STRING_WITH_LEN(",\n"));
754
750
      if (column_format)
755
751
      {
756
752
        packet->append(STRING_WITH_LEN(" /*!"));
757
 
        packet->append(STRING_WITH_LEN(DRIZZLE_VERSION_TABLESPACE_IN_FRM_STR));
 
753
        packet->append(STRING_WITH_LEN(MYSQL_VERSION_TABLESPACE_IN_FRM_STR));
758
754
        packet->append(STRING_WITH_LEN(" COLUMN_FORMAT"));
759
755
        if (column_format == COLUMN_FORMAT_TYPE_FIXED)
760
756
          packet->append(STRING_WITH_LEN(" FIXED */"));
783
779
  }
784
780
 
785
781
  key_info= table->key_info;
786
 
  memset(&create_info, 0, sizeof(create_info));
 
782
  memset((char*) &create_info, 0, sizeof(create_info));
787
783
  /* Allow update_create_info to update row type */
788
784
  create_info.row_type= share->row_type;
789
785
  file->update_create_info(&create_info);
790
786
  primary_key= share->primary_key;
791
787
 
792
 
  for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
 
788
  for (uint i=0 ; i < share->keys ; i++,key_info++)
793
789
  {
794
790
    KEY_PART_INFO *key_part= key_info->key_part;
795
791
    bool found_primary=0;
814
810
 
815
811
    packet->append(STRING_WITH_LEN(" ("));
816
812
 
817
 
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
813
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
818
814
    {
819
815
      if (j)
820
816
        packet->append(',');
888
884
      packet->append(buff, (uint) (end - buff));
889
885
    }
890
886
 
 
887
    
 
888
    if (share->table_charset)
 
889
    {
 
890
      /*
 
891
        IF   check_create_info
 
892
        THEN add DEFAULT CHARSET only if it was used when creating the table
 
893
      */
 
894
      if (!create_info_arg ||
 
895
          (create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
 
896
      {
 
897
        packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
 
898
        packet->append(share->table_charset->csname);
 
899
        if (!(share->table_charset->state & MY_CS_PRIMARY))
 
900
        {
 
901
          packet->append(STRING_WITH_LEN(" COLLATE="));
 
902
          packet->append(table->s->table_charset->name);
 
903
        }
 
904
      }
 
905
    }
 
906
 
891
907
    if (share->min_rows)
892
908
    {
893
909
      char *end;
943
959
      end= int64_t10_to_str(table->s->key_block_size, buff, 10);
944
960
      packet->append(buff, (uint) (end - buff));
945
961
    }
946
 
    if (share->block_size)
947
 
    {
948
 
      char *end;
949
 
      packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
950
 
      end= int64_t10_to_str(share->block_size, buff,10);
951
 
      packet->append(buff, (uint) (end - buff));
952
 
    }
953
962
    table->file->append_create_info(packet);
954
963
    if (share->comment.length)
955
964
    {
964
973
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
965
974
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
966
975
  }
967
 
  table->restore_column_map(old_map);
 
976
  tmp_restore_column_map(table->read_set, old_map);
968
977
  return(0);
969
978
}
970
979
 
994
1003
                          HA_CREATE_INFO *create_info)
995
1004
{
996
1005
  HA_CREATE_INFO create;
997
 
  uint32_t create_options = create_info ? create_info->options : 0;
 
1006
  uint create_options = create_info ? create_info->options : 0;
998
1007
 
999
1008
  if (!my_strcasecmp(system_charset_info, dbname,
1000
1009
                     INFORMATION_SCHEMA_NAME.str))
1037
1046
}
1038
1047
 
1039
1048
static void store_key_options(THD *thd __attribute__((unused)),
1040
 
                              String *packet, Table *table,
 
1049
                              String *packet, TABLE *table,
1041
1050
                              KEY *key_info)
1042
1051
{
1043
1052
  char *end, buff[32];
1084
1093
 
1085
1094
  ulong thread_id;
1086
1095
  time_t start_time;
1087
 
  uint32_t   command;
 
1096
  uint   command;
1088
1097
  const char *user,*host,*db,*proc_info,*state_info;
1089
1098
  char *query;
1090
1099
};
1117
1126
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1118
1127
    return;
1119
1128
 
1120
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1129
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1121
1130
  if (!thd->killed)
1122
1131
  {
1123
1132
    I_List_iterator<THD> it(threads);
1134
1143
        thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1135
1144
                                    (tmp->system_thread ?
1136
1145
                                     "system user" : "unauthenticated user"));
1137
 
        thd_info->host= thd->strdup(tmp_sctx->ip);
 
1146
        thd_info->host= thd->strdup(tmp_sctx->host_or_ip[0] ? 
 
1147
                                    tmp_sctx->host_or_ip : 
 
1148
                                    tmp_sctx->host ? tmp_sctx->host : "");
1138
1149
        if ((thd_info->db=tmp->db))             // Safe test
1139
1150
          thd_info->db=thd->strdup(thd_info->db);
1140
1151
        thd_info->command=(int) tmp->command;
1144
1155
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1156
                                       (tmp->net.reading_or_writing == 2 ?
1146
1157
                                        "Writing to net" :
1147
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1158
                                        thd_info->command == COM_SLEEP ? NullS :
1148
1159
                                        "Reading from net") :
1149
 
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
 
1160
                                       tmp->proc_info ? tmp->proc_info :
1150
1161
                                       tmp->mysys_var &&
1151
1162
                                       tmp->mysys_var->current_cond ?
1152
 
                                       "Waiting on cond" : NULL);
 
1163
                                       "Waiting on cond" : NullS);
1153
1164
        if (mysys_var)
1154
1165
          pthread_mutex_unlock(&mysys_var->mutex);
1155
1166
 
1162
1173
            the comment in sql_class.h why this prevents crashes in possible
1163
1174
            races with query_length
1164
1175
          */
1165
 
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
 
1176
          uint length= min(max_query_length, tmp->query_length);
1166
1177
          thd_info->query=(char*) thd->strmake(tmp->query,length);
1167
1178
        }
1168
1179
        thread_infos.append(thd_info);
1169
1180
      }
1170
1181
    }
1171
1182
  }
1172
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1183
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1173
1184
 
1174
1185
  thread_info *thd_info;
1175
1186
  time_t now= my_time(0);
1197
1208
  return;
1198
1209
}
1199
1210
 
1200
 
int fill_schema_processlist(THD* thd, TableList* tables,
 
1211
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1201
1212
                            COND* cond __attribute__((unused)))
1202
1213
{
1203
 
  Table *table= tables->table;
1204
 
  const CHARSET_INFO * const cs= system_charset_info;
 
1214
  TABLE *table= tables->table;
 
1215
  CHARSET_INFO *cs= system_charset_info;
1205
1216
  char *user;
1206
1217
  time_t now= my_time(0);
1207
1218
 
1208
 
  user= NULL;
 
1219
  user= NullS;
1209
1220
 
1210
 
  pthread_mutex_lock(&LOCK_thread_count);
 
1221
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1211
1222
 
1212
1223
  if (!thd->killed)
1213
1224
  {
1231
1242
            (tmp->system_thread ? "system user" : "unauthenticated user");
1232
1243
      table->field[1]->store(val, strlen(val), cs);
1233
1244
      /* HOST */
1234
 
      table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
 
1245
      table->field[2]->store(tmp_sctx->host_or_ip,
 
1246
                             strlen(tmp_sctx->host_or_ip), cs);
1235
1247
      /* DB */
1236
1248
      if (tmp->db)
1237
1249
      {
1254
1266
      val= (char*) (tmp->net.reading_or_writing ?
1255
1267
                    (tmp->net.reading_or_writing == 2 ?
1256
1268
                     "Writing to net" :
1257
 
                     tmp->command == COM_SLEEP ? NULL :
 
1269
                     tmp->command == COM_SLEEP ? NullS :
1258
1270
                     "Reading from net") :
1259
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
 
1271
                    tmp->proc_info ? tmp->proc_info :
1260
1272
                    tmp->mysys_var &&
1261
1273
                    tmp->mysys_var->current_cond ?
1262
 
                    "Waiting on cond" : NULL);
 
1274
                    "Waiting on cond" : NullS);
1263
1275
      if (val)
1264
1276
      {
1265
1277
        table->field[6]->store(val, strlen(val), cs);
1273
1285
      if (tmp->query)
1274
1286
      {
1275
1287
        table->field[7]->store(tmp->query,
1276
 
                               cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
 
1288
                               min(PROCESS_LIST_INFO_WIDTH,
1277
1289
                                   tmp->query_length), cs);
1278
1290
        table->field[7]->set_notnull();
1279
1291
      }
1280
1292
 
1281
1293
      if (schema_table_store_record(thd, table))
1282
1294
      {
1283
 
        pthread_mutex_unlock(&LOCK_thread_count);
 
1295
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
1284
1296
        return(1);
1285
1297
      }
1286
1298
    }
1287
1299
  }
1288
1300
 
1289
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1301
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1290
1302
  return(0);
1291
1303
}
1292
1304
 
1307
1319
*/
1308
1320
static void shrink_var_array(DYNAMIC_ARRAY *array)
1309
1321
{
1310
 
  uint32_t a,b;
 
1322
  uint a,b;
1311
1323
  SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1312
1324
 
1313
1325
  for (a= b= 0; b < array->elements; b++)
1353
1365
    goto err;
1354
1366
  }
1355
1367
  while (list->name)
1356
 
    res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
1357
 
  res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
 
1368
    res|= insert_dynamic(&all_status_vars, (uchar*)list++);
 
1369
  res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1358
1370
  all_status_vars.elements--; // but next insert_dynamic should overwite it
1359
1371
  if (status_vars_inited)
1360
1372
    sort_dynamic(&all_status_vars, show_var_cmp);
1448
1460
  else
1449
1461
  {
1450
1462
    SHOW_VAR *all= dynamic_element(&all_status_vars, 0, SHOW_VAR *);
1451
 
    uint32_t i;
 
1463
    uint i;
1452
1464
    for (; list->name; list++)
1453
1465
    {
1454
1466
      for (i= 0; i < all_status_vars.elements; i++)
1473
1485
                              SHOW_VAR *variables,
1474
1486
                              enum enum_var_type value_type,
1475
1487
                              struct system_status_var *status_var,
1476
 
                              const char *prefix, Table *table,
 
1488
                              const char *prefix, TABLE *table,
1477
1489
                              bool ucase_names)
1478
1490
{
1479
1491
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1488
1500
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1489
1501
  null_lex_str.length= 0;
1490
1502
 
1491
 
  prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1503
  prefix_end=strnmov(name_buffer, prefix, sizeof(name_buffer)-1);
1492
1504
  if (*prefix)
1493
1505
    *prefix_end++= '_';
1494
1506
  len=name_buffer + sizeof(name_buffer) - prefix_end;
1495
1507
 
1496
1508
  for (; variables->name; variables++)
1497
1509
  {
1498
 
    my_stpncpy(prefix_end, variables->name, len);
 
1510
    strnmov(prefix_end, variables->name, len);
1499
1511
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
1500
1512
    if (ucase_names)
1501
1513
      make_upper(name_buffer);
1560
1572
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1561
1573
          break;
1562
1574
        case SHOW_BOOL:
1563
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1575
          end= strmov(buff, *(bool*) value ? "ON" : "OFF");
1564
1576
          break;
1565
1577
        case SHOW_MY_BOOL:
1566
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1578
          end= strmov(buff, *(bool*) value ? "ON" : "OFF");
1567
1579
          break;
1568
1580
        case SHOW_INT:
1569
1581
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1572
1584
        {
1573
1585
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
1586
          pos= show_comp_option_name[(int) tmp];
1575
 
          end= strchr(pos, '\0');
 
1587
          end= strend(pos);
1576
1588
          break;
1577
1589
        }
1578
1590
        case SHOW_CHAR:
1579
1591
        {
1580
1592
          if (!(pos= value))
1581
1593
            pos= "";
1582
 
          end= strchr(pos, '\0');
 
1594
          end= strend(pos);
1583
1595
          break;
1584
1596
        }
1585
1597
       case SHOW_CHAR_PTR:
1586
1598
        {
1587
1599
          if (!(pos= *(char**) value))
1588
1600
            pos= "";
1589
 
          end= strchr(pos, '\0');
 
1601
          end= strend(pos);
1590
1602
          break;
1591
1603
        }
1592
1604
        case SHOW_KEY_CACHE_LONG:
1628
1640
{
1629
1641
 
1630
1642
  /* Ensure that thread id not killed during loop */
1631
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1643
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1632
1644
 
1633
1645
  I_List_iterator<THD> it(threads);
1634
1646
  THD *tmp;
1640
1652
  while ((tmp= it++))
1641
1653
    add_to_status(to, &tmp->status_var);
1642
1654
  
1643
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1655
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1644
1656
  return;
1645
1657
}
1646
1658
 
1669
1681
    1                     error
1670
1682
*/
1671
1683
 
1672
 
bool schema_table_store_record(THD *thd, Table *table)
 
1684
bool schema_table_store_record(THD *thd, TABLE *table)
1673
1685
{
1674
1686
  int error;
1675
1687
  if ((error= table->file->ha_write_row(table->record[0])))
1715
1727
*/
1716
1728
 
1717
1729
bool get_lookup_value(THD *thd, Item_func *item_func,
1718
 
                      TableList *table, 
 
1730
                      TABLE_LIST *table, 
1719
1731
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1720
1732
{
1721
1733
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1732
1744
    char tmp[MAX_FIELD_WIDTH];
1733
1745
    String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1734
1746
    Item_field *item_field;
1735
 
    const CHARSET_INFO * const cs= system_charset_info;
 
1747
    CHARSET_INFO *cs= system_charset_info;
1736
1748
 
1737
1749
    if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1738
1750
        item_func->arguments()[1]->const_item())
1759
1771
      return 1;
1760
1772
 
1761
1773
    /* Lookup value is database name */
1762
 
    if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1763
 
                               (unsigned char *) item_field->field_name,
 
1774
    if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1775
                               (uchar *) item_field->field_name,
1764
1776
                               strlen(item_field->field_name), 0))
1765
1777
    {
1766
1778
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1779
                           tmp_str->length(), false);
1768
1780
    }
1769
1781
    /* Lookup value is table name */
1770
 
    else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
 
1782
    else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1771
1783
                                    strlen(field_name2),
1772
 
                                    (unsigned char *) item_field->field_name,
 
1784
                                    (uchar *) item_field->field_name,
1773
1785
                                    strlen(item_field->field_name), 0))
1774
1786
    {
1775
1787
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1797
1809
    1             error, there can be no matching records for the condition
1798
1810
*/
1799
1811
 
1800
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1812
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1801
1813
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1802
1814
{
1803
1815
  if (!cond)
1832
1844
}
1833
1845
 
1834
1846
 
1835
 
bool uses_only_table_name_fields(Item *item, TableList *table)
 
1847
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1836
1848
{
1837
1849
  if (item->type() == Item::FUNC_ITEM)
1838
1850
  {
1839
1851
    Item_func *item_func= (Item_func*)item;
1840
 
    for (uint32_t i=0; i<item_func->argument_count(); i++)
 
1852
    for (uint i=0; i<item_func->argument_count(); i++)
1841
1853
    {
1842
1854
      if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1843
1855
        return 0;
1846
1858
  else if (item->type() == Item::FIELD_ITEM)
1847
1859
  {
1848
1860
    Item_field *item_field= (Item_field*)item;
1849
 
    const CHARSET_INFO * const cs= system_charset_info;
 
1861
    CHARSET_INFO *cs= system_charset_info;
1850
1862
    ST_SCHEMA_TABLE *schema_table= table->schema_table;
1851
1863
    ST_FIELD_INFO *field_info= schema_table->fields_info;
1852
1864
    const char *field_name1= schema_table->idx_field1 >= 0 ?
1854
1866
    const char *field_name2= schema_table->idx_field2 >= 0 ?
1855
1867
      field_info[schema_table->idx_field2].field_name : "";
1856
1868
    if (table->table != item_field->field->table ||
1857
 
        (cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1858
 
                               (unsigned char *) item_field->field_name,
 
1869
        (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1870
                               (uchar *) item_field->field_name,
1859
1871
                               strlen(item_field->field_name), 0) &&
1860
 
         cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1861
 
                               (unsigned char *) item_field->field_name,
 
1872
         cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
 
1873
                               (uchar *) item_field->field_name,
1862
1874
                               strlen(item_field->field_name), 0)))
1863
1875
      return 0;
1864
1876
  }
1872
1884
}
1873
1885
 
1874
1886
 
1875
 
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
 
1887
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
1876
1888
{
1877
1889
  if (!cond)
1878
1890
    return (COND*) 0;
1946
1958
    1             error, there can be no matching records for the condition
1947
1959
*/
1948
1960
 
1949
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1961
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1950
1962
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1951
1963
{
1952
1964
  LEX *lex= thd->lex;
1953
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
 
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
 
1965
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
1966
  memset((char*) lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1967
  switch (lex->sql_command) {
1956
1968
  case SQLCOM_SHOW_DATABASES:
1957
1969
    if (wild)
2031
2043
      if (files->push_back(i_s_name_copy))
2032
2044
        return 1;
2033
2045
    }
2034
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
2046
    return (find_files(thd, files, NullS, mysql_data_home,
2035
2047
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2036
2048
  }
2037
2049
 
2062
2074
  if (files->push_back(i_s_name_copy))
2063
2075
    return 1;
2064
2076
  *with_i_schema= 1;
2065
 
  return (find_files(thd, files, NULL,
2066
 
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
 
2077
  return (find_files(thd, files, NullS,
 
2078
                     mysql_data_home, NullS, 1) != FIND_FILES_OK);
2067
2079
}
2068
2080
 
2069
2081
 
2140
2152
  add_data.files= files;
2141
2153
  add_data.wild= wild;
2142
2154
  if (plugin_foreach(thd, add_schema_table,
2143
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
 
2155
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data))
2144
2156
    return(1);
2145
2157
 
2146
2158
  return(0);
2227
2239
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2228
2240
 
2229
2241
  @param[in]      thd                      thread handler
2230
 
  @param[in]      tables                   TableList for I_S table
 
2242
  @param[in]      tables                   TABLE_LIST for I_S table
2231
2243
  @param[in]      schema_table             pointer to I_S structure
2232
2244
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2233
2245
                                           which is used to save|restore original
2240
2252
*/
2241
2253
 
2242
2254
static int 
2243
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2255
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2244
2256
                              ST_SCHEMA_TABLE *schema_table,
2245
2257
                              Open_tables_state *open_tables_state_backup)
2246
2258
{
2248
2260
  bool res;
2249
2261
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2262
  enum_sql_command save_sql_command= lex->sql_command;
2251
 
  TableList *show_table_list= (TableList*) tables->schema_select_lex->
 
2263
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2252
2264
    table_list.first;
2253
 
  Table *table= tables->table;
 
2265
  TABLE *table= tables->table;
2254
2266
  int error= 1;
2255
2267
 
2256
2268
  lex->all_selects_list= tables->schema_select_lex;
2269
2281
  */
2270
2282
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
2283
  res= open_normal_and_derived_tables(thd, show_table_list,
2272
 
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
 
2284
                                      MYSQL_LOCK_IGNORE_FLUSH);
2273
2285
  lex->sql_command= save_sql_command;
2274
2286
  /*
2275
2287
    get_all_tables() returns 1 on failure and 0 on success thus
2298
2310
 
2299
2311
 
2300
2312
/**
2301
 
  @brief          Fill I_S table for SHOW Table NAMES commands
 
2313
  @brief          Fill I_S table for SHOW TABLE NAMES commands
2302
2314
 
2303
2315
  @param[in]      thd                      thread handler
2304
 
  @param[in]      table                    Table struct for I_S table
 
2316
  @param[in]      table                    TABLE struct for I_S table
2305
2317
  @param[in]      db_name                  database name
2306
2318
  @param[in]      table_name               table name
2307
2319
  @param[in]      with_i_schema            I_S table if true
2311
2323
    @retval       1           error
2312
2324
*/
2313
2325
 
2314
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2326
static int fill_schema_table_names(THD *thd, TABLE *table,
2315
2327
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2316
2328
                                   bool with_i_schema)
2317
2329
{
2326
2338
    char path[FN_REFLEN];
2327
2339
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2328
2340
                                table_name->str, reg_ext, 0);
2329
 
    if (mysql_frm_type(thd, path, &not_used)) 
2330
 
    {
2331
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
 
                             system_charset_info);
2333
 
    }
2334
 
    else
2335
 
    {
 
2341
    switch (mysql_frm_type(thd, path, &not_used)) {
 
2342
    case FRMTYPE_ERROR:
2336
2343
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2337
2344
                             system_charset_info);
 
2345
      break;
 
2346
    case FRMTYPE_TABLE:
 
2347
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
 
2348
                             system_charset_info);
 
2349
      break;
 
2350
    default:
 
2351
      assert(0);
2338
2352
    }
2339
 
 
2340
2353
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2341
2354
    {
2342
2355
      thd->clear_error();
2365
2378
    @retval       SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2366
2379
*/
2367
2380
 
2368
 
static uint32_t get_table_open_method(TableList *tables,
 
2381
static uint get_table_open_method(TABLE_LIST *tables,
2369
2382
                                  ST_SCHEMA_TABLE *schema_table,
2370
2383
                                  enum enum_schema_tables schema_table_idx __attribute__((unused)))
2371
2384
{
2393
2406
  @brief          Fill I_S table with data from FRM file only
2394
2407
 
2395
2408
  @param[in]      thd                      thread handler
2396
 
  @param[in]      table                    Table struct for I_S table
 
2409
  @param[in]      table                    TABLE struct for I_S table
2397
2410
  @param[in]      schema_table             I_S table struct
2398
2411
  @param[in]      db_name                  database name
2399
2412
  @param[in]      table_name               table name
2406
2419
                              open_tables function for this table
2407
2420
*/
2408
2421
 
2409
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
 
2422
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2410
2423
                                      ST_SCHEMA_TABLE *schema_table,
2411
2424
                                      LEX_STRING *db_name,
2412
2425
                                      LEX_STRING *table_name,
2413
2426
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
2414
2427
{
2415
 
  Table *table= tables->table;
 
2428
  TABLE *table= tables->table;
2416
2429
  TABLE_SHARE *share;
2417
 
  Table tbl;
2418
 
  TableList table_list;
2419
 
  uint32_t res= 0;
 
2430
  TABLE tbl;
 
2431
  TABLE_LIST table_list;
 
2432
  uint res= 0;
2420
2433
  int error;
2421
2434
  char key[MAX_DBKEY_LENGTH];
2422
 
  uint32_t key_length;
 
2435
  uint key_length;
2423
2436
 
2424
 
  memset(&table_list, 0, sizeof(TableList));
2425
 
  memset(&tbl, 0, sizeof(Table));
 
2437
  memset((char*) &table_list, 0, sizeof(TABLE_LIST));
 
2438
  memset((char*) &tbl, 0, sizeof(TABLE));
2426
2439
 
2427
2440
  table_list.table_name= table_name->str;
2428
2441
  table_list.db= db_name->str;
2430
2443
  key_length= create_table_def_key(thd, key, &table_list, 0);
2431
2444
  pthread_mutex_lock(&LOCK_open);
2432
2445
  share= get_table_share(thd, &table_list, key,
2433
 
                         key_length, 0, &error);
 
2446
                         key_length, OPEN_VIEW, &error);
2434
2447
  if (!share)
2435
2448
  {
2436
2449
    res= 0;
2473
2486
    @retval       1                        error
2474
2487
*/
2475
2488
 
2476
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2489
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2477
2490
{
2478
2491
  LEX *lex= thd->lex;
2479
 
  Table *table= tables->table;
 
2492
  TABLE *table= tables->table;
2480
2493
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2481
2494
  enum_sql_command save_sql_command= lex->sql_command;
2482
2495
  SELECT_LEX *lsel= tables->schema_select_lex;
2489
2502
  List<LEX_STRING> db_names;
2490
2503
  List_iterator_fast<LEX_STRING> it(db_names);
2491
2504
  COND *partial_cond= 0;
2492
 
  uint32_t derived_tables= lex->derived_tables; 
 
2505
  uint derived_tables= lex->derived_tables; 
2493
2506
  int error= 1;
2494
2507
  Open_tables_state open_tables_state_backup;
2495
2508
  Query_tables_list query_tables_list_backup;
2496
 
  uint32_t table_open_method;
 
2509
  uint table_open_method;
2497
2510
  bool old_value= thd->no_warnings_for_error;
2498
2511
 
2499
2512
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2601
2614
            continue;
2602
2615
          }
2603
2616
 
2604
 
          /* SHOW Table NAMES command */
 
2617
          /* SHOW TABLE NAMES command */
2605
2618
          if (schema_table_idx == SCH_TABLE_NAMES)
2606
2619
          {
2607
2620
            if (fill_schema_table_names(thd, tables->table, db_name,
2632
2645
              goto err;
2633
2646
            if (make_table_list(thd, &sel, db_name, table_name))
2634
2647
              goto err;
2635
 
            TableList *show_table_list= (TableList*) sel.table_list.first;
 
2648
            TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2636
2649
            lex->all_selects_list= &sel;
2637
2650
            lex->derived_tables= 0;
2638
2651
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2652
            show_table_list->i_s_requested_object=
2640
2653
              schema_table->i_s_requested_object;
2641
2654
            res= open_normal_and_derived_tables(thd, show_table_list,
2642
 
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
 
2655
                                                MYSQL_LOCK_IGNORE_FLUSH);
2643
2656
            lex->sql_command= save_sql_command;
2644
2657
            /*
2645
2658
              XXX:  show_table_list has a flag i_is_requested,
2703
2716
}
2704
2717
 
2705
2718
 
2706
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2707
 
                          const CHARSET_INFO * const cs)
 
2719
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
 
2720
                          CHARSET_INFO *cs)
2708
2721
{
2709
2722
  restore_record(table, s->default_values);
2710
2723
  table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2714
2727
}
2715
2728
 
2716
2729
 
2717
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2730
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
2718
2731
{
2719
2732
  /*
2720
2733
    TODO: fill_schema_shemata() is called when new client is connected.
2726
2739
  LEX_STRING *db_name;
2727
2740
  bool with_i_schema;
2728
2741
  HA_CREATE_INFO create;
2729
 
  Table *table= tables->table;
 
2742
  TABLE *table= tables->table;
2730
2743
 
2731
2744
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2732
2745
    return(0);
2741
2754
     !with_i_schema)
2742
2755
  {
2743
2756
    char path[FN_REFLEN+16];
2744
 
    uint32_t path_len;
 
2757
    uint path_len;
2745
2758
    struct stat stat_info;
2746
2759
    if (!lookup_field_vals.db_value.str[0])
2747
2760
      return(0);
2774
2787
}
2775
2788
 
2776
2789
 
2777
 
static int get_schema_tables_record(THD *thd, TableList *tables,
2778
 
                                    Table *table, bool res,
 
2790
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
 
2791
                                    TABLE *table, bool res,
2779
2792
                                    LEX_STRING *db_name,
2780
2793
                                    LEX_STRING *table_name)
2781
2794
{
2782
2795
  const char *tmp_buff;
2783
2796
  DRIZZLE_TIME time;
2784
 
  const CHARSET_INFO * const cs= system_charset_info;
 
2797
  CHARSET_INFO *cs= system_charset_info;
2785
2798
 
2786
2799
  restore_record(table, s->default_values);
2787
2800
  table->field[1]->store(db_name->str, db_name->length, cs);
2795
2808
    if (tables->schema_table)
2796
2809
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2797
2810
    else
2798
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2811
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2799
2812
    table->field[20]->store(error, strlen(error), cs);
2800
2813
    thd->clear_error();
2801
2814
  }
2802
2815
  else
2803
2816
  {
2804
 
    char option_buff[400],*ptr;
2805
 
    Table *show_table= tables->table;
 
2817
    char option_buff[350],*ptr;
 
2818
    TABLE *show_table= tables->table;
2806
2819
    TABLE_SHARE *share= show_table->s;
2807
2820
    handler *file= show_table->file;
2808
2821
    handlerton *tmp_db_type= share->db_type();
2811
2824
    else if (share->tmp_table)
2812
2825
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2813
2826
    else
2814
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2827
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2815
2828
 
2816
2829
    for (int i= 4; i < 20; i++)
2817
2830
    {
2826
2839
    ptr=option_buff;
2827
2840
    if (share->min_rows)
2828
2841
    {
2829
 
      ptr=my_stpcpy(ptr," min_rows=");
 
2842
      ptr=strmov(ptr," min_rows=");
2830
2843
      ptr=int64_t10_to_str(share->min_rows,ptr,10);
2831
2844
    }
2832
2845
    if (share->max_rows)
2833
2846
    {
2834
 
      ptr=my_stpcpy(ptr," max_rows=");
 
2847
      ptr=strmov(ptr," max_rows=");
2835
2848
      ptr=int64_t10_to_str(share->max_rows,ptr,10);
2836
2849
    }
2837
2850
    if (share->avg_row_length)
2838
2851
    {
2839
 
      ptr=my_stpcpy(ptr," avg_row_length=");
 
2852
      ptr=strmov(ptr," avg_row_length=");
2840
2853
      ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2841
2854
    }
2842
2855
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
 
      ptr=my_stpcpy(ptr," pack_keys=1");
 
2856
      ptr=strmov(ptr," pack_keys=1");
2844
2857
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
 
      ptr=my_stpcpy(ptr," pack_keys=0");
 
2858
      ptr=strmov(ptr," pack_keys=0");
2846
2859
    /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2860
    if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
 
      ptr=my_stpcpy(ptr," checksum=1");
 
2861
      ptr=strmov(ptr," checksum=1");
2849
2862
    if (share->page_checksum != HA_CHOICE_UNDEF)
2850
2863
      ptr= strxmov(ptr, " page_checksum=",
2851
 
                   ha_choice_values[(uint) share->page_checksum], NULL);
 
2864
                   ha_choice_values[(uint) share->page_checksum], NullS);
2852
2865
    if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
 
      ptr=my_stpcpy(ptr," delay_key_write=1");
 
2866
      ptr=strmov(ptr," delay_key_write=1");
2854
2867
    if (share->row_type != ROW_TYPE_DEFAULT)
2855
2868
      ptr=strxmov(ptr, " row_format=", 
2856
2869
                  ha_row_type[(uint) share->row_type],
2857
 
                  NULL);
2858
 
    if (share->block_size)
2859
 
    {
2860
 
      ptr= my_stpcpy(ptr, " block_size=");
2861
 
      ptr= int64_t10_to_str(share->block_size, ptr, 10);
2862
 
    }
2863
 
    
 
2870
                  NullS);
2864
2871
    if (share->transactional != HA_CHOICE_UNDEF)
2865
2872
    {
2866
2873
      ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
2874
                   (share->transactional == HA_CHOICE_YES ? "1" : "0"),
2868
 
                   NULL);
 
2875
                   NullS);
2869
2876
    }
2870
2877
    if (share->transactional != HA_CHOICE_UNDEF)
2871
2878
      ptr= strxmov(ptr, " transactional=",
2872
 
                   ha_choice_values[(uint) share->transactional], NULL);
 
2879
                   ha_choice_values[(uint) share->transactional], NullS);
2873
2880
    table->field[19]->store(option_buff+1,
2874
2881
                            (ptr == option_buff ? 0 : 
2875
2882
                             (uint) (ptr-option_buff)-1), cs);
2978
2985
  @return         void
2979
2986
*/
2980
2987
 
2981
 
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2982
 
                       uint32_t offset)
 
2988
void store_column_type(TABLE *table, Field *field, CHARSET_INFO *cs,
 
2989
                       uint offset)
2983
2990
{
2984
2991
  bool is_blob;
2985
2992
  int decimals, field_length;
3025
3032
    field_length= ((Field_new_decimal*) field)->precision;
3026
3033
    break;
3027
3034
  case DRIZZLE_TYPE_TINY:
 
3035
  case DRIZZLE_TYPE_SHORT:
3028
3036
  case DRIZZLE_TYPE_LONG:
3029
3037
  case DRIZZLE_TYPE_LONGLONG:
3030
3038
    field_length= field->max_display_length() - 1;
3065
3073
}
3066
3074
 
3067
3075
 
3068
 
static int get_schema_column_record(THD *thd, TableList *tables,
3069
 
                                    Table *table, bool res,
 
3076
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
 
3077
                                    TABLE *table, bool res,
3070
3078
                                    LEX_STRING *db_name,
3071
3079
                                    LEX_STRING *table_name)
3072
3080
{
3073
3081
  LEX *lex= thd->lex;
3074
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3075
 
  const CHARSET_INFO * const cs= system_charset_info;
3076
 
  Table *show_table;
 
3082
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
 
3083
  CHARSET_INFO *cs= system_charset_info;
 
3084
  TABLE *show_table;
3077
3085
  TABLE_SHARE *show_table_share;
3078
3086
  Field **ptr, *field, *timestamp_field;
3079
3087
  int count;
3087
3095
        rather than in SHOW COLUMNS
3088
3096
      */ 
3089
3097
      if (thd->is_error())
3090
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3098
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3091
3099
                     thd->main_da.sql_errno(), thd->main_da.message());
3092
3100
      thd->clear_error();
3093
3101
      res= 0;
3116
3124
    if (!show_table->read_set)
3117
3125
    {
3118
3126
      /* to satisfy 'field->val_str' ASSERTs */
3119
 
      unsigned char *bitmaps;
3120
 
      uint32_t bitmap_size= show_table_share->column_bitmap_size;
3121
 
      if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
 
3127
      uchar *bitmaps;
 
3128
      uint bitmap_size= show_table_share->column_bitmap_size;
 
3129
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3122
3130
        return(0);
3123
3131
      bitmap_init(&show_table->def_read_set,
3124
3132
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3130
3138
 
3131
3139
  for (; (field= *ptr) ; ptr++)
3132
3140
  {
3133
 
    unsigned char *pos;
 
3141
    uchar *pos;
3134
3142
    char tmp[MAX_FIELD_WIDTH];
3135
3143
    String type(tmp,sizeof(tmp), system_charset_info);
3136
3144
    char *end;
3158
3166
      table->field[5]->store(type.ptr(), type.length(), cs);
3159
3167
      table->field[5]->set_notnull();
3160
3168
    }
3161
 
    pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
 
3169
    pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
3162
3170
    table->field[6]->store((const char*) pos,
3163
3171
                           strlen((const char*) pos), cs);
3164
3172
    store_column_type(table, field, cs, 7);
3165
3173
 
3166
 
    pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
 
3174
    pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3167
3175
                 (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3168
3176
                 (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3169
3177
    table->field[15]->store((const char*) pos,
3181
3189
    {
3182
3190
      enum column_format_type column_format= (enum column_format_type)
3183
3191
        ((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3184
 
      pos=(unsigned char*)"Default";
 
3192
      pos=(uchar*)"Default";
3185
3193
      table->field[19]->store((const char*) pos,
3186
3194
                              strlen((const char*) pos), cs);
3187
 
      pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
 
3195
      pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3188
3196
                   column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3189
3197
                                                             "Dynamic");
3190
3198
      table->field[20]->store((const char*) pos,
3198
3206
 
3199
3207
 
3200
3208
 
3201
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3209
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3202
3210
{
3203
3211
  CHARSET_INFO **cs;
3204
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3205
 
  Table *table= tables->table;
3206
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3212
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3213
  TABLE *table= tables->table;
 
3214
  CHARSET_INFO *scs= system_charset_info;
3207
3215
 
3208
3216
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3209
3217
  {
3210
 
    const CHARSET_INFO * const tmp_cs= cs[0];
 
3218
    CHARSET_INFO *tmp_cs= cs[0];
3211
3219
    if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) && 
3212
3220
        (tmp_cs->state & MY_CS_AVAILABLE) &&
3213
3221
        !(tmp_cs->state & MY_CS_HIDDEN) &&
3214
3222
        !(wild && wild[0] &&
3215
 
          wild_case_compare(scs, tmp_cs->csname,wild)))
 
3223
          wild_case_compare(scs, tmp_cs->csname,wild)))
3216
3224
    {
3217
3225
      const char *comment;
3218
3226
      restore_record(table, s->default_values);
3229
3237
}
3230
3238
 
3231
3239
 
3232
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3240
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3233
3241
{
3234
3242
  CHARSET_INFO **cs;
3235
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3236
 
  Table *table= tables->table;
3237
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3243
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3244
  TABLE *table= tables->table;
 
3245
  CHARSET_INFO *scs= system_charset_info;
3238
3246
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3239
3247
  {
3240
3248
    CHARSET_INFO **cl;
3241
 
    const CHARSET_INFO *tmp_cs= cs[0];
 
3249
    CHARSET_INFO *tmp_cs= cs[0];
3242
3250
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3243
3251
         (tmp_cs->state & MY_CS_HIDDEN) ||
3244
3252
        !(tmp_cs->state & MY_CS_PRIMARY))
3245
3253
      continue;
3246
3254
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3247
3255
    {
3248
 
      const CHARSET_INFO *tmp_cl= cl[0];
 
3256
      CHARSET_INFO *tmp_cl= cl[0];
3249
3257
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
3250
3258
          !my_charset_same(tmp_cs, tmp_cl))
3251
 
        continue;
 
3259
        continue;
3252
3260
      if (!(wild && wild[0] &&
3253
 
          wild_case_compare(scs, tmp_cl->name,wild)))
 
3261
          wild_case_compare(scs, tmp_cl->name,wild)))
3254
3262
      {
3255
 
        const char *tmp_buff;
3256
 
        restore_record(table, s->default_values);
3257
 
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
 
3263
        const char *tmp_buff;
 
3264
        restore_record(table, s->default_values);
 
3265
        table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3258
3266
        table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3259
3267
        table->field[2]->store((int64_t) tmp_cl->number, true);
3260
3268
        tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3261
 
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
 
3269
        table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3262
3270
        tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3263
 
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
 
3271
        table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3264
3272
        table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3265
3273
        if (schema_table_store_record(thd, table))
3266
3274
          return 1;
3271
3279
}
3272
3280
 
3273
3281
 
3274
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3282
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3275
3283
{
3276
3284
  CHARSET_INFO **cs;
3277
 
  Table *table= tables->table;
3278
 
  const CHARSET_INFO * const scs= system_charset_info;
 
3285
  TABLE *table= tables->table;
 
3286
  CHARSET_INFO *scs= system_charset_info;
3279
3287
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3280
3288
  {
3281
3289
    CHARSET_INFO **cl;
3282
 
    const CHARSET_INFO *tmp_cs= cs[0];
 
3290
    CHARSET_INFO *tmp_cs= cs[0];
3283
3291
    if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) || 
3284
3292
        !(tmp_cs->state & MY_CS_PRIMARY))
3285
3293
      continue;
3286
3294
    for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3287
3295
    {
3288
 
      const CHARSET_INFO *tmp_cl= cl[0];
 
3296
      CHARSET_INFO *tmp_cl= cl[0];
3289
3297
      if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) || 
3290
3298
          !my_charset_same(tmp_cs,tmp_cl))
3291
3299
        continue;
3300
3308
}
3301
3309
 
3302
3310
 
3303
 
static int get_schema_stat_record(THD *thd, TableList *tables,
3304
 
                                  Table *table, bool res,
 
3311
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
 
3312
                                  TABLE *table, bool res,
3305
3313
                                  LEX_STRING *db_name,
3306
3314
                                  LEX_STRING *table_name)
3307
3315
{
3308
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3316
  CHARSET_INFO *cs= system_charset_info;
3309
3317
  if (res)
3310
3318
  {
3311
3319
    if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3315
3323
        rather than in SHOW KEYS
3316
3324
      */
3317
3325
      if (thd->is_error())
3318
 
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3326
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3319
3327
                     thd->main_da.sql_errno(), thd->main_da.message());
3320
3328
      thd->clear_error();
3321
3329
      res= 0;
3324
3332
  }
3325
3333
  else
3326
3334
  {
3327
 
    Table *show_table= tables->table;
 
3335
    TABLE *show_table= tables->table;
3328
3336
    KEY *key_info=show_table->s->key_info;
3329
3337
    if (show_table->file)
3330
3338
      show_table->file->info(HA_STATUS_VARIABLE |
3331
3339
                             HA_STATUS_NO_LOCK |
3332
3340
                             HA_STATUS_TIME);
3333
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
 
3341
    for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3334
3342
    {
3335
3343
      KEY_PART_INFO *key_part= key_info->key_part;
3336
3344
      const char *str;
3337
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3345
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3338
3346
      {
3339
3347
        restore_record(table, s->default_values);
3340
3348
        table->field[1]->store(db_name->str, db_name->length, cs);
3375
3383
                                  key_part->field->charset()->mbmaxlen, true);
3376
3384
          table->field[10]->set_notnull();
3377
3385
        }
3378
 
        uint32_t flags= key_part->field ? key_part->field->flags : 0;
 
3386
        uint flags= key_part->field ? key_part->field->flags : 0;
3379
3387
        const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
3388
        table->field[12]->store(pos, strlen(pos), cs);
3381
3389
        if (!show_table->s->keys_in_use.is_set(i))
3397
3405
}
3398
3406
 
3399
3407
 
3400
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3408
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3401
3409
                       LEX_STRING *table_name, const char *key_name,
3402
 
                       uint32_t key_len, const char *con_type, uint32_t con_len)
 
3410
                       uint key_len, const char *con_type, uint con_len)
3403
3411
{
3404
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3412
  CHARSET_INFO *cs= system_charset_info;
3405
3413
  restore_record(table, s->default_values);
3406
3414
  table->field[1]->store(db_name->str, db_name->length, cs);
3407
3415
  table->field[2]->store(key_name, key_len, cs);
3412
3420
}
3413
3421
 
3414
3422
 
3415
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
3416
 
                                         Table *table, bool res,
 
3423
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
 
3424
                                         TABLE *table, bool res,
3417
3425
                                         LEX_STRING *db_name,
3418
3426
                                         LEX_STRING *table_name)
3419
3427
{
3420
3428
  if (res)
3421
3429
  {
3422
3430
    if (thd->is_error())
3423
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3431
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3424
3432
                   thd->main_da.sql_errno(), thd->main_da.message());
3425
3433
    thd->clear_error();
3426
3434
    return(0);
3428
3436
  else
3429
3437
  {
3430
3438
    List<FOREIGN_KEY_INFO> f_key_list;
3431
 
    Table *show_table= tables->table;
 
3439
    TABLE *show_table= tables->table;
3432
3440
    KEY *key_info=show_table->key_info;
3433
 
    uint32_t primary_key= show_table->s->primary_key;
 
3441
    uint primary_key= show_table->s->primary_key;
3434
3442
    show_table->file->info(HA_STATUS_VARIABLE | 
3435
3443
                           HA_STATUS_NO_LOCK |
3436
3444
                           HA_STATUS_TIME);
3437
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3445
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3438
3446
    {
3439
3447
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3440
3448
        continue;
3471
3479
}
3472
3480
 
3473
3481
 
3474
 
void store_key_column_usage(Table *table, LEX_STRING *db_name,
 
3482
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3475
3483
                            LEX_STRING *table_name, const char *key_name,
3476
 
                            uint32_t key_len, const char *con_type, uint32_t con_len,
 
3484
                            uint key_len, const char *con_type, uint con_len,
3477
3485
                            int64_t idx)
3478
3486
{
3479
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3487
  CHARSET_INFO *cs= system_charset_info;
3480
3488
  table->field[1]->store(db_name->str, db_name->length, cs);
3481
3489
  table->field[2]->store(key_name, key_len, cs);
3482
3490
  table->field[4]->store(db_name->str, db_name->length, cs);
3487
3495
 
3488
3496
 
3489
3497
static int get_schema_key_column_usage_record(THD *thd,
3490
 
                                              TableList *tables,
3491
 
                                              Table *table, bool res,
 
3498
                                              TABLE_LIST *tables,
 
3499
                                              TABLE *table, bool res,
3492
3500
                                              LEX_STRING *db_name,
3493
3501
                                              LEX_STRING *table_name)
3494
3502
{
3495
3503
  if (res)
3496
3504
  {
3497
3505
    if (thd->is_error())
3498
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3506
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3499
3507
                   thd->main_da.sql_errno(), thd->main_da.message());
3500
3508
    thd->clear_error();
3501
3509
    return(0);
3503
3511
  else
3504
3512
  {
3505
3513
    List<FOREIGN_KEY_INFO> f_key_list;
3506
 
    Table *show_table= tables->table;
 
3514
    TABLE *show_table= tables->table;
3507
3515
    KEY *key_info=show_table->key_info;
3508
 
    uint32_t primary_key= show_table->s->primary_key;
 
3516
    uint primary_key= show_table->s->primary_key;
3509
3517
    show_table->file->info(HA_STATUS_VARIABLE | 
3510
3518
                           HA_STATUS_NO_LOCK |
3511
3519
                           HA_STATUS_TIME);
3512
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3520
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3513
3521
    {
3514
3522
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3515
3523
        continue;
3516
 
      uint32_t f_idx= 0;
 
3524
      uint f_idx= 0;
3517
3525
      KEY_PART_INFO *key_part= key_info->key_part;
3518
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3526
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3519
3527
      {
3520
3528
        if (key_part->field)
3521
3529
        {
3542
3550
      LEX_STRING *r_info;
3543
3551
      List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3544
3552
        it1(f_key_info->referenced_fields);
3545
 
      uint32_t f_idx= 0;
 
3553
      uint f_idx= 0;
3546
3554
      while ((f_info= it++))
3547
3555
      {
3548
3556
        r_info= it1++;
3575
3583
}
3576
3584
 
3577
3585
 
3578
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3586
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3579
3587
{
3580
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3581
 
  Table *table= tables->table;
3582
 
  const CHARSET_INFO * const cs= system_charset_info;
3583
 
  OPEN_TableList *open_list;
 
3588
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3589
  TABLE *table= tables->table;
 
3590
  CHARSET_INFO *cs= system_charset_info;
 
3591
  OPEN_TABLE_LIST *open_list;
3584
3592
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
3593
            && thd->is_fatal_error)
3586
3594
    return(1);
3599
3607
}
3600
3608
 
3601
3609
 
3602
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3610
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3603
3611
{
3604
3612
  int res= 0;
3605
3613
  LEX *lex= thd->lex;
3606
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3614
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3607
3615
  enum enum_schema_tables schema_table_idx=
3608
3616
    get_schema_table_idx(tables->schema_table);
3609
3617
  enum enum_var_type option_type= OPT_SESSION;
3622
3630
}
3623
3631
 
3624
3632
 
3625
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3633
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3626
3634
{
3627
3635
  LEX *lex= thd->lex;
3628
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3636
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3629
3637
  int res= 0;
3630
3638
  STATUS_VAR *tmp1, tmp;
3631
3639
  enum enum_schema_tables schema_table_idx=
3683
3691
*/
3684
3692
 
3685
3693
static int
3686
 
get_referential_constraints_record(THD *thd, TableList *tables,
3687
 
                                   Table *table, bool res,
 
3694
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
 
3695
                                   TABLE *table, bool res,
3688
3696
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3689
3697
{
3690
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3698
  CHARSET_INFO *cs= system_charset_info;
3691
3699
 
3692
3700
  if (res)
3693
3701
  {
3694
3702
    if (thd->is_error())
3695
 
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
3703
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3696
3704
                   thd->main_da.sql_errno(), thd->main_da.message());
3697
3705
    thd->clear_error();
3698
3706
    return(0);
3700
3708
 
3701
3709
  {
3702
3710
    List<FOREIGN_KEY_INFO> f_key_list;
3703
 
    Table *show_table= tables->table;
 
3711
    TABLE *show_table= tables->table;
3704
3712
    show_table->file->info(HA_STATUS_VARIABLE | 
3705
3713
                           HA_STATUS_NO_LOCK |
3706
3714
                           HA_STATUS_TIME);
3807
3815
 
3808
3816
  schema_table_a.table_name= table_name;
3809
3817
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
3810
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
 
3818
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3811
3819
    return(schema_table_a.schema_table);
3812
3820
 
3813
3821
  return(NULL);
3835
3843
  @retval  NULL           Can't create table
3836
3844
*/
3837
3845
 
3838
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3846
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3839
3847
{
3840
3848
  int field_count= 0;
3841
3849
  Item *item;
3842
 
  Table *table;
 
3850
  TABLE *table;
3843
3851
  List<Item> field_list;
3844
3852
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3845
3853
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3846
 
  const CHARSET_INFO * const cs= system_charset_info;
 
3854
  CHARSET_INFO *cs= system_charset_info;
3847
3855
 
3848
3856
  for (; fields_info->field_name; fields_info++)
3849
3857
  {
3850
3858
    switch (fields_info->field_type) {
3851
3859
    case DRIZZLE_TYPE_TINY:
3852
3860
    case DRIZZLE_TYPE_LONG:
 
3861
    case DRIZZLE_TYPE_SHORT:
3853
3862
    case DRIZZLE_TYPE_LONGLONG:
3854
3863
      if (!(item= new Item_return_int(fields_info->field_name,
3855
3864
                                      fields_info->field_length,
3918
3927
  tmp_table_param->schema_table= 1;
3919
3928
  SELECT_LEX *select_lex= thd->lex->current_select;
3920
3929
  if (!(table= create_tmp_table(thd, tmp_table_param,
3921
 
                                field_list, (order_st*) 0, 0, 0, 
 
3930
                                field_list, (ORDER*) 0, 0, 0, 
3922
3931
                                (select_lex->options | thd->options |
3923
3932
                                 TMP_TABLE_ALL_COLUMNS),
3924
3933
                                HA_POS_ERROR, table_list->alias)))
3958
3967
    if (field_info->old_name)
3959
3968
    {
3960
3969
      Item_field *field= new Item_field(context,
3961
 
                                        NULL, NULL, field_info->field_name);
 
3970
                                        NullS, NullS, field_info->field_name);
3962
3971
      if (field)
3963
3972
      {
3964
3973
        field->set_name(field_info->old_name,
3985
3994
    ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3986
3995
    String buffer(tmp,sizeof(tmp), system_charset_info);
3987
3996
    Item_field *field= new Item_field(context,
3988
 
                                      NULL, NULL, field_info->field_name);
 
3997
                                      NullS, NullS, field_info->field_name);
3989
3998
    if (!field || add_item_to_list(thd, field))
3990
3999
      return 1;
3991
4000
    buffer.length(0);
4020
4029
    buffer.append(')');
4021
4030
  }
4022
4031
  Item_field *field= new Item_field(context,
4023
 
                                    NULL, NULL, field_info->field_name);
 
4032
                                    NullS, NullS, field_info->field_name);
4024
4033
  if (add_item_to_list(thd, field))
4025
4034
    return 1;
4026
4035
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4028
4037
  {
4029
4038
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
4039
    field_info= &schema_table->fields_info[3];
4031
 
    field= new Item_field(context, NULL, NULL, field_info->field_name);
 
4040
    field= new Item_field(context, NullS, NullS, field_info->field_name);
4032
4041
    if (add_item_to_list(thd, field))
4033
4042
      return 1;
4034
4043
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4053
4062
                               *field_num == 18))
4054
4063
      continue;
4055
4064
    Item_field *field= new Item_field(context,
4056
 
                                      NULL, NULL, field_info->field_name);
 
4065
                                      NullS, NullS, field_info->field_name);
4057
4066
    if (field)
4058
4067
    {
4059
4068
      field->set_name(field_info->old_name,
4078
4087
  {
4079
4088
    field_info= &schema_table->fields_info[*field_num];
4080
4089
    Item_field *field= new Item_field(context,
4081
 
                                      NULL, NULL, field_info->field_name);
 
4090
                                      NullS, NullS, field_info->field_name);
4082
4091
    if (field)
4083
4092
    {
4084
4093
      field->set_name(field_info->old_name,
4106
4115
    1   error
4107
4116
*/
4108
4117
 
4109
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4118
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4110
4119
{
4111
 
  Table *table;
 
4120
  TABLE *table;
4112
4121
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4113
4122
    return(1);
4114
4123
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4149
4158
    }
4150
4159
    List_iterator_fast<Item> it(sel->item_list);
4151
4160
    if (!(transl=
4152
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
 
4161
          (Field_translator*)(thd->stmt_arena->
 
4162
                              alloc(sel->item_list.elements *
4153
4163
                                    sizeof(Field_translator)))))
4154
4164
    {
4155
4165
      return(1);
4235
4245
    if (!tab->table || !tab->table->pos_in_table_list)
4236
4246
      break;
4237
4247
 
4238
 
    TableList *table_list= tab->table->pos_in_table_list;
 
4248
    TABLE_LIST *table_list= tab->table->pos_in_table_list;
4239
4249
    if (table_list->schema_table)
4240
4250
    {
4241
4251
      bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4582
4592
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
4593
  {"COLUMNS", columns_fields_info, create_schema_table, 
4584
4594
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
 
   OPTIMIZE_I_S_TABLE},
 
4595
   OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4586
4596
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4587
4597
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4588
4598
  {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4649
4659
 
4650
4660
    if (plugin->plugin->init(schema_table))
4651
4661
    {
4652
 
      sql_print_error(_("Plugin '%s' init function returned error."),
 
4662
      sql_print_error("Plugin '%s' init function returned error.",
4653
4663
                      plugin->name.str);
4654
4664
      goto err;
4655
4665
    }
4660
4670
 
4661
4671
  return(0);
4662
4672
err:
4663
 
  free(schema_table);
 
4673
  my_free(schema_table, MYF(0));
4664
4674
  return(1);
4665
4675
}
4666
4676
 
4669
4679
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4670
4680
 
4671
4681
  if (schema_table && plugin->plugin->deinit)
4672
 
    free(schema_table);
 
4682
    my_free(schema_table, MYF(0));
4673
4683
 
4674
4684
  return(0);
4675
4685
}