~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Brian Aker
  • Date: 2008-08-12 03:12:57 UTC
  • Revision ID: brian@tangent.org-20080812031257-ln3uk87y1r22byeg
First pass of new sql_db.cc work

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <drizzled/sql_show.h>
21
21
#include "repl_failsafe.h"
22
22
#include <mysys/my_dir.h>
23
 
#include <libdrizzle/gettext.h>
24
23
 
25
 
inline const char *
26
 
str_or_nil(const char *str)
27
 
{
28
 
  return str ? str : "<nil>";
29
 
}
 
24
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
30
25
 
31
26
/* Match the values of enum ha_choice */
32
27
static const char *ha_choice_values[] = {"", "0", "1"};
33
28
 
34
 
static void store_key_options(THD *thd, String *packet, Table *table,
 
29
static void store_key_options(THD *thd, String *packet, TABLE *table,
35
30
                              KEY *key_info);
36
31
 
37
32
 
89
84
static bool show_plugins(THD *thd, plugin_ref plugin,
90
85
                            void *arg)
91
86
{
92
 
  Table *table= (Table*) arg;
 
87
  TABLE *table= (TABLE*) arg;
93
88
  struct st_mysql_plugin *plug= plugin_decl(plugin);
94
89
  struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
95
90
  const CHARSET_INFO * const cs= system_charset_info;
172
167
}
173
168
 
174
169
 
175
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
170
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
176
171
{
177
 
  Table *table= tables->table;
 
172
  TABLE *table= tables->table;
178
173
 
179
 
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
 
174
  if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
180
175
                               ~PLUGIN_IS_FREED, table))
181
176
    return(1);
182
177
 
191
186
    find_files()
192
187
    thd                 thread handler
193
188
    files               put found files in this list
194
 
    db                  database name to set in TableList structure
 
189
    db                  database name to set in TABLE_LIST structure
195
190
    path                path to database
196
191
    wild                filter for found files
197
192
    dir                 read databases in path if true, read .frm files in
208
203
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
209
204
           const char *path, const char *wild, bool dir)
210
205
{
211
 
  uint32_t i;
 
206
  uint i;
212
207
  char *ext;
213
208
  MY_DIR *dirp;
214
209
  FILEINFO *file;
215
210
  LEX_STRING *file_name= 0;
216
 
  uint32_t file_name_len;
217
 
  TableList table_list;
 
211
  uint file_name_len;
 
212
  TABLE_LIST table_list;
218
213
 
219
214
  if (wild && !wild[0])
220
215
    wild=0;
249
244
        char *end;
250
245
        *ext=0;                                 /* Remove extension */
251
246
        unpack_dirname(buff, file->name);
252
 
        end= strchr(buff, '\0');
 
247
        end= strend(buff);
253
248
        if (end != buff && end[-1] == FN_LIBCHAR)
254
249
          end[-1]= 0;                           // Remove end FN_LIBCHAR
255
250
        if (stat(buff, file->mystat))
303
298
 
304
299
 
305
300
bool
306
 
mysqld_show_create(THD *thd, TableList *table_list)
 
301
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
307
302
{
308
303
  Protocol *protocol= thd->protocol;
309
304
  char buff[2048];
334
329
    field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
335
330
    // 1024 is for not to confuse old clients
336
331
    field_list.push_back(new Item_empty_string("Create Table",
337
 
                                               cmax(buffer.length(),(uint32_t)1024)));
 
332
                                               max(buffer.length(),(uint32_t)1024)));
338
333
  }
339
334
 
340
335
  if (protocol->send_fields(&field_list,
401
396
****************************************************************************/
402
397
 
403
398
void
404
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
399
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
405
400
{
406
 
  Table *table;
 
401
  TABLE *table;
407
402
 
408
403
  if (open_normal_and_derived_tables(thd, table_list, 0))
409
404
    return;
443
438
    0   No conflicting character
444
439
*/
445
440
 
446
 
static const char *require_quotes(const char *name, uint32_t name_length)
 
441
static const char *require_quotes(const char *name, uint name_length)
447
442
{
448
 
  uint32_t length;
 
443
  uint length;
449
444
  bool pure_digit= true;
450
445
  const char *end= name + name_length;
451
446
 
452
447
  for (; name < end ; name++)
453
448
  {
454
 
    unsigned char chr= (unsigned char) *name;
 
449
    uchar chr= (uchar) *name;
455
450
    length= my_mbcharlen(system_charset_info, chr);
456
451
    if (length == 1 && !system_charset_info->ident_map[chr])
457
452
      return name;
477
472
*/
478
473
 
479
474
void
480
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
 
475
append_identifier(THD *thd, String *packet, const char *name, uint length)
481
476
{
482
477
  const char *name_end;
483
478
  char quote_char;
494
489
   it's a keyword
495
490
  */
496
491
 
497
 
  packet->reserve(length*2 + 2);
 
492
  VOID(packet->reserve(length*2 + 2));
498
493
  quote_char= (char) q;
499
494
  packet->append(&quote_char, 1, system_charset_info);
500
495
 
501
496
  for (name_end= name+length ; name < name_end ; name+= length)
502
497
  {
503
 
    unsigned char chr= (unsigned char) *name;
 
498
    uchar chr= (uchar) *name;
504
499
    length= my_mbcharlen(system_charset_info, chr);
505
500
    /*
506
501
      my_mbcharlen can return 0 on a wrong multibyte
511
506
    */
512
507
    if (!length)
513
508
      length= 1;
514
 
    if (length == 1 && chr == (unsigned char) quote_char)
 
509
    if (length == 1 && chr == (uchar) quote_char)
515
510
      packet->append(&quote_char, 1, system_charset_info);
516
511
    packet->append(name, length, system_charset_info);
517
512
  }
542
537
    #     Quote character
543
538
*/
544
539
 
545
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
540
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
546
541
{
547
542
  if (length &&
548
543
      !is_keyword(name,length) &&
549
544
      !require_quotes(name, length) &&
550
545
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
551
546
    return EOF;
552
 
  return '`';
 
547
  return '"';
553
548
}
554
549
 
555
550
 
561
556
{
562
557
  if (filename)
563
558
  {
564
 
    uint32_t length= dirname_length(filename);
 
559
    uint length= dirname_length(filename);
565
560
    packet->append(' ');
566
561
    packet->append(dir_type);
567
562
    packet->append(STRING_WITH_LEN(" DIRECTORY='"));
606
601
      if (type.length())
607
602
      {
608
603
        String def_val;
609
 
        uint32_t dummy_errors;
 
604
        uint dummy_errors;
610
605
        /* convert to system_charset_info == utf8 */
611
606
        def_val.copy(type.ptr(), type.length(), field->charset(),
612
607
                     system_charset_info, &dummy_errors);
650
645
    0       OK
651
646
 */
652
647
 
653
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
648
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
654
649
                      HA_CREATE_INFO *create_info_arg)
655
650
{
656
651
  List<Item> field_list;
659
654
  String type(tmp, sizeof(tmp), system_charset_info);
660
655
  String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
656
  Field **ptr,*field;
662
 
  uint32_t primary_key;
 
657
  uint primary_key;
663
658
  KEY *key_info;
664
 
  Table *table= table_list->table;
 
659
  TABLE *table= table_list->table;
665
660
  handler *file= table->file;
666
661
  TABLE_SHARE *share= table->s;
667
662
  HA_CREATE_INFO create_info;
695
690
    We have to restore the read_set if we are called from insert in case
696
691
    of row based replication.
697
692
  */
698
 
  old_map= table->use_all_columns(table->read_set);
 
693
  old_map= tmp_use_all_columns(table, table->read_set);
699
694
 
700
695
  for (ptr=table->field ; (field= *ptr); ptr++)
701
696
  {
702
 
    uint32_t flags = field->flags;
 
697
    uint flags = field->flags;
703
698
 
704
699
    if (ptr != table->field)
705
700
      packet->append(STRING_WITH_LEN(",\n"));
754
749
      if (column_format)
755
750
      {
756
751
        packet->append(STRING_WITH_LEN(" /*!"));
757
 
        packet->append(STRING_WITH_LEN(DRIZZLE_VERSION_TABLESPACE_IN_FRM_STR));
 
752
        packet->append(STRING_WITH_LEN(MYSQL_VERSION_TABLESPACE_IN_FRM_STR));
758
753
        packet->append(STRING_WITH_LEN(" COLUMN_FORMAT"));
759
754
        if (column_format == COLUMN_FORMAT_TYPE_FIXED)
760
755
          packet->append(STRING_WITH_LEN(" FIXED */"));
789
784
  file->update_create_info(&create_info);
790
785
  primary_key= share->primary_key;
791
786
 
792
 
  for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
 
787
  for (uint i=0 ; i < share->keys ; i++,key_info++)
793
788
  {
794
789
    KEY_PART_INFO *key_part= key_info->key_part;
795
790
    bool found_primary=0;
814
809
 
815
810
    packet->append(STRING_WITH_LEN(" ("));
816
811
 
817
 
    for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
812
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
818
813
    {
819
814
      if (j)
820
815
        packet->append(',');
888
883
      packet->append(buff, (uint) (end - buff));
889
884
    }
890
885
 
 
886
    
 
887
    if (share->table_charset)
 
888
    {
 
889
      /*
 
890
        IF   check_create_info
 
891
        THEN add DEFAULT CHARSET only if it was used when creating the table
 
892
      */
 
893
      if (!create_info_arg ||
 
894
          (create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
 
895
      {
 
896
        packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
 
897
        packet->append(share->table_charset->csname);
 
898
        if (!(share->table_charset->state & MY_CS_PRIMARY))
 
899
        {
 
900
          packet->append(STRING_WITH_LEN(" COLLATE="));
 
901
          packet->append(table->s->table_charset->name);
 
902
        }
 
903
      }
 
904
    }
 
905
 
891
906
    if (share->min_rows)
892
907
    {
893
908
      char *end;
964
979
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
965
980
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
966
981
  }
967
 
  table->restore_column_map(old_map);
 
982
  tmp_restore_column_map(table->read_set, old_map);
968
983
  return(0);
969
984
}
970
985
 
994
1009
                          HA_CREATE_INFO *create_info)
995
1010
{
996
1011
  HA_CREATE_INFO create;
997
 
  uint32_t create_options = create_info ? create_info->options : 0;
 
1012
  uint create_options = create_info ? create_info->options : 0;
998
1013
 
999
1014
  if (!my_strcasecmp(system_charset_info, dbname,
1000
1015
                     INFORMATION_SCHEMA_NAME.str))
1037
1052
}
1038
1053
 
1039
1054
static void store_key_options(THD *thd __attribute__((unused)),
1040
 
                              String *packet, Table *table,
 
1055
                              String *packet, TABLE *table,
1041
1056
                              KEY *key_info)
1042
1057
{
1043
1058
  char *end, buff[32];
1084
1099
 
1085
1100
  ulong thread_id;
1086
1101
  time_t start_time;
1087
 
  uint32_t   command;
 
1102
  uint   command;
1088
1103
  const char *user,*host,*db,*proc_info,*state_info;
1089
1104
  char *query;
1090
1105
};
1117
1132
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1118
1133
    return;
1119
1134
 
1120
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1135
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1121
1136
  if (!thd->killed)
1122
1137
  {
1123
1138
    I_List_iterator<THD> it(threads);
1144
1159
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1160
                                       (tmp->net.reading_or_writing == 2 ?
1146
1161
                                        "Writing to net" :
1147
 
                                        thd_info->command == COM_SLEEP ? NULL :
 
1162
                                        thd_info->command == COM_SLEEP ? NullS :
1148
1163
                                        "Reading from net") :
1149
 
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
 
1164
                                       tmp->proc_info ? tmp->proc_info :
1150
1165
                                       tmp->mysys_var &&
1151
1166
                                       tmp->mysys_var->current_cond ?
1152
 
                                       "Waiting on cond" : NULL);
 
1167
                                       "Waiting on cond" : NullS);
1153
1168
        if (mysys_var)
1154
1169
          pthread_mutex_unlock(&mysys_var->mutex);
1155
1170
 
1162
1177
            the comment in sql_class.h why this prevents crashes in possible
1163
1178
            races with query_length
1164
1179
          */
1165
 
          uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
 
1180
          uint length= min((uint32_t)max_query_length, tmp->query_length);
1166
1181
          thd_info->query=(char*) thd->strmake(tmp->query,length);
1167
1182
        }
1168
1183
        thread_infos.append(thd_info);
1169
1184
      }
1170
1185
    }
1171
1186
  }
1172
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1187
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1173
1188
 
1174
1189
  thread_info *thd_info;
1175
1190
  time_t now= my_time(0);
1197
1212
  return;
1198
1213
}
1199
1214
 
1200
 
int fill_schema_processlist(THD* thd, TableList* tables,
 
1215
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1201
1216
                            COND* cond __attribute__((unused)))
1202
1217
{
1203
 
  Table *table= tables->table;
 
1218
  TABLE *table= tables->table;
1204
1219
  const CHARSET_INFO * const cs= system_charset_info;
1205
1220
  char *user;
1206
1221
  time_t now= my_time(0);
1207
1222
 
1208
 
  user= NULL;
 
1223
  user= NullS;
1209
1224
 
1210
 
  pthread_mutex_lock(&LOCK_thread_count);
 
1225
  VOID(pthread_mutex_lock(&LOCK_thread_count));
1211
1226
 
1212
1227
  if (!thd->killed)
1213
1228
  {
1254
1269
      val= (char*) (tmp->net.reading_or_writing ?
1255
1270
                    (tmp->net.reading_or_writing == 2 ?
1256
1271
                     "Writing to net" :
1257
 
                     tmp->command == COM_SLEEP ? NULL :
 
1272
                     tmp->command == COM_SLEEP ? NullS :
1258
1273
                     "Reading from net") :
1259
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
 
1274
                    tmp->proc_info ? tmp->proc_info :
1260
1275
                    tmp->mysys_var &&
1261
1276
                    tmp->mysys_var->current_cond ?
1262
 
                    "Waiting on cond" : NULL);
 
1277
                    "Waiting on cond" : NullS);
1263
1278
      if (val)
1264
1279
      {
1265
1280
        table->field[6]->store(val, strlen(val), cs);
1273
1288
      if (tmp->query)
1274
1289
      {
1275
1290
        table->field[7]->store(tmp->query,
1276
 
                               cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
 
1291
                               min((uint32_t)PROCESS_LIST_INFO_WIDTH,
1277
1292
                                   tmp->query_length), cs);
1278
1293
        table->field[7]->set_notnull();
1279
1294
      }
1280
1295
 
1281
1296
      if (schema_table_store_record(thd, table))
1282
1297
      {
1283
 
        pthread_mutex_unlock(&LOCK_thread_count);
 
1298
        VOID(pthread_mutex_unlock(&LOCK_thread_count));
1284
1299
        return(1);
1285
1300
      }
1286
1301
    }
1287
1302
  }
1288
1303
 
1289
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1304
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1290
1305
  return(0);
1291
1306
}
1292
1307
 
1307
1322
*/
1308
1323
static void shrink_var_array(DYNAMIC_ARRAY *array)
1309
1324
{
1310
 
  uint32_t a,b;
 
1325
  uint a,b;
1311
1326
  SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1312
1327
 
1313
1328
  for (a= b= 0; b < array->elements; b++)
1353
1368
    goto err;
1354
1369
  }
1355
1370
  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
 
1371
    res|= insert_dynamic(&all_status_vars, (uchar*)list++);
 
1372
  res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1358
1373
  all_status_vars.elements--; // but next insert_dynamic should overwite it
1359
1374
  if (status_vars_inited)
1360
1375
    sort_dynamic(&all_status_vars, show_var_cmp);
1448
1463
  else
1449
1464
  {
1450
1465
    SHOW_VAR *all= dynamic_element(&all_status_vars, 0, SHOW_VAR *);
1451
 
    uint32_t i;
 
1466
    uint i;
1452
1467
    for (; list->name; list++)
1453
1468
    {
1454
1469
      for (i= 0; i < all_status_vars.elements; i++)
1473
1488
                              SHOW_VAR *variables,
1474
1489
                              enum enum_var_type value_type,
1475
1490
                              struct system_status_var *status_var,
1476
 
                              const char *prefix, Table *table,
 
1491
                              const char *prefix, TABLE *table,
1477
1492
                              bool ucase_names)
1478
1493
{
1479
1494
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1488
1503
  null_lex_str.str= 0;                          // For sys_var->value_ptr()
1489
1504
  null_lex_str.length= 0;
1490
1505
 
1491
 
  prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
 
1506
  prefix_end=stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1492
1507
  if (*prefix)
1493
1508
    *prefix_end++= '_';
1494
1509
  len=name_buffer + sizeof(name_buffer) - prefix_end;
1495
1510
 
1496
1511
  for (; variables->name; variables++)
1497
1512
  {
1498
 
    my_stpncpy(prefix_end, variables->name, len);
 
1513
    stpncpy(prefix_end, variables->name, len);
1499
1514
    name_buffer[sizeof(name_buffer)-1]=0;       /* Safety */
1500
1515
    if (ucase_names)
1501
1516
      make_upper(name_buffer);
1560
1575
          end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1561
1576
          break;
1562
1577
        case SHOW_BOOL:
1563
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1578
          end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1564
1579
          break;
1565
1580
        case SHOW_MY_BOOL:
1566
 
          end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
 
1581
          end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1567
1582
          break;
1568
1583
        case SHOW_INT:
1569
1584
          end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1572
1587
        {
1573
1588
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
1589
          pos= show_comp_option_name[(int) tmp];
1575
 
          end= strchr(pos, '\0');
 
1590
          end= strend(pos);
1576
1591
          break;
1577
1592
        }
1578
1593
        case SHOW_CHAR:
1579
1594
        {
1580
1595
          if (!(pos= value))
1581
1596
            pos= "";
1582
 
          end= strchr(pos, '\0');
 
1597
          end= strend(pos);
1583
1598
          break;
1584
1599
        }
1585
1600
       case SHOW_CHAR_PTR:
1586
1601
        {
1587
1602
          if (!(pos= *(char**) value))
1588
1603
            pos= "";
1589
 
          end= strchr(pos, '\0');
 
1604
          end= strend(pos);
1590
1605
          break;
1591
1606
        }
1592
1607
        case SHOW_KEY_CACHE_LONG:
1628
1643
{
1629
1644
 
1630
1645
  /* Ensure that thread id not killed during loop */
1631
 
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
 
1646
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1632
1647
 
1633
1648
  I_List_iterator<THD> it(threads);
1634
1649
  THD *tmp;
1640
1655
  while ((tmp= it++))
1641
1656
    add_to_status(to, &tmp->status_var);
1642
1657
  
1643
 
  pthread_mutex_unlock(&LOCK_thread_count);
 
1658
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1644
1659
  return;
1645
1660
}
1646
1661
 
1669
1684
    1                     error
1670
1685
*/
1671
1686
 
1672
 
bool schema_table_store_record(THD *thd, Table *table)
 
1687
bool schema_table_store_record(THD *thd, TABLE *table)
1673
1688
{
1674
1689
  int error;
1675
1690
  if ((error= table->file->ha_write_row(table->record[0])))
1715
1730
*/
1716
1731
 
1717
1732
bool get_lookup_value(THD *thd, Item_func *item_func,
1718
 
                      TableList *table, 
 
1733
                      TABLE_LIST *table, 
1719
1734
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1720
1735
{
1721
1736
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1759
1774
      return 1;
1760
1775
 
1761
1776
    /* 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,
 
1777
    if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1778
                               (uchar *) item_field->field_name,
1764
1779
                               strlen(item_field->field_name), 0))
1765
1780
    {
1766
1781
      thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1782
                           tmp_str->length(), false);
1768
1783
    }
1769
1784
    /* Lookup value is table name */
1770
 
    else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
 
1785
    else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1771
1786
                                    strlen(field_name2),
1772
 
                                    (unsigned char *) item_field->field_name,
 
1787
                                    (uchar *) item_field->field_name,
1773
1788
                                    strlen(item_field->field_name), 0))
1774
1789
    {
1775
1790
      thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1797
1812
    1             error, there can be no matching records for the condition
1798
1813
*/
1799
1814
 
1800
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1815
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1801
1816
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1802
1817
{
1803
1818
  if (!cond)
1832
1847
}
1833
1848
 
1834
1849
 
1835
 
bool uses_only_table_name_fields(Item *item, TableList *table)
 
1850
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1836
1851
{
1837
1852
  if (item->type() == Item::FUNC_ITEM)
1838
1853
  {
1839
1854
    Item_func *item_func= (Item_func*)item;
1840
 
    for (uint32_t i=0; i<item_func->argument_count(); i++)
 
1855
    for (uint i=0; i<item_func->argument_count(); i++)
1841
1856
    {
1842
1857
      if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1843
1858
        return 0;
1854
1869
    const char *field_name2= schema_table->idx_field2 >= 0 ?
1855
1870
      field_info[schema_table->idx_field2].field_name : "";
1856
1871
    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,
 
1872
        (cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
 
1873
                               (uchar *) item_field->field_name,
1859
1874
                               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,
 
1875
         cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
 
1876
                               (uchar *) item_field->field_name,
1862
1877
                               strlen(item_field->field_name), 0)))
1863
1878
      return 0;
1864
1879
  }
1872
1887
}
1873
1888
 
1874
1889
 
1875
 
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
 
1890
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
1876
1891
{
1877
1892
  if (!cond)
1878
1893
    return (COND*) 0;
1946
1961
    1             error, there can be no matching records for the condition
1947
1962
*/
1948
1963
 
1949
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1964
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1950
1965
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1951
1966
{
1952
1967
  LEX *lex= thd->lex;
1953
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
1968
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
1954
1969
  memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1970
  switch (lex->sql_command) {
1956
1971
  case SQLCOM_SHOW_DATABASES:
2031
2046
      if (files->push_back(i_s_name_copy))
2032
2047
        return 1;
2033
2048
    }
2034
 
    return (find_files(thd, files, NULL, mysql_data_home,
 
2049
    return (find_files(thd, files, NullS, mysql_data_home,
2035
2050
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2036
2051
  }
2037
2052
 
2062
2077
  if (files->push_back(i_s_name_copy))
2063
2078
    return 1;
2064
2079
  *with_i_schema= 1;
2065
 
  return (find_files(thd, files, NULL,
2066
 
                     mysql_data_home, NULL, 1) != FIND_FILES_OK);
 
2080
  return (find_files(thd, files, NullS,
 
2081
                     mysql_data_home, NullS, 1) != FIND_FILES_OK);
2067
2082
}
2068
2083
 
2069
2084
 
2140
2155
  add_data.files= files;
2141
2156
  add_data.wild= wild;
2142
2157
  if (plugin_foreach(thd, add_schema_table,
2143
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &add_data))
 
2158
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data))
2144
2159
    return(1);
2145
2160
 
2146
2161
  return(0);
2227
2242
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2228
2243
 
2229
2244
  @param[in]      thd                      thread handler
2230
 
  @param[in]      tables                   TableList for I_S table
 
2245
  @param[in]      tables                   TABLE_LIST for I_S table
2231
2246
  @param[in]      schema_table             pointer to I_S structure
2232
2247
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2233
2248
                                           which is used to save|restore original
2240
2255
*/
2241
2256
 
2242
2257
static int 
2243
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2258
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2244
2259
                              ST_SCHEMA_TABLE *schema_table,
2245
2260
                              Open_tables_state *open_tables_state_backup)
2246
2261
{
2248
2263
  bool res;
2249
2264
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2265
  enum_sql_command save_sql_command= lex->sql_command;
2251
 
  TableList *show_table_list= (TableList*) tables->schema_select_lex->
 
2266
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2252
2267
    table_list.first;
2253
 
  Table *table= tables->table;
 
2268
  TABLE *table= tables->table;
2254
2269
  int error= 1;
2255
2270
 
2256
2271
  lex->all_selects_list= tables->schema_select_lex;
2269
2284
  */
2270
2285
  lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
2286
  res= open_normal_and_derived_tables(thd, show_table_list,
2272
 
                                      DRIZZLE_LOCK_IGNORE_FLUSH);
 
2287
                                      MYSQL_LOCK_IGNORE_FLUSH);
2273
2288
  lex->sql_command= save_sql_command;
2274
2289
  /*
2275
2290
    get_all_tables() returns 1 on failure and 0 on success thus
2298
2313
 
2299
2314
 
2300
2315
/**
2301
 
  @brief          Fill I_S table for SHOW Table NAMES commands
 
2316
  @brief          Fill I_S table for SHOW TABLE NAMES commands
2302
2317
 
2303
2318
  @param[in]      thd                      thread handler
2304
 
  @param[in]      table                    Table struct for I_S table
 
2319
  @param[in]      table                    TABLE struct for I_S table
2305
2320
  @param[in]      db_name                  database name
2306
2321
  @param[in]      table_name               table name
2307
2322
  @param[in]      with_i_schema            I_S table if true
2311
2326
    @retval       1           error
2312
2327
*/
2313
2328
 
2314
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2329
static int fill_schema_table_names(THD *thd, TABLE *table,
2315
2330
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2316
2331
                                   bool with_i_schema)
2317
2332
{
2326
2341
    char path[FN_REFLEN];
2327
2342
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2328
2343
                                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
 
    {
 
2344
    switch (mysql_frm_type(thd, path, &not_used)) {
 
2345
    case FRMTYPE_ERROR:
2336
2346
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2337
2347
                             system_charset_info);
 
2348
      break;
 
2349
    case FRMTYPE_TABLE:
 
2350
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
 
2351
                             system_charset_info);
 
2352
      break;
 
2353
    default:
 
2354
      assert(0);
2338
2355
    }
2339
 
 
2340
2356
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2341
2357
    {
2342
2358
      thd->clear_error();
2365
2381
    @retval       SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2366
2382
*/
2367
2383
 
2368
 
static uint32_t get_table_open_method(TableList *tables,
 
2384
static uint get_table_open_method(TABLE_LIST *tables,
2369
2385
                                  ST_SCHEMA_TABLE *schema_table,
2370
2386
                                  enum enum_schema_tables schema_table_idx __attribute__((unused)))
2371
2387
{
2393
2409
  @brief          Fill I_S table with data from FRM file only
2394
2410
 
2395
2411
  @param[in]      thd                      thread handler
2396
 
  @param[in]      table                    Table struct for I_S table
 
2412
  @param[in]      table                    TABLE struct for I_S table
2397
2413
  @param[in]      schema_table             I_S table struct
2398
2414
  @param[in]      db_name                  database name
2399
2415
  @param[in]      table_name               table name
2406
2422
                              open_tables function for this table
2407
2423
*/
2408
2424
 
2409
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
 
2425
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2410
2426
                                      ST_SCHEMA_TABLE *schema_table,
2411
2427
                                      LEX_STRING *db_name,
2412
2428
                                      LEX_STRING *table_name,
2413
2429
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
2414
2430
{
2415
 
  Table *table= tables->table;
 
2431
  TABLE *table= tables->table;
2416
2432
  TABLE_SHARE *share;
2417
 
  Table tbl;
2418
 
  TableList table_list;
2419
 
  uint32_t res= 0;
 
2433
  TABLE tbl;
 
2434
  TABLE_LIST table_list;
 
2435
  uint res= 0;
2420
2436
  int error;
2421
2437
  char key[MAX_DBKEY_LENGTH];
2422
 
  uint32_t key_length;
 
2438
  uint key_length;
2423
2439
 
2424
 
  memset(&table_list, 0, sizeof(TableList));
2425
 
  memset(&tbl, 0, sizeof(Table));
 
2440
  memset(&table_list, 0, sizeof(TABLE_LIST));
 
2441
  memset(&tbl, 0, sizeof(TABLE));
2426
2442
 
2427
2443
  table_list.table_name= table_name->str;
2428
2444
  table_list.db= db_name->str;
2430
2446
  key_length= create_table_def_key(thd, key, &table_list, 0);
2431
2447
  pthread_mutex_lock(&LOCK_open);
2432
2448
  share= get_table_share(thd, &table_list, key,
2433
 
                         key_length, 0, &error);
 
2449
                         key_length, OPEN_VIEW, &error);
2434
2450
  if (!share)
2435
2451
  {
2436
2452
    res= 0;
2473
2489
    @retval       1                        error
2474
2490
*/
2475
2491
 
2476
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2492
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2477
2493
{
2478
2494
  LEX *lex= thd->lex;
2479
 
  Table *table= tables->table;
 
2495
  TABLE *table= tables->table;
2480
2496
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2481
2497
  enum_sql_command save_sql_command= lex->sql_command;
2482
2498
  SELECT_LEX *lsel= tables->schema_select_lex;
2489
2505
  List<LEX_STRING> db_names;
2490
2506
  List_iterator_fast<LEX_STRING> it(db_names);
2491
2507
  COND *partial_cond= 0;
2492
 
  uint32_t derived_tables= lex->derived_tables; 
 
2508
  uint derived_tables= lex->derived_tables; 
2493
2509
  int error= 1;
2494
2510
  Open_tables_state open_tables_state_backup;
2495
2511
  Query_tables_list query_tables_list_backup;
2496
 
  uint32_t table_open_method;
 
2512
  uint table_open_method;
2497
2513
  bool old_value= thd->no_warnings_for_error;
2498
2514
 
2499
2515
  lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2601
2617
            continue;
2602
2618
          }
2603
2619
 
2604
 
          /* SHOW Table NAMES command */
 
2620
          /* SHOW TABLE NAMES command */
2605
2621
          if (schema_table_idx == SCH_TABLE_NAMES)
2606
2622
          {
2607
2623
            if (fill_schema_table_names(thd, tables->table, db_name,
2632
2648
              goto err;
2633
2649
            if (make_table_list(thd, &sel, db_name, table_name))
2634
2650
              goto err;
2635
 
            TableList *show_table_list= (TableList*) sel.table_list.first;
 
2651
            TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2636
2652
            lex->all_selects_list= &sel;
2637
2653
            lex->derived_tables= 0;
2638
2654
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2655
            show_table_list->i_s_requested_object=
2640
2656
              schema_table->i_s_requested_object;
2641
2657
            res= open_normal_and_derived_tables(thd, show_table_list,
2642
 
                                                DRIZZLE_LOCK_IGNORE_FLUSH);
 
2658
                                                MYSQL_LOCK_IGNORE_FLUSH);
2643
2659
            lex->sql_command= save_sql_command;
2644
2660
            /*
2645
2661
              XXX:  show_table_list has a flag i_is_requested,
2703
2719
}
2704
2720
 
2705
2721
 
2706
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
 
2722
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
2707
2723
                          const CHARSET_INFO * const cs)
2708
2724
{
2709
2725
  restore_record(table, s->default_values);
2714
2730
}
2715
2731
 
2716
2732
 
2717
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2733
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
2718
2734
{
2719
2735
  /*
2720
2736
    TODO: fill_schema_shemata() is called when new client is connected.
2726
2742
  LEX_STRING *db_name;
2727
2743
  bool with_i_schema;
2728
2744
  HA_CREATE_INFO create;
2729
 
  Table *table= tables->table;
 
2745
  TABLE *table= tables->table;
2730
2746
 
2731
2747
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2732
2748
    return(0);
2741
2757
     !with_i_schema)
2742
2758
  {
2743
2759
    char path[FN_REFLEN+16];
2744
 
    uint32_t path_len;
 
2760
    uint path_len;
2745
2761
    struct stat stat_info;
2746
2762
    if (!lookup_field_vals.db_value.str[0])
2747
2763
      return(0);
2774
2790
}
2775
2791
 
2776
2792
 
2777
 
static int get_schema_tables_record(THD *thd, TableList *tables,
2778
 
                                    Table *table, bool res,
 
2793
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
 
2794
                                    TABLE *table, bool res,
2779
2795
                                    LEX_STRING *db_name,
2780
2796
                                    LEX_STRING *table_name)
2781
2797
{
2795
2811
    if (tables->schema_table)
2796
2812
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2797
2813
    else
2798
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2814
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2799
2815
    table->field[20]->store(error, strlen(error), cs);
2800
2816
    thd->clear_error();
2801
2817
  }
2802
2818
  else
2803
2819
  {
2804
2820
    char option_buff[400],*ptr;
2805
 
    Table *show_table= tables->table;
 
2821
    TABLE *show_table= tables->table;
2806
2822
    TABLE_SHARE *share= show_table->s;
2807
2823
    handler *file= show_table->file;
2808
2824
    handlerton *tmp_db_type= share->db_type();
2811
2827
    else if (share->tmp_table)
2812
2828
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2813
2829
    else
2814
 
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
 
2830
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2815
2831
 
2816
2832
    for (int i= 4; i < 20; i++)
2817
2833
    {
2826
2842
    ptr=option_buff;
2827
2843
    if (share->min_rows)
2828
2844
    {
2829
 
      ptr=my_stpcpy(ptr," min_rows=");
 
2845
      ptr=stpcpy(ptr," min_rows=");
2830
2846
      ptr=int64_t10_to_str(share->min_rows,ptr,10);
2831
2847
    }
2832
2848
    if (share->max_rows)
2833
2849
    {
2834
 
      ptr=my_stpcpy(ptr," max_rows=");
 
2850
      ptr=stpcpy(ptr," max_rows=");
2835
2851
      ptr=int64_t10_to_str(share->max_rows,ptr,10);
2836
2852
    }
2837
2853
    if (share->avg_row_length)
2838
2854
    {
2839
 
      ptr=my_stpcpy(ptr," avg_row_length=");
 
2855
      ptr=stpcpy(ptr," avg_row_length=");
2840
2856
      ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2841
2857
    }
2842
2858
    if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
 
      ptr=my_stpcpy(ptr," pack_keys=1");
 
2859
      ptr=stpcpy(ptr," pack_keys=1");
2844
2860
    if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
 
      ptr=my_stpcpy(ptr," pack_keys=0");
 
2861
      ptr=stpcpy(ptr," pack_keys=0");
2846
2862
    /* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2863
    if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
 
      ptr=my_stpcpy(ptr," checksum=1");
 
2864
      ptr=stpcpy(ptr," checksum=1");
2849
2865
    if (share->page_checksum != HA_CHOICE_UNDEF)
2850
2866
      ptr= strxmov(ptr, " page_checksum=",
2851
 
                   ha_choice_values[(uint) share->page_checksum], NULL);
 
2867
                   ha_choice_values[(uint) share->page_checksum], NullS);
2852
2868
    if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
 
      ptr=my_stpcpy(ptr," delay_key_write=1");
 
2869
      ptr=stpcpy(ptr," delay_key_write=1");
2854
2870
    if (share->row_type != ROW_TYPE_DEFAULT)
2855
2871
      ptr=strxmov(ptr, " row_format=", 
2856
2872
                  ha_row_type[(uint) share->row_type],
2857
 
                  NULL);
 
2873
                  NullS);
2858
2874
    if (share->block_size)
2859
2875
    {
2860
 
      ptr= my_stpcpy(ptr, " block_size=");
 
2876
      ptr= stpcpy(ptr, " block_size=");
2861
2877
      ptr= int64_t10_to_str(share->block_size, ptr, 10);
2862
2878
    }
2863
2879
    
2865
2881
    {
2866
2882
      ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
2883
                   (share->transactional == HA_CHOICE_YES ? "1" : "0"),
2868
 
                   NULL);
 
2884
                   NullS);
2869
2885
    }
2870
2886
    if (share->transactional != HA_CHOICE_UNDEF)
2871
2887
      ptr= strxmov(ptr, " transactional=",
2872
 
                   ha_choice_values[(uint) share->transactional], NULL);
 
2888
                   ha_choice_values[(uint) share->transactional], NullS);
2873
2889
    table->field[19]->store(option_buff+1,
2874
2890
                            (ptr == option_buff ? 0 : 
2875
2891
                             (uint) (ptr-option_buff)-1), cs);
2978
2994
  @return         void
2979
2995
*/
2980
2996
 
2981
 
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2982
 
                       uint32_t offset)
 
2997
void store_column_type(TABLE *table, Field *field, const CHARSET_INFO * const cs,
 
2998
                       uint offset)
2983
2999
{
2984
3000
  bool is_blob;
2985
3001
  int decimals, field_length;
3025
3041
    field_length= ((Field_new_decimal*) field)->precision;
3026
3042
    break;
3027
3043
  case DRIZZLE_TYPE_TINY:
 
3044
  case DRIZZLE_TYPE_SHORT:
3028
3045
  case DRIZZLE_TYPE_LONG:
3029
3046
  case DRIZZLE_TYPE_LONGLONG:
3030
3047
    field_length= field->max_display_length() - 1;
3065
3082
}
3066
3083
 
3067
3084
 
3068
 
static int get_schema_column_record(THD *thd, TableList *tables,
3069
 
                                    Table *table, bool res,
 
3085
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
 
3086
                                    TABLE *table, bool res,
3070
3087
                                    LEX_STRING *db_name,
3071
3088
                                    LEX_STRING *table_name)
3072
3089
{
3073
3090
  LEX *lex= thd->lex;
3074
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3091
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3075
3092
  const CHARSET_INFO * const cs= system_charset_info;
3076
 
  Table *show_table;
 
3093
  TABLE *show_table;
3077
3094
  TABLE_SHARE *show_table_share;
3078
3095
  Field **ptr, *field, *timestamp_field;
3079
3096
  int count;
3116
3133
    if (!show_table->read_set)
3117
3134
    {
3118
3135
      /* 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)))
 
3136
      uchar *bitmaps;
 
3137
      uint bitmap_size= show_table_share->column_bitmap_size;
 
3138
      if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3122
3139
        return(0);
3123
3140
      bitmap_init(&show_table->def_read_set,
3124
3141
                  (my_bitmap_map*) bitmaps, show_table_share->fields, false);
3130
3147
 
3131
3148
  for (; (field= *ptr) ; ptr++)
3132
3149
  {
3133
 
    unsigned char *pos;
 
3150
    uchar *pos;
3134
3151
    char tmp[MAX_FIELD_WIDTH];
3135
3152
    String type(tmp,sizeof(tmp), system_charset_info);
3136
3153
    char *end;
3158
3175
      table->field[5]->store(type.ptr(), type.length(), cs);
3159
3176
      table->field[5]->set_notnull();
3160
3177
    }
3161
 
    pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
 
3178
    pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ?  "NO" : "YES");
3162
3179
    table->field[6]->store((const char*) pos,
3163
3180
                           strlen((const char*) pos), cs);
3164
3181
    store_column_type(table, field, cs, 7);
3165
3182
 
3166
 
    pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
 
3183
    pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3167
3184
                 (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3168
3185
                 (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3169
3186
    table->field[15]->store((const char*) pos,
3181
3198
    {
3182
3199
      enum column_format_type column_format= (enum column_format_type)
3183
3200
        ((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3184
 
      pos=(unsigned char*)"Default";
 
3201
      pos=(uchar*)"Default";
3185
3202
      table->field[19]->store((const char*) pos,
3186
3203
                              strlen((const char*) pos), cs);
3187
 
      pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
 
3204
      pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3188
3205
                   column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3189
3206
                                                             "Dynamic");
3190
3207
      table->field[20]->store((const char*) pos,
3198
3215
 
3199
3216
 
3200
3217
 
3201
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3218
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3202
3219
{
3203
3220
  CHARSET_INFO **cs;
3204
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3205
 
  Table *table= tables->table;
 
3221
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3222
  TABLE *table= tables->table;
3206
3223
  const CHARSET_INFO * const scs= system_charset_info;
3207
3224
 
3208
3225
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3229
3246
}
3230
3247
 
3231
3248
 
3232
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3249
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3233
3250
{
3234
3251
  CHARSET_INFO **cs;
3235
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3236
 
  Table *table= tables->table;
 
3252
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3253
  TABLE *table= tables->table;
3237
3254
  const CHARSET_INFO * const scs= system_charset_info;
3238
3255
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3239
3256
  {
3271
3288
}
3272
3289
 
3273
3290
 
3274
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3291
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3275
3292
{
3276
3293
  CHARSET_INFO **cs;
3277
 
  Table *table= tables->table;
 
3294
  TABLE *table= tables->table;
3278
3295
  const CHARSET_INFO * const scs= system_charset_info;
3279
3296
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3280
3297
  {
3300
3317
}
3301
3318
 
3302
3319
 
3303
 
static int get_schema_stat_record(THD *thd, TableList *tables,
3304
 
                                  Table *table, bool res,
 
3320
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
 
3321
                                  TABLE *table, bool res,
3305
3322
                                  LEX_STRING *db_name,
3306
3323
                                  LEX_STRING *table_name)
3307
3324
{
3324
3341
  }
3325
3342
  else
3326
3343
  {
3327
 
    Table *show_table= tables->table;
 
3344
    TABLE *show_table= tables->table;
3328
3345
    KEY *key_info=show_table->s->key_info;
3329
3346
    if (show_table->file)
3330
3347
      show_table->file->info(HA_STATUS_VARIABLE |
3331
3348
                             HA_STATUS_NO_LOCK |
3332
3349
                             HA_STATUS_TIME);
3333
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
 
3350
    for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3334
3351
    {
3335
3352
      KEY_PART_INFO *key_part= key_info->key_part;
3336
3353
      const char *str;
3337
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3354
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3338
3355
      {
3339
3356
        restore_record(table, s->default_values);
3340
3357
        table->field[1]->store(db_name->str, db_name->length, cs);
3375
3392
                                  key_part->field->charset()->mbmaxlen, true);
3376
3393
          table->field[10]->set_notnull();
3377
3394
        }
3378
 
        uint32_t flags= key_part->field ? key_part->field->flags : 0;
 
3395
        uint flags= key_part->field ? key_part->field->flags : 0;
3379
3396
        const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
3397
        table->field[12]->store(pos, strlen(pos), cs);
3381
3398
        if (!show_table->s->keys_in_use.is_set(i))
3397
3414
}
3398
3415
 
3399
3416
 
3400
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3417
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3401
3418
                       LEX_STRING *table_name, const char *key_name,
3402
 
                       uint32_t key_len, const char *con_type, uint32_t con_len)
 
3419
                       uint key_len, const char *con_type, uint con_len)
3403
3420
{
3404
3421
  const CHARSET_INFO * const cs= system_charset_info;
3405
3422
  restore_record(table, s->default_values);
3412
3429
}
3413
3430
 
3414
3431
 
3415
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
3416
 
                                         Table *table, bool res,
 
3432
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
 
3433
                                         TABLE *table, bool res,
3417
3434
                                         LEX_STRING *db_name,
3418
3435
                                         LEX_STRING *table_name)
3419
3436
{
3428
3445
  else
3429
3446
  {
3430
3447
    List<FOREIGN_KEY_INFO> f_key_list;
3431
 
    Table *show_table= tables->table;
 
3448
    TABLE *show_table= tables->table;
3432
3449
    KEY *key_info=show_table->key_info;
3433
 
    uint32_t primary_key= show_table->s->primary_key;
 
3450
    uint primary_key= show_table->s->primary_key;
3434
3451
    show_table->file->info(HA_STATUS_VARIABLE | 
3435
3452
                           HA_STATUS_NO_LOCK |
3436
3453
                           HA_STATUS_TIME);
3437
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3454
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3438
3455
    {
3439
3456
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3440
3457
        continue;
3471
3488
}
3472
3489
 
3473
3490
 
3474
 
void store_key_column_usage(Table *table, LEX_STRING *db_name,
 
3491
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3475
3492
                            LEX_STRING *table_name, const char *key_name,
3476
 
                            uint32_t key_len, const char *con_type, uint32_t con_len,
 
3493
                            uint key_len, const char *con_type, uint con_len,
3477
3494
                            int64_t idx)
3478
3495
{
3479
3496
  const CHARSET_INFO * const cs= system_charset_info;
3487
3504
 
3488
3505
 
3489
3506
static int get_schema_key_column_usage_record(THD *thd,
3490
 
                                              TableList *tables,
3491
 
                                              Table *table, bool res,
 
3507
                                              TABLE_LIST *tables,
 
3508
                                              TABLE *table, bool res,
3492
3509
                                              LEX_STRING *db_name,
3493
3510
                                              LEX_STRING *table_name)
3494
3511
{
3503
3520
  else
3504
3521
  {
3505
3522
    List<FOREIGN_KEY_INFO> f_key_list;
3506
 
    Table *show_table= tables->table;
 
3523
    TABLE *show_table= tables->table;
3507
3524
    KEY *key_info=show_table->key_info;
3508
 
    uint32_t primary_key= show_table->s->primary_key;
 
3525
    uint primary_key= show_table->s->primary_key;
3509
3526
    show_table->file->info(HA_STATUS_VARIABLE | 
3510
3527
                           HA_STATUS_NO_LOCK |
3511
3528
                           HA_STATUS_TIME);
3512
 
    for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
 
3529
    for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3513
3530
    {
3514
3531
      if (i != primary_key && !(key_info->flags & HA_NOSAME))
3515
3532
        continue;
3516
 
      uint32_t f_idx= 0;
 
3533
      uint f_idx= 0;
3517
3534
      KEY_PART_INFO *key_part= key_info->key_part;
3518
 
      for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
 
3535
      for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3519
3536
      {
3520
3537
        if (key_part->field)
3521
3538
        {
3542
3559
      LEX_STRING *r_info;
3543
3560
      List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3544
3561
        it1(f_key_info->referenced_fields);
3545
 
      uint32_t f_idx= 0;
 
3562
      uint f_idx= 0;
3546
3563
      while ((f_info= it++))
3547
3564
      {
3548
3565
        r_info= it1++;
3575
3592
}
3576
3593
 
3577
3594
 
3578
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3595
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3579
3596
{
3580
 
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3581
 
  Table *table= tables->table;
 
3597
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
 
3598
  TABLE *table= tables->table;
3582
3599
  const CHARSET_INFO * const cs= system_charset_info;
3583
 
  OPEN_TableList *open_list;
 
3600
  OPEN_TABLE_LIST *open_list;
3584
3601
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
3602
            && thd->is_fatal_error)
3586
3603
    return(1);
3599
3616
}
3600
3617
 
3601
3618
 
3602
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3619
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3603
3620
{
3604
3621
  int res= 0;
3605
3622
  LEX *lex= thd->lex;
3606
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3623
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3607
3624
  enum enum_schema_tables schema_table_idx=
3608
3625
    get_schema_table_idx(tables->schema_table);
3609
3626
  enum enum_var_type option_type= OPT_SESSION;
3622
3639
}
3623
3640
 
3624
3641
 
3625
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3642
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3626
3643
{
3627
3644
  LEX *lex= thd->lex;
3628
 
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
 
3645
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3629
3646
  int res= 0;
3630
3647
  STATUS_VAR *tmp1, tmp;
3631
3648
  enum enum_schema_tables schema_table_idx=
3683
3700
*/
3684
3701
 
3685
3702
static int
3686
 
get_referential_constraints_record(THD *thd, TableList *tables,
3687
 
                                   Table *table, bool res,
 
3703
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
 
3704
                                   TABLE *table, bool res,
3688
3705
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3689
3706
{
3690
3707
  const CHARSET_INFO * const cs= system_charset_info;
3700
3717
 
3701
3718
  {
3702
3719
    List<FOREIGN_KEY_INFO> f_key_list;
3703
 
    Table *show_table= tables->table;
 
3720
    TABLE *show_table= tables->table;
3704
3721
    show_table->file->info(HA_STATUS_VARIABLE | 
3705
3722
                           HA_STATUS_NO_LOCK |
3706
3723
                           HA_STATUS_TIME);
3807
3824
 
3808
3825
  schema_table_a.table_name= table_name;
3809
3826
  if (plugin_foreach(thd, find_schema_table_in_plugin, 
3810
 
                     DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
 
3827
                     MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3811
3828
    return(schema_table_a.schema_table);
3812
3829
 
3813
3830
  return(NULL);
3835
3852
  @retval  NULL           Can't create table
3836
3853
*/
3837
3854
 
3838
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3855
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3839
3856
{
3840
3857
  int field_count= 0;
3841
3858
  Item *item;
3842
 
  Table *table;
 
3859
  TABLE *table;
3843
3860
  List<Item> field_list;
3844
3861
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3845
3862
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
3850
3867
    switch (fields_info->field_type) {
3851
3868
    case DRIZZLE_TYPE_TINY:
3852
3869
    case DRIZZLE_TYPE_LONG:
 
3870
    case DRIZZLE_TYPE_SHORT:
3853
3871
    case DRIZZLE_TYPE_LONGLONG:
3854
3872
      if (!(item= new Item_return_int(fields_info->field_name,
3855
3873
                                      fields_info->field_length,
3918
3936
  tmp_table_param->schema_table= 1;
3919
3937
  SELECT_LEX *select_lex= thd->lex->current_select;
3920
3938
  if (!(table= create_tmp_table(thd, tmp_table_param,
3921
 
                                field_list, (order_st*) 0, 0, 0, 
 
3939
                                field_list, (ORDER*) 0, 0, 0, 
3922
3940
                                (select_lex->options | thd->options |
3923
3941
                                 TMP_TABLE_ALL_COLUMNS),
3924
3942
                                HA_POS_ERROR, table_list->alias)))
3958
3976
    if (field_info->old_name)
3959
3977
    {
3960
3978
      Item_field *field= new Item_field(context,
3961
 
                                        NULL, NULL, field_info->field_name);
 
3979
                                        NullS, NullS, field_info->field_name);
3962
3980
      if (field)
3963
3981
      {
3964
3982
        field->set_name(field_info->old_name,
3985
4003
    ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3986
4004
    String buffer(tmp,sizeof(tmp), system_charset_info);
3987
4005
    Item_field *field= new Item_field(context,
3988
 
                                      NULL, NULL, field_info->field_name);
 
4006
                                      NullS, NullS, field_info->field_name);
3989
4007
    if (!field || add_item_to_list(thd, field))
3990
4008
      return 1;
3991
4009
    buffer.length(0);
4020
4038
    buffer.append(')');
4021
4039
  }
4022
4040
  Item_field *field= new Item_field(context,
4023
 
                                    NULL, NULL, field_info->field_name);
 
4041
                                    NullS, NullS, field_info->field_name);
4024
4042
  if (add_item_to_list(thd, field))
4025
4043
    return 1;
4026
4044
  field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4028
4046
  {
4029
4047
    field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
4048
    field_info= &schema_table->fields_info[3];
4031
 
    field= new Item_field(context, NULL, NULL, field_info->field_name);
 
4049
    field= new Item_field(context, NullS, NullS, field_info->field_name);
4032
4050
    if (add_item_to_list(thd, field))
4033
4051
      return 1;
4034
4052
    field->set_name(field_info->old_name, strlen(field_info->old_name),
4053
4071
                               *field_num == 18))
4054
4072
      continue;
4055
4073
    Item_field *field= new Item_field(context,
4056
 
                                      NULL, NULL, field_info->field_name);
 
4074
                                      NullS, NullS, field_info->field_name);
4057
4075
    if (field)
4058
4076
    {
4059
4077
      field->set_name(field_info->old_name,
4078
4096
  {
4079
4097
    field_info= &schema_table->fields_info[*field_num];
4080
4098
    Item_field *field= new Item_field(context,
4081
 
                                      NULL, NULL, field_info->field_name);
 
4099
                                      NullS, NullS, field_info->field_name);
4082
4100
    if (field)
4083
4101
    {
4084
4102
      field->set_name(field_info->old_name,
4106
4124
    1   error
4107
4125
*/
4108
4126
 
4109
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4127
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4110
4128
{
4111
 
  Table *table;
 
4129
  TABLE *table;
4112
4130
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4113
4131
    return(1);
4114
4132
  table->s->tmp_table= SYSTEM_TMP_TABLE;
4149
4167
    }
4150
4168
    List_iterator_fast<Item> it(sel->item_list);
4151
4169
    if (!(transl=
4152
 
          (Field_translator*)(thd->alloc(sel->item_list.elements *
 
4170
          (Field_translator*)(thd->stmt_arena->
 
4171
                              alloc(sel->item_list.elements *
4153
4172
                                    sizeof(Field_translator)))))
4154
4173
    {
4155
4174
      return(1);
4235
4254
    if (!tab->table || !tab->table->pos_in_table_list)
4236
4255
      break;
4237
4256
 
4238
 
    TableList *table_list= tab->table->pos_in_table_list;
 
4257
    TABLE_LIST *table_list= tab->table->pos_in_table_list;
4239
4258
    if (table_list->schema_table)
4240
4259
    {
4241
4260
      bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4582
4601
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
4602
  {"COLUMNS", columns_fields_info, create_schema_table, 
4584
4603
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
 
   OPTIMIZE_I_S_TABLE},
 
4604
   OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4586
4605
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4587
4606
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4588
4607
  {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4649
4668
 
4650
4669
    if (plugin->plugin->init(schema_table))
4651
4670
    {
4652
 
      sql_print_error(_("Plugin '%s' init function returned error."),
 
4671
      sql_print_error("Plugin '%s' init function returned error.",
4653
4672
                      plugin->name.str);
4654
4673
      goto err;
4655
4674
    }
4660
4679
 
4661
4680
  return(0);
4662
4681
err:
4663
 
  free(schema_table);
 
4682
  my_free(schema_table, MYF(0));
4664
4683
  return(1);
4665
4684
}
4666
4685
 
4669
4688
  ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4670
4689
 
4671
4690
  if (schema_table && plugin->plugin->deinit)
4672
 
    free(schema_table);
 
4691
    my_free(schema_table, MYF(0));
4673
4692
 
4674
4693
  return(0);
4675
4694
}