~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Monty Taylor
  • Date: 2008-08-18 23:04:17 UTC
  • mfrom: (327.1.12 drizzle)
  • Revision ID: monty@inaugust.com-20080818230417-442rhihpahnout34
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

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