21
21
* Michael 'Monty' Widenius
22
* Andi Gutmans <andi@zend.com>
22
* Andi Gutmans <andi@zend.com>
23
23
* Zeev Suraski <zeev@zend.com>
24
24
* Jani Tolonen <jani@mysql.com>
25
* Matt Wagner <mwagner@mysql.com>
26
* Jeremy Cole <jcole@mysql.com>
120
122
no_rehash=0,skip_updates=0,safe_updates=0,one_database=0,
122
124
vertical=0,skip_line_numbers=0,skip_column_names=0,opt_html=0,
123
opt_nopager=1, opt_outfile=0, no_named_cmds=1;
125
opt_xml=0,opt_nopager=1, opt_outfile=0, no_named_cmds=1;
124
126
static uint verbose=0,opt_silent=0,opt_mysql_port=0;
125
127
static my_string opt_mysql_unix_port=0;
126
128
static int connect_flag=CLIENT_INTERACTIVE;
131
133
static int wait_time = 5;
132
134
static STATUS status;
133
135
static ulong select_limit,max_join_size,opt_connect_timeout=0;
136
static char *xmlmeta[] = {
134
141
static char default_pager[FN_REFLEN];
135
142
char pager[FN_REFLEN], outfile[FN_REFLEN];
136
143
FILE *PAGER, *OUTFILE;
167
174
static int put_info(const char *str,INFO_TYPE info,uint error=0);
168
175
static void safe_put_field(const char *pos,ulong length);
176
static char *array_value(char **array, char *key);
177
static char *xmlencode(char *dest, char *src);
178
static void my_chomp(char *end);
169
179
static void init_pager();
170
180
static void end_pager();
171
181
static void init_tee();
250
260
static void remove_cntrl(String &buffer);
251
261
static void print_table_data(MYSQL_RES *result);
252
262
static void print_table_data_html(MYSQL_RES *result);
263
static void print_table_data_xml(MYSQL_RES *result);
253
264
static void print_tab_data(MYSQL_RES *result);
254
265
static void print_table_data_vertically(MYSQL_RES *result);
255
266
static ulong start_timer(void);
314
325
#ifdef HAVE_READLINE
315
326
initialize_readline(my_progname);
316
if (!status.batch && !quick && !opt_html)
327
if (!status.batch && !quick && !opt_html && !opt_xml)
318
329
/*read-history from file, default ~/.mysql_history*/
319
330
if (getenv("MYSQL_HISTFILE"))
396
407
{"force", no_argument, 0, 'f'},
397
408
{"help", no_argument, 0, '?'},
398
409
{"html", no_argument, 0, 'H'},
410
{"xml", no_argument, 0, 'X'},
399
411
{"host", required_argument, 0, 'h'},
400
412
{"ignore-spaces", no_argument, 0, 'i'},
401
413
{"no-auto-rehash",no_argument, 0, 'A'},
490
502
-i, --ignore-space Ignore space after function names.\n\
491
503
-h, --host=... Connect to host.\n\
492
504
-H, --html Produce HTML output.\n\
505
-X, --xml Produce XML output.\n\
493
506
-L, --skip-line-numbers\n\
494
507
Don't write line number for errors.\n");
565
578
set_all_changeable_vars(changeable_vars);
566
579
while ((c=getopt_long(argc,argv,
567
"?ABCD:LfgGHinNoqrstTU::vVw::WEe:h:O:P:S:u:#::p::",
580
"?ABCD:LfgGHXinNoqrstTU::vVw::WEe:h:O:P:S:u:#::p::",
568
581
long_options, &option_index)) != EOF)
685
698
case 'G': no_named_cmds=0; break;
686
699
case 'g': no_named_cmds=1; break;
687
700
case 'H': opt_html=1; break;
701
case 'X': opt_xml=1; break;
688
702
case 'i': connect_flag|= CLIENT_IGNORE_SPACE; break;
690
704
if (!status.batch)
1664
print_table_data_xml(MYSQL_RES *result)
1667
MYSQL_FIELD *fields;
1669
mysql_field_seek(result,0);
1672
statement=(char*) my_malloc(strlen(glob_buffer.ptr())*5+1, MYF(MY_WME));
1673
xmlencode(statement, (char*) glob_buffer.ptr());
1675
(void) my_chomp(strend(statement));
1677
tee_fprintf(PAGER,"<?xml version=\"1.0\"?>\n\n<resultset statement=\"%s\">", statement);
1679
my_free(statement,MYF(MY_ALLOW_ZERO_PTR));
1681
fields = mysql_fetch_fields(result);
1683
while ((cur = mysql_fetch_row(result)))
1685
(void) tee_fputs("\n <row>\n", PAGER);
1686
for (uint i=0; i < mysql_num_fields(result); i++)
1689
ulong *lengths=mysql_fetch_lengths(result);
1690
data=(char*) my_malloc(lengths[i]*5+1, MYF(MY_WME));
1691
tee_fprintf(PAGER, "\t<%s>", (fields[i].name ?
1692
(fields[i].name[0] ? fields[i].name :
1693
" ") : "NULL"));
1694
xmlencode(data, cur[i]);
1695
safe_put_field(data, strlen(data));
1696
tee_fprintf(PAGER, "</%s>\n", (fields[i].name ?
1697
(fields[i].name[0] ? fields[i].name :
1698
" ") : "NULL"));
1699
my_free(data,MYF(MY_ALLOW_ZERO_PTR));
1701
(void) tee_fputs(" </row>\n", PAGER);
1703
(void) tee_fputs("</resultset>\n", PAGER);
1649
1708
print_table_data_vertically(MYSQL_RES *result)
1738
*array_value(char **array, char *key) {
1740
for(x=0; array[x]; x+=2)
1741
if(!strcmp(array[x], key))
1747
*xmlencode(char *dest, char *src) {
1750
char s[2] = { 0, 0 };
1755
if(!(t=array_value(xmlmeta, s))) t = s;
1762
my_chomp(char *end) {
1767
if (isspace(*mend)) {
1771
} while (mend && *mend);
1680
1776
safe_put_field(const char *pos,ulong length)