~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Brian Aker
  • Date: 2008-08-16 22:34:15 UTC
  • mto: This revision was merged to the branch mainline in revision 346.
  • Revision ID: brian@tangent.org-20080816223415-n24esdpfcqi4pwpy
Refactor around classes. TABLE_LIST has been factored out of table.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
/* Match the values of enum ha_choice */
27
27
static const char *ha_choice_values[] = {"", "0", "1"};
28
28
 
29
 
static void store_key_options(THD *thd, String *packet, TABLE *table,
 
29
static void store_key_options(THD *thd, String *packet, Table *table,
30
30
                              KEY *key_info);
31
31
 
32
32
 
84
84
static bool show_plugins(THD *thd, plugin_ref plugin,
85
85
                            void *arg)
86
86
{
87
 
  TABLE *table= (TABLE*) arg;
 
87
  Table *table= (Table*) arg;
88
88
  struct st_mysql_plugin *plug= plugin_decl(plugin);
89
89
  struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
90
90
  const CHARSET_INFO * const cs= system_charset_info;
169
169
 
170
170
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
171
171
{
172
 
  TABLE *table= tables->table;
 
172
  Table *table= tables->table;
173
173
 
174
174
  if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
175
175
                               ~PLUGIN_IS_FREED, table))
398
398
void
399
399
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
400
400
{
401
 
  TABLE *table;
 
401
  Table *table;
402
402
 
403
403
  if (open_normal_and_derived_tables(thd, table_list, 0))
404
404
    return;
656
656
  Field **ptr,*field;
657
657
  uint primary_key;
658
658
  KEY *key_info;
659
 
  TABLE *table= table_list->table;
 
659
  Table *table= table_list->table;
660
660
  handler *file= table->file;
661
661
  TABLE_SHARE *share= table->s;
662
662
  HA_CREATE_INFO create_info;
1052
1052
}
1053
1053
 
1054
1054
static void store_key_options(THD *thd __attribute__((unused)),
1055
 
                              String *packet, TABLE *table,
 
1055
                              String *packet, Table *table,
1056
1056
                              KEY *key_info)
1057
1057
{
1058
1058
  char *end, buff[32];
1215
1215
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1216
1216
                            COND* cond __attribute__((unused)))
1217
1217
{
1218
 
  TABLE *table= tables->table;
 
1218
  Table *table= tables->table;
1219
1219
  const CHARSET_INFO * const cs= system_charset_info;
1220
1220
  char *user;
1221
1221
  time_t now= my_time(0);
1488
1488
                              SHOW_VAR *variables,
1489
1489
                              enum enum_var_type value_type,
1490
1490
                              struct system_status_var *status_var,
1491
 
                              const char *prefix, TABLE *table,
 
1491
                              const char *prefix, Table *table,
1492
1492
                              bool ucase_names)
1493
1493
{
1494
1494
  MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1684
1684
    1                     error
1685
1685
*/
1686
1686
 
1687
 
bool schema_table_store_record(THD *thd, TABLE *table)
 
1687
bool schema_table_store_record(THD *thd, Table *table)
1688
1688
{
1689
1689
  int error;
1690
1690
  if ((error= table->file->ha_write_row(table->record[0])))
2265
2265
  enum_sql_command save_sql_command= lex->sql_command;
2266
2266
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2267
2267
    table_list.first;
2268
 
  TABLE *table= tables->table;
 
2268
  Table *table= tables->table;
2269
2269
  int error= 1;
2270
2270
 
2271
2271
  lex->all_selects_list= tables->schema_select_lex;
2313
2313
 
2314
2314
 
2315
2315
/**
2316
 
  @brief          Fill I_S table for SHOW TABLE NAMES commands
 
2316
  @brief          Fill I_S table for SHOW Table NAMES commands
2317
2317
 
2318
2318
  @param[in]      thd                      thread handler
2319
 
  @param[in]      table                    TABLE struct for I_S table
 
2319
  @param[in]      table                    Table struct for I_S table
2320
2320
  @param[in]      db_name                  database name
2321
2321
  @param[in]      table_name               table name
2322
2322
  @param[in]      with_i_schema            I_S table if true
2326
2326
    @retval       1           error
2327
2327
*/
2328
2328
 
2329
 
static int fill_schema_table_names(THD *thd, TABLE *table,
 
2329
static int fill_schema_table_names(THD *thd, Table *table,
2330
2330
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2331
2331
                                   bool with_i_schema)
2332
2332
{
2341
2341
    char path[FN_REFLEN];
2342
2342
    (void) build_table_filename(path, sizeof(path), db_name->str, 
2343
2343
                                table_name->str, reg_ext, 0);
2344
 
    switch (mysql_frm_type(thd, path, &not_used)) {
2345
 
    case FRMTYPE_ERROR:
 
2344
    if (mysql_frm_type(thd, path, &not_used)) 
 
2345
    {
 
2346
      table->field[3]->store(STRING_WITH_LEN("BASE Table"),
 
2347
                             system_charset_info);
 
2348
    }
 
2349
    else
 
2350
    {
2346
2351
      table->field[3]->store(STRING_WITH_LEN("ERROR"),
2347
2352
                             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);
2355
2353
    }
 
2354
 
2356
2355
    if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2357
2356
    {
2358
2357
      thd->clear_error();
2409
2408
  @brief          Fill I_S table with data from FRM file only
2410
2409
 
2411
2410
  @param[in]      thd                      thread handler
2412
 
  @param[in]      table                    TABLE struct for I_S table
 
2411
  @param[in]      table                    Table struct for I_S table
2413
2412
  @param[in]      schema_table             I_S table struct
2414
2413
  @param[in]      db_name                  database name
2415
2414
  @param[in]      table_name               table name
2428
2427
                                      LEX_STRING *table_name,
2429
2428
                                      enum enum_schema_tables schema_table_idx __attribute__((unused)))
2430
2429
{
2431
 
  TABLE *table= tables->table;
 
2430
  Table *table= tables->table;
2432
2431
  TABLE_SHARE *share;
2433
 
  TABLE tbl;
 
2432
  Table tbl;
2434
2433
  TABLE_LIST table_list;
2435
2434
  uint res= 0;
2436
2435
  int error;
2438
2437
  uint key_length;
2439
2438
 
2440
2439
  memset(&table_list, 0, sizeof(TABLE_LIST));
2441
 
  memset(&tbl, 0, sizeof(TABLE));
 
2440
  memset(&tbl, 0, sizeof(Table));
2442
2441
 
2443
2442
  table_list.table_name= table_name->str;
2444
2443
  table_list.db= db_name->str;
2492
2491
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2493
2492
{
2494
2493
  LEX *lex= thd->lex;
2495
 
  TABLE *table= tables->table;
 
2494
  Table *table= tables->table;
2496
2495
  SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2497
2496
  enum_sql_command save_sql_command= lex->sql_command;
2498
2497
  SELECT_LEX *lsel= tables->schema_select_lex;
2617
2616
            continue;
2618
2617
          }
2619
2618
 
2620
 
          /* SHOW TABLE NAMES command */
 
2619
          /* SHOW Table NAMES command */
2621
2620
          if (schema_table_idx == SCH_TABLE_NAMES)
2622
2621
          {
2623
2622
            if (fill_schema_table_names(thd, tables->table, db_name,
2719
2718
}
2720
2719
 
2721
2720
 
2722
 
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
 
2721
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2723
2722
                          const CHARSET_INFO * const cs)
2724
2723
{
2725
2724
  restore_record(table, s->default_values);
2742
2741
  LEX_STRING *db_name;
2743
2742
  bool with_i_schema;
2744
2743
  HA_CREATE_INFO create;
2745
 
  TABLE *table= tables->table;
 
2744
  Table *table= tables->table;
2746
2745
 
2747
2746
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2748
2747
    return(0);
2791
2790
 
2792
2791
 
2793
2792
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
2794
 
                                    TABLE *table, bool res,
 
2793
                                    Table *table, bool res,
2795
2794
                                    LEX_STRING *db_name,
2796
2795
                                    LEX_STRING *table_name)
2797
2796
{
2811
2810
    if (tables->schema_table)
2812
2811
      table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2813
2812
    else
2814
 
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
 
2813
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2815
2814
    table->field[20]->store(error, strlen(error), cs);
2816
2815
    thd->clear_error();
2817
2816
  }
2818
2817
  else
2819
2818
  {
2820
2819
    char option_buff[400],*ptr;
2821
 
    TABLE *show_table= tables->table;
 
2820
    Table *show_table= tables->table;
2822
2821
    TABLE_SHARE *share= show_table->s;
2823
2822
    handler *file= show_table->file;
2824
2823
    handlerton *tmp_db_type= share->db_type();
2827
2826
    else if (share->tmp_table)
2828
2827
      table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2829
2828
    else
2830
 
      table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
 
2829
      table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2831
2830
 
2832
2831
    for (int i= 4; i < 20; i++)
2833
2832
    {
2994
2993
  @return         void
2995
2994
*/
2996
2995
 
2997
 
void store_column_type(TABLE *table, Field *field, const CHARSET_INFO * const cs,
 
2996
void store_column_type(Table *table, Field *field, const CHARSET_INFO * const cs,
2998
2997
                       uint offset)
2999
2998
{
3000
2999
  bool is_blob;
3083
3082
 
3084
3083
 
3085
3084
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
3086
 
                                    TABLE *table, bool res,
 
3085
                                    Table *table, bool res,
3087
3086
                                    LEX_STRING *db_name,
3088
3087
                                    LEX_STRING *table_name)
3089
3088
{
3090
3089
  LEX *lex= thd->lex;
3091
3090
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3092
3091
  const CHARSET_INFO * const cs= system_charset_info;
3093
 
  TABLE *show_table;
 
3092
  Table *show_table;
3094
3093
  TABLE_SHARE *show_table_share;
3095
3094
  Field **ptr, *field, *timestamp_field;
3096
3095
  int count;
3219
3218
{
3220
3219
  CHARSET_INFO **cs;
3221
3220
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3222
 
  TABLE *table= tables->table;
 
3221
  Table *table= tables->table;
3223
3222
  const CHARSET_INFO * const scs= system_charset_info;
3224
3223
 
3225
3224
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3250
3249
{
3251
3250
  CHARSET_INFO **cs;
3252
3251
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3253
 
  TABLE *table= tables->table;
 
3252
  Table *table= tables->table;
3254
3253
  const CHARSET_INFO * const scs= system_charset_info;
3255
3254
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3256
3255
  {
3291
3290
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3292
3291
{
3293
3292
  CHARSET_INFO **cs;
3294
 
  TABLE *table= tables->table;
 
3293
  Table *table= tables->table;
3295
3294
  const CHARSET_INFO * const scs= system_charset_info;
3296
3295
  for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3297
3296
  {
3318
3317
 
3319
3318
 
3320
3319
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
3321
 
                                  TABLE *table, bool res,
 
3320
                                  Table *table, bool res,
3322
3321
                                  LEX_STRING *db_name,
3323
3322
                                  LEX_STRING *table_name)
3324
3323
{
3341
3340
  }
3342
3341
  else
3343
3342
  {
3344
 
    TABLE *show_table= tables->table;
 
3343
    Table *show_table= tables->table;
3345
3344
    KEY *key_info=show_table->s->key_info;
3346
3345
    if (show_table->file)
3347
3346
      show_table->file->info(HA_STATUS_VARIABLE |
3414
3413
}
3415
3414
 
3416
3415
 
3417
 
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
 
3416
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3418
3417
                       LEX_STRING *table_name, const char *key_name,
3419
3418
                       uint key_len, const char *con_type, uint con_len)
3420
3419
{
3430
3429
 
3431
3430
 
3432
3431
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
3433
 
                                         TABLE *table, bool res,
 
3432
                                         Table *table, bool res,
3434
3433
                                         LEX_STRING *db_name,
3435
3434
                                         LEX_STRING *table_name)
3436
3435
{
3445
3444
  else
3446
3445
  {
3447
3446
    List<FOREIGN_KEY_INFO> f_key_list;
3448
 
    TABLE *show_table= tables->table;
 
3447
    Table *show_table= tables->table;
3449
3448
    KEY *key_info=show_table->key_info;
3450
3449
    uint primary_key= show_table->s->primary_key;
3451
3450
    show_table->file->info(HA_STATUS_VARIABLE | 
3488
3487
}
3489
3488
 
3490
3489
 
3491
 
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
 
3490
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3492
3491
                            LEX_STRING *table_name, const char *key_name,
3493
3492
                            uint key_len, const char *con_type, uint con_len,
3494
3493
                            int64_t idx)
3505
3504
 
3506
3505
static int get_schema_key_column_usage_record(THD *thd,
3507
3506
                                              TABLE_LIST *tables,
3508
 
                                              TABLE *table, bool res,
 
3507
                                              Table *table, bool res,
3509
3508
                                              LEX_STRING *db_name,
3510
3509
                                              LEX_STRING *table_name)
3511
3510
{
3520
3519
  else
3521
3520
  {
3522
3521
    List<FOREIGN_KEY_INFO> f_key_list;
3523
 
    TABLE *show_table= tables->table;
 
3522
    Table *show_table= tables->table;
3524
3523
    KEY *key_info=show_table->key_info;
3525
3524
    uint primary_key= show_table->s->primary_key;
3526
3525
    show_table->file->info(HA_STATUS_VARIABLE | 
3595
3594
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3596
3595
{
3597
3596
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3598
 
  TABLE *table= tables->table;
 
3597
  Table *table= tables->table;
3599
3598
  const CHARSET_INFO * const cs= system_charset_info;
3600
3599
  OPEN_TABLE_LIST *open_list;
3601
3600
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3701
3700
 
3702
3701
static int
3703
3702
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3704
 
                                   TABLE *table, bool res,
 
3703
                                   Table *table, bool res,
3705
3704
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3706
3705
{
3707
3706
  const CHARSET_INFO * const cs= system_charset_info;
3717
3716
 
3718
3717
  {
3719
3718
    List<FOREIGN_KEY_INFO> f_key_list;
3720
 
    TABLE *show_table= tables->table;
 
3719
    Table *show_table= tables->table;
3721
3720
    show_table->file->info(HA_STATUS_VARIABLE | 
3722
3721
                           HA_STATUS_NO_LOCK |
3723
3722
                           HA_STATUS_TIME);
3852
3851
  @retval  NULL           Can't create table
3853
3852
*/
3854
3853
 
3855
 
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
 
3854
Table *create_schema_table(THD *thd, TABLE_LIST *table_list)
3856
3855
{
3857
3856
  int field_count= 0;
3858
3857
  Item *item;
3859
 
  TABLE *table;
 
3858
  Table *table;
3860
3859
  List<Item> field_list;
3861
3860
  ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3862
3861
  ST_FIELD_INFO *fields_info= schema_table->fields_info;
4126
4125
 
4127
4126
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4128
4127
{
4129
 
  TABLE *table;
 
4128
  Table *table;
4130
4129
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4131
4130
    return(1);
4132
4131
  table->s->tmp_table= SYSTEM_TMP_TABLE;