~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:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/* Copyright (C) 2008 Drizzle development team
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
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 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
 
27
27
#define EX_USAGE 1
28
28
#define EX_MYSQLERR 2
29
29
 
30
 
static MYSQL mysql_connection, *sock = 0;
 
30
static DRIZZLE drizzle_connection, *sock = 0;
31
31
static bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
32
32
               opt_compress = 0, opt_databases = 0, opt_fast = 0,
33
33
               opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
38
38
static uint verbose = 0, opt_mysql_port=0;
39
39
static int my_end_arg;
40
40
static char * opt_mysql_unix_port = 0;
41
 
static char *opt_password = 0, *current_user = 0, 
42
 
            *default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME,
43
 
            *current_host = 0;
 
41
static char *opt_password = 0, *current_user = 0,
 
42
      *default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME,
 
43
      *current_host = 0;
44
44
static int first_error = 0;
45
45
DYNAMIC_ARRAY tables4repair;
46
46
static uint opt_protocol=0;
132
132
   (char**) &opt_mysql_port,
133
133
   (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
134
134
   0},
135
 
  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
 
135
  {"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
136
136
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
137
137
  {"quick", 'q',
138
138
   "If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table.",
178
178
static int handle_request_for_tables(char *tables, uint length);
179
179
static int dbConnect(char *host, char *user,char *passwd);
180
180
static void dbDisconnect(char *host);
181
 
static void DBerror(MYSQL *mysql, const char *when);
 
181
static void DBerror(DRIZZLE *drizzle, const char *when);
182
182
static void safe_exit(int error);
183
183
static void print_result(void);
184
184
static uint fixed_name_length(const char *name);
203
203
  puts("This program can be used to CHECK (-c,-m,-C), REPAIR (-r), ANALYZE (-a)");
204
204
  puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be");
205
205
  puts("used at the same time. Not all options are supported by all storage engines.");
206
 
  puts("Please consult the MySQL manual for latest information about the");
 
206
  puts("Please consult the Drizzle manual for latest information about the");
207
207
  puts("above. The options -c,-r,-a and -o are exclusive to each other, which");
208
208
  puts("means that the last option will be used, if several was specified.\n");
209
209
  puts("The option -c will be used by default, if none was specified. You");
214
214
  puts("mysqloptimize: The default option will be -o\n");
215
215
  printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
216
216
  printf("OR     %s [OPTIONS] --databases DB1 [DB2 DB3...]\n",
217
 
         my_progname);
 
217
   my_progname);
218
218
  printf("OR     %s [OPTIONS] --all-databases\n", my_progname);
219
219
  print_defaults("my", load_default_groups);
220
220
  my_print_help(my_long_options);
225
225
 
226
226
static bool
227
227
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
228
 
               char *argument)
 
228
         char *argument)
229
229
{
230
230
  switch(optid) {
231
231
  case 'a':
264
264
      char *start = argument;
265
265
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
266
266
      opt_password = my_strdup(argument, MYF(MY_FAE));
267
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
267
      while (*argument) *argument++= 'x';    /* Destroy argument */
268
268
      if (*start)
269
 
        start[1] = 0;                             /* Cut length of argument */
 
269
  start[1] = 0;                             /* Cut length of argument */
270
270
      tty_password= 0;
271
271
    }
272
272
    else
286
286
    verbose++;
287
287
    break;
288
288
  case 'V': print_version(); exit(0);
289
 
  case OPT_MYSQL_PROTOCOL:
 
289
  case OPT_DRIZZLE_PROTOCOL:
290
290
    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
291
291
                                    opt->name);
292
292
    break;
328
328
 
329
329
  /* TODO: This variable is not yet used */
330
330
  if (strcmp(default_charset, charset_info->csname) &&
331
 
      !(charset_info= get_charset_by_csname(default_charset, 
332
 
                                            MY_CS_PRIMARY, MYF(MY_WME))))
 
331
      !(charset_info= get_charset_by_csname(default_charset,
 
332
                MY_CS_PRIMARY, MYF(MY_WME))))
333
333
      exit(1);
334
334
  if (*argc > 0 && opt_alldbs)
335
335
  {
336
336
    printf("You should give only options, no arguments at all, with option\n");
337
337
    printf("--all-databases. Please see %s --help for more information.\n",
338
 
           my_progname);
 
338
     my_progname);
339
339
    return 1;
340
340
  }
341
341
  if (*argc < 1 && !opt_alldbs)
342
342
  {
343
343
    printf("You forgot to give the arguments! Please see %s --help\n",
344
 
           my_progname);
 
344
     my_progname);
345
345
    printf("for more information.\n");
346
346
    return 1;
347
347
  }
357
357
 
358
358
static int process_all_databases()
359
359
{
360
 
  MYSQL_ROW row;
361
 
  MYSQL_RES *tableres;
 
360
  DRIZZLE_ROW row;
 
361
  DRIZZLE_RES *tableres;
362
362
  int result = 0;
363
363
 
364
 
  if (mysql_query(sock, "SHOW DATABASES") ||
365
 
      !(tableres = mysql_store_result(sock)))
 
364
  if (drizzle_query(sock, "SHOW DATABASES") ||
 
365
      !(tableres = drizzle_store_result(sock)))
366
366
  {
367
367
    my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s",
368
 
                    MYF(0), mysql_error(sock));
 
368
        MYF(0), drizzle_error(sock));
369
369
    return 1;
370
370
  }
371
 
  while ((row = mysql_fetch_row(tableres)))
 
371
  while ((row = drizzle_fetch_row(tableres)))
372
372
  {
373
373
    if (process_one_db(row[0]))
374
374
      result = 1;
396
396
    return 1;
397
397
  if (opt_all_in_1)
398
398
  {
399
 
    /* 
 
399
    /*
400
400
      We need table list in form `a`, `b`, `c`
401
401
      that's why we need 2 more chars added to to each table name
402
402
      space is for more readable output in logs and in case of error
403
 
    */    
 
403
    */   
404
404
    char *table_names_comma_sep, *end;
405
405
    int i, tot_length = 0;
406
406
 
408
408
      tot_length+= fixed_name_length(*(table_names + i)) + 2;
409
409
 
410
410
    if (!(table_names_comma_sep = (char *)
411
 
          my_malloc((sizeof(char) * tot_length) + 4, MYF(MY_WME))))
 
411
    my_malloc((sizeof(char) * tot_length) + 4, MYF(MY_WME))))
412
412
      return 1;
413
413
 
414
414
    for (end = table_names_comma_sep + 1; tables > 0;
415
 
         tables--, table_names++)
 
415
   tables--, table_names++)
416
416
    {
417
417
      end= fix_table_name(end, *table_names);
418
418
      *end++= ',';
432
432
{
433
433
  const char *p;
434
434
  uint extra_length= 2;  /* count the first/last backticks */
435
 
  
 
435
 
436
436
  for (p= name; *p; p++)
437
437
  {
438
438
    if (*p == '`')
469
469
 
470
470
static int process_all_tables_in_db(char *database)
471
471
{
472
 
  MYSQL_RES *res;
473
 
  MYSQL_ROW row;
 
472
  DRIZZLE_RES *res;
 
473
  DRIZZLE_ROW row;
474
474
  uint num_columns;
475
475
 
476
476
  if (use_db(database))
477
477
    return 1;
478
 
  if (mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") ||
479
 
        !((res= mysql_store_result(sock))))
 
478
  if (drizzle_query(sock, "SHOW /*!50002 FULL*/ TABLES") ||
 
479
  !((res= drizzle_store_result(sock))))
480
480
    return 1;
481
481
 
482
 
  num_columns= mysql_num_fields(res);
 
482
  num_columns= drizzle_num_fields(res);
483
483
 
484
484
  if (opt_all_in_1)
485
485
  {
492
492
    char *tables, *end;
493
493
    uint tot_length = 0;
494
494
 
495
 
    while ((row = mysql_fetch_row(res)))
 
495
    while ((row = drizzle_fetch_row(res)))
496
496
      tot_length+= fixed_name_length(row[0]) + 2;
497
 
    mysql_data_seek(res, 0);
 
497
    drizzle_data_seek(res, 0);
498
498
 
499
499
    if (!(tables=(char *) my_malloc(sizeof(char)*tot_length+4, MYF(MY_WME))))
500
500
    {
501
 
      mysql_free_result(res);
 
501
      drizzle_free_result(res);
502
502
      return 1;
503
503
    }
504
 
    for (end = tables + 1; (row = mysql_fetch_row(res)) ;)
 
504
    for (end = tables + 1; (row = drizzle_fetch_row(res)) ;)
505
505
    {
506
506
      if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
507
507
        continue;
516
516
  }
517
517
  else
518
518
  {
519
 
    while ((row = mysql_fetch_row(res)))
 
519
    while ((row = drizzle_fetch_row(res)))
520
520
    {
521
521
      /* Skip views if we don't perform renaming. */
522
522
      if ((what_to_do != DO_UPGRADE) && (num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
525
525
      handle_request_for_tables(row[0], fixed_name_length(row[0]));
526
526
    }
527
527
  }
528
 
  mysql_free_result(res);
 
528
  drizzle_free_result(res);
529
529
  return 0;
530
530
} /* process_all_tables_in_db */
531
531
 
538
538
  if (strncmp(name, "#mysql50#", 9))
539
539
    return 1;
540
540
  sprintf(qbuf, "RENAME TABLE `%s` TO `%s`", name, name + 9);
541
 
  if (mysql_query(sock, qbuf))
 
541
  if (drizzle_query(sock, qbuf))
542
542
  {
543
543
    fprintf(stderr, "Failed to %s\n", qbuf);
544
 
    fprintf(stderr, "Error: %s\n", mysql_error(sock));
 
544
    fprintf(stderr, "Error: %s\n", drizzle_error(sock));
545
545
    rc= 1;
546
546
  }
547
547
  if (verbose)
556
556
  if (strncmp(name, "#mysql50#", 9))
557
557
    return 1;
558
558
  sprintf(qbuf, "ALTER DATABASE `%s` UPGRADE DATA DIRECTORY NAME", name);
559
 
  if (mysql_query(sock, qbuf))
 
559
  if (drizzle_query(sock, qbuf))
560
560
  {
561
561
    fprintf(stderr, "Failed to %s\n", qbuf);
562
 
    fprintf(stderr, "Error: %s\n", mysql_error(sock));
 
562
    fprintf(stderr, "Error: %s\n", drizzle_error(sock));
563
563
    rc= 1;
564
564
  }
565
565
  if (verbose)
586
586
 
587
587
static int use_db(char *database)
588
588
{
589
 
  if (mysql_get_server_version(sock) >= 50003 &&
 
589
  if (drizzle_get_server_version(sock) >= 50003 &&
590
590
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
591
591
    return 1;
592
 
  if (mysql_select_db(sock, database))
 
592
  if (drizzle_select_db(sock, database))
593
593
  {
594
594
    DBerror(sock, "when selecting the database");
595
595
    return 1;
648
648
    ptr= strxmov(ptr, " ", options, NullS);
649
649
    query_length= (uint) (ptr - query);
650
650
  }
651
 
  if (mysql_real_query(sock, query, query_length))
 
651
  if (drizzle_real_query(sock, query, query_length))
652
652
  {
653
653
    sprintf(message, "when executing '%s TABLE ... %s'", op, options);
654
654
    DBerror(sock, message);
662
662
 
663
663
static void print_result()
664
664
{
665
 
  MYSQL_RES *res;
666
 
  MYSQL_ROW row;
 
665
  DRIZZLE_RES *res;
 
666
  DRIZZLE_ROW row;
667
667
  char prev[NAME_LEN*2+2];
668
668
  uint i;
669
669
  bool found_error=0;
670
670
 
671
 
  res = mysql_use_result(sock);
 
671
  res = drizzle_use_result(sock);
672
672
 
673
673
  prev[0] = '\0';
674
 
  for (i = 0; (row = mysql_fetch_row(res)); i++)
 
674
  for (i = 0; (row = drizzle_fetch_row(res)); i++)
675
675
  {
676
676
    int changed = strcmp(prev, row[0]);
677
677
    bool status = !strcmp(row[2], "status");
684
684
        list
685
685
      */
686
686
      if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
687
 
          strcmp(row[3],"OK"))
688
 
        insert_dynamic(&tables4repair, (uchar*) prev);
 
687
    strcmp(row[3],"OK"))
 
688
  insert_dynamic(&tables4repair, (uchar*) prev);
689
689
      found_error=0;
690
690
      if (opt_silent)
691
 
        continue;
 
691
  continue;
692
692
    }
693
693
    if (status && changed)
694
694
      printf("%-50s %s", row[0], row[3]);
696
696
    {
697
697
      printf("%s\n%-9s: %s", row[0], row[2], row[3]);
698
698
      if (strcmp(row[2],"note"))
699
 
        found_error=1;
 
699
  found_error=1;
700
700
    }
701
701
    else
702
702
      printf("%-9s: %s", row[2], row[3]);
706
706
  /* add the last table to be repaired to the list */
707
707
  if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
708
708
    insert_dynamic(&tables4repair, (uchar*) prev);
709
 
  mysql_free_result(res);
 
709
  drizzle_free_result(res);
710
710
}
711
711
 
712
712
 
717
717
  {
718
718
    fprintf(stderr, "# Connecting to %s...\n", host ? host : "localhost");
719
719
  }
720
 
  mysql_init(&mysql_connection);
 
720
  drizzle_init(&drizzle_connection);
721
721
  if (opt_compress)
722
 
    mysql_options(&mysql_connection, MYSQL_OPT_COMPRESS, NullS);
 
722
    drizzle_options(&drizzle_connection, DRIZZLE_OPT_COMPRESS, NullS);
723
723
  if (opt_protocol)
724
 
    mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
725
 
  if (!(sock = mysql_real_connect(&mysql_connection, host, user, passwd,
 
724
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
 
725
  if (!(sock = drizzle_connect(&drizzle_connection, host, user, passwd,
726
726
         NULL, opt_mysql_port, opt_mysql_unix_port, 0)))
727
727
  {
728
 
    DBerror(&mysql_connection, "when trying to connect");
 
728
    DBerror(&drizzle_connection, "when trying to connect");
729
729
    return 1;
730
730
  }
731
 
  mysql_connection.reconnect= 1;
 
731
  drizzle_connection.reconnect= 1;
732
732
  return 0;
733
733
} /* dbConnect */
734
734
 
737
737
{
738
738
  if (verbose)
739
739
    fprintf(stderr, "# Disconnecting from %s...\n", host ? host : "localhost");
740
 
  mysql_close(sock);
 
740
  drizzle_close(sock);
741
741
} /* dbDisconnect */
742
742
 
743
743
 
744
 
static void DBerror(MYSQL *mysql, const char *when)
 
744
static void DBerror(DRIZZLE *drizzle, const char *when)
745
745
{
746
746
  my_printf_error(0,"Got error: %d: %s %s", MYF(0),
747
 
                  mysql_errno(mysql), mysql_error(mysql), when);
 
747
      drizzle_errno(drizzle), drizzle_error(drizzle), when);
748
748
  safe_exit(EX_MYSQLERR);
749
749
  return;
750
750
} /* DBerror */
757
757
  if (ignore_errors)
758
758
    return;
759
759
  if (sock)
760
 
    mysql_close(sock);
 
760
    drizzle_close(sock);
761
761
  exit(error);
762
762
}
763
763