~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Brian Aker
  • Date: 2008-08-11 17:33:54 UTC
  • mfrom: (287.3.17 codestyle)
  • Revision ID: brian@tangent.org-20080811173354-ys7tgjknox52semx
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#define DUMP_VERSION "10.13"
28
28
 
29
 
#include <config.h>
30
29
#include <string>
31
30
#include "client_priv.h"
32
31
 
83
82
                opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
84
83
                opt_complete_insert= 0, opt_drop_database= 0,
85
84
                opt_replace_into= 0,
86
 
                opt_routines=0,
 
85
                opt_routines=0, opt_tz_utc=1,
87
86
                opt_slave_apply= 0, 
88
87
                opt_include_master_host_port= 0,
89
88
                opt_events= 0,
116
115
FILE *md_result_file= 0;
117
116
FILE *stderror_file=0;
118
117
 
 
118
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
 
119
 
119
120
/*
120
121
  Constant for detection of default value of default_charset.
121
122
  If default_charset is equal to drizzle_universal_client_charset, then
122
123
  it is the default value which assigned at the very beginning of main().
123
124
*/
124
125
static const char *drizzle_universal_client_charset=
125
 
  DRIZZLE_UNIVERSAL_CLIENT_CHARSET;
 
126
  MYSQL_UNIVERSAL_CLIENT_CHARSET;
126
127
static char *default_charset;
127
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
 
128
static const CHARSET_INFO *charset_info= &my_charset_latin1;
128
129
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
129
130
/* have we seen any VIEWs during table scanning? */
130
131
bool seen_views= 0;
133
134
  "MYSQL323", "MYSQL40", "POSTGRESQL", "ORACLE", "MSSQL", "DB2",
134
135
  "MAXDB", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS",
135
136
  "ANSI",
136
 
  NULL
 
137
  NullS
137
138
};
138
139
#define MASK_ANSI_QUOTES \
139
140
(\
379
380
  {"routines", 'R', "Dump stored routines (functions and procedures).",
380
381
     (char**) &opt_routines, (char**) &opt_routines, 0, GET_BOOL,
381
382
     NO_ARG, 0, 0, 0, 0, 0, 0},
 
383
  {"set-charset", OPT_SET_CHARSET,
 
384
   "Add 'SET NAMES default_character_set' to the output.",
 
385
   (char**) &opt_set_charset, (char**) &opt_set_charset, 0, GET_BOOL, NO_ARG, 1,
 
386
   0, 0, 0, 0, 0},
382
387
  {"set-variable", 'O',
383
388
   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
384
389
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
410
415
   (char**) &path, (char**) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
411
416
  {"tables", OPT_TABLES, "Overrides option --databases (-B).",
412
417
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
418
  {"tz-utc", OPT_TZ_UTC,
 
419
    "SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones.",
 
420
    (char**) &opt_tz_utc, (char**) &opt_tz_utc, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
413
421
#ifndef DONT_ALLOW_USER_CHANGE
414
422
  {"user", 'u', "User for login if not current user.",
415
423
   (char**) &current_user, (char**) &current_user, 0, GET_STR, REQUIRED_ARG,
505
513
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
506
514
  puts("Dumping definition and data DRIZZLE database or table");
507
515
  short_usage_sub();
508
 
  print_defaults("drizzle",load_default_groups);
 
516
  print_defaults("my",load_default_groups);
509
517
  my_print_help(my_long_options);
510
518
  my_print_variables(my_long_options);
511
519
} /* usage */
550
558
    }
551
559
    if (opt_set_charset)
552
560
      fprintf(sql_file,
 
561
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"
 
562
"\n/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;"
553
563
"\n/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;"
554
564
"\n/*!40101 SET NAMES %s */;\n",default_charset);
555
565
 
 
566
    if (opt_tz_utc)
 
567
    {
 
568
      fprintf(sql_file, "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;\n");
 
569
      fprintf(sql_file, "/*!40103 SET TIME_ZONE='+00:00' */;\n");
 
570
    }
 
571
 
556
572
    if (!path)
557
573
    {
558
574
      fprintf(md_result_file,"\
574
590
  }
575
591
  else if (!opt_compact)
576
592
  {
 
593
    if (opt_tz_utc)
 
594
      fprintf(sql_file,"/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;\n");
 
595
 
577
596
    if (!path)
578
597
    {
579
598
      fprintf(md_result_file,"\
581
600
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n");
582
601
    }
583
602
    if (opt_set_charset)
584
 
      fprintf(sql_file, "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
 
603
      fprintf(sql_file,
 
604
"/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"
 
605
"/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"
 
606
"/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n");
 
607
    fprintf(sql_file,
 
608
            "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n");
 
609
    fputs("\n", sql_file);
585
610
    if (opt_comments)
586
611
    {
587
612
      if (opt_dump_date)
601
626
 
602
627
static void free_table_ent(char *key)
603
628
{
604
 
  free(key);
 
629
  my_free(key, MYF(0));
605
630
}
606
631
 
607
632
 
608
 
static unsigned char* get_table_key(const char *entry, size_t *length,
 
633
static uchar* get_table_key(const char *entry, size_t *length,
609
634
                            bool not_used __attribute__((unused)))
610
635
{
611
636
  *length= strlen(entry);
612
 
  return (unsigned char*) entry;
 
637
  return (uchar*) entry;
613
638
}
614
639
 
615
640
 
622
647
    if (argument)
623
648
    {
624
649
      char *start=argument;
625
 
      free(opt_password);
 
650
      my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
626
651
      opt_password=my_strdup(argument,MYF(MY_FAE));
627
652
      while (*argument) *argument++= 'x';               /* Destroy argument */
628
653
      if (*start)
633
658
      tty_password=1;
634
659
    break;
635
660
  case 'r':
636
 
    if (!(md_result_file= my_fopen(argument, O_WRONLY,
 
661
    if (!(md_result_file= my_fopen(argument, O_WRONLY | FILE_BINARY,
637
662
                                    MYF(MY_WME))))
638
663
      exit(1);
639
664
    break;
697
722
      fprintf(stderr, "Illegal use of option --ignore-table=<database>.<table>\n");
698
723
      exit(1);
699
724
    }
700
 
    if (my_hash_insert(&ignore_table, (unsigned char*)my_strdup(argument, MYF(0))))
 
725
    if (my_hash_insert(&ignore_table, (uchar*)my_strdup(argument, MYF(0))))
701
726
      exit(EX_EOM);
702
727
    break;
703
728
  }
717
742
                                    &err_ptr, &error_len);
718
743
      if (error_len)
719
744
      {
720
 
        strmake(buff, err_ptr, min((uint32_t)sizeof(buff), error_len));
 
745
        strmake(buff, err_ptr, min(sizeof(buff), error_len));
721
746
        fprintf(stderr, "Invalid mode to --compatible: %s\n", buff);
722
747
        exit(1);
723
748
      }
726
751
      {
727
752
        if (mode & 1)
728
753
        {
729
 
          end= my_stpcpy(end, compatible_mode_names[i]);
730
 
          end= my_stpcpy(end, ",");
 
754
          end= stpcpy(end, compatible_mode_names[i]);
 
755
          end= stpcpy(end, ",");
731
756
        }
732
757
      }
733
758
      if (end!=compatible_mode_normal_str)
737
762
        been reset yet by --default-character-set=xxx.
738
763
      */
739
764
      if (default_charset == drizzle_universal_client_charset)
740
 
        default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
 
765
        default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
741
766
      break;
742
767
    }
743
768
  }
753
778
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
754
779
 
755
780
  md_result_file= stdout;
756
 
  load_defaults("drizzle",load_default_groups,argc,argv);
 
781
  load_defaults("my",load_default_groups,argc,argv);
757
782
  defaults_argv= *argv;
758
783
 
759
784
  if (hash_init(&ignore_table, charset_info, 16, 0, 0,
762
787
    return(EX_EOM);
763
788
  /* Don't copy internal log tables */
764
789
  if (my_hash_insert(&ignore_table,
765
 
                     (unsigned char*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
766
 
      my_hash_insert(&ignore_table,
767
 
                     (unsigned char*) my_strdup("mysql.schema", MYF(MY_WME))) ||
768
 
      my_hash_insert(&ignore_table,
769
 
                     (unsigned char*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
770
 
      my_hash_insert(&ignore_table,
771
 
                     (unsigned char*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
772
 
      my_hash_insert(&ignore_table,
773
 
                     (unsigned char*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
774
 
      my_hash_insert(&ignore_table,
775
 
                     (unsigned char*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
 
790
                     (uchar*) my_strdup("mysql.apply_status", MYF(MY_WME))) ||
 
791
      my_hash_insert(&ignore_table,
 
792
                     (uchar*) my_strdup("mysql.schema", MYF(MY_WME))) ||
 
793
      my_hash_insert(&ignore_table,
 
794
                     (uchar*) my_strdup("mysql.general_log", MYF(MY_WME))) ||
 
795
      my_hash_insert(&ignore_table,
 
796
                     (uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))) ||
 
797
      my_hash_insert(&ignore_table,
 
798
                     (uchar*) my_strdup("mysql.online_backup", MYF(MY_WME))) ||
 
799
      my_hash_insert(&ignore_table,
 
800
                     (uchar*) my_strdup("mysql.online_backup_progress", MYF(MY_WME))))
776
801
    return(EX_EOM);
777
802
 
778
803
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
841
866
    return EX_USAGE;
842
867
  }
843
868
  if (tty_password)
844
 
    opt_password=get_tty_password(NULL);
 
869
    opt_password=get_tty_password(NullS);
845
870
  return(0);
846
871
} /* get_options */
847
872
 
996
1021
{
997
1022
  FILE* res;
998
1023
  char filename[FN_REFLEN], tmp_path[FN_REFLEN];
999
 
  convert_dirname(tmp_path,path,NULL);
 
1024
  convert_dirname(tmp_path,path,NullS);
1000
1025
  res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4),
1001
1026
                O_WRONLY, MYF(MY_WME));
1002
1027
  return res;
1007
1032
{
1008
1033
  if (md_result_file && md_result_file != stdout)
1009
1034
    my_fclose(md_result_file, MYF(0));
1010
 
  free(opt_password);
 
1035
  my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1011
1036
  if (hash_inited(&ignore_table))
1012
1037
    hash_free(&ignore_table);
1013
1038
  if (defaults_argv)
1035
1060
 
1036
1061
static int connect_to_db(char *host, char *user,char *passwd)
1037
1062
{
 
1063
  char buff[20+FN_REFLEN];
 
1064
 
 
1065
 
1038
1066
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1039
1067
  drizzle_create(&drizzle_connection);
1040
1068
  if (opt_compress)
1041
 
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NULL);
 
1069
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
 
1070
  if (opt_protocol)
 
1071
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
 
1072
  drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
1042
1073
  if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
1043
1074
                                  NULL,opt_drizzle_port, NULL,
1044
1075
                                  0)))
1046
1077
    DB_error(&drizzle_connection, "when trying to connect");
1047
1078
    return(1);
1048
1079
  }
 
1080
  if (drizzle_get_server_version(&drizzle_connection) < 40100)
 
1081
  {
 
1082
    /* Don't dump SET NAMES with a pre-4.1 server (bug#7997).  */
 
1083
    opt_set_charset= 0;
1049
1084
 
 
1085
    /* Don't switch charsets for 4.1 and earlier.  (bug#34192). */
 
1086
    server_supports_switching_charsets= false;
 
1087
  } 
 
1088
  /*
 
1089
    set time_zone to UTC to allow dumping date types between servers with
 
1090
    different time zone settings
 
1091
  */
 
1092
  if (opt_tz_utc)
 
1093
  {
 
1094
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
 
1095
    if (drizzle_query_with_error_report(drizzle, 0, buff))
 
1096
      return(1);
 
1097
  }
1050
1098
  return(0);
1051
1099
} /* connect_to_db */
1052
1100
 
1068
1116
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1069
1117
    die(EX_DRIZZLEERR, "Couldn't allocate memory");
1070
1118
 
1071
 
  drizzle_escape_string(tmp, pos, length);
 
1119
  drizzle_real_escape_string(&drizzle_connection, tmp, pos, length);
1072
1120
  fputc('\'', file);
1073
1121
  fputs(tmp, file);
1074
1122
  fputc('\'', file);
1075
1123
  check_io(file);
1076
 
  free(tmp);
 
1124
  my_free(tmp, MYF(MY_WME));
1077
1125
  return;
1078
1126
} /* unescape */
1079
1127
 
1214
1262
 
1215
1263
  SYNOPSIS
1216
1264
    print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name, 
1217
 
                    ..., attribute_name_n, attribute_value_n, NULL)
 
1265
                    ..., attribute_name_n, attribute_value_n, NullS)
1218
1266
    xml_file              - output file
1219
1267
    sbeg                  - line beginning
1220
1268
    line_end              - line ending
1251
1299
 
1252
1300
  va_start(arg_list, first_attribute_name);
1253
1301
  attribute_name= first_attribute_name;
1254
 
  while (attribute_name != NULL)
 
1302
  while (attribute_name != NullS)
1255
1303
  {
1256
1304
    attribute_value= va_arg(arg_list, char *);
1257
 
    assert(attribute_value != NULL);
 
1305
    assert(attribute_value != NullS);
1258
1306
 
1259
1307
    fputc(' ', xml_file);
1260
1308
    fputs(attribute_name, xml_file);    
1369
1417
    /* sakaik got the idea to to provide blob's in hex notation. */
1370
1418
    const char *ptr= str, *end= ptr + len;
1371
1419
    for (; ptr < end ; ptr++)
1372
 
      fprintf(output_file, "%02X", *((unsigned char *)ptr));
 
1420
      fprintf(output_file, "%02X", *((uchar *)ptr));
1373
1421
    check_io(output_file);
1374
1422
}
1375
1423
 
1433
1481
 
1434
1482
  if (opt_order_by_primary)
1435
1483
  {
1436
 
    free(order_by);
 
1484
    my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
1437
1485
    order_by= primary_key_fields(result_table);
1438
1486
  }
1439
1487
 
1520
1568
          if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1521
1569
            fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1522
1570
 
1523
 
          free(scv_buff);
 
1571
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1524
1572
 
1525
1573
          return(0);
1526
1574
        }
1527
1575
        else
1528
 
          free(scv_buff);
 
1576
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1529
1577
 
1530
1578
        if (drizzle_num_rows(result))
1531
1579
        {
1542
1590
          }
1543
1591
 
1544
1592
          fprintf(sql_file,
 
1593
                  "SET @saved_cs_client     = @@character_set_client;\n"
 
1594
                  "SET character_set_client = utf8;\n"
1545
1595
                  "/*!50001 CREATE TABLE %s (\n",
1546
1596
                  result_table);
1547
1597
 
1562
1612
            fprintf(sql_file, ",\n  %s %s",
1563
1613
                    quote_name(row[0], name_buff, 0), row[1]);
1564
1614
          }
1565
 
          fprintf(sql_file, "\n) */;\n"); 
 
1615
          fprintf(sql_file,
 
1616
                  "\n) */;\n"
 
1617
                  "SET character_set_client = @saved_cs_client;\n");
 
1618
 
1566
1619
          check_io(sql_file);
1567
1620
        }
1568
1621
 
1577
1630
 
1578
1631
      row= drizzle_fetch_row(result);
1579
1632
 
1580
 
      fprintf(sql_file, "%s;\n", row[1]);
 
1633
      fprintf(sql_file,
 
1634
              "SET @saved_cs_client     = @@character_set_client;\n"
 
1635
              "SET character_set_client = utf8;\n"
 
1636
              "%s;\n"
 
1637
              "SET character_set_client = @saved_cs_client;\n",
 
1638
              row[1]);
1581
1639
 
1582
1640
      check_io(sql_file);
1583
1641
      drizzle_free_result(result);
1661
1719
        fprintf(sql_file, "CREATE TABLE %s (\n", result_table);
1662
1720
      else
1663
1721
        print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table, 
1664
 
                NULL);
 
1722
                NullS);
1665
1723
      check_io(sql_file);
1666
1724
    }
1667
1725
 
2008
2066
     discarding SHOW CREATE EVENT statements generation. The myslq.event
2009
2067
     table data should be skipped too.
2010
2068
  */
2011
 
  if (!opt_events && !my_strcasecmp(&my_charset_utf8_general_ci, db, "mysql") &&
2012
 
      !my_strcasecmp(&my_charset_utf8_general_ci, table, "event"))
 
2069
  if (!opt_events && !my_strcasecmp(&my_charset_latin1, db, "mysql") &&
 
2070
      !my_strcasecmp(&my_charset_latin1, table, "event"))
2013
2071
  {
2014
2072
    verbose_msg("-- Skipping data table mysql.event, --skip-events was used\n");
2015
2073
    return;
2031
2089
      Convert the path to native os format
2032
2090
      and resolve to the full filepath.
2033
2091
    */
2034
 
    convert_dirname(tmp_path,path,NULL);    
 
2092
    convert_dirname(tmp_path,path,NullS);    
2035
2093
    my_load_path(tmp_path, tmp_path, NULL);
2036
2094
    fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
2037
2095
 
2159
2217
    init_length=(uint) insert_pat.length()+4;
2160
2218
    if (opt_xml)
2161
2219
      print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table,
2162
 
              NULL);
 
2220
              NullS);
2163
2221
    if (opt_autocommit)
2164
2222
    {
2165
2223
      fprintf(md_result_file, "set autocommit=0;\n");
2213
2271
          {
2214
2272
            if (length)
2215
2273
            {
2216
 
              if (!(field->type & NUM_FLAG))
 
2274
              if (!IS_NUM_FIELD(field))
2217
2275
              {
2218
2276
                /*
2219
2277
                  "length * 2 + 2" is OK for both HEX and non-HEX modes:
2234
2292
                else
2235
2293
                {
2236
2294
                  extended_row.append("'");
2237
 
                  drizzle_escape_string(tmp_str,
2238
 
                                        row[i],length);
 
2295
                  drizzle_real_escape_string(&drizzle_connection,
 
2296
                                             tmp_str,
 
2297
                                             row[i],length);
2239
2298
                  extended_row.append(tmp_str);
2240
2299
                  extended_row.append("'");
2241
2300
                }
2269
2328
          }
2270
2329
          if (row[i])
2271
2330
          {
2272
 
            if (!(field->type & NUM_FLAG))
 
2331
            if (!IS_NUM_FIELD(field))
2273
2332
            {
2274
2333
              if (opt_xml)
2275
2334
              {
2277
2336
                {
2278
2337
                  /* Define xsi:type="xs:hexBinary" for hex encoded data */
2279
2338
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2280
 
                                field->name, "xsi:type=", "xs:hexBinary", NULL);
 
2339
                                field->name, "xsi:type=", "xs:hexBinary", NullS);
2281
2340
                  print_blob_as_hex(md_result_file, row[i], length);
2282
2341
                }
2283
2342
                else
2284
2343
                {
2285
2344
                  print_xml_tag(md_result_file, "\t\t", "", "field", "name=", 
2286
 
                                field->name, NULL);
 
2345
                                field->name, NullS);
2287
2346
                  print_quoted_xml(md_result_file, row[i], length);
2288
2347
                }
2289
2348
                fputs("</field>\n", md_result_file);
2303
2362
              if (opt_xml)
2304
2363
              {
2305
2364
                print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
2306
 
                        field->name, NULL);
 
2365
                        field->name, NullS);
2307
2366
                fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL",
2308
2367
                      md_result_file);
2309
2368
                fputs("</field>\n", md_result_file);
2419
2478
 
2420
2479
  if (!res)
2421
2480
  {
2422
 
    if (!(res= drizzle_list_tables(drizzle,NULL)))
 
2481
    if (!(res= drizzle_list_tables(drizzle,NullS)))
2423
2482
      return(NULL);
2424
2483
  }
2425
2484
  if ((row= drizzle_fetch_row(res)))
2527
2586
static int init_dumping(char *database, int init_func(char*))
2528
2587
{
2529
2588
  if (drizzle_get_server_version(drizzle) >= 50003 &&
2530
 
      !my_strcasecmp(&my_charset_utf8_general_ci, database, "information_schema"))
 
2589
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2531
2590
    return 1;
2532
2591
 
2533
2592
  if (drizzle_select_db(drizzle, database))
2565
2624
 
2566
2625
/* Return 1 if we should copy the table */
2567
2626
 
2568
 
static bool include_table(const unsigned char *hash_key, size_t len)
 
2627
static bool include_table(const uchar *hash_key, size_t len)
2569
2628
{
2570
2629
  return !hash_search(&ignore_table, hash_key, len);
2571
2630
}
2578
2637
  char table_buff[NAME_LEN*2+3];
2579
2638
  char hash_key[2*NAME_LEN+2];  /* "db.tablename" */
2580
2639
  char *afterdot;
2581
 
  int using_mysql_db= my_strcasecmp(&my_charset_utf8_general_ci, database, "mysql");
2582
 
 
2583
 
 
2584
 
  afterdot= my_stpcpy(hash_key, database);
 
2640
  int using_mysql_db= my_strcasecmp(&my_charset_latin1, database, "mysql");
 
2641
 
 
2642
 
 
2643
  afterdot= stpcpy(hash_key, database);
2585
2644
  *afterdot++= '.';
2586
2645
 
2587
2646
  if (init_dumping(database, init_dumping_tables))
2588
2647
    return(1);
2589
2648
  if (opt_xml)
2590
 
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NULL);
 
2649
    print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS);
2591
2650
  if (lock_tables)
2592
2651
  {
2593
2652
    string query;
2594
2653
    query= "LOCK TABLES ";
2595
2654
    for (numrows= 0 ; (table= getTableName(1)) ; )
2596
2655
    {
2597
 
      char *end= my_stpcpy(afterdot, table);
2598
 
      if (include_table((unsigned char*) hash_key,end - hash_key))
 
2656
      char *end= stpcpy(afterdot, table);
 
2657
      if (include_table((uchar*) hash_key,end - hash_key))
2599
2658
      {
2600
2659
        numrows++;
2601
2660
        query.append( quote_name(table, table_buff, 1));
2615
2674
  }
2616
2675
  while ((table= getTableName(0)))
2617
2676
  {
2618
 
    char *end= my_stpcpy(afterdot, table);
2619
 
    if (include_table((unsigned char*) hash_key, end - hash_key))
 
2677
    char *end= stpcpy(afterdot, table);
 
2678
    if (include_table((uchar*) hash_key, end - hash_key))
2620
2679
    {
2621
2680
      dump_table(table,database);
2622
 
      free(order_by);
 
2681
      my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2623
2682
      order_by= 0;
2624
2683
    }
2625
2684
  }
2629
2688
    check_io(md_result_file);
2630
2689
  }
2631
2690
  if (lock_tables)
2632
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2691
    VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2633
2692
  if (flush_privileges && using_mysql_db == 0)
2634
2693
  {
2635
2694
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2665
2724
           quote_for_like(old_table_name, show_name_buff));
2666
2725
 
2667
2726
  if (drizzle_query_with_error_report(drizzle, 0, query))
2668
 
    return NULL;
 
2727
    return NullS;
2669
2728
 
2670
2729
  if ((table_res= drizzle_store_result(drizzle)))
2671
2730
  {
2752
2811
     /* We shall countinue here, if --force was given */
2753
2812
  }
2754
2813
  if (opt_xml)
2755
 
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NULL);
 
2814
    print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS);
2756
2815
 
2757
2816
  /* Dump each selected table */
2758
2817
  for (pos= dump_tables; pos < end; pos++)
2759
2818
    dump_table(*pos, db);
2760
2819
 
2761
2820
  free_root(&root, MYF(0));
2762
 
  free(order_by);
 
2821
  my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
2763
2822
  order_by= 0;
2764
2823
  if (opt_xml)
2765
2824
  {
2767
2826
    check_io(md_result_file);
2768
2827
  }
2769
2828
  if (lock_tables)
2770
 
    drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES");
 
2829
    VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2771
2830
  return(0);
2772
2831
} /* dump_selected_tables */
2773
2832
 
3048
3107
 
3049
3108
      for (; pos != end && *pos != ','; pos++) ;
3050
3109
      var_len= (uint32_t) (pos - start);
3051
 
      strmake(buff, start, min((uint32_t)sizeof(buff), var_len));
 
3110
      strmake(buff, start, min(sizeof(buff), var_len));
3052
3111
      find= find_type(buff, lib, var_len);
3053
3112
      if (!find)
3054
3113
      {
3173
3232
      If these two types, we do want to skip dumping the table
3174
3233
    */
3175
3234
    if (!opt_no_data &&
3176
 
        (!my_strcasecmp(&my_charset_utf8_general_ci, table_type, "MRG_MyISAM") ||
 
3235
        (!my_strcasecmp(&my_charset_latin1, table_type, "MRG_MyISAM") ||
3177
3236
         !strcmp(table_type,"MRG_ISAM")))
3178
3237
      result= IGNORE_DATA;
3179
3238
  }
3253
3312
    drizzle_data_seek(res, 0);
3254
3313
    row= drizzle_fetch_row(res);
3255
3314
    quoted_field= quote_name(row[4], buff, 0);
3256
 
    end= my_stpcpy(result, quoted_field);
 
3315
    end= stpcpy(result, quoted_field);
3257
3316
    while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3258
3317
    {
3259
3318
      quoted_field= quote_name(row[4], buff, 0);
3260
 
      end= strxmov(end, ",", quoted_field, NULL);
 
3319
      end= strxmov(end, ",", quoted_field, NullS);
3261
3320
    }
3262
3321
  }
3263
3322