~mdcallag/+junk/5.1-map

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

  • Committer: sasha at sashanet
  • Date: 2001-04-12 01:09:00 UTC
  • mfrom: (669.1.1)
  • Revision ID: sp1r-sasha@mysql.sashanet.com-20010412010900-14282
Ugly merge of 3.23 changes into 4.0 - fix up needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
        (grant_option && !check_grant_db(thd, file_name)))
82
82
      {
83
83
      thd->packet.length(0);
84
 
      net_store_data(&thd->packet,file_name);
 
84
      net_store_data(&thd->packet, thd->convert_set, file_name);
85
85
      if (my_net_write(&thd->net, (char*) thd->packet.ptr(),
86
86
                       thd->packet.length()))
87
87
        DBUG_RETURN(-1);
95
95
** List all open tables in a database
96
96
***************************************************************************/
97
97
 
98
 
int mysqld_show_open_tables(THD *thd,const char *db,const char *wild)
 
98
int mysqld_show_open_tables(THD *thd,const char *wild)
99
99
{
100
 
  Item_string *field=new Item_string("",0);
101
100
  List<Item> field_list;
102
 
  char *end,*table_name;
103
 
  List<char> tables;
 
101
  OPEN_TABLE_LIST *open_list;
 
102
  CONVERT *convert=thd->convert_set;
104
103
  DBUG_ENTER("mysqld_show_open_tables");
105
104
 
106
 
  field->name=(char*) thd->alloc(20+(uint) strlen(db)+(wild ? (uint) strlen(wild)+4:0));
107
 
  end=strxmov(field->name,"Open_tables_in_",db,NullS);
108
 
  if (wild && wild[0])
109
 
    strxmov(end," (",wild,")",NullS);
110
 
  field->max_length=NAME_LEN;
111
 
  field_list.push_back(field);
112
 
  field_list.push_back(new Item_empty_string("Comment",80));
 
105
  field_list.push_back(new Item_empty_string("Database",NAME_LEN));
 
106
  field_list.push_back(new Item_empty_string("Table",NAME_LEN));
 
107
  field_list.push_back(new Item_int("In_use",0, 4));
 
108
  field_list.push_back(new Item_int("Name_locked",0, 4));
113
109
 
114
110
  if (send_fields(thd,field_list,1))
115
111
    DBUG_RETURN(1);
116
112
 
117
 
  if (list_open_tables(thd,&tables,db,wild))
 
113
  if (!(open_list=list_open_tables(thd,wild)))
118
114
    DBUG_RETURN(-1);
119
115
 
120
 
  List_iterator<char> it(tables);
121
 
  while ((table_name=it++))
 
116
  for ( ; open_list ; open_list=open_list->next)
122
117
  {
123
118
    thd->packet.length(0);
124
 
    net_store_data(&thd->packet,table_name);
125
 
    net_store_data(&thd->packet,query_table_status(thd,db,table_name));
 
119
    net_store_data(&thd->packet,convert, open_list->db);
 
120
    net_store_data(&thd->packet,convert, open_list->table);
 
121
    net_store_data(&thd->packet,open_list->in_use);
 
122
    net_store_data(&thd->packet,open_list->locked);
126
123
    if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
127
124
      DBUG_RETURN(-1);
128
125
  }
129
 
 
130
 
 
131
126
  send_eof(&thd->net);
132
127
  DBUG_RETURN(0);
133
128
}
162
157
  while ((file_name=it++))
163
158
  {
164
159
    thd->packet.length(0);
165
 
    net_store_data(&thd->packet,file_name);
 
160
    net_store_data(&thd->packet, thd->convert_set, file_name);
166
161
    if (my_net_write(&thd->net,(char*) thd->packet.ptr(),thd->packet.length()))
167
162
      DBUG_RETURN(-1);
168
163
  }
248
243
  char *file_name;
249
244
  TABLE *table;
250
245
  String *packet= &thd->packet;
 
246
  CONVERT *convert=thd->convert_set;
251
247
  DBUG_ENTER("mysqld_extend_show_tables");
252
248
 
253
249
  (void) sprintf(path,"%s/%s",mysql_data_home,db);
293
289
    TABLE_LIST table_list;
294
290
    bzero((char*) &table_list,sizeof(table_list));
295
291
    packet->length(0);
296
 
    net_store_data(packet,file_name);
 
292
    net_store_data(packet,convert, file_name);
297
293
    table_list.db=(char*) db;
298
294
    table_list.real_name=table_list.name=file_name;
299
295
    if (!(table = open_ltable(thd, &table_list, TL_READ)))
300
296
    {
301
297
      for (uint i=0 ; i < field_list.elements ; i++)
302
298
        net_store_null(packet);
303
 
      net_store_data(packet,thd->net.last_error);
 
299
      net_store_data(packet,convert, thd->net.last_error);
304
300
      thd->net.last_error[0]=0;
305
301
    }
306
302
    else
308
304
      struct tm tm_tmp;
309
305
      handler *file=table->file;
310
306
      file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_NO_LOCK);
311
 
      net_store_data(packet, file->table_type());
312
 
      net_store_data(packet,
 
307
      net_store_data(packet, convert, file->table_type());
 
308
      net_store_data(packet, convert,
313
309
                     (table->db_options_in_use & HA_OPTION_PACK_RECORD) ?
314
310
                     "Dynamic" :
315
311
                     (table->db_options_in_use & HA_OPTION_COMPRESS_RECORD)
390
386
                  my_raid_type(file->raid_type), file->raid_chunks, file->raid_chunksize/RAID_BLOCK_SIZE);
391
387
          ptr=strmov(ptr,buff);
392
388
        }
393
 
        net_store_data(packet, option_buff+1,
 
389
        net_store_data(packet, convert, option_buff+1,
394
390
                       (ptr == option_buff ? 0 : (uint) (ptr-option_buff)-1));
395
391
      }
396
392
      {
422
418
  TABLE *table;
423
419
  handler *file;
424
420
  char tmp[MAX_FIELD_WIDTH];
 
421
  CONVERT *convert=thd->convert_set;
425
422
  DBUG_ENTER("mysqld_show_fields");
426
423
  DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
427
424
                      table_list->real_name));
476
473
        bool null_default_value=0;
477
474
 
478
475
        packet->length(0);
479
 
        net_store_data(packet,field->field_name);
 
476
        net_store_data(packet,convert,field->field_name);
480
477
        field->sql_type(type);
481
 
        net_store_data(packet,type.ptr(),type.length());
 
478
        net_store_data(packet,convert,type.ptr(),type.length());
482
479
 
483
480
        pos=(byte*) ((flags & NOT_NULL_FLAG) &&
484
481
                     field->type() != FIELD_TYPE_TIMESTAMP ?
485
482
                     "" : "YES");
486
 
        net_store_data(packet,(const char*) pos);
 
483
        net_store_data(packet,convert,(const char*) pos);
487
484
        pos=(byte*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
488
485
                     (field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
489
486
                     (field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
490
 
        net_store_data(packet,(char*) pos);
 
487
        net_store_data(packet,convert,(char*) pos);
491
488
 
492
489
        if (field->type() == FIELD_TYPE_TIMESTAMP ||
493
490
            field->unireg_check == Field::NEXT_NUMBER)
496
493
        {                                               // Not null by default
497
494
          type.set(tmp,sizeof(tmp));
498
495
          field->val_str(&type,&type);
499
 
          net_store_data(packet,type.ptr(),type.length());
 
496
          net_store_data(packet,convert,type.ptr(),type.length());
500
497
        }
501
498
        else if (field->maybe_null() || null_default_value)
502
499
          net_store_null(packet);                       // Null as default
503
500
        else
504
 
          net_store_data(packet,tmp,0);
 
501
          net_store_data(packet,convert,tmp,0);
505
502
 
506
503
        char *end=tmp;
507
504
        if (field->unireg_check == Field::NEXT_NUMBER)
508
505
          end=strmov(tmp,"auto_increment");
509
 
        net_store_data(packet,tmp,(uint) (end-tmp));
 
506
        net_store_data(packet,convert,tmp,(uint) (end-tmp));
510
507
 
511
508
        if (verbose)
512
509
        {
521
518
              end=strmov(end,grant_types.type_names[bitnr]);
522
519
            }
523
520
          }
524
 
          net_store_data(packet,tmp+1,end == tmp ? 0 : (uint) (end-tmp-1));
 
521
          net_store_data(packet,convert, tmp+1,end == tmp ? 0 : (uint) (end-tmp-1));
525
522
        }
526
523
        if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
527
524
          DBUG_RETURN(1);
536
533
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
537
534
{
538
535
  TABLE *table;
 
536
  CONVERT *convert=thd->convert_set;
539
537
  DBUG_ENTER("mysqld_show_create");
540
538
  DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
541
539
                      table_list->real_name));
557
555
  String *packet = &thd->packet;
558
556
  {
559
557
    packet->length(0);
560
 
    net_store_data(packet, table->table_name);
 
558
    net_store_data(packet,convert, table->table_name);
561
559
    // a hack - we need to reserve some space for the length before
562
560
    // we know what it is - let's assume that the length of create table
563
561
    // statement will fit into 3 bytes ( 16 MB max :-) )
614
612
{
615
613
  TABLE *table;
616
614
  char buff[256];
 
615
  CONVERT *convert=thd->convert_set;
617
616
  DBUG_ENTER("mysqld_show_keys");
618
617
  DBUG_PRINT("enter",("db: %s  table: %s",table_list->db,
619
618
                      table_list->real_name));
655
654
    for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
656
655
    {
657
656
      packet->length(0);
658
 
      net_store_data(packet,table->table_name);
659
 
      net_store_data(packet,((key_info->flags & HA_NOSAME) ? "0" :"1"), 1);
660
 
      net_store_data(packet,key_info->name);
 
657
      net_store_data(packet,convert,table->table_name);
 
658
      net_store_data(packet,convert,((key_info->flags & HA_NOSAME) ? "0" :"1"), 1);
 
659
      net_store_data(packet,convert,key_info->name);
661
660
      end=int10_to_str((long) (j+1),(char*) buff,10);
662
 
      net_store_data(packet,buff,(uint) (end-buff));
663
 
      net_store_data(packet,key_part->field ? key_part->field->field_name :
 
661
      net_store_data(packet,convert,buff,(uint) (end-buff));
 
662
      net_store_data(packet,convert,
 
663
                     key_part->field ? key_part->field->field_name :
664
664
                     "?unknown field?");
665
665
      if (table->file->option_flag() & HA_READ_ORDER)
666
 
        net_store_data(packet,((key_part->key_part_flag & HA_REVERSE_SORT)
667
 
                               ? "D" : "A"), 1);
 
666
        net_store_data(packet,convert,
 
667
                       ((key_part->key_part_flag & HA_REVERSE_SORT) ?
 
668
                        "D" : "A"), 1);
668
669
      else
669
670
        net_store_null(packet); /* purecov: inspected */
670
671
      KEY *key=table->key_info+i;
672
673
      {
673
674
        ulong records=(table->file->records / key->rec_per_key[j]);
674
675
        end=int10_to_str((long) records, buff, 10);
675
 
        net_store_data(packet,buff,(uint) (end-buff));
 
676
        net_store_data(packet,convert,buff,(uint) (end-buff));
676
677
      }
677
678
      else
678
679
        net_store_null(packet);
681
682
          table->field[key_part->fieldnr-1]->key_length())
682
683
      {
683
684
        end=int10_to_str((long) key_part->length, buff,10); /* purecov: inspected */
684
 
        net_store_data(packet,buff,(uint) (end-buff)); /* purecov: inspected */
 
685
        net_store_data(packet,convert,buff,(uint) (end-buff)); /* purecov: inspected */
685
686
      }
686
687
      else
687
688
        net_store_null(packet);
688
689
      net_store_null(packet);                   // No pack_information yet
689
 
      net_store_data(packet,key_info->flags & HA_FULLTEXT ? "FULLTEXT":"");
 
690
      net_store_data(packet,convert,
 
691
                     key_info->flags & HA_FULLTEXT ? "FULLTEXT":"");
690
692
      if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
691
693
        DBUG_RETURN(1); /* purecov: inspected */
692
694
    }
731
733
int
732
734
mysqld_dump_create_info(THD *thd, TABLE *table, int fd)
733
735
{
 
736
  CONVERT *convert=thd->convert_set;
734
737
  DBUG_ENTER("mysqld_dump_create_info");
735
738
  DBUG_PRINT("enter",("table: %s",table->real_name));
 
739
 
736
740
  String* packet = &thd->packet;
737
741
  packet->length(0);
738
 
 
739
 
  if(store_create_info(thd,table,packet))
 
742
  if (store_create_info(thd,table,packet))
740
743
    DBUG_RETURN(-1);
741
744
 
742
 
  if(fd < 0)
 
745
  if (convert)
 
746
    convert->convert((char*) packet->ptr(), packet->length());
 
747
  if (fd < 0)
743
748
  {
744
749
    if(my_net_write(&thd->net, (char*)packet->ptr(), packet->length()))
745
750
      DBUG_RETURN(-1);
950
955
  List<Item> field_list;
951
956
  I_List<thread_info> thread_infos;
952
957
  ulong max_query_length= verbose ? max_allowed_packet : PROCESS_LIST_WIDTH;
 
958
  CONVERT *convert=thd->convert_set;
953
959
  DBUG_ENTER("mysqld_list_processes");
954
960
 
955
961
  field_list.push_back(new Item_int("Id",0,7));
1033
1039
    char buff[20],*end;
1034
1040
    packet->length(0);
1035
1041
    end=int10_to_str((long) thd_info->thread_id, buff,10);
1036
 
    net_store_data(packet,buff,(uint) (end-buff));
1037
 
    net_store_data(packet,thd_info->user);
1038
 
    net_store_data(packet,thd_info->host);
 
1042
    net_store_data(packet,convert,buff,(uint) (end-buff));
 
1043
    net_store_data(packet,convert,thd_info->user);
 
1044
    net_store_data(packet,convert,thd_info->host);
1039
1045
    if (thd_info->db)
1040
 
      net_store_data(packet,thd_info->db);
 
1046
      net_store_data(packet,convert,thd_info->db);
1041
1047
    else
1042
1048
      net_store_null(packet);
1043
1049
    if (thd_info->proc_info)
1044
 
      net_store_data(packet,thd_info->proc_info);
 
1050
      net_store_data(packet,convert,thd_info->proc_info);
1045
1051
    else
1046
 
      net_store_data(packet,command_name[thd_info->command]);
 
1052
      net_store_data(packet,convert,command_name[thd_info->command]);
1047
1053
    if (thd_info->start_time)
1048
 
      net_store_data(packet,(uint32)
1049
 
                     (time((time_t*) 0) - thd_info->start_time));
 
1054
      net_store_data(packet,
 
1055
                     (uint32) (time((time_t*) 0) - thd_info->start_time));
1050
1056
    else
1051
1057
      net_store_null(packet);
1052
1058
    if (thd_info->state_info)
1053
 
      net_store_data(packet,thd_info->state_info);
 
1059
      net_store_data(packet,convert,thd_info->state_info);
1054
1060
    else
1055
1061
      net_store_null(packet);
1056
1062
    if (thd_info->query)
1057
 
      net_store_data(packet,thd_info->query);
 
1063
      net_store_data(packet,convert,thd_info->query);
1058
1064
    else
1059
1065
      net_store_null(packet);
1060
1066
    if (my_net_write(&thd->net,(char*) packet->ptr(),packet->length()))
1076
1082
  char buff[8192];
1077
1083
  String packet2(buff,sizeof(buff));
1078
1084
  List<Item> field_list;
 
1085
  CONVERT *convert=thd->convert_set;
1079
1086
  DBUG_ENTER("mysqld_show");
1080
1087
  field_list.push_back(new Item_empty_string("Variable_name",30));
1081
1088
  field_list.push_back(new Item_empty_string("Value",256));
1089
1096
    if (!(wild && wild[0] && wild_compare(variables[i].name,wild)))
1090
1097
    {
1091
1098
      packet2.length(0);
1092
 
      net_store_data(&packet2,variables[i].name);
 
1099
      net_store_data(&packet2,convert,variables[i].name);
1093
1100
      switch (variables[i].type){
1094
1101
      case SHOW_LONG:
1095
1102
      case SHOW_LONG_CONST:
1116
1123
        break;
1117
1124
      }
1118
1125
      case SHOW_CHAR:
1119
 
        net_store_data(&packet2,variables[i].value);
 
1126
        net_store_data(&packet2,convert, variables[i].value);
1120
1127
        break;
1121
1128
      case SHOW_STARTTIME:
1122
1129
        net_store_data(&packet2,(uint32) (thd->query_start() - start_time));
1130
1137
      case SHOW_CHAR_PTR:
1131
1138
        {
1132
1139
          char *value= *(char**) variables[i].value;
1133
 
          net_store_data(&packet2,value ? value : "");
 
1140
          net_store_data(&packet2,convert, value ? value : "");
1134
1141
          break;
1135
1142
        }
1136
1143
      }