~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_show.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 03:40:03 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020034003-t2dcnl0ayr2ymm8k
THD -> Session rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
/* Match the values of enum ha_choice */
33
33
static const char *ha_choice_values[] = {"", "0", "1"};
34
34
 
35
 
static void store_key_options(THD *thd, String *packet, Table *table,
 
35
static void store_key_options(Session *thd, String *packet, Table *table,
36
36
                              KEY *key_info);
37
37
 
38
38
 
87
87
** List all table types supported
88
88
***************************************************************************/
89
89
 
90
 
static bool show_plugins(THD *thd, plugin_ref plugin,
 
90
static bool show_plugins(Session *thd, plugin_ref plugin,
91
91
                            void *arg)
92
92
{
93
93
  Table *table= (Table*) arg;
173
173
}
174
174
 
175
175
 
176
 
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
176
int fill_plugins(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
177
177
{
178
178
  Table *table= tables->table;
179
179
 
206
206
 
207
207
 
208
208
find_files_result
209
 
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
 
209
find_files(Session *thd, List<LEX_STRING> *files, const char *db,
210
210
           const char *path, const char *wild, bool dir)
211
211
{
212
212
  uint32_t i;
304
304
 
305
305
 
306
306
bool
307
 
mysqld_show_create(THD *thd, TableList *table_list)
 
307
mysqld_show_create(Session *thd, TableList *table_list)
308
308
{
309
309
  Protocol *protocol= thd->protocol;
310
310
  char buff[2048];
359
359
  return(false);
360
360
}
361
361
 
362
 
bool mysqld_show_create_db(THD *thd, char *dbname,
 
362
bool mysqld_show_create_db(Session *thd, char *dbname,
363
363
                           HA_CREATE_INFO *create_info)
364
364
{
365
365
  char buff[2048];
402
402
****************************************************************************/
403
403
 
404
404
void
405
 
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
 
405
mysqld_list_fields(Session *thd, TableList *table_list, const char *wild)
406
406
{
407
407
  Table *table;
408
408
 
478
478
*/
479
479
 
480
480
void
481
 
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
 
481
append_identifier(Session *thd, String *packet, const char *name, uint32_t length)
482
482
{
483
483
  const char *name_end;
484
484
  char quote_char;
543
543
    #     Quote character
544
544
*/
545
545
 
546
 
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
 
546
int get_quote_char_for_identifier(Session *thd, const char *name, uint32_t length)
547
547
{
548
548
  if (length &&
549
549
      !is_keyword(name,length) &&
556
556
 
557
557
/* Append directory name (if exists) to CREATE INFO */
558
558
 
559
 
static void append_directory(THD *thd __attribute__((unused)),
 
559
static void append_directory(Session *thd __attribute__((unused)),
560
560
                             String *packet, const char *dir_type,
561
561
                             const char *filename)
562
562
{
574
574
 
575
575
#define LIST_PROCESS_HOST_LEN 64
576
576
 
577
 
static bool get_field_default_value(THD *thd __attribute__((unused)),
 
577
static bool get_field_default_value(Session *thd __attribute__((unused)),
578
578
                                    Field *timestamp_field,
579
579
                                    Field *field, String *def_value,
580
580
                                    bool quoted)
651
651
    0       OK
652
652
 */
653
653
 
654
 
int store_create_info(THD *thd, TableList *table_list, String *packet,
 
654
int store_create_info(Session *thd, TableList *table_list, String *packet,
655
655
                      HA_CREATE_INFO *create_info_arg)
656
656
{
657
657
  List<Item> field_list;
1001
1001
  @returns true if errors are detected, false otherwise.
1002
1002
*/
1003
1003
 
1004
 
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
 
1004
bool store_db_create_info(Session *thd, const char *dbname, String *buffer,
1005
1005
                          HA_CREATE_INFO *create_info)
1006
1006
{
1007
1007
  HA_CREATE_INFO create;
1047
1047
  return(false);
1048
1048
}
1049
1049
 
1050
 
static void store_key_options(THD *thd __attribute__((unused)),
 
1050
static void store_key_options(Session *thd __attribute__((unused)),
1051
1051
                              String *packet, Table *table,
1052
1052
                              KEY *key_info)
1053
1053
{
1104
1104
template class I_List<thread_info>;
1105
1105
#endif
1106
1106
 
1107
 
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
 
1107
void mysqld_list_processes(Session *thd,const char *user, bool verbose)
1108
1108
{
1109
1109
  Item *field;
1110
1110
  List<Item> field_list;
1131
1131
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1132
1132
  if (!thd->killed)
1133
1133
  {
1134
 
    I_List_iterator<THD> it(threads);
1135
 
    THD *tmp;
 
1134
    I_List_iterator<Session> it(threads);
 
1135
    Session *tmp;
1136
1136
    while ((tmp=it++))
1137
1137
    {
1138
1138
      Security_context *tmp_sctx= tmp->security_ctx;
1151
1151
        thd_info->command=(int) tmp->command;
1152
1152
        if ((mysys_var= tmp->mysys_var))
1153
1153
          pthread_mutex_lock(&mysys_var->mutex);
1154
 
        thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
 
1154
        thd_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1155
1155
        thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1156
1156
                                       (tmp->net.reading_or_writing == 2 ?
1157
1157
                                        "Writing to net" :
1208
1208
  return;
1209
1209
}
1210
1210
 
1211
 
int fill_schema_processlist(THD* thd, TableList* tables,
 
1211
int fill_schema_processlist(Session* thd, TableList* tables,
1212
1212
                            COND* cond __attribute__((unused)))
1213
1213
{
1214
1214
  Table *table= tables->table;
1222
1222
 
1223
1223
  if (!thd->killed)
1224
1224
  {
1225
 
    I_List_iterator<THD> it(threads);
1226
 
    THD* tmp;
 
1225
    I_List_iterator<Session> it(threads);
 
1226
    Session* tmp;
1227
1227
 
1228
1228
    while ((tmp= it++))
1229
1229
    {
1253
1253
      if ((mysys_var= tmp->mysys_var))
1254
1254
        pthread_mutex_lock(&mysys_var->mutex);
1255
1255
      /* COMMAND */
1256
 
      if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
 
1256
      if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
1257
1257
        table->field[4]->store(val, strlen(val), cs);
1258
1258
      else
1259
1259
        table->field[4]->store(command_name[tmp->command].str,
1480
1480
    *buf= my_toupper(system_charset_info, *buf);
1481
1481
}
1482
1482
 
1483
 
static bool show_status_array(THD *thd, const char *wild,
 
1483
static bool show_status_array(Session *thd, const char *wild,
1484
1484
                              SHOW_VAR *variables,
1485
1485
                              enum enum_var_type value_type,
1486
1486
                              struct system_status_var *status_var,
1641
1641
  /* Ensure that thread id not killed during loop */
1642
1642
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1643
1643
 
1644
 
  I_List_iterator<THD> it(threads);
1645
 
  THD *tmp;
 
1644
  I_List_iterator<Session> it(threads);
 
1645
  Session *tmp;
1646
1646
  
1647
1647
  /* Get global values as base */
1648
1648
  *to= global_status_var;
1680
1680
    1                     error
1681
1681
*/
1682
1682
 
1683
 
bool schema_table_store_record(THD *thd, Table *table)
 
1683
bool schema_table_store_record(Session *thd, Table *table)
1684
1684
{
1685
1685
  int error;
1686
1686
  if ((error= table->file->ha_write_row(table->record[0])))
1695
1695
}
1696
1696
 
1697
1697
 
1698
 
int make_table_list(THD *thd, SELECT_LEX *sel,
 
1698
int make_table_list(Session *thd, SELECT_LEX *sel,
1699
1699
                    LEX_STRING *db_name, LEX_STRING *table_name)
1700
1700
{
1701
1701
  Table_ident *table_ident;
1725
1725
    1             error, there can be no matching records for the condition
1726
1726
*/
1727
1727
 
1728
 
bool get_lookup_value(THD *thd, Item_func *item_func,
 
1728
bool get_lookup_value(Session *thd, Item_func *item_func,
1729
1729
                      TableList *table, 
1730
1730
                      LOOKUP_FIELD_VALUES *lookup_field_vals)
1731
1731
{
1808
1808
    1             error, there can be no matching records for the condition
1809
1809
*/
1810
1810
 
1811
 
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
 
1811
bool calc_lookup_values_from_cond(Session *thd, COND *cond, TableList *table,
1812
1812
                                  LOOKUP_FIELD_VALUES *lookup_field_vals)
1813
1813
{
1814
1814
  if (!cond)
1957
1957
    1             error, there can be no matching records for the condition
1958
1958
*/
1959
1959
 
1960
 
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
 
1960
bool get_lookup_field_values(Session *thd, COND *cond, TableList *tables,
1961
1961
                             LOOKUP_FIELD_VALUES *lookup_field_values)
1962
1962
{
1963
1963
  LEX *lex= thd->lex;
2017
2017
    non-zero              error
2018
2018
*/
2019
2019
 
2020
 
int make_db_list(THD *thd, List<LEX_STRING> *files,
 
2020
int make_db_list(Session *thd, List<LEX_STRING> *files,
2021
2021
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
2022
2022
                 bool *with_i_schema)
2023
2023
{
2085
2085
};
2086
2086
 
2087
2087
 
2088
 
static bool add_schema_table(THD *thd, plugin_ref plugin,
 
2088
static bool add_schema_table(Session *thd, plugin_ref plugin,
2089
2089
                                void* p_data)
2090
2090
{
2091
2091
  LEX_STRING *file_name= 0;
2118
2118
}
2119
2119
 
2120
2120
 
2121
 
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
 
2121
int schema_tables_add(Session *thd, List<LEX_STRING> *files, const char *wild)
2122
2122
{
2123
2123
  LEX_STRING *file_name= 0;
2124
2124
  ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2178
2178
*/
2179
2179
 
2180
2180
static int
2181
 
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
 
2181
make_table_name_list(Session *thd, List<LEX_STRING> *table_names, LEX *lex,
2182
2182
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
2183
2183
                     bool with_i_schema, LEX_STRING *db_name)
2184
2184
{
2251
2251
*/
2252
2252
 
2253
2253
static int 
2254
 
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
 
2254
fill_schema_show_cols_or_idxs(Session *thd, TableList *tables,
2255
2255
                              ST_SCHEMA_TABLE *schema_table,
2256
2256
                              Open_tables_state *open_tables_state_backup)
2257
2257
{
2322
2322
    @retval       1           error
2323
2323
*/
2324
2324
 
2325
 
static int fill_schema_table_names(THD *thd, Table *table,
 
2325
static int fill_schema_table_names(Session *thd, Table *table,
2326
2326
                                   LEX_STRING *db_name, LEX_STRING *table_name,
2327
2327
                                   bool with_i_schema)
2328
2328
{
2417
2417
                              open_tables function for this table
2418
2418
*/
2419
2419
 
2420
 
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
 
2420
static int fill_schema_table_from_frm(Session *thd,TableList *tables,
2421
2421
                                      ST_SCHEMA_TABLE *schema_table,
2422
2422
                                      LEX_STRING *db_name,
2423
2423
                                      LEX_STRING *table_name,
2484
2484
    @retval       1                        error
2485
2485
*/
2486
2486
 
2487
 
int get_all_tables(THD *thd, TableList *tables, COND *cond)
 
2487
int get_all_tables(Session *thd, TableList *tables, COND *cond)
2488
2488
{
2489
2489
  LEX *lex= thd->lex;
2490
2490
  Table *table= tables->table;
2656
2656
              XXX:  show_table_list has a flag i_is_requested,
2657
2657
              and when it's set, open_normal_and_derived_tables()
2658
2658
              can return an error without setting an error message
2659
 
              in THD, which is a hack. This is why we have to
 
2659
              in Session, which is a hack. This is why we have to
2660
2660
              check for res, then for thd->is_error() only then
2661
2661
              for thd->main_da.sql_errno().
2662
2662
            */
2714
2714
}
2715
2715
 
2716
2716
 
2717
 
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
 
2717
bool store_schema_shemata(Session* thd, Table *table, LEX_STRING *db_name,
2718
2718
                          const CHARSET_INFO * const cs)
2719
2719
{
2720
2720
  restore_record(table, s->default_values);
2725
2725
}
2726
2726
 
2727
2727
 
2728
 
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
 
2728
int fill_schema_schemata(Session *thd, TableList *tables, COND *cond)
2729
2729
{
2730
2730
  /*
2731
2731
    TODO: fill_schema_shemata() is called when new client is connected.
2785
2785
}
2786
2786
 
2787
2787
 
2788
 
static int get_schema_tables_record(THD *thd, TableList *tables,
 
2788
static int get_schema_tables_record(Session *thd, TableList *tables,
2789
2789
                                    Table *table, bool res,
2790
2790
                                    LEX_STRING *db_name,
2791
2791
                                    LEX_STRING *table_name)
3075
3075
}
3076
3076
 
3077
3077
 
3078
 
static int get_schema_column_record(THD *thd, TableList *tables,
 
3078
static int get_schema_column_record(Session *thd, TableList *tables,
3079
3079
                                    Table *table, bool res,
3080
3080
                                    LEX_STRING *db_name,
3081
3081
                                    LEX_STRING *table_name)
3209
3209
 
3210
3210
 
3211
3211
 
3212
 
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3212
int fill_schema_charsets(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3213
3213
{
3214
3214
  CHARSET_INFO **cs;
3215
3215
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3240
3240
}
3241
3241
 
3242
3242
 
3243
 
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3243
int fill_schema_collation(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3244
3244
{
3245
3245
  CHARSET_INFO **cs;
3246
3246
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3282
3282
}
3283
3283
 
3284
3284
 
3285
 
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3285
int fill_schema_coll_charset_app(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3286
3286
{
3287
3287
  CHARSET_INFO **cs;
3288
3288
  Table *table= tables->table;
3311
3311
}
3312
3312
 
3313
3313
 
3314
 
static int get_schema_stat_record(THD *thd, TableList *tables,
 
3314
static int get_schema_stat_record(Session *thd, TableList *tables,
3315
3315
                                  Table *table, bool res,
3316
3316
                                  LEX_STRING *db_name,
3317
3317
                                  LEX_STRING *table_name)
3408
3408
}
3409
3409
 
3410
3410
 
3411
 
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
 
3411
bool store_constraints(Session *thd, Table *table, LEX_STRING *db_name,
3412
3412
                       LEX_STRING *table_name, const char *key_name,
3413
3413
                       uint32_t key_len, const char *con_type, uint32_t con_len)
3414
3414
{
3423
3423
}
3424
3424
 
3425
3425
 
3426
 
static int get_schema_constraints_record(THD *thd, TableList *tables,
 
3426
static int get_schema_constraints_record(Session *thd, TableList *tables,
3427
3427
                                         Table *table, bool res,
3428
3428
                                         LEX_STRING *db_name,
3429
3429
                                         LEX_STRING *table_name)
3497
3497
}
3498
3498
 
3499
3499
 
3500
 
static int get_schema_key_column_usage_record(THD *thd,
 
3500
static int get_schema_key_column_usage_record(Session *thd,
3501
3501
                                              TableList *tables,
3502
3502
                                              Table *table, bool res,
3503
3503
                                              LEX_STRING *db_name,
3586
3586
}
3587
3587
 
3588
3588
 
3589
 
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3589
int fill_open_tables(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3590
3590
{
3591
3591
  const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3592
3592
  Table *table= tables->table;
3610
3610
}
3611
3611
 
3612
3612
 
3613
 
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3613
int fill_variables(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3614
3614
{
3615
3615
  int res= 0;
3616
3616
  LEX *lex= thd->lex;
3633
3633
}
3634
3634
 
3635
3635
 
3636
 
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
 
3636
int fill_status(Session *thd, TableList *tables, COND *cond __attribute__((unused)))
3637
3637
{
3638
3638
  LEX *lex= thd->lex;
3639
3639
  const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3694
3694
*/
3695
3695
 
3696
3696
static int
3697
 
get_referential_constraints_record(THD *thd, TableList *tables,
 
3697
get_referential_constraints_record(Session *thd, TableList *tables,
3698
3698
                                   Table *table, bool res,
3699
3699
                                   LEX_STRING *db_name, LEX_STRING *table_name)
3700
3700
{
3771
3771
    0   table not found
3772
3772
    1   found the schema table
3773
3773
*/
3774
 
static bool find_schema_table_in_plugin(THD *thd __attribute__((unused)),
 
3774
static bool find_schema_table_in_plugin(Session *thd __attribute__((unused)),
3775
3775
                                           plugin_ref plugin,
3776
3776
                                           void* p_table)
3777
3777
{
3803
3803
    #   pointer to 'schema_tables' element
3804
3804
*/
3805
3805
 
3806
 
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
 
3806
ST_SCHEMA_TABLE *find_schema_table(Session *thd, const char* table_name)
3807
3807
{
3808
3808
  schema_table_ref schema_table_a;
3809
3809
  ST_SCHEMA_TABLE *schema_table= schema_tables;
3846
3846
  @retval  NULL           Can't create table
3847
3847
*/
3848
3848
 
3849
 
Table *create_schema_table(THD *thd, TableList *table_list)
 
3849
Table *create_schema_table(Session *thd, TableList *table_list)
3850
3850
{
3851
3851
  int field_count= 0;
3852
3852
  Item *item;
3959
3959
   0    success
3960
3960
*/
3961
3961
 
3962
 
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3962
int make_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
3963
3963
{
3964
3964
  ST_FIELD_INFO *field_info= schema_table->fields_info;
3965
3965
  Name_resolution_context *context= &thd->lex->select_lex.context;
3983
3983
}
3984
3984
 
3985
3985
 
3986
 
int make_schemata_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
3986
int make_schemata_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
3987
3987
{
3988
3988
  char tmp[128];
3989
3989
  LEX *lex= thd->lex;
4012
4012
}
4013
4013
 
4014
4014
 
4015
 
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4015
int make_table_names_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
4016
4016
{
4017
4017
  char tmp[128];
4018
4018
  String buffer(tmp,sizeof(tmp), thd->charset());
4048
4048
}
4049
4049
 
4050
4050
 
4051
 
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4051
int make_columns_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
4052
4052
{
4053
4053
  int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4054
4054
  int *field_num= fields_arr;
4077
4077
}
4078
4078
 
4079
4079
 
4080
 
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
 
4080
int make_character_sets_old_format(Session *thd, ST_SCHEMA_TABLE *schema_table)
4081
4081
{
4082
4082
  int fields_arr[]= {0, 2, 1, 3, -1};
4083
4083
  int *field_num= fields_arr;
4116
4116
    1   error
4117
4117
*/
4118
4118
 
4119
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
 
4119
int mysql_schema_table(Session *thd, LEX *lex, TableList *table_list)
4120
4120
{
4121
4121
  Table *table;
4122
4122
  if (!(table= table_list->schema_table->create_table(thd, table_list)))
4195
4195
    1   error
4196
4196
*/
4197
4197
 
4198
 
int make_schema_select(THD *thd, SELECT_LEX *sel,
 
4198
int make_schema_select(Session *thd, SELECT_LEX *sel,
4199
4199
                       enum enum_schema_tables schema_table_idx)
4200
4200
{
4201
4201
  ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4235
4235
                              enum enum_schema_table_state executed_place)
4236
4236
{
4237
4237
  JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4238
 
  THD *thd= join->thd;
 
4238
  Session *thd= join->thd;
4239
4239
  LEX *lex= thd->lex;
4240
4240
  bool result= 0;
4241
4241