~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzlecheck.c

  • Committer: Patrick Galbraith
  • Date: 2008-07-24 16:57:40 UTC
  • mto: (202.2.4 rename-mysql-to-drizzle)
  • mto: This revision was merged to the branch mainline in revision 212.
  • Revision ID: patg@ishvara-20080724165740-x58yw6zs6d9o17lf
Most everything working with client rename
mysqlslap test still fails... can't connect to the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/* By Jani Tolonen, 2001-04-20, MySQL, MYSQL Development Team */
 
16
/* By Jani Tolonen, 2001-04-20, MySQL, DRIZZLE Development Team */
17
17
 
18
18
#define CHECK_VERSION "2.5.0"
19
19
 
20
 
#include "config.h"
21
 
#include <vector>
22
 
#include <string>
23
20
#include "client_priv.h"
24
 
#include <mystrings/m_ctype.h>
25
 
 
26
 
template class std::vector<std::string>;
27
 
 
28
 
using namespace std;
 
21
#include <m_ctype.h>
 
22
#include <drizzle_version.h>
 
23
#include <mysqld_error.h>
 
24
 
29
25
/* Exit codes */
30
26
 
31
27
#define EX_USAGE 1
43
39
static int my_end_arg;
44
40
static char * opt_mysql_unix_port = 0;
45
41
static char *opt_password = 0, *current_user = 0,
46
 
      *default_charset = (char *)DRIZZLE_DEFAULT_CHARSET_NAME,
 
42
      *default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME,
47
43
      *current_host = 0;
48
44
static int first_error = 0;
49
 
vector<string> tables4repair;
 
45
DYNAMIC_ARRAY tables4repair;
50
46
static uint opt_protocol=0;
51
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
47
static CHARSET_INFO *charset_info= &my_charset_latin1;
52
48
 
53
49
enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
54
50
 
128
124
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
129
125
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
130
126
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
131
 
   "order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
132
 
   "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
 
127
   "order of preference, my.cnf, $MYSQL_TCP_PORT, "
 
128
#if MYSQL_PORT_DEFAULT == 0
 
129
   "/etc/services, "
 
130
#endif
 
131
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
133
132
   (char**) &opt_mysql_port,
134
133
   (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
135
134
   0},
176
175
static int process_all_tables_in_db(char *database);
177
176
static int process_one_db(char *database);
178
177
static int use_db(char *database);
179
 
static int handle_request_for_tables(const char *tables, uint length);
 
178
static int handle_request_for_tables(char *tables, uint length);
180
179
static int dbConnect(char *host, char *user,char *passwd);
181
180
static void dbDisconnect(char *host);
182
181
static void DBerror(DRIZZLE *drizzle, const char *when);
183
182
static void safe_exit(int error);
184
183
static void print_result(void);
185
184
static uint fixed_name_length(const char *name);
186
 
static char *fix_table_name(char *dest, const char *src);
 
185
static char *fix_table_name(char *dest, char *src);
187
186
int what_to_do = 0;
188
187
 
 
188
#include <help_start.h>
 
189
 
189
190
static void print_version(void)
190
191
{
191
192
  printf("%s  Ver %s Distrib %s, for %s (%s)\n", my_progname, CHECK_VERSION,
192
 
   drizzle_get_client_info(), SYSTEM_TYPE, MACHINE_TYPE);
 
193
   MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
193
194
} /* print_version */
194
195
 
 
196
 
195
197
static void usage(void)
196
198
{
197
199
  print_version();
219
221
  my_print_variables(my_long_options);
220
222
} /* usage */
221
223
 
 
224
#include <help_end.h>
 
225
 
222
226
static bool
223
227
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
224
228
         char *argument)
258
262
    if (argument)
259
263
    {
260
264
      char *start = argument;
261
 
      free(opt_password);
 
265
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
262
266
      opt_password = my_strdup(argument, MYF(MY_FAE));
263
267
      while (*argument) *argument++= 'x';    /* Destroy argument */
264
268
      if (*start)
283
287
    break;
284
288
  case 'V': print_version(); exit(0);
285
289
  case OPT_DRIZZLE_PROTOCOL:
 
290
    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
 
291
                                    opt->name);
286
292
    break;
287
293
  }
288
294
  return 0;
340
346
    return 1;
341
347
  }
342
348
  if (tty_password)
343
 
    opt_password = get_tty_password(NULL);
 
349
    opt_password = get_tty_password(NullS);
344
350
  if (debug_info_flag)
345
351
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
346
352
  if (debug_check_flag)
413
419
    }
414
420
    *--end = 0;
415
421
    handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1);
416
 
    free(table_names_comma_sep);
 
422
    my_free(table_names_comma_sep, MYF(0));
417
423
  }
418
424
  else
419
425
    for (; tables > 0; tables--, table_names++)
438
444
}
439
445
 
440
446
 
441
 
static char *fix_table_name(char *dest, const char *src)
 
447
static char *fix_table_name(char *dest, char *src)
442
448
{
443
449
  *dest++= '`';
444
450
  for (; *src; src++)
506
512
    *--end = 0;
507
513
    if (tot_length)
508
514
      handle_request_for_tables(tables + 1, tot_length - 1);
509
 
    free(tables);
 
515
    my_free(tables, MYF(0));
510
516
  }
511
517
  else
512
518
  {
581
587
static int use_db(char *database)
582
588
{
583
589
  if (drizzle_get_server_version(sock) >= 50003 &&
584
 
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
 
590
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
585
591
    return 1;
586
592
  if (drizzle_select_db(sock, database))
587
593
  {
592
598
} /* use_db */
593
599
 
594
600
 
595
 
static int handle_request_for_tables(const char *tables, uint length)
 
601
static int handle_request_for_tables(char *tables, uint length)
596
602
{
597
603
  char *query, *end, options[100], message[100];
598
604
  uint query_length= 0;
603
609
  switch (what_to_do) {
604
610
  case DO_CHECK:
605
611
    op = "CHECK";
606
 
    if (opt_quick)              end = my_stpcpy(end, " QUICK");
607
 
    if (opt_fast)               end = my_stpcpy(end, " FAST");
608
 
    if (opt_medium_check)       end = my_stpcpy(end, " MEDIUM"); /* Default */
609
 
    if (opt_extended)           end = my_stpcpy(end, " EXTENDED");
610
 
    if (opt_check_only_changed) end = my_stpcpy(end, " CHANGED");
611
 
    if (opt_upgrade)            end = my_stpcpy(end, " FOR UPGRADE");
 
612
    if (opt_quick)              end = strmov(end, " QUICK");
 
613
    if (opt_fast)               end = strmov(end, " FAST");
 
614
    if (opt_medium_check)       end = strmov(end, " MEDIUM"); /* Default */
 
615
    if (opt_extended)           end = strmov(end, " EXTENDED");
 
616
    if (opt_check_only_changed) end = strmov(end, " CHANGED");
 
617
    if (opt_upgrade)            end = strmov(end, " FOR UPGRADE");
612
618
    break;
613
619
  case DO_REPAIR:
614
620
    op= (opt_write_binlog) ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG";
615
 
    if (opt_quick)              end = my_stpcpy(end, " QUICK");
616
 
    if (opt_extended)           end = my_stpcpy(end, " EXTENDED");
617
 
    if (opt_frm)                end = my_stpcpy(end, " USE_FRM");
 
621
    if (opt_quick)              end = strmov(end, " QUICK");
 
622
    if (opt_extended)           end = strmov(end, " EXTENDED");
 
623
    if (opt_frm)                end = strmov(end, " USE_FRM");
618
624
    break;
619
625
  case DO_ANALYZE:
620
626
    op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
637
643
  {
638
644
    char *ptr;
639
645
 
640
 
    ptr= my_stpcpy(my_stpcpy(query, op), " TABLE ");
 
646
    ptr= strmov(strmov(query, op), " TABLE ");
641
647
    ptr= fix_table_name(ptr, tables);
642
 
    ptr= strxmov(ptr, " ", options, NULL);
 
648
    ptr= strxmov(ptr, " ", options, NullS);
643
649
    query_length= (uint) (ptr - query);
644
650
  }
645
651
  if (drizzle_real_query(sock, query, query_length))
649
655
    return 1;
650
656
  }
651
657
  print_result();
652
 
  free(query);
 
658
  my_free(query, MYF(0));
653
659
  return 0;
654
660
}
655
661
 
678
684
        list
679
685
      */
680
686
      if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
681
 
          strcmp(row[3],"OK"))
682
 
        tables4repair.push_back(string(prev));
 
687
    strcmp(row[3],"OK"))
 
688
  insert_dynamic(&tables4repair, (uchar*) prev);
683
689
      found_error=0;
684
690
      if (opt_silent)
685
691
  continue;
694
700
    }
695
701
    else
696
702
      printf("%-9s: %s", row[2], row[3]);
697
 
    my_stpcpy(prev, row[0]);
 
703
    strmov(prev, row[0]);
698
704
    putchar('\n');
699
705
  }
700
706
  /* add the last table to be repaired to the list */
701
707
  if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
702
 
    tables4repair.push_back(string(prev));
 
708
    insert_dynamic(&tables4repair, (uchar*) prev);
703
709
  drizzle_free_result(res);
704
710
}
705
711
 
711
717
  {
712
718
    fprintf(stderr, "# Connecting to %s...\n", host ? host : "localhost");
713
719
  }
714
 
  drizzle_create(&drizzle_connection);
 
720
  drizzle_init(&drizzle_connection);
715
721
  if (opt_compress)
716
 
    drizzle_options(&drizzle_connection, DRIZZLE_OPT_COMPRESS, NULL);
 
722
    drizzle_options(&drizzle_connection, DRIZZLE_OPT_COMPRESS, NullS);
717
723
  if (opt_protocol)
718
724
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
719
725
  if (!(sock = drizzle_connect(&drizzle_connection, host, user, passwd,
770
776
  if (dbConnect(current_host, current_user, opt_password))
771
777
    exit(EX_MYSQLERR);
772
778
 
773
 
  if (opt_auto_repair)
 
779
  if (opt_auto_repair &&
 
780
      my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64))
774
781
  {
775
 
    tables4repair.reserve(64);
776
 
    if (tables4repair.capacity() == 0)
777
 
    {
778
 
      first_error = 1;
779
 
      goto end;
780
 
    }
 
782
    first_error = 1;
 
783
    goto end;
781
784
  }
782
785
 
783
 
 
784
786
  if (opt_alldbs)
785
787
    process_all_databases();
786
788
  /* Only one database and selected table(s) */
791
793
    process_databases(argv);
792
794
  if (opt_auto_repair)
793
795
  {
 
796
    uint i;
794
797
 
795
 
    if (!opt_silent && (tables4repair.size() > 0))
 
798
    if (!opt_silent && tables4repair.elements)
796
799
      puts("\nRepairing tables");
797
800
    what_to_do = DO_REPAIR;
798
 
    vector<string>::iterator i;
799
 
    for ( i= tables4repair.begin() ; i < tables4repair.end() ; i++)
 
801
    for (i = 0; i < tables4repair.elements ; i++)
800
802
    {
801
 
      const char *name= (*i).c_str();
 
803
      char *name= (char*) dynamic_array_ptr(&tables4repair, i);
802
804
      handle_request_for_tables(name, fixed_name_length(name));
803
805
    }
804
806
  }
805
807
 end:
806
808
  dbDisconnect(current_host);
807
 
  free(opt_password);
 
809
  if (opt_auto_repair)
 
810
    delete_dynamic(&tables4repair);
 
811
  my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
808
812
  my_end(my_end_arg);
809
813
  return(first_error!=0);
810
814
} /* main */