~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

  • Committer: Monty Taylor
  • Date: 2008-12-30 17:53:54 UTC
  • mfrom: (673.5.15 usability-cli-port)
  • mto: This revision was merged to the branch mainline in revision 755.
  • Revision ID: mordred@inaugust.com-20081230175354-4z4p06vztdxdjjri
Merged from LinuxJedi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <mysys/hash.h>
36
36
#include <stdarg.h>
37
37
 
 
38
#include <drizzled/gettext.h>
 
39
 
38
40
#include <drizzled/error.h>
39
41
 
40
42
using namespace std;
69
71
                      char **err_pos, uint *err_len);
70
72
 
71
73
static void field_escape(string &in, const char *from);
72
 
static bool  verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
73
 
                quick= 1, extended_insert= 1,
74
 
                lock_tables=1,ignore_errors=0,flush_logs=0,
75
 
                opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0,
76
 
                opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0,
77
 
                opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0,
78
 
                opt_set_charset=0, opt_dump_date=1,
79
 
                opt_autocommit=0,opt_disable_keys=1,opt_xml=0,
80
 
                opt_delete_master_logs=0, tty_password=0,
81
 
                opt_single_transaction=0, opt_comments= 0, opt_compact= 0,
82
 
                opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0,
83
 
                opt_complete_insert= 0, opt_drop_database= 0,
84
 
                opt_replace_into= 0,
85
 
                opt_routines=0,
86
 
                opt_slave_apply= 0,
87
 
                opt_include_master_host_port= 0,
88
 
                opt_alltspcs=0;
89
 
static bool debug_info_flag= 0, debug_check_flag= 0;
 
74
static bool  verbose= false, opt_no_create_info= false, opt_no_data= false,
 
75
                quick= true, extended_insert= true,
 
76
                lock_tables= true, ignore_errors= false, flush_logs= false,
 
77
                opt_drop= true, opt_keywords= false,
 
78
                opt_lock= true, opt_compress= false,
 
79
                opt_delayed= false, create_options= true, opt_quoted= false,
 
80
                opt_databases= false, opt_alldbs= false, opt_create_db= false,
 
81
                opt_lock_all_tables= false,
 
82
                opt_set_charset= false, opt_dump_date= true,
 
83
                opt_autocommit= false, opt_disable_keys= true, opt_xml= false,
 
84
                opt_delete_master_logs= false, tty_password= false,
 
85
                opt_single_transaction= false, opt_comments= false,
 
86
                opt_compact= false, opt_hex_blob= false, 
 
87
                opt_order_by_primary=false, opt_ignore= false,
 
88
                opt_complete_insert= false, opt_drop_database= false,
 
89
                opt_replace_into= false,
 
90
                opt_routines= false,
 
91
                opt_slave_apply= false,
 
92
                opt_include_master_host_port= false,
 
93
                opt_alltspcs= false;
 
94
static bool debug_info_flag= false, debug_check_flag= false;
90
95
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
91
 
static DRIZZLE drizzle_connection,*drizzle=0;
 
96
static DRIZZLE drizzle_connection, *drizzle= 0;
92
97
static string insert_pat;
93
 
static char  *opt_password=0,*current_user=0,
94
 
             *current_host=0,*path=0,*fields_terminated=0,
95
 
             *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0,
96
 
             *where=0, *order_by=0,
97
 
             *opt_compatible_mode_str= 0,
98
 
             *err_ptr= 0,
 
98
static char  *opt_password= NULL, *current_user= NULL,
 
99
             *current_host= NULL, *path= NULL, *fields_terminated= NULL,
 
100
             *lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
 
101
             *escaped= NULL,
 
102
             *where= NULL, *order_by= NULL,
 
103
             *opt_compatible_mode_str= NULL,
 
104
             *err_ptr= NULL,
99
105
             *log_error_file= NULL;
100
 
static char **defaults_argv= 0;
 
106
static char **defaults_argv= NULL;
101
107
static char compatible_mode_normal_str[255];
102
108
/* Server supports character_set_results session variable? */
103
109
static bool server_supports_switching_charsets= true;
106
112
#define DRIZZLE_OPT_MASTER_DATA_COMMENTED_SQL 2
107
113
#define DRIZZLE_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
108
114
#define DRIZZLE_OPT_SLAVE_DATA_COMMENTED_SQL 2
109
 
static uint opt_drizzle_port= 0, opt_master_data;
 
115
static uint32_t opt_drizzle_port= 0;
 
116
static uint opt_master_data;
110
117
static uint opt_slave_data;
111
118
static uint my_end_arg;
112
 
static int   first_error=0;
 
119
static int first_error= 0;
113
120
static string extended_row;
114
121
FILE *md_result_file= 0;
115
 
FILE *stderror_file=0;
 
122
FILE *stderror_file= 0;
116
123
 
117
124
/*
118
125
  Constant for detection of default value of default_charset.
342
349
  {"order-by-primary", OPT_ORDER_BY_PRIMARY,
343
350
   "Sorts each table's rows by primary key, or first unique key, if such a key exists.  Useful when dumping a MyISAM table to be loaded into an InnoDB table, but will make the dump itself take considerably longer.",
344
351
   (char**) &opt_order_by_primary, (char**) &opt_order_by_primary, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
345
 
  {"password", 'p',
 
352
  {"password", 'P',
346
353
   "Password to use when connecting to server. If password is not given it's solicited on the tty.",
347
354
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
348
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
349
 
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
350
 
   0},
 
355
  {"port", 'p', "Port number to use for connection.", 
 
356
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
351
357
  {"quick", 'q', "Don't buffer query, dump directly to stdout.",
352
358
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
353
359
  {"quote-names",'Q', "Quote table and column names with backticks (`).",
595
601
extern "C"
596
602
bool get_one_option(int optid, const struct my_option *, char *argument)
597
603
{
 
604
  char *endchar= NULL;
 
605
  uint64_t temp_drizzle_port= 0;
 
606
 
598
607
  switch (optid) {
599
608
  case 'p':
 
609
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
610
    /* if there is an alpha character this is not a valid port */
 
611
    if (strlen(endchar) != 0)
 
612
    {
 
613
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
 
614
      exit(EX_USAGE);
 
615
    }
 
616
    /* If the port number is > 65535 it is not a valid port
 
617
 *        This also helps with potential data loss casting unsigned long to a
 
618
 *               uint32_t. */
 
619
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
620
    {
 
621
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
 
622
      exit(EX_USAGE);
 
623
    }
 
624
    else
 
625
    {
 
626
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
627
    }
 
628
    break;
 
629
  case 'P':
600
630
    if (argument)
601
631
    {
602
 
      char *start=argument;
 
632
      char *start= argument;
603
633
      if (opt_password)
604
634
        free(opt_password);
605
 
      opt_password=strdup(argument);
 
635
      opt_password= strdup(argument);
606
636
      if (opt_password == NULL)
607
637
      {
608
638
        fprintf(stderr, "Memory allocation error while copying password. "
609
639
                        "Aborting.\n");
610
640
        exit(ENOMEM);
611
641
      }
612
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
642
      while (*argument)
 
643
      {
 
644
        /* Overwriting password with 'x' */
 
645
        *argument++= 'x';
 
646
      }
613
647
      if (*start)
614
 
        start[1]=0;                             /* Cut length of argument */
 
648
      {
 
649
        /* Cut length of argument */
 
650
        start[1]= 0;
 
651
      }
615
652
      tty_password= 0;
616
653
    }
617
654
    else
618
 
      tty_password=1;
 
655
    {
 
656
      tty_password= 1;
 
657
    }
619
658
    break;
620
659
  case 'r':
621
660
    if (!(md_result_file= my_fopen(argument, O_WRONLY,