~mkindahl/drizzle/remove-mem-casts

« back to all changes in this revision

Viewing changes to client/drizzledump.c

  • Committer: Brian Aker
  • Date: 2008-07-26 04:51:46 UTC
  • mfrom: (202.1.25 codestyle)
  • Revision ID: brian@tangent.org-20080726045146-ax7ofn8aqnkycjl3
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/* Copyright (C) 2008 Drizzle Open Source Development Project
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
 
/* mysqldump.c  - Dump a tables contents and format to an ASCII file
 
16
/* drizzledump.c  - Dump a tables contents and format to an ASCII file
17
17
**
18
18
** The author's original notes follow :-
19
19
**
22
22
** WARRANTY: None, expressed, impressed, implied
23
23
**          or other
24
24
** STATUS: Public domain
25
 
** Adapted and optimized for MySQL by
 
25
** Adapted and optimized for DRIZZLE by
26
26
** Michael Widenius, Sinisa Milivojevic, Jani Tolonen
27
27
** -w --where added 9/10/98 by Jim Faucette
28
28
** slave code by David Saez Padros <david@ols.es>
31
31
** Andrei Errapart <andreie@no.spam.ee>
32
32
** Tõnu Samuel  <tonu@please.do.not.remove.this.spam.ee>
33
33
** XML by Gary Huntress <ghuntress@mediaone.net> 10/10/01, cleaned up
34
 
** and adapted to mysqldump 05/11/01 by Jani Tolonen
 
34
** and adapted to drizzledump 05/11/01 by Jani Tolonen
35
35
** Added --single-transaction option 06/06/2002 by Peter Zaitsev
36
36
** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov
37
37
*/
52
52
/* Exit codes */
53
53
 
54
54
#define EX_USAGE 1
55
 
#define EX_MYSQLERR 2
 
55
#define EX_DRIZZLEERR 2
56
56
#define EX_CONSCHECK 3
57
57
#define EX_EOM 4
58
58
#define EX_EOF 5 /* ferror for output file was got */
100
100
                opt_alltspcs=0, opt_notspcs= 0;
101
101
static bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
102
102
static ulong opt_max_allowed_packet, opt_net_buffer_length;
103
 
static MYSQL mysql_connection,*mysql=0;
 
103
static DRIZZLE drizzle_connection,*drizzle=0;
104
104
static DYNAMIC_STRING insert_pat;
105
105
static char  *opt_password=0,*current_user=0,
106
106
             *current_host=0,*path=0,*fields_terminated=0,
114
114
/* Server supports character_set_results session variable? */
115
115
static bool server_supports_switching_charsets= true;
116
116
static ulong opt_compatible_mode= 0;
117
 
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
118
 
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
119
 
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
120
 
#define MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL 2
121
 
static uint opt_mysql_port= 0, opt_master_data;
 
117
#define DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL 1
 
118
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
 
119
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
 
120
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
 
121
static uint opt_drizzle_port= 0, opt_master_data;
122
122
static uint opt_slave_data;
123
123
static uint my_end_arg;
124
124
static int   first_error=0;
126
126
FILE *md_result_file= 0;
127
127
FILE *stderror_file=0;
128
128
 
129
 
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
 
129
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
130
130
 
131
131
/*
132
132
Dynamic_string wrapper functions. In this file use these
142
142
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size);
143
143
/*
144
144
  Constant for detection of default value of default_charset.
145
 
  If default_charset is equal to mysql_universal_client_charset, then
 
145
  If default_charset is equal to drizzle_universal_client_charset, then
146
146
  it is the default value which assigned at the very beginning of main().
147
147
*/
148
 
static const char *mysql_universal_client_charset=
 
148
static const char *drizzle_universal_client_charset=
149
149
  MYSQL_UNIVERSAL_CLIENT_CHARSET;
150
150
static char *default_charset;
151
151
static CHARSET_INFO *charset_info= &my_charset_latin1;
152
 
const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace";
 
152
const char *default_dbug_option="d:t:o,/tmp/drizzledump.trace";
153
153
/* have we seen any VIEWs during table scanning? */
154
154
bool seen_views= 0;
155
155
const char *compatible_mode_names[]=
202
202
  {"allow-keywords", OPT_KEYWORDS,
203
203
   "Allow creation of column names that are keywords.", (char**) &opt_keywords,
204
204
   (char**) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
205
 
  {"apply-slave-statements", OPT_MYSQLDUMP_SLAVE_APPLY,
 
205
  {"apply-slave-statements", OPT_DRIZZLEDUMP_SLAVE_APPLY,
206
206
   "Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump.",
207
207
   (char**) &opt_slave_apply, (char**) &opt_slave_apply, 0, GET_BOOL, NO_ARG,
208
208
   0, 0, 0, 0, 0, 0},
213
213
   (char**) &opt_comments, (char**) &opt_comments, 0, GET_BOOL, NO_ARG,
214
214
   1, 0, 0, 0, 0, 0},
215
215
  {"compatible", OPT_COMPATIBLE,
216
 
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires MySQL server version 4.1.0 or higher. This option is ignored with earlier server versions.",
 
216
   "Change the dump to be compatible with a given mode. By default tables are dumped in a format optimized for MySQL. Legal modes are: ansi, mysql323, mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, no_field_options. One can use several modes separated by commas. Note: Requires DRIZZLE server version 4.1.0 or higher. This option is ignored with earlier server versions.",
217
217
   (char**) &opt_compatible_mode_str, (char**) &opt_compatible_mode_str, 0,
218
218
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
219
219
  {"compact", OPT_COMPACT,
227
227
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
228
228
   0, 0, 0},
229
229
  {"create-options", OPT_CREATE_OPTIONS,
230
 
   "Include all MySQL specific create options.",
 
230
   "Include all DRIZZLE specific create options.",
231
231
   (char**) &create_options, (char**) &create_options, 0, GET_BOOL, NO_ARG, 1,
232
232
   0, 0, 0, 0, 0},
233
233
  {"databases", 'B',
253
253
  {"disable-keys", 'K',
254
254
   "'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (char**) &opt_disable_keys,
255
255
   (char**) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
256
 
  {"dump-slave", OPT_MYSQLDUMP_SLAVE_DATA,
 
256
  {"dump-slave", OPT_DRIZZLEDUMP_SLAVE_DATA,
257
257
   "This causes the binary log position and filename of the master to be "
258
258
   "appended to the dumped data output. Setting the value to 1, will print"
259
259
   "it as a CHANGE MASTER command in the dumped data output; if equal"
265
265
   "any action on logs will happen at the exact moment of the dump."
266
266
   "Option automatically turns --lock-tables off.",
267
267
   (char**) &opt_slave_data, (char**) &opt_slave_data, 0,
268
 
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
 
268
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL, 0, 0, 0},
269
269
  {"events", 'E', "Dump events.",
270
270
     (char**) &opt_events, (char**) &opt_events, 0, GET_BOOL,
271
271
     NO_ARG, 0, 0, 0, 0, 0, 0},
299
299
   (char**) &flush_logs, (char**) &flush_logs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
300
300
   0, 0},
301
301
  {"flush-privileges", OPT_ESC, "Emit a FLUSH PRIVILEGES statement "
302
 
   "after dumping the mysql database.  This option should be used any "
303
 
   "time the dump contains the mysql database and any other database "
304
 
   "that depends on the data in the mysql database for proper restore. ",
 
302
   "after dumping the DRIZZLE database.  This option should be used any "
 
303
   "time the dump contains the DRIZZLE database and any other database "
 
304
   "that depends on the data in the DRIZZLE database for proper restore. ",
305
305
   (char**) &flush_privileges, (char**) &flush_privileges, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
306
306
   0, 0},
307
307
  {"force", 'f', "Continue even if we get an sql-error.",
319
319
   "use the directive multiple times, once for each table.  Each table must "
320
320
   "be specified with both database and table names, e.g. --ignore-table=database.table",
321
321
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
322
 
  {"include-master-host-port", OPT_MYSQLDUMP_INCLUDE_MASTER_HOST_PORT,
 
322
  {"include-master-host-port", OPT_DRIZZLEDUMP_INCLUDE_MASTER_HOST_PORT,
323
323
   "Adds 'MASTER_HOST=<host>, MASTER_PORT=<port>' to 'CHANGE MASTER TO..' in dump produced with --dump-slave.",
324
324
   (char**) &opt_include_master_host_port, 
325
325
   (char**) &opt_include_master_host_port, 
352
352
   "any action on logs will happen at the exact moment of the dump."
353
353
   "Option automatically turns --lock-tables off.",
354
354
   (char**) &opt_master_data, (char**) &opt_master_data, 0,
355
 
   GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
 
355
   GET_UINT, OPT_ARG, 0, 0, DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0},
356
356
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
357
357
    (char**) &opt_max_allowed_packet, (char**) &opt_max_allowed_packet, 0,
358
358
    GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096,
386
386
  {"password", 'p',
387
387
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
388
388
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
389
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
390
 
   (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
 
389
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
 
390
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
391
391
   0},
392
392
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
393
393
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
394
394
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
395
395
   (char**) &opt_quoted, (char**) &opt_quoted, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
396
396
   0, 0},
397
 
  {"replace", OPT_MYSQL_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
 
397
  {"replace", OPT_DRIZZLE_REPLACE_INTO, "Use REPLACE INTO instead of INSERT INTO.",
398
398
   (char**) &opt_replace_into, (char**) &opt_replace_into, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
399
399
   0, 0},
400
400
  {"result-file", 'r',
457
457
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
458
458
};
459
459
 
460
 
static const char *load_default_groups[]= { "mysqldump","client",0 };
 
460
static const char *load_default_groups[]= { "drizzledump","client",0 };
461
461
 
462
462
static void maybe_exit(int error);
463
463
static void die(int error, const char* reason, ...);
464
464
static void maybe_die(int error, const char* reason, ...);
465
465
static void write_header(FILE *sql_file, char *db_name);
466
 
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
 
466
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
467
467
                        const char *prefix,const char *name,
468
468
                        int string_value);
469
469
static int dump_selected_tables(char *db, char **table_names, int tables);
534
534
  print_version();
535
535
  puts("By Igor Romanenko, Monty, Jani & Sinisa");
536
536
  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");
537
 
  puts("Dumping definition and data mysql database or table");
 
537
  puts("Dumping definition and data DRIZZLE database or table");
538
538
  short_usage_sub();
539
539
  print_defaults("my",load_default_groups);
540
540
  my_print_help(my_long_options);
557
557
      Schema reference.  Allows use of xsi:nil for NULL values and 
558
558
      xsi:type to define an element's data type.
559
559
    */
560
 
    fputs("<mysqldump ", sql_file);
 
560
    fputs("<drizzledump ", sql_file);
561
561
    fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
562
562
          sql_file);
563
563
    fputs(">\n", sql_file);
568
568
    if (opt_comments)
569
569
    {
570
570
      fprintf(sql_file,
571
 
              "-- MySQL dump %s  Distrib %s, for %s (%s)\n--\n",
 
571
              "-- DRIZZLE dump %s  Distrib %s, for %s (%s)\n--\n",
572
572
              DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
573
573
      fprintf(sql_file, "-- Host: %s    Database: %s\n",
574
574
              current_host ? current_host : "localhost", db_name ? db_name :
576
576
      fputs("-- ------------------------------------------------------\n",
577
577
            sql_file);
578
578
      fprintf(sql_file, "-- Server version\t%s\n",
579
 
              mysql_get_server_info(&mysql_connection));
 
579
              drizzle_get_server_info(&drizzle_connection));
580
580
    }
581
581
    if (opt_set_charset)
582
582
      fprintf(sql_file,
607
607
{
608
608
  if (opt_xml)
609
609
  {
610
 
    fputs("</mysqldump>\n", sql_file);
 
610
    fputs("</drizzledump>\n", sql_file);
611
611
    check_io(sql_file);
612
612
  }
613
613
  else if (!opt_compact)
714
714
    exit(0);
715
715
  case (int) OPT_MASTER_DATA:
716
716
    if (!argument) /* work like in old versions */
717
 
      opt_master_data= MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL;
 
717
      opt_master_data= DRIZZLE_OPT_MASTER_DATA_EFFECTIVE_SQL;
718
718
    break;
719
 
  case (int) OPT_MYSQLDUMP_SLAVE_DATA:
 
719
  case (int) OPT_DRIZZLEDUMP_SLAVE_DATA:
720
720
    if (!argument) /* work like in old versions */
721
 
      opt_slave_data= MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL;
 
721
      opt_slave_data= DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL;
722
722
    break;
723
723
  case (int) OPT_OPTIMIZE:
724
724
    extended_insert= opt_drop= opt_lock= quick= create_options=
783
783
        Set charset to the default compiled value if it hasn't
784
784
        been reset yet by --default-character-set=xxx.
785
785
      */
786
 
      if (default_charset == mysql_universal_client_charset)
 
786
      if (default_charset == drizzle_universal_client_charset)
787
787
        default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
788
788
      break;
789
789
    }
794
794
static int get_options(int *argc, char ***argv)
795
795
{
796
796
  int ho_error;
797
 
  MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
 
797
  DRIZZLE_PARAMETERS *drizzle_params= drizzle_get_parameters();
798
798
 
799
 
  opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
800
 
  opt_net_buffer_length= *mysql_params->p_net_buffer_length;
 
799
  opt_max_allowed_packet= *drizzle_params->p_max_allowed_packet;
 
800
  opt_net_buffer_length= *drizzle_params->p_net_buffer_length;
801
801
 
802
802
  md_result_file= stdout;
803
803
  load_defaults("my",load_default_groups,argc,argv);
825
825
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
826
826
    return(ho_error);
827
827
 
828
 
  *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
829
 
  *mysql_params->p_net_buffer_length= opt_net_buffer_length;
 
828
  *drizzle_params->p_max_allowed_packet= opt_max_allowed_packet;
 
829
  *drizzle_params->p_net_buffer_length= opt_net_buffer_length;
830
830
  if (debug_info_flag)
831
831
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
832
832
  if (debug_check_flag)
852
852
 
853
853
  /* Ensure consistency of the set of binlog & locking options */
854
854
  if (opt_delete_master_logs && !opt_master_data)
855
 
    opt_master_data= MYSQL_OPT_MASTER_DATA_COMMENTED_SQL;
 
855
    opt_master_data= DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL;
856
856
  if (opt_single_transaction && opt_lock_all_tables)
857
857
  {
858
858
    fprintf(stderr, "%s: You can't use --single-transaction and "
894
894
 
895
895
 
896
896
/*
897
 
** DB_error -- prints mysql error message and exits the program.
 
897
** DB_error -- prints DRIZZLE error message and exits the program.
898
898
*/
899
 
static void DB_error(MYSQL *mysql_arg, const char *when)
 
899
static void DB_error(DRIZZLE *drizzle_arg, const char *when)
900
900
{
901
901
 
902
 
  maybe_die(EX_MYSQLERR, "Got error: %d: %s %s",
903
 
          mysql_errno(mysql_arg), mysql_error(mysql_arg), when);
 
902
  maybe_die(EX_DRIZZLEERR, "Got error: %d: %s %s",
 
903
          drizzle_errno(drizzle_arg), drizzle_error(drizzle_arg), when);
904
904
  return;
905
905
}
906
906
 
974
974
  some.
975
975
 
976
976
  SYNOPSIS
977
 
    mysql_query_with_error_report()
978
 
    mysql_con       connection to use
 
977
    drizzle_query_with_error_report()
 
978
    drizzle_con       connection to use
979
979
    res             if non zero, result will be put there with
980
 
                    mysql_store_result()
 
980
                    drizzle_store_result()
981
981
    query           query to send to server
982
982
 
983
983
  RETURN VALUES
985
985
    1               error
986
986
*/
987
987
 
988
 
static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
 
988
static int drizzle_query_with_error_report(DRIZZLE *drizzle_con, DRIZZLE_RES **res,
989
989
                                         const char *query)
990
990
{
991
 
  if (mysql_query(mysql_con, query) ||
992
 
      (res && !((*res)= mysql_store_result(mysql_con))))
 
991
  if (drizzle_query(drizzle_con, query) ||
 
992
      (res && !((*res)= drizzle_store_result(drizzle_con))))
993
993
  {
994
 
    maybe_die(EX_MYSQLERR, "Couldn't execute '%s': %s (%d)",
995
 
            query, mysql_error(mysql_con), mysql_errno(mysql_con));
 
994
    maybe_die(EX_DRIZZLEERR, "Couldn't execute '%s': %s (%d)",
 
995
            query, drizzle_error(drizzle_con), drizzle_errno(drizzle_con));
996
996
    return 1;
997
997
  }
998
998
  return 0;
1011
1011
 
1012
1012
  @returns  whether there was an error or not
1013
1013
*/
1014
 
static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
 
1014
static int switch_character_set_results(DRIZZLE *drizzle, const char *cs_name)
1015
1015
{
1016
1016
  char query_buffer[QUERY_LENGTH];
1017
1017
  size_t query_length;
1025
1025
                         "SET SESSION character_set_results = '%s'",
1026
1026
                         (const char *) cs_name);
1027
1027
 
1028
 
  return mysql_real_query(mysql, query_buffer, query_length);
 
1028
  return drizzle_real_query(drizzle, query_buffer, query_length);
1029
1029
}
1030
1030
 
1031
1031
/*
1073
1073
    first_error= error;
1074
1074
  if (ignore_errors)
1075
1075
    return;
1076
 
  if (mysql)
1077
 
    mysql_close(mysql);
 
1076
  if (drizzle)
 
1077
    drizzle_close(drizzle);
1078
1078
  free_resources();
1079
1079
  exit(error);
1080
1080
}
1090
1090
 
1091
1091
 
1092
1092
  verbose_msg("-- Connecting to %s...\n", host ? host : "localhost");
1093
 
  mysql_init(&mysql_connection);
 
1093
  drizzle_create(&drizzle_connection);
1094
1094
  if (opt_compress)
1095
 
    mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
 
1095
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_COMPRESS,NullS);
1096
1096
  if (opt_protocol)
1097
 
    mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
1098
 
  mysql_options(&mysql_connection, MYSQL_SET_CHARSET_NAME, default_charset);
1099
 
  if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd,
1100
 
                                  NULL,opt_mysql_port, NULL,
 
1097
    drizzle_options(&drizzle_connection,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
 
1098
  drizzle_options(&drizzle_connection, DRIZZLE_SET_CHARSET_NAME, default_charset);
 
1099
  if (!(drizzle= drizzle_connect(&drizzle_connection,host,user,passwd,
 
1100
                                  NULL,opt_drizzle_port, NULL,
1101
1101
                                  0)))
1102
1102
  {
1103
 
    DB_error(&mysql_connection, "when trying to connect");
 
1103
    DB_error(&drizzle_connection, "when trying to connect");
1104
1104
    return(1);
1105
1105
  }
1106
 
  if (mysql_get_server_version(&mysql_connection) < 40100)
 
1106
  if (drizzle_get_server_version(&drizzle_connection) < 40100)
1107
1107
  {
1108
1108
    /* Don't dump SET NAMES with a pre-4.1 server (bug#7997).  */
1109
1109
    opt_set_charset= 0;
1118
1118
  if (opt_tz_utc)
1119
1119
  {
1120
1120
    snprintf(buff, sizeof(buff), "/*!40103 SET TIME_ZONE='+00:00' */");
1121
 
    if (mysql_query_with_error_report(mysql, 0, buff))
 
1121
    if (drizzle_query_with_error_report(drizzle, 0, buff))
1122
1122
      return(1);
1123
1123
  }
1124
1124
  return(0);
1131
1131
static void dbDisconnect(char *host)
1132
1132
{
1133
1133
  verbose_msg("-- Disconnecting from %s...\n", host ? host : "localhost");
1134
 
  mysql_close(mysql);
 
1134
  drizzle_close(drizzle);
1135
1135
} /* dbDisconnect */
1136
1136
 
1137
1137
 
1140
1140
  char *tmp;
1141
1141
 
1142
1142
  if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
1143
 
    die(EX_MYSQLERR, "Couldn't allocate memory");
 
1143
    die(EX_DRIZZLEERR, "Couldn't allocate memory");
1144
1144
 
1145
 
  mysql_real_escape_string(&mysql_connection, tmp, pos, length);
 
1145
  drizzle_real_escape_string(&drizzle_connection, tmp, pos, length);
1146
1146
  fputc('\'', file);
1147
1147
  fputs(tmp, file);
1148
1148
  fputc('\'', file);
1209
1209
  DESCRIPTION
1210
1210
    Quote \, _, ' and % characters
1211
1211
 
1212
 
    Note: Because MySQL uses the C escape syntax in strings
 
1212
    Note: Because DRIZZLE uses the C escape syntax in strings
1213
1213
    (for example, '\n' to represent newline), you must double
1214
1214
    any '\' that you use in your LIKE  strings. For example, to
1215
1215
    search for '\n', specify it as '\\n'. To search for '\', specify
1399
1399
*/
1400
1400
 
1401
1401
static void print_xml_row(FILE *xml_file, const char *row_name,
1402
 
                          MYSQL_RES *tableRes, MYSQL_ROW *row)
 
1402
                          DRIZZLE_RES *tableRes, DRIZZLE_ROW *row)
1403
1403
{
1404
1404
  uint i;
1405
 
  MYSQL_FIELD *field;
1406
 
  uint32_t *lengths= mysql_fetch_lengths(tableRes);
 
1405
  DRIZZLE_FIELD *field;
 
1406
  uint32_t *lengths= drizzle_fetch_lengths(tableRes);
1407
1407
 
1408
1408
  fprintf(xml_file, "\t\t<%s", row_name);
1409
1409
  check_io(xml_file);
1410
 
  mysql_field_seek(tableRes, 0);
1411
 
  for (i= 0; (field= mysql_fetch_field(tableRes)); i++)
 
1410
  drizzle_field_seek(tableRes, 0);
 
1411
  for (i= 0; (field= drizzle_fetch_field(tableRes)); i++)
1412
1412
  {
1413
1413
    if ((*row)[i])
1414
1414
    {
1473
1473
  char       table_buff2[NAME_LEN*2+3], query_buff[QUERY_LENGTH];
1474
1474
  FILE       *sql_file= md_result_file;
1475
1475
  int        len;
1476
 
  MYSQL_RES  *result;
1477
 
  MYSQL_ROW  row;
 
1476
  DRIZZLE_RES  *result;
 
1477
  DRIZZLE_ROW  row;
1478
1478
 
1479
1479
  *ignore_flag= check_if_ignore_table(table, table_type);
1480
1480
 
1517
1517
    order_by= primary_key_fields(result_table);
1518
1518
  }
1519
1519
 
1520
 
  if (!opt_xml && !mysql_query_with_error_report(mysql, 0, query_buff))
 
1520
  if (!opt_xml && !drizzle_query_with_error_report(drizzle, 0, query_buff))
1521
1521
  {
1522
1522
    /* using SHOW CREATE statement */
1523
1523
    if (!opt_no_create_info)
1524
1524
    {
1525
1525
      /* Make an sql-file, if path was given iow. option -T was given */
1526
1526
      char buff[20+FN_REFLEN];
1527
 
      MYSQL_FIELD *field;
 
1527
      DRIZZLE_FIELD *field;
1528
1528
 
1529
1529
      snprintf(buff, sizeof(buff), "show create table %s", result_table);
1530
1530
 
1531
 
      if (switch_character_set_results(mysql, "binary") ||
1532
 
          mysql_query_with_error_report(mysql, &result, buff) ||
1533
 
          switch_character_set_results(mysql, default_charset))
 
1531
      if (switch_character_set_results(drizzle, "binary") ||
 
1532
          drizzle_query_with_error_report(drizzle, &result, buff) ||
 
1533
          switch_character_set_results(drizzle, default_charset))
1534
1534
        return(0);
1535
1535
 
1536
1536
      if (path)
1561
1561
        check_io(sql_file);
1562
1562
      }
1563
1563
 
1564
 
      field= mysql_fetch_field_direct(result, 0);
 
1564
      field= drizzle_fetch_field_direct(result, 0);
1565
1565
      if (strcmp(field->name, "View") == 0)
1566
1566
      {
1567
1567
        char *scv_buff= NULL;
1569
1569
        verbose_msg("-- It's a view, create dummy table for view\n");
1570
1570
 
1571
1571
        /* save "show create" statement for later */
1572
 
        if ((row= mysql_fetch_row(result)) && (scv_buff=row[1]))
 
1572
        if ((row= drizzle_fetch_row(result)) && (scv_buff=row[1]))
1573
1573
          scv_buff= my_strdup(scv_buff, MYF(0));
1574
1574
 
1575
 
        mysql_free_result(result);
 
1575
        drizzle_free_result(result);
1576
1576
 
1577
1577
        /*
1578
1578
          Create a table with the same name as the view and with columns of
1587
1587
        */
1588
1588
        snprintf(query_buff, sizeof(query_buff),
1589
1589
                 "SHOW FIELDS FROM %s", result_table);
1590
 
        if (switch_character_set_results(mysql, "binary") ||
1591
 
            mysql_query_with_error_report(mysql, &result, query_buff) ||
1592
 
            switch_character_set_results(mysql, default_charset))
 
1590
        if (switch_character_set_results(drizzle, "binary") ||
 
1591
            drizzle_query_with_error_report(drizzle, &result, query_buff) ||
 
1592
            switch_character_set_results(drizzle, default_charset))
1593
1593
        {
1594
1594
          /*
1595
1595
            View references invalid or privileged table/col/fun (err 1356),
1597
1597
            a comment with the view's 'show create' statement. (Bug #17371)
1598
1598
          */
1599
1599
 
1600
 
          if (mysql_errno(mysql) == ER_VIEW_INVALID)
 
1600
          if (drizzle_errno(drizzle) == ER_VIEW_INVALID)
1601
1601
            fprintf(sql_file, "\n-- failed on view %s: %s\n\n", result_table, scv_buff ? scv_buff : "");
1602
1602
 
1603
1603
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1607
1607
        else
1608
1608
          my_free(scv_buff, MYF(MY_ALLOW_ZERO_PTR));
1609
1609
 
1610
 
        if (mysql_num_rows(result))
 
1610
        if (drizzle_num_rows(result))
1611
1611
        {
1612
1612
          if (opt_drop)
1613
1613
          {
1633
1633
            there should be a _trailing_ comma.
1634
1634
          */
1635
1635
 
1636
 
          row= mysql_fetch_row(result);
 
1636
          row= drizzle_fetch_row(result);
1637
1637
 
1638
1638
          fprintf(sql_file, "  %s %s", quote_name(row[0], name_buff, 0),
1639
1639
                  row[1]);
1640
1640
 
1641
 
          while((row= mysql_fetch_row(result)))
 
1641
          while((row= drizzle_fetch_row(result)))
1642
1642
          {
1643
1643
            /* col name, col type */
1644
1644
            fprintf(sql_file, ",\n  %s %s",
1651
1651
          check_io(sql_file);
1652
1652
        }
1653
1653
 
1654
 
        mysql_free_result(result);
 
1654
        drizzle_free_result(result);
1655
1655
 
1656
1656
        if (path)
1657
1657
          my_fclose(sql_file, MYF(MY_WME));
1660
1660
        return(0);
1661
1661
      }
1662
1662
 
1663
 
      row= mysql_fetch_row(result);
 
1663
      row= drizzle_fetch_row(result);
1664
1664
 
1665
1665
      fprintf(sql_file,
1666
1666
              "SET @saved_cs_client     = @@character_set_client;\n"
1670
1670
              row[1]);
1671
1671
 
1672
1672
      check_io(sql_file);
1673
 
      mysql_free_result(result);
 
1673
      drizzle_free_result(result);
1674
1674
    }
1675
1675
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1676
1676
             result_table);
1677
 
    if (mysql_query_with_error_report(mysql, &result, query_buff))
 
1677
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1678
1678
    {
1679
1679
      if (path)
1680
1680
        my_fclose(sql_file, MYF(MY_WME));
1708
1708
      }
1709
1709
    }
1710
1710
 
1711
 
    while ((row= mysql_fetch_row(result)))
 
1711
    while ((row= drizzle_fetch_row(result)))
1712
1712
    {
1713
1713
      if (complete_insert)
1714
1714
      {
1721
1721
                      quote_name(row[SHOW_FIELDNAME], name_buff, 0));
1722
1722
      }
1723
1723
    }
1724
 
    num_fields= mysql_num_rows(result);
1725
 
    mysql_free_result(result);
 
1724
    num_fields= drizzle_num_rows(result);
 
1725
    drizzle_free_result(result);
1726
1726
  }
1727
1727
  else
1728
1728
  {
1729
1729
    verbose_msg("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
1730
 
                my_progname, mysql_error(mysql));
 
1730
                my_progname, drizzle_error(drizzle));
1731
1731
 
1732
1732
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1733
1733
             result_table);
1734
 
    if (mysql_query_with_error_report(mysql, &result, query_buff))
 
1734
    if (drizzle_query_with_error_report(drizzle, &result, query_buff))
1735
1735
      return(0);
1736
1736
 
1737
1737
    /* Make an sql-file, if path was given iow. option -T was given */
1775
1775
      }
1776
1776
    }
1777
1777
 
1778
 
    while ((row= mysql_fetch_row(result)))
 
1778
    while ((row= drizzle_fetch_row(result)))
1779
1779
    {
1780
 
      uint32_t *lengths= mysql_fetch_lengths(result);
 
1780
      uint32_t *lengths= drizzle_fetch_lengths(result);
1781
1781
      if (init)
1782
1782
      {
1783
1783
        if (!opt_xml && !opt_no_create_info)
1820
1820
        check_io(sql_file);
1821
1821
      }
1822
1822
    }
1823
 
    num_fields= mysql_num_rows(result);
1824
 
    mysql_free_result(result);
 
1823
    num_fields= drizzle_num_rows(result);
 
1824
    drizzle_free_result(result);
1825
1825
    if (!opt_no_create_info)
1826
1826
    {
1827
1827
      /* Make an sql-file, if path was given iow. option -T was given */
1828
1828
      char buff[20+FN_REFLEN];
1829
1829
      uint keynr,primary_key;
1830
1830
      snprintf(buff, sizeof(buff), "show keys from %s", result_table);
1831
 
      if (mysql_query_with_error_report(mysql, &result, buff))
 
1831
      if (drizzle_query_with_error_report(drizzle, &result, buff))
1832
1832
      {
1833
 
        if (mysql_errno(mysql) == ER_WRONG_OBJECT)
 
1833
        if (drizzle_errno(drizzle) == ER_WRONG_OBJECT)
1834
1834
        {
1835
1835
          /* it is VIEW */
1836
1836
          fputs("\t\t<options Comment=\"view\" />\n", sql_file);
1837
1837
          goto continue_xml;
1838
1838
        }
1839
1839
        fprintf(stderr, "%s: Can't get keys for table %s (%s)\n",
1840
 
                my_progname, result_table, mysql_error(mysql));
 
1840
                my_progname, result_table, drizzle_error(drizzle));
1841
1841
        if (path)
1842
1842
          my_fclose(sql_file, MYF(MY_WME));
1843
1843
        return(0);
1846
1846
      /* Find first which key is primary key */
1847
1847
      keynr=0;
1848
1848
      primary_key=INT_MAX;
1849
 
      while ((row= mysql_fetch_row(result)))
 
1849
      while ((row= drizzle_fetch_row(result)))
1850
1850
      {
1851
1851
        if (atoi(row[3]) == 1)
1852
1852
        {
1862
1862
          }
1863
1863
        }
1864
1864
      }
1865
 
      mysql_data_seek(result,0);
 
1865
      drizzle_data_seek(result,0);
1866
1866
      keynr=0;
1867
 
      while ((row= mysql_fetch_row(result)))
 
1867
      while ((row= drizzle_fetch_row(result)))
1868
1868
      {
1869
1869
        if (opt_xml)
1870
1870
        {
1892
1892
          fprintf(sql_file, " (%s)",row[7]);      /* Sub key */
1893
1893
        check_io(sql_file);
1894
1894
      }
1895
 
      mysql_free_result(result);
 
1895
      drizzle_free_result(result);
1896
1896
      if (!opt_xml)
1897
1897
      {
1898
1898
        if (keynr)
1901
1901
        check_io(sql_file);
1902
1902
      }
1903
1903
 
1904
 
      /* Get MySQL specific create options */
 
1904
      /* Get DRIZZLE specific create options */
1905
1905
      if (create_options)
1906
1906
      {
1907
1907
        char show_name_buff[NAME_LEN*2+2+24];
1910
1910
        snprintf(buff, sizeof(buff), "show table status like %s",
1911
1911
                 quote_for_like(table, show_name_buff));
1912
1912
 
1913
 
        if (mysql_query_with_error_report(mysql, &result, buff))
 
1913
        if (drizzle_query_with_error_report(drizzle, &result, buff))
1914
1914
        {
1915
 
          if (mysql_errno(mysql) != ER_PARSE_ERROR)
1916
 
          {                                     /* If old MySQL version */
 
1915
          if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
1916
          {                                     /* If old DRIZZLE version */
1917
1917
            verbose_msg("-- Warning: Couldn't get status information for " \
1918
 
                        "table %s (%s)\n", result_table,mysql_error(mysql));
 
1918
                        "table %s (%s)\n", result_table,drizzle_error(drizzle));
1919
1919
          }
1920
1920
        }
1921
 
        else if (!(row= mysql_fetch_row(result)))
 
1921
        else if (!(row= drizzle_fetch_row(result)))
1922
1922
        {
1923
1923
          fprintf(stderr,
1924
1924
                  "Error: Couldn't read status information for table %s (%s)\n",
1925
 
                  result_table,mysql_error(mysql));
 
1925
                  result_table,drizzle_error(drizzle));
1926
1926
        }
1927
1927
        else
1928
1928
        {
1938
1938
            check_io(sql_file);
1939
1939
          }
1940
1940
        }
1941
 
        mysql_free_result(result);              /* Is always safe to free */
 
1941
        drizzle_free_result(result);              /* Is always safe to free */
1942
1942
      }
1943
1943
continue_xml:
1944
1944
      if (!opt_xml)
2010
2010
    {
2011
2011
      if (*from == '\'' && !end_backslashes)
2012
2012
      {
2013
 
        /* We want a duplicate of "'" for MySQL */
 
2013
        /* We want a duplicate of "'" for DRIZZLE */
2014
2014
        dynstr_append_checked(in, "\'");
2015
2015
      }
2016
2016
      end_backslashes=0;
2052
2052
  int error= 0;
2053
2053
  ulong         rownr, row_break, total_length, init_length;
2054
2054
  uint num_fields;
2055
 
  MYSQL_RES     *res;
2056
 
  MYSQL_FIELD   *field;
2057
 
  MYSQL_ROW     row;
 
2055
  DRIZZLE_RES     *res;
 
2056
  DRIZZLE_FIELD   *field;
 
2057
  DRIZZLE_ROW     row;
2058
2058
 
2059
2059
 
2060
2060
  /*
2162
2162
      dynstr_append_checked(&query_string, order_by);
2163
2163
    }
2164
2164
 
2165
 
    if (mysql_real_query(mysql, query_string.str, query_string.length))
 
2165
    if (drizzle_real_query(drizzle, query_string.str, query_string.length))
2166
2166
    {
2167
 
      DB_error(mysql, "when executing 'SELECT INTO OUTFILE'");
 
2167
      DB_error(drizzle, "when executing 'SELECT INTO OUTFILE'");
2168
2168
      dynstr_free(&query_string);
2169
2169
      return;
2170
2170
    }
2208
2208
      fputs("\n", md_result_file);
2209
2209
      check_io(md_result_file);
2210
2210
    }
2211
 
    if (mysql_query_with_error_report(mysql, 0, query_string.str))
 
2211
    if (drizzle_query_with_error_report(drizzle, 0, query_string.str))
2212
2212
    {
2213
 
      DB_error(mysql, "when retrieving data from server");
 
2213
      DB_error(drizzle, "when retrieving data from server");
2214
2214
      goto err;
2215
2215
    }
2216
2216
    if (quick)
2217
 
      res=mysql_use_result(mysql);
 
2217
      res=drizzle_use_result(drizzle);
2218
2218
    else
2219
 
      res=mysql_store_result(mysql);
 
2219
      res=drizzle_store_result(drizzle);
2220
2220
    if (!res)
2221
2221
    {
2222
 
      DB_error(mysql, "when retrieving data from server");
 
2222
      DB_error(drizzle, "when retrieving data from server");
2223
2223
      goto err;
2224
2224
    }
2225
2225
 
2226
2226
    verbose_msg("-- Retrieving rows...\n");
2227
 
    if (mysql_num_fields(res) != num_fields)
 
2227
    if (drizzle_num_fields(res) != num_fields)
2228
2228
    {
2229
2229
      fprintf(stderr,"%s: Error in field count for table: %s !  Aborting.\n",
2230
2230
              my_progname, result_table);
2258
2258
      check_io(md_result_file);
2259
2259
    }
2260
2260
 
2261
 
    while ((row= mysql_fetch_row(res)))
 
2261
    while ((row= drizzle_fetch_row(res)))
2262
2262
    {
2263
2263
      uint i;
2264
 
      uint32_t *lengths= mysql_fetch_lengths(res);
 
2264
      uint32_t *lengths= drizzle_fetch_lengths(res);
2265
2265
      rownr++;
2266
2266
      if (!extended_insert && !opt_xml)
2267
2267
      {
2268
2268
        fputs(insert_pat.str,md_result_file);
2269
2269
        check_io(md_result_file);
2270
2270
      }
2271
 
      mysql_field_seek(res,0);
 
2271
      drizzle_field_seek(res,0);
2272
2272
 
2273
2273
      if (opt_xml)
2274
2274
      {
2276
2276
        check_io(md_result_file);
2277
2277
      }
2278
2278
 
2279
 
      for (i= 0; i < mysql_num_fields(res); i++)
 
2279
      for (i= 0; i < drizzle_num_fields(res); i++)
2280
2280
      {
2281
2281
        int is_blob;
2282
2282
        ulong length= lengths[i];
2283
2283
 
2284
 
        if (!(field= mysql_fetch_field(res)))
 
2284
        if (!(field= drizzle_fetch_field(res)))
2285
2285
          die(EX_CONSCHECK,
2286
2286
                      "Not enough fields from table %s! Aborting.\n",
2287
2287
                      result_table);
2320
2320
                if (opt_hex_blob && is_blob)
2321
2321
                {
2322
2322
                  dynstr_append_checked(&extended_row, "0x");
2323
 
                  extended_row.length+= mysql_hex_string(extended_row.str +
 
2323
                  extended_row.length+= drizzle_hex_string(extended_row.str +
2324
2324
                                                         extended_row.length,
2325
2325
                                                         row[i], length);
2326
2326
                  assert(extended_row.length+1 <= extended_row.max_length);
2327
 
                  /* mysql_hex_string() already terminated string by '\0' */
 
2327
                  /* drizzle_hex_string() already terminated string by '\0' */
2328
2328
                  assert(extended_row.str[extended_row.length] == '\0');
2329
2329
                }
2330
2330
                else
2331
2331
                {
2332
2332
                  dynstr_append_checked(&extended_row,"'");
2333
2333
                  extended_row.length +=
2334
 
                  mysql_real_escape_string(&mysql_connection,
 
2334
                  drizzle_real_escape_string(&drizzle_connection,
2335
2335
                                           &extended_row.str[extended_row.length],
2336
2336
                                           row[i],length);
2337
2337
                  extended_row.str[extended_row.length]='\0';
2468
2468
      fputs(";\n", md_result_file);             /* If not empty table */
2469
2469
    fflush(md_result_file);
2470
2470
    check_io(md_result_file);
2471
 
    if (mysql_errno(mysql))
 
2471
    if (drizzle_errno(drizzle))
2472
2472
    {
2473
2473
      snprintf(buf, sizeof(buf),
2474
2474
               "%s: Error %d: %s when dumping table %s at row: %ld\n",
2475
2475
               my_progname,
2476
 
               mysql_errno(mysql),
2477
 
               mysql_error(mysql),
 
2476
               drizzle_errno(drizzle),
 
2477
               drizzle_error(drizzle),
2478
2478
               result_table,
2479
2479
               rownr);
2480
2480
      fputs(buf,stderr);
2499
2499
      fprintf(md_result_file, "commit;\n");
2500
2500
      check_io(md_result_file);
2501
2501
    }
2502
 
    mysql_free_result(res);
 
2502
    drizzle_free_result(res);
2503
2503
  }
2504
2504
  dynstr_free(&query_string);
2505
2505
  return;
2513
2513
 
2514
2514
static char *getTableName(int reset)
2515
2515
{
2516
 
  static MYSQL_RES *res= NULL;
2517
 
  MYSQL_ROW    row;
 
2516
  static DRIZZLE_RES *res= NULL;
 
2517
  DRIZZLE_ROW    row;
2518
2518
 
2519
2519
  if (!res)
2520
2520
  {
2521
 
    if (!(res= mysql_list_tables(mysql,NullS)))
 
2521
    if (!(res= drizzle_list_tables(drizzle,NullS)))
2522
2522
      return(NULL);
2523
2523
  }
2524
 
  if ((row= mysql_fetch_row(res)))
 
2524
  if ((row= drizzle_fetch_row(res)))
2525
2525
    return((char*) row[0]);
2526
2526
 
2527
2527
  if (reset)
2528
 
    mysql_data_seek(res,0);      /* We want to read again */
 
2528
    drizzle_data_seek(res,0);      /* We want to read again */
2529
2529
  else
2530
2530
  {
2531
 
    mysql_free_result(res);
 
2531
    drizzle_free_result(res);
2532
2532
    res= NULL;
2533
2533
  }
2534
2534
  return(NULL);
2537
2537
 
2538
2538
static int dump_all_databases()
2539
2539
{
2540
 
  MYSQL_ROW row;
2541
 
  MYSQL_RES *tableres;
 
2540
  DRIZZLE_ROW row;
 
2541
  DRIZZLE_RES *tableres;
2542
2542
  int result=0;
2543
2543
 
2544
 
  if (mysql_query_with_error_report(mysql, &tableres, "SHOW DATABASES"))
 
2544
  if (drizzle_query_with_error_report(drizzle, &tableres, "SHOW DATABASES"))
2545
2545
    return 1;
2546
 
  while ((row= mysql_fetch_row(tableres)))
 
2546
  while ((row= drizzle_fetch_row(tableres)))
2547
2547
  {
2548
2548
    if (dump_all_tables_in_db(row[0]))
2549
2549
      result=1;
2587
2587
  if (!opt_create_db)
2588
2588
  {
2589
2589
    char qbuf[256];
2590
 
    MYSQL_ROW row;
2591
 
    MYSQL_RES *dbinfo;
 
2590
    DRIZZLE_ROW row;
 
2591
    DRIZZLE_RES *dbinfo;
2592
2592
 
2593
2593
    snprintf(qbuf, sizeof(qbuf),
2594
2594
             "SHOW CREATE DATABASE IF NOT EXISTS %s",
2595
2595
             qdatabase);
2596
2596
 
2597
 
    if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
 
2597
    if (drizzle_query(drizzle, qbuf) || !(dbinfo = drizzle_store_result(drizzle)))
2598
2598
    {
2599
2599
      /* Old server version, dump generic CREATE DATABASE */
2600
2600
      if (opt_drop_database)
2611
2611
        fprintf(md_result_file,
2612
2612
                "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
2613
2613
                qdatabase);
2614
 
      row = mysql_fetch_row(dbinfo);
 
2614
      row = drizzle_fetch_row(dbinfo);
2615
2615
      if (row[1])
2616
2616
      {
2617
2617
        fprintf(md_result_file,"\n%s;\n",row[1]);
2618
2618
      }
2619
 
      mysql_free_result(dbinfo);
 
2619
      drizzle_free_result(dbinfo);
2620
2620
    }
2621
2621
  }
2622
2622
  return(0);
2625
2625
 
2626
2626
static int init_dumping(char *database, int init_func(char*))
2627
2627
{
2628
 
  if (mysql_get_server_version(mysql) >= 50003 &&
 
2628
  if (drizzle_get_server_version(drizzle) >= 50003 &&
2629
2629
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
2630
2630
    return 1;
2631
2631
 
2632
 
  if (mysql_select_db(mysql, database))
 
2632
  if (drizzle_select_db(drizzle, database))
2633
2633
  {
2634
 
    DB_error(mysql, "when selecting the database");
 
2634
    DB_error(drizzle, "when selecting the database");
2635
2635
    return 1;                   /* If --force */
2636
2636
  }
2637
2637
  if (!path && !opt_xml)
2701
2701
        dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
2702
2702
      }
2703
2703
    }
2704
 
    if (numrows && mysql_real_query(mysql, query.str, query.length-1))
2705
 
      DB_error(mysql, "when using LOCK TABLES");
 
2704
    if (numrows && drizzle_real_query(drizzle, query.str, query.length-1))
 
2705
      DB_error(drizzle, "when using LOCK TABLES");
2706
2706
            /* We shall continue here, if --force was given */
2707
2707
    dynstr_free(&query);
2708
2708
  }
2709
2709
  if (flush_logs)
2710
2710
  {
2711
 
    if (mysql_refresh(mysql, REFRESH_LOG))
2712
 
      DB_error(mysql, "when doing refresh");
 
2711
    if (drizzle_refresh(drizzle, REFRESH_LOG))
 
2712
      DB_error(drizzle, "when doing refresh");
2713
2713
           /* We shall continue here, if --force was given */
2714
2714
  }
2715
2715
  while ((table= getTableName(0)))
2728
2728
    check_io(md_result_file);
2729
2729
  }
2730
2730
  if (lock_tables)
2731
 
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
 
2731
    VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2732
2732
  if (flush_privileges && using_mysql_db == 0)
2733
2733
  {
2734
2734
    fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n");
2752
2752
static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root)
2753
2753
{
2754
2754
  char *name= 0;
2755
 
  MYSQL_RES  *table_res;
2756
 
  MYSQL_ROW  row;
 
2755
  DRIZZLE_RES  *table_res;
 
2756
  DRIZZLE_ROW  row;
2757
2757
  char query[50 + 2*NAME_LEN];
2758
2758
  char show_name_buff[FN_REFLEN];
2759
2759
 
2763
2763
  snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
2764
2764
           quote_for_like(old_table_name, show_name_buff));
2765
2765
 
2766
 
  if (mysql_query_with_error_report(mysql, 0, query))
 
2766
  if (drizzle_query_with_error_report(drizzle, 0, query))
2767
2767
    return NullS;
2768
2768
 
2769
 
  if ((table_res= mysql_store_result(mysql)))
 
2769
  if ((table_res= drizzle_store_result(drizzle)))
2770
2770
  {
2771
 
    uint64_t num_rows= mysql_num_rows(table_res);
 
2771
    uint64_t num_rows= drizzle_num_rows(table_res);
2772
2772
    if (num_rows > 0)
2773
2773
    {
2774
2774
      uint32_t *lengths;
2776
2776
        Return first row
2777
2777
        TODO: Return all matching rows
2778
2778
      */
2779
 
      row= mysql_fetch_row(table_res);
2780
 
      lengths= mysql_fetch_lengths(table_res);
 
2779
      row= drizzle_fetch_row(table_res);
 
2780
      lengths= drizzle_fetch_lengths(table_res);
2781
2781
      name= strmake_root(root, row[0], lengths[0]);
2782
2782
    }
2783
 
    mysql_free_result(table_res);
 
2783
    drizzle_free_result(table_res);
2784
2784
  }
2785
2785
  return(name);
2786
2786
}
2830
2830
 
2831
2831
  if (lock_tables)
2832
2832
  {
2833
 
    if (mysql_real_query(mysql, lock_tables_query.str,
 
2833
    if (drizzle_real_query(drizzle, lock_tables_query.str,
2834
2834
                         lock_tables_query.length-1))
2835
2835
    {
2836
2836
      if (!ignore_errors)
2838
2838
        dynstr_free(&lock_tables_query);
2839
2839
        free_root(&root, MYF(0));
2840
2840
      }
2841
 
      DB_error(mysql, "when doing LOCK TABLES");
 
2841
      DB_error(drizzle, "when doing LOCK TABLES");
2842
2842
       /* We shall countinue here, if --force was given */
2843
2843
    }
2844
2844
  }
2845
2845
  dynstr_free(&lock_tables_query);
2846
2846
  if (flush_logs)
2847
2847
  {
2848
 
    if (mysql_refresh(mysql, REFRESH_LOG))
 
2848
    if (drizzle_refresh(drizzle, REFRESH_LOG))
2849
2849
    {
2850
2850
      if (!ignore_errors)
2851
2851
        free_root(&root, MYF(0));
2852
 
      DB_error(mysql, "when doing refresh");
 
2852
      DB_error(drizzle, "when doing refresh");
2853
2853
    }
2854
2854
     /* We shall countinue here, if --force was given */
2855
2855
  }
2869
2869
    check_io(md_result_file);
2870
2870
  }
2871
2871
  if (lock_tables)
2872
 
    VOID(mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"));
 
2872
    VOID(drizzle_query_with_error_report(drizzle, 0, "UNLOCK TABLES"));
2873
2873
  return(0);
2874
2874
} /* dump_selected_tables */
2875
2875
 
2876
2876
 
2877
 
static int do_show_master_status(MYSQL *mysql_con)
 
2877
static int do_show_master_status(DRIZZLE *drizzle_con)
2878
2878
{
2879
 
  MYSQL_ROW row;
2880
 
  MYSQL_RES *master;
 
2879
  DRIZZLE_ROW row;
 
2880
  DRIZZLE_RES *master;
2881
2881
  const char *comment_prefix=
2882
 
    (opt_master_data == MYSQL_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
2883
 
  if (mysql_query_with_error_report(mysql_con, &master, "SHOW MASTER STATUS"))
 
2882
    (opt_master_data == DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL) ? "-- " : "";
 
2883
  if (drizzle_query_with_error_report(drizzle_con, &master, "SHOW MASTER STATUS"))
2884
2884
  {
2885
2885
    return 1;
2886
2886
  }
2887
2887
  else
2888
2888
  {
2889
 
    row= mysql_fetch_row(master);
 
2889
    row= drizzle_fetch_row(master);
2890
2890
    if (row && row[0] && row[1])
2891
2891
    {
2892
2892
      /* SHOW MASTER STATUS reports file and position */
2904
2904
      /* SHOW MASTER STATUS reports nothing and --force is not enabled */
2905
2905
      my_printf_error(0, "Error: Binlogging on server not active",
2906
2906
                      MYF(0));
2907
 
      mysql_free_result(master);
2908
 
      maybe_exit(EX_MYSQLERR);
 
2907
      drizzle_free_result(master);
 
2908
      maybe_exit(EX_DRIZZLEERR);
2909
2909
      return 1;
2910
2910
    }
2911
 
    mysql_free_result(master);
 
2911
    drizzle_free_result(master);
2912
2912
  }
2913
2913
  return 0;
2914
2914
}
2915
2915
 
2916
 
static int do_stop_slave_sql(MYSQL *mysql_con)
 
2916
static int do_stop_slave_sql(DRIZZLE *drizzle_con)
2917
2917
{
2918
 
  MYSQL_RES *slave;
 
2918
  DRIZZLE_RES *slave;
2919
2919
  /* We need to check if the slave sql is running in the first place */
2920
 
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
 
2920
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2921
2921
    return(1);
2922
2922
  else
2923
2923
  {
2924
 
    MYSQL_ROW row= mysql_fetch_row(slave);
 
2924
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2925
2925
    if (row && row[11])
2926
2926
    {
2927
2927
      /* if SLAVE SQL is not running, we don't stop it */
2928
2928
      if (!strcmp(row[11],"No"))
2929
2929
      {
2930
 
        mysql_free_result(slave);
 
2930
        drizzle_free_result(slave);
2931
2931
        /* Silently assume that they don't have the slave running */
2932
2932
        return(0);
2933
2933
      }
2934
2934
    }
2935
2935
  }
2936
 
  mysql_free_result(slave);
 
2936
  drizzle_free_result(slave);
2937
2937
 
2938
2938
  /* now, stop slave if running */
2939
 
  if (mysql_query_with_error_report(mysql_con, 0, "STOP SLAVE SQL_THREAD"))
 
2939
  if (drizzle_query_with_error_report(drizzle_con, 0, "STOP SLAVE SQL_THREAD"))
2940
2940
    return(1);
2941
2941
 
2942
2942
  return(0);
2960
2960
  return(0);
2961
2961
}
2962
2962
 
2963
 
static int do_show_slave_status(MYSQL *mysql_con)
 
2963
static int do_show_slave_status(DRIZZLE *drizzle_con)
2964
2964
{
2965
 
  MYSQL_RES *slave;
 
2965
  DRIZZLE_RES *slave;
2966
2966
  const char *comment_prefix=
2967
 
    (opt_slave_data == MYSQL_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
2968
 
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
 
2967
    (opt_slave_data == DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL) ? "-- " : "";
 
2968
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
2969
2969
  {
2970
2970
    if (!ignore_errors)
2971
2971
    {
2976
2976
  }
2977
2977
  else
2978
2978
  {
2979
 
    MYSQL_ROW row= mysql_fetch_row(slave);
 
2979
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
2980
2980
    if (row && row[9] && row[21])
2981
2981
    {
2982
2982
      /* SHOW MASTER STATUS reports file and position */
2999
2999
 
3000
3000
      check_io(md_result_file);
3001
3001
    }
3002
 
    mysql_free_result(slave);
 
3002
    drizzle_free_result(slave);
3003
3003
  }
3004
3004
  return 0;
3005
3005
}
3006
3006
 
3007
 
static int do_start_slave_sql(MYSQL *mysql_con)
 
3007
static int do_start_slave_sql(DRIZZLE *drizzle_con)
3008
3008
{
3009
 
  MYSQL_RES *slave;
 
3009
  DRIZZLE_RES *slave;
3010
3010
  /* We need to check if the slave sql is stopped in the first place */
3011
 
  if (mysql_query_with_error_report(mysql_con, &slave, "SHOW SLAVE STATUS"))
 
3011
  if (drizzle_query_with_error_report(drizzle_con, &slave, "SHOW SLAVE STATUS"))
3012
3012
    return(1);
3013
3013
  else
3014
3014
  {
3015
 
    MYSQL_ROW row= mysql_fetch_row(slave);
 
3015
    DRIZZLE_ROW row= drizzle_fetch_row(slave);
3016
3016
    if (row && row[11])
3017
3017
    {
3018
3018
      /* if SLAVE SQL is not running, we don't start it */
3019
3019
      if (!strcmp(row[11],"Yes"))
3020
3020
      {
3021
 
        mysql_free_result(slave);
 
3021
        drizzle_free_result(slave);
3022
3022
        /* Silently assume that they don't have the slave running */
3023
3023
        return(0);
3024
3024
      }
3025
3025
    }
3026
3026
  }
3027
 
  mysql_free_result(slave);
 
3027
  drizzle_free_result(slave);
3028
3028
 
3029
3029
  /* now, start slave if stopped */
3030
 
  if (mysql_query_with_error_report(mysql_con, 0, "START SLAVE"))
 
3030
  if (drizzle_query_with_error_report(drizzle_con, 0, "START SLAVE"))
3031
3031
  {
3032
3032
    my_printf_error(0, "Error: Unable to start slave", MYF(0));
3033
3033
    return 1;
3037
3037
 
3038
3038
 
3039
3039
 
3040
 
static int do_flush_tables_read_lock(MYSQL *mysql_con)
 
3040
static int do_flush_tables_read_lock(DRIZZLE *drizzle_con)
3041
3041
{
3042
3042
  /*
3043
3043
    We do first a FLUSH TABLES. If a long update is running, the FLUSH TABLES
3048
3048
    update starts between the two FLUSHes, we have that bad stall.
3049
3049
  */
3050
3050
  return
3051
 
    ( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") ||
3052
 
      mysql_query_with_error_report(mysql_con, 0,
 
3051
    ( drizzle_query_with_error_report(drizzle_con, 0, "FLUSH TABLES") ||
 
3052
      drizzle_query_with_error_report(drizzle_con, 0,
3053
3053
                                    "FLUSH TABLES WITH READ LOCK") );
3054
3054
}
3055
3055
 
3056
3056
 
3057
 
static int do_unlock_tables(MYSQL *mysql_con)
 
3057
static int do_unlock_tables(DRIZZLE *drizzle_con)
3058
3058
{
3059
 
  return mysql_query_with_error_report(mysql_con, 0, "UNLOCK TABLES");
 
3059
  return drizzle_query_with_error_report(drizzle_con, 0, "UNLOCK TABLES");
3060
3060
}
3061
3061
 
3062
 
static int get_bin_log_name(MYSQL *mysql_con,
 
3062
static int get_bin_log_name(DRIZZLE *drizzle_con,
3063
3063
                            char* buff_log_name, uint buff_len)
3064
3064
{
3065
 
  MYSQL_RES *res;
3066
 
  MYSQL_ROW row;
 
3065
  DRIZZLE_RES *res;
 
3066
  DRIZZLE_ROW row;
3067
3067
 
3068
 
  if (mysql_query(mysql_con, "SHOW MASTER STATUS") ||
3069
 
      !(res= mysql_store_result(mysql)))
 
3068
  if (drizzle_query(drizzle_con, "SHOW MASTER STATUS") ||
 
3069
      !(res= drizzle_store_result(drizzle)))
3070
3070
    return 1;
3071
3071
 
3072
 
  if (!(row= mysql_fetch_row(res)))
 
3072
  if (!(row= drizzle_fetch_row(res)))
3073
3073
  {
3074
 
    mysql_free_result(res);
 
3074
    drizzle_free_result(res);
3075
3075
    return 1;
3076
3076
  }
3077
3077
  /*
3080
3080
  */
3081
3081
  strmake(buff_log_name, row[0], buff_len - 1);
3082
3082
 
3083
 
  mysql_free_result(res);
 
3083
  drizzle_free_result(res);
3084
3084
  return 0;
3085
3085
}
3086
3086
 
3087
 
static int purge_bin_logs_to(MYSQL *mysql_con, char* log_name)
 
3087
static int purge_bin_logs_to(DRIZZLE *drizzle_con, char* log_name)
3088
3088
{
3089
3089
  DYNAMIC_STRING str;
3090
3090
  int err;
3091
3091
  init_dynamic_string_checked(&str, "PURGE BINARY LOGS TO '", 1024, 1024);
3092
3092
  dynstr_append_checked(&str, log_name);
3093
3093
  dynstr_append_checked(&str, "'");
3094
 
  err = mysql_query_with_error_report(mysql_con, 0, str.str);
 
3094
  err = drizzle_query_with_error_report(drizzle_con, 0, str.str);
3095
3095
  dynstr_free(&str);
3096
3096
  return err;
3097
3097
}
3098
3098
 
3099
3099
 
3100
 
static int start_transaction(MYSQL *mysql_con)
 
3100
static int start_transaction(DRIZZLE *drizzle_con)
3101
3101
{
3102
3102
  /*
3103
3103
    We use BEGIN for old servers. --single-transaction --master-data will fail
3108
3108
    need the REPEATABLE READ level (not anything lower, for example READ
3109
3109
    COMMITTED would give one new consistent read per dumped table).
3110
3110
  */
3111
 
  if ((mysql_get_server_version(mysql_con) < 40100) && opt_master_data)
 
3111
  if ((drizzle_get_server_version(drizzle_con) < 40100) && opt_master_data)
3112
3112
  {
3113
3113
    fprintf(stderr, "-- %s: the combination of --single-transaction and "
3114
 
            "--master-data requires a MySQL server version of at least 4.1 "
 
3114
            "--master-data requires a DRIZZLE server version of at least 4.1 "
3115
3115
            "(current server's version is %s). %s\n",
3116
3116
            ignore_errors ? "Warning" : "Error",
3117
 
            mysql_con->server_version ? mysql_con->server_version : "unknown",
 
3117
            drizzle_con->server_version ? drizzle_con->server_version : "unknown",
3118
3118
            ignore_errors ? "Continuing due to --force, backup may not be consistent across all tables!" : "Aborting.");
3119
3119
    if (!ignore_errors)
3120
 
      exit(EX_MYSQLERR);
 
3120
      exit(EX_DRIZZLEERR);
3121
3121
  }
3122
3122
 
3123
 
  return (mysql_query_with_error_report(mysql_con, 0,
 
3123
  return (drizzle_query_with_error_report(drizzle_con, 0,
3124
3124
                                        "SET SESSION TRANSACTION ISOLATION "
3125
3125
                                        "LEVEL REPEATABLE READ") ||
3126
 
          mysql_query_with_error_report(mysql_con, 0,
 
3126
          drizzle_query_with_error_report(drizzle_con, 0,
3127
3127
                                        "START TRANSACTION "
3128
3128
                                        "/*!40100 WITH CONSISTENT SNAPSHOT */"));
3129
3129
}
3171
3171
 
3172
3172
 
3173
3173
/* Print a value with a prefix on file */
3174
 
static void print_value(FILE *file, MYSQL_RES  *result, MYSQL_ROW row,
 
3174
static void print_value(FILE *file, DRIZZLE_RES  *result, DRIZZLE_ROW row,
3175
3175
                        const char *prefix, const char *name,
3176
3176
                        int string_value)
3177
3177
{
3178
 
  MYSQL_FIELD   *field;
3179
 
  mysql_field_seek(result, 0);
 
3178
  DRIZZLE_FIELD   *field;
 
3179
  drizzle_field_seek(result, 0);
3180
3180
 
3181
 
  for ( ; (field= mysql_fetch_field(result)) ; row++)
 
3181
  for ( ; (field= drizzle_fetch_field(result)) ; row++)
3182
3182
  {
3183
3183
    if (!strcmp(field->name,name))
3184
3184
    {
3216
3216
    table_type                  Type of table
3217
3217
 
3218
3218
  GLOBAL VARIABLES
3219
 
    mysql                       MySQL connection
 
3219
    drizzle                       Drizzle connection
3220
3220
    verbose                     Write warning messages
3221
3221
 
3222
3222
  RETURN
3227
3227
{
3228
3228
  char result= IGNORE_NONE;
3229
3229
  char buff[FN_REFLEN+80], show_name_buff[FN_REFLEN];
3230
 
  MYSQL_RES *res= NULL;
3231
 
  MYSQL_ROW row;
 
3230
  DRIZZLE_RES *res= NULL;
 
3231
  DRIZZLE_ROW row;
3232
3232
 
3233
3233
 
3234
3234
  /* Check memory for quote_for_like() */
3235
3235
  assert(2*sizeof(table_name) < sizeof(show_name_buff));
3236
3236
  snprintf(buff, sizeof(buff), "show table status like %s",
3237
3237
           quote_for_like(table_name, show_name_buff));
3238
 
  if (mysql_query_with_error_report(mysql, &res, buff))
 
3238
  if (drizzle_query_with_error_report(drizzle, &res, buff))
3239
3239
  {
3240
 
    if (mysql_errno(mysql) != ER_PARSE_ERROR)
3241
 
    {                                   /* If old MySQL version */
 
3240
    if (drizzle_errno(drizzle) != ER_PARSE_ERROR)
 
3241
    {                                   /* If old DRIZZLE version */
3242
3242
      verbose_msg("-- Warning: Couldn't get status information for "
3243
 
                  "table %s (%s)\n", table_name, mysql_error(mysql));
 
3243
                  "table %s (%s)\n", table_name, drizzle_error(drizzle));
3244
3244
      return(result);                       /* assume table is ok */
3245
3245
    }
3246
3246
  }
3247
 
  if (!(row= mysql_fetch_row(res)))
 
3247
  if (!(row= drizzle_fetch_row(res)))
3248
3248
  {
3249
3249
    fprintf(stderr,
3250
3250
            "Error: Couldn't read status information for table %s (%s)\n",
3251
 
            table_name, mysql_error(mysql));
3252
 
    mysql_free_result(res);
 
3251
            table_name, drizzle_error(drizzle));
 
3252
    drizzle_free_result(res);
3253
3253
    return(result);                         /* assume table is ok */
3254
3254
  }
3255
3255
  if (!(row[1]))
3281
3281
         !strcmp(table_type,"MRG_ISAM")))
3282
3282
      result= IGNORE_DATA;
3283
3283
  }
3284
 
  mysql_free_result(res);
 
3284
  drizzle_free_result(res);
3285
3285
  return(result);
3286
3286
}
3287
3287
 
3306
3306
 
3307
3307
static char *primary_key_fields(const char *table_name)
3308
3308
{
3309
 
  MYSQL_RES  *res= NULL;
3310
 
  MYSQL_ROW  row;
 
3309
  DRIZZLE_RES  *res= NULL;
 
3310
  DRIZZLE_ROW  row;
3311
3311
  /* SHOW KEYS FROM + table name * 2 (escaped) + 2 quotes + \0 */
3312
3312
  char show_keys_buff[15 + NAME_LEN * 2 + 3];
3313
3313
  uint result_length= 0;
3317
3317
 
3318
3318
  snprintf(show_keys_buff, sizeof(show_keys_buff),
3319
3319
           "SHOW KEYS FROM %s", table_name);
3320
 
  if (mysql_query(mysql, show_keys_buff) ||
3321
 
      !(res= mysql_store_result(mysql)))
 
3320
  if (drizzle_query(drizzle, show_keys_buff) ||
 
3321
      !(res= drizzle_store_result(drizzle)))
3322
3322
  {
3323
3323
    fprintf(stderr, "Warning: Couldn't read keys from table %s;"
3324
3324
            " records are NOT sorted (%s)\n",
3325
 
            table_name, mysql_error(mysql));
 
3325
            table_name, drizzle_error(drizzle));
3326
3326
    /* Don't exit, because it's better to print out unsorted records */
3327
3327
    goto cleanup;
3328
3328
  }
3333
3333
   * row, and UNIQUE keys come before others.  So we only need to check
3334
3334
   * the first key, not all keys.
3335
3335
   */
3336
 
  if ((row= mysql_fetch_row(res)) && atoi(row[1]) == 0)
 
3336
  if ((row= drizzle_fetch_row(res)) && atoi(row[1]) == 0)
3337
3337
  {
3338
3338
    /* Key is unique */
3339
3339
    do
3340
3340
    {
3341
3341
      quoted_field= quote_name(row[4], buff, 0);
3342
3342
      result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
3343
 
    } while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
 
3343
    } while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1);
3344
3344
  }
3345
3345
 
3346
3346
  /* Build the ORDER BY clause result */
3354
3354
      fprintf(stderr, "Error: Not enough memory to store ORDER BY clause\n");
3355
3355
      goto cleanup;
3356
3356
    }
3357
 
    mysql_data_seek(res, 0);
3358
 
    row= mysql_fetch_row(res);
 
3357
    drizzle_data_seek(res, 0);
 
3358
    row= drizzle_fetch_row(res);
3359
3359
    quoted_field= quote_name(row[4], buff, 0);
3360
3360
    end= strmov(result, quoted_field);
3361
 
    while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1)
 
3361
    while ((row= drizzle_fetch_row(res)) && atoi(row[3]) > 1)
3362
3362
    {
3363
3363
      quoted_field= quote_name(row[4], buff, 0);
3364
3364
      end= strxmov(end, ",", quoted_field, NullS);
3367
3367
 
3368
3368
cleanup:
3369
3369
  if (res)
3370
 
    mysql_free_result(res);
 
3370
    drizzle_free_result(res);
3371
3371
 
3372
3372
  return result;
3373
3373
}
3383
3383
                            uint init_alloc, uint alloc_increment)
3384
3384
{
3385
3385
  if (init_dynamic_string(str, init_str, init_alloc, alloc_increment))
3386
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3386
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3387
3387
}
3388
3388
 
3389
3389
static void dynstr_append_checked(DYNAMIC_STRING* dest, const char* src)
3390
3390
{
3391
3391
  if (dynstr_append(dest, src))
3392
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3392
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3393
3393
}
3394
3394
 
3395
3395
static void dynstr_set_checked(DYNAMIC_STRING *str, const char *init_str)
3396
3396
{
3397
3397
  if (dynstr_set(str, init_str))
3398
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3398
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3399
3399
}
3400
3400
 
3401
3401
static void dynstr_append_mem_checked(DYNAMIC_STRING *str, const char *append,
3402
3402
                          uint length)
3403
3403
{
3404
3404
  if (dynstr_append_mem(str, append, length))
3405
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3405
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3406
3406
}
3407
3407
 
3408
3408
static void dynstr_realloc_checked(DYNAMIC_STRING *str, ulong additional_size)
3409
3409
{
3410
3410
  if (dynstr_realloc(str, additional_size))
3411
 
    die(EX_MYSQLERR, DYNAMIC_STR_ERROR_MSG);
 
3411
    die(EX_DRIZZLEERR, DYNAMIC_STR_ERROR_MSG);
3412
3412
}
3413
3413
 
3414
3414
 
3419
3419
  MY_INIT("mysqldump");
3420
3420
 
3421
3421
  compatible_mode_normal_str[0]= 0;
3422
 
  default_charset= (char *)mysql_universal_client_charset;
 
3422
  default_charset= (char *)drizzle_universal_client_charset;
3423
3423
  bzero((char*) &ignore_table, sizeof(ignore_table));
3424
3424
 
3425
3425
  exit_code= get_options(&argc, &argv);
3434
3434
    if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
3435
3435
    {
3436
3436
      free_resources();
3437
 
      exit(EX_MYSQLERR);
 
3437
      exit(EX_DRIZZLEERR);
3438
3438
    }
3439
3439
  }
3440
3440
 
3441
3441
  if (connect_to_db(current_host, current_user, opt_password))
3442
3442
  {
3443
3443
    free_resources();
3444
 
    exit(EX_MYSQLERR);
 
3444
    exit(EX_DRIZZLEERR);
3445
3445
  }
3446
3446
  if (!path)
3447
3447
    write_header(md_result_file, *argv);
3448
3448
 
3449
 
  if (opt_slave_data && do_stop_slave_sql(mysql))
 
3449
  if (opt_slave_data && do_stop_slave_sql(drizzle))
3450
3450
    goto err;
3451
3451
 
3452
3452
  if ((opt_lock_all_tables || opt_master_data) &&
3453
 
      do_flush_tables_read_lock(mysql))
 
3453
      do_flush_tables_read_lock(drizzle))
3454
3454
    goto err;
3455
 
  if (opt_single_transaction && start_transaction(mysql))
 
3455
  if (opt_single_transaction && start_transaction(drizzle))
3456
3456
      goto err;
3457
3457
  if (opt_delete_master_logs)
3458
3458
  {
3459
 
    if (mysql_refresh(mysql, REFRESH_LOG) ||
3460
 
        get_bin_log_name(mysql, bin_log_name, sizeof(bin_log_name)))
 
3459
    if (drizzle_refresh(drizzle, REFRESH_LOG) ||
 
3460
        get_bin_log_name(drizzle, bin_log_name, sizeof(bin_log_name)))
3461
3461
      goto err;
3462
3462
    flush_logs= 0;
3463
3463
  }
3464
3464
  if (opt_lock_all_tables || opt_master_data)
3465
3465
  {
3466
 
    if (flush_logs && mysql_refresh(mysql, REFRESH_LOG))
 
3466
    if (flush_logs && drizzle_refresh(drizzle, REFRESH_LOG))
3467
3467
      goto err;
3468
3468
    flush_logs= 0; /* not anymore; that would not be sensible */
3469
3469
  }
3470
3470
  /* Add 'STOP SLAVE to beginning of dump */
3471
3471
  if (opt_slave_apply && add_stop_slave())
3472
3472
    goto err;
3473
 
  if (opt_master_data && do_show_master_status(mysql))
3474
 
    goto err;
3475
 
  if (opt_slave_data && do_show_slave_status(mysql))
3476
 
    goto err;
3477
 
  if (opt_single_transaction && do_unlock_tables(mysql)) /* unlock but no commit! */
 
3473
  if (opt_master_data && do_show_master_status(drizzle))
 
3474
    goto err;
 
3475
  if (opt_slave_data && do_show_slave_status(drizzle))
 
3476
    goto err;
 
3477
  if (opt_single_transaction && do_unlock_tables(drizzle)) /* unlock but no commit! */
3478
3478
    goto err;
3479
3479
 
3480
3480
  if (opt_alldbs)
3492
3492
  }
3493
3493
 
3494
3494
  /* if --dump-slave , start the slave sql thread */
3495
 
  if (opt_slave_data && do_start_slave_sql(mysql))
 
3495
  if (opt_slave_data && do_start_slave_sql(drizzle))
3496
3496
    goto err;
3497
3497
 
3498
3498
  /* add 'START SLAVE' to end of dump */
3503
3503
  if (md_result_file && fflush(md_result_file))
3504
3504
  {
3505
3505
    if (!first_error)
3506
 
      first_error= EX_MYSQLERR;
 
3506
      first_error= EX_DRIZZLEERR;
3507
3507
    goto err;
3508
3508
  }
3509
3509
  /* everything successful, purge the old logs files */
3510
 
  if (opt_delete_master_logs && purge_bin_logs_to(mysql, bin_log_name))
 
3510
  if (opt_delete_master_logs && purge_bin_logs_to(drizzle, bin_log_name))
3511
3511
    goto err;
3512
3512
 
3513
3513
  /*