~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Brian Aker
  • Date: 2008-08-18 04:35:40 UTC
  • mfrom: (342 codestyle)
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: brian@tangent.org-20080818043540-numg7vydi7b0bzcd
Mering Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <mysys/my_dir.h>
23
23
#include <libdrizzle/gettext.h>
24
24
 
25
 
inline const char *
26
 
str_or_nil(const char *str)
27
 
{
28
 
  return str ? str : "<nil>";
29
 
}
 
25
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
30
26
 
31
27
/* Match the values of enum ha_choice */
32
28
static const char *ha_choice_values[] = {"", "0", "1"};
172
168
}
173
169
 
174
170
 
175
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
171
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
176
172
{
177
173
  Table *table= tables->table;
178
174
 
191
187
    find_files()
192
188
    thd                 thread handler
193
189
    files               put found files in this list
194
 
    db                  database name to set in TableList structure
 
190
    db                  database name to set in TABLE_LIST structure
195
191
    path                path to database
196
192
    wild                filter for found files
197
193
    dir                 read databases in path if true, read .frm files in
214
210
  FILEINFO *file;
215
211
  LEX_STRING *file_name= 0;
216
212
  uint file_name_len;
217
 
  TableList table_list;
 
213
  TABLE_LIST table_list;
218
214
 
219
215
  if (wild && !wild[0])
220
216
    wild=0;
249
245
        char *end;
250
246
        *ext=0;                                 /* Remove extension */
251
247
        unpack_dirname(buff, file->name);
252
 
        end= strchr(buff, '\0');
 
248
        end= strend(buff);
253
249
        if (end != buff && end[-1] == FN_LIBCHAR)
254
250
          end[-1]= 0;                           // Remove end FN_LIBCHAR
255
251
        if (stat(buff, file->mystat))
303
299
 
304
300
 
305
301
bool
306
 
mysqld_show_create(THD *thd, TableList *table_list)
 
302
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
307
303
{
308
304
  Protocol *protocol= thd->protocol;
309
305
  char buff[2048];
401
397
****************************************************************************/
402
398
 
403
399
void
404
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
400
mysqld_list_fields(THD *thd, TABLE_LIST *table_list, const char *wild)
405
401
{
406
402
  Table *table;
407
403
 
549
545
      !require_quotes(name, length) &&
550
546
      !(thd->options & OPTION_QUOTE_SHOW_CREATE))
551
547
    return EOF;
552
 
  return '`';
 
548
  return '"';
553
549
}
554
550
 
555
551
 
650
646
    0       OK
651
647
 */
652
648
 
653
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
649
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
654
650
                      HA_CREATE_INFO *create_info_arg)
655
651
{
656
652
  List<Item> field_list;
695
691
    We have to restore the read_set if we are called from insert in case
696
692
    of row based replication.
697
693
  */
698
 
  old_map= table->use_all_columns(table->read_set);
 
694
  old_map= tmp_use_all_columns(table, table->read_set);
699
695
 
700
696
  for (ptr=table->field ; (field= *ptr); ptr++)
701
697
  {
888
884
      packet->append(buff, (uint) (end - buff));
889
885
    }
890
886
 
 
887
    
 
888
    if (share->table_charset)
 
889
    {
 
890
      /*
 
891
        IF   check_create_info
 
892
        THEN add DEFAULT CHARSET only if it was used when creating the table
 
893
      */
 
894
      if (!create_info_arg ||
 
895
          (create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
 
896
      {
 
897
        packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
 
898
        packet->append(share->table_charset->csname);
 
899
        if (!(share->table_charset->state & MY_CS_PRIMARY))
 
900
        {
 
901
          packet->append(STRING_WITH_LEN(" COLLATE="));
 
902
          packet->append(table->s->table_charset->name);
 
903
        }
 
904
      }
 
905
    }
 
906
 
891
907
    if (share->min_rows)
892
908
    {
893
909
      char *end;
964
980
    append_directory(thd, packet, "DATA",  create_info.data_file_name);
965
981
    append_directory(thd, packet, "INDEX", create_info.index_file_name);
966
982
  }
967
 
  table->restore_column_map(old_map);
 
983
  tmp_restore_column_map(table->read_set, old_map);
968
984
  return(0);
969
985
}
970
986
 
1146
1162
                                        "Writing to net" :
1147
1163
                                        thd_info->command == COM_SLEEP ? NullS :
1148
1164
                                        "Reading from net") :
1149
 
                                       tmp->get_proc_info() ? tmp->get_proc_info() :
 
1165
                                       tmp->proc_info ? tmp->proc_info :
1150
1166
                                       tmp->mysys_var &&
1151
1167
                                       tmp->mysys_var->current_cond ?
1152
1168
                                       "Waiting on cond" : NullS);
1197
1213
  return;
1198
1214
}
1199
1215
 
1200
 
int fill_schema_processlist(THD* thd, TableList* tables,
 
1216
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1201
1217
                            COND* cond __attribute__((unused)))
1202
1218
{
1203
1219
  Table *table= tables->table;
1256
1272
                     "Writing to net" :
1257
1273
                     tmp->command == COM_SLEEP ? NullS :
1258
1274
                     "Reading from net") :
1259
 
                    tmp->get_proc_info() ? tmp->get_proc_info() :
 
1275
                    tmp->proc_info ? tmp->proc_info :
1260
1276
                    tmp->mysys_var &&
1261
1277
                    tmp->mysys_var->current_cond ?
1262
1278
                    "Waiting on cond" : NullS);
1572
1588
        {
1573
1589
          SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
1590
          pos= show_comp_option_name[(int) tmp];
1575
 
          end= strchr(pos, '\0');
 
1591
          end= strend(pos);
1576
1592
          break;
1577
1593
        }
1578
1594
        case SHOW_CHAR:
1579
1595
        {
1580
1596
          if (!(pos= value))
1581
1597
            pos= "";
1582
 
          end= strchr(pos, '\0');
 
1598
          end= strend(pos);
1583
1599
          break;
1584
1600
        }
1585
1601
       case SHOW_CHAR_PTR:
1586
1602
        {
1587
1603
          if (!(pos= *(char**) value))
1588
1604
            pos= "";
1589
 
          end= strchr(pos, '\0');
 
1605
          end= strend(pos);
1590
1606
          break;
1591
1607
        }
1592
1608
        case SHOW_KEY_CACHE_LONG:
1715
1731
*/
1716
1732
 
1717
1733
bool get_lookup_value(THD *thd, Item_func *item_func,
1718
 
                      TableList *table, 
 
1734
                      TABLE_LIST *table, 
1719
1735
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1720
1736
{
1721
1737
  ST_SCHEMA_TABLE *schema_table= table->schema_table;
1797
1813
    1             error, there can be no matching records for the condition
1798
1814
*/
1799
1815
 
1800
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1816
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1801
1817
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1802
1818
{
1803
1819
  if (!cond)
1832
1848
}
1833
1849
 
1834
1850
 
1835
 
bool uses_only_table_name_fields(Item *item, TableList *table)
 
1851
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1836
1852
{
1837
1853
  if (item->type() == Item::FUNC_ITEM)
1838
1854
  {
1872
1888
}
1873
1889
 
1874
1890
 
1875
 
static COND * make_cond_for_info_schema(COND *cond, TableList *table)
 
1891
static COND * make_cond_for_info_schema(COND *cond, TABLE_LIST *table)
1876
1892
{
1877
1893
  if (!cond)
1878
1894
    return (COND*) 0;
1946
1962
    1             error, there can be no matching records for the condition
1947
1963
*/
1948
1964
 
1949
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1965
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1950
1966
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1951
1967
{
1952
1968
  LEX *lex= thd->lex;
2227
2243
  @brief          Fill I_S table for SHOW COLUMNS|INDEX commands
2228
2244
 
2229
2245
  @param[in]      thd                      thread handler
2230
 
  @param[in]      tables                   TableList for I_S table
 
2246
  @param[in]      tables                   TABLE_LIST for I_S table
2231
2247
  @param[in]      schema_table             pointer to I_S structure
2232
2248
  @param[in]      open_tables_state_backup pointer to Open_tables_state object
2233
2249
                                           which is used to save|restore original
2240
2256
*/
2241
2257
 
2242
2258
static int 
2243
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2259
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2244
2260
                              ST_SCHEMA_TABLE *schema_table,
2245
2261
                              Open_tables_state *open_tables_state_backup)
2246
2262
{
2248
2264
  bool res;
2249
2265
  LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2266
  enum_sql_command save_sql_command= lex->sql_command;
2251
 
  TableList *show_table_list= (TableList*) tables->schema_select_lex->
 
2267
  TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2252
2268
    table_list.first;
2253
2269
  Table *table= tables->table;
2254
2270
  int error= 1;
2365
2381
    @retval       SKIP_OPEN_TABLE | OPEN_FRM_ONLY | OPEN_FULL_TABLE
2366
2382
*/
2367
2383
 
2368
 
static uint 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
{
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,
2415
2431
  Table *table= tables->table;
2416
2432
  TABLE_SHARE *share;
2417
2433
  Table tbl;
2418
 
  TableList table_list;
 
2434
  TABLE_LIST table_list;
2419
2435
  uint res= 0;
2420
2436
  int error;
2421
2437
  char key[MAX_DBKEY_LENGTH];
2422
2438
  uint key_length;
2423
2439
 
2424
 
  memset(&table_list, 0, sizeof(TableList));
 
2440
  memset(&table_list, 0, sizeof(TABLE_LIST));
2425
2441
  memset(&tbl, 0, sizeof(Table));
2426
2442
 
2427
2443
  table_list.table_name= table_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
2495
  Table *table= tables->table;
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;
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.
2774
2790
}
2775
2791
 
2776
2792
 
2777
 
static int get_schema_tables_record(THD *thd, TableList *tables,
 
2793
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
2778
2794
                                    Table *table, bool res,
2779
2795
                                    LEX_STRING *db_name,
2780
2796
                                    LEX_STRING *table_name)
3066
3082
}
3067
3083
 
3068
3084
 
3069
 
static int get_schema_column_record(THD *thd, TableList *tables,
 
3085
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
3070
3086
                                    Table *table, bool res,
3071
3087
                                    LEX_STRING *db_name,
3072
3088
                                    LEX_STRING *table_name)
3199
3215
 
3200
3216
 
3201
3217
 
3202
 
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)))
3203
3219
{
3204
3220
  CHARSET_INFO **cs;
3205
3221
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3230
3246
}
3231
3247
 
3232
3248
 
3233
 
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)))
3234
3250
{
3235
3251
  CHARSET_INFO **cs;
3236
3252
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3272
3288
}
3273
3289
 
3274
3290
 
3275
 
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)))
3276
3292
{
3277
3293
  CHARSET_INFO **cs;
3278
3294
  Table *table= tables->table;
3301
3317
}
3302
3318
 
3303
3319
 
3304
 
static int get_schema_stat_record(THD *thd, TableList *tables,
 
3320
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
3305
3321
                                  Table *table, bool res,
3306
3322
                                  LEX_STRING *db_name,
3307
3323
                                  LEX_STRING *table_name)
3413
3429
}
3414
3430
 
3415
3431
 
3416
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
 
3432
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
3417
3433
                                         Table *table, bool res,
3418
3434
                                         LEX_STRING *db_name,
3419
3435
                                         LEX_STRING *table_name)
3488
3504
 
3489
3505
 
3490
3506
static int get_schema_key_column_usage_record(THD *thd,
3491
 
                                              TableList *tables,
 
3507
                                              TABLE_LIST *tables,
3492
3508
                                              Table *table, bool res,
3493
3509
                                              LEX_STRING *db_name,
3494
3510
                                              LEX_STRING *table_name)
3576
3592
}
3577
3593
 
3578
3594
 
3579
 
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)))
3580
3596
{
3581
3597
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3582
3598
  Table *table= tables->table;
3583
3599
  const CHARSET_INFO * const cs= system_charset_info;
3584
 
  OPEN_TableList *open_list;
 
3600
  OPEN_TABLE_LIST *open_list;
3585
3601
  if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3586
3602
            && thd->is_fatal_error)
3587
3603
    return(1);
3600
3616
}
3601
3617
 
3602
3618
 
3603
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3619
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3604
3620
{
3605
3621
  int res= 0;
3606
3622
  LEX *lex= thd->lex;
3623
3639
}
3624
3640
 
3625
3641
 
3626
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3642
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3627
3643
{
3628
3644
  LEX *lex= thd->lex;
3629
3645
  const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3684
3700
*/
3685
3701
 
3686
3702
static int
3687
 
get_referential_constraints_record(THD *thd, TableList *tables,
 
3703
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3688
3704
                                   Table *table, bool res,
3689
3705
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3690
3706
{
3836
3852
  @retval  NULL           Can't create table
3837
3853
*/
3838
3854
 
3839
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3855
Table *create_schema_table(THD *thd, TABLE_LIST *table_list)
3840
3856
{
3841
3857
  int field_count= 0;
3842
3858
  Item *item;
3920
3936
  tmp_table_param->schema_table= 1;
3921
3937
  SELECT_LEX *select_lex= thd->lex->current_select;
3922
3938
  if (!(table= create_tmp_table(thd, tmp_table_param,
3923
 
                                field_list, (order_st*) 0, 0, 0, 
 
3939
                                field_list, (ORDER*) 0, 0, 0, 
3924
3940
                                (select_lex->options | thd->options |
3925
3941
                                 TMP_TABLE_ALL_COLUMNS),
3926
3942
                                HA_POS_ERROR, table_list->alias)))
4108
4124
    1   error
4109
4125
*/
4110
4126
 
4111
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4127
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list)
4112
4128
{
4113
4129
  Table *table;
4114
4130
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4238
4254
    if (!tab->table || !tab->table->pos_in_table_list)
4239
4255
      break;
4240
4256
 
4241
 
    TableList *table_list= tab->table->pos_in_table_list;
 
4257
    TABLE_LIST *table_list= tab->table->pos_in_table_list;
4242
4258
    if (table_list->schema_table)
4243
4259
    {
4244
4260
      bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
4585
4601
   create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4586
4602
  {"COLUMNS", columns_fields_info, create_schema_table, 
4587
4603
   get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4588
 
   OPTIMIZE_I_S_TABLE},
 
4604
   OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4589
4605
  {"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4590
4606
   fill_status, make_old_format, 0, -1, -1, 0, 0},
4591
4607
  {"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,