147
147
connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
148
148
opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
149
149
opt_compress=0, using_opt_local_infile=0,
150
vertical=0, line_numbers=1, column_names=1,opt_html=0,
151
opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
150
vertical=0, line_numbers=1, column_names=1,
151
opt_nopager=1, opt_outfile=0, named_cmds= 0,
152
152
tty_password= 0, opt_nobeep=0, opt_reconnect=1,
153
153
default_charset_used= 0, opt_secure_auth= 0,
154
154
default_pager_set= 0, opt_sigint_ignore= 0,
176
176
static uint32_t max_join_size;
177
177
static ulong opt_connect_timeout= 0;
178
178
static char drizzle_charsets_dir[FN_REFLEN+1];
179
static const char *xmlmeta[] = {
186
179
// TODO: Need to i18n these
187
180
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
188
181
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
199
192
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
200
193
static const CHARSET_INFO *charset_info= &my_charset_latin1;
202
const char *default_dbug_option="d:t:o,/tmp/drizzle.trace";
203
195
int drizzle_real_query_for_lazy(const char *buf, int length);
204
196
int drizzle_store_result_for_lazy(DRIZZLE_RES **result);
233
225
const char *sql_state);
234
226
static int put_error(DRIZZLE *drizzle);
235
227
static void safe_put_field(const char *pos,ulong length);
236
static void xmlencode_print(const char *src, uint length);
237
228
static void init_pager(void);
238
229
static void end_pager(void);
239
230
static void init_tee(const char *);
1002
993
static const char *load_default_groups[]= { "drizzle","client",0 };
1004
static int embedded_server_arg_count= 0;
1005
static char *embedded_server_args[MAX_SERVER_ARGS];
1007
995
int history_length;
1008
996
static int not_in_history(const char *line);
1009
997
static void initialize_readline (const char *name);
1014
1002
bool *ml_comment);
1015
1003
static void remove_cntrl(DYNAMIC_STRING *buffer);
1016
1004
static void print_table_data(DRIZZLE_RES *result);
1017
static void print_table_data_html(DRIZZLE_RES *result);
1018
static void print_table_data_xml(DRIZZLE_RES *result);
1019
1005
static void print_tab_data(DRIZZLE_RES *result);
1020
1006
static void print_table_data_vertically(DRIZZLE_RES *result);
1021
1007
static void print_warnings(void);
1141
1127
dynstr_set(glob_buffer, NULL);
1143
1129
initialize_readline(my_progname);
1144
if (!status.batch && !quick && !opt_html && !opt_xml)
1130
if (!status.batch && !quick)
1146
1132
/* read-history from file, default ~/.drizzle_history*/
1147
if (getenv("MYSQL_HISTFILE"))
1148
histfile= strdup(getenv("MYSQL_HISTFILE"));
1133
if (getenv("DRIZZLE_HISTFILE"))
1134
histfile= strdup(getenv("DRIZZLE_HISTFILE"));
1149
1135
else if (getenv("HOME"))
1151
1137
histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1223
1209
my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
1224
1210
my_free(default_prompt,MYF(MY_ALLOW_ZERO_PTR));
1225
1211
my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
1226
while (embedded_server_arg_count > 1)
1227
my_free(embedded_server_args[--embedded_server_arg_count],MYF(0));
1228
1212
drizzle_server_end();
1229
1213
free_defaults(defaults_argv);
1230
1214
my_end(my_end_arg);
1345
1329
(char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1346
1330
{"host", 'h', N_("Connect to host."), (char**) ¤t_host,
1347
1331
(char**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1348
{"html", 'H', N_("Produce HTML output."), (char**) &opt_html, (char**) &opt_html,
1349
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1350
{"xml", 'X', N_("Produce XML output"), (char**) &opt_xml, (char**) &opt_xml, 0,
1351
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1352
1332
{"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
1353
1333
(char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1354
1334
NO_ARG, 1, 0, 0, 0, 0, 0},
1380
1360
{"password", 'p',
1381
1361
N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1382
1362
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1383
{"port", 'P', N_("Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, ")
1363
{"port", 'P', N_("Port number to use for connection or 0 for default to, in order of preference, my.cnf, $DRIZZLE_TCP_PORT, ")
1384
1364
N_("built-in default") " (" STRINGIFY_ARG(MYSQL_PORT) ").",
1385
1365
(char**) &opt_drizzle_port,
1386
1366
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1452
1432
{"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
1453
1433
(char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1454
{"server-arg", OPT_SERVER_ARG, N_("Send embedded server this as a parameter."),
1455
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1456
1434
{"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1457
1435
(char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1458
1436
0, 0, 0, 0, 0, 0},
2773
2751
if (!drizzle_num_rows(result) && ! quick && !column_types_flag)
2775
2753
strmov(buff, _("Empty set"));
2779
We must print XML header and footer
2780
to produce a well-formed XML even if
2781
the result set is empty (Bug#27608).
2784
print_table_data_xml(result);
2792
print_table_data_html(result);
2794
print_table_data_xml(result);
2795
else if (vertical || (auto_vertical_output && (terminal_width < get_result_width(result))))
2758
if (vertical || (auto_vertical_output &&
2759
(terminal_width < get_result_width(result))))
2796
2760
print_table_data_vertically(result);
2797
2761
else if (opt_silent && verbose <= 2 && !output_tables)
2798
2762
print_tab_data(result);
3202
print_table_data_html(DRIZZLE_RES *result)
3205
DRIZZLE_FIELD *field;
3207
drizzle_field_seek(result,0);
3208
(void) tee_fputs("<TABLE BORDER=1><TR>", PAGER);
3211
while((field = drizzle_fetch_field(result)))
3213
tee_fprintf(PAGER, "<TH>%s</TH>", (field->name ?
3214
(field->name[0] ? field->name :
3215
" ") : "NULL"));
3217
(void) tee_fputs("</TR>", PAGER);
3219
while ((cur = drizzle_fetch_row(result)))
3221
if (interrupted_query)
3223
uint32_t *lengths=drizzle_fetch_lengths(result);
3224
(void) tee_fputs("<TR>", PAGER);
3225
for (uint32_t i= 0; i < drizzle_num_fields(result); i++)
3227
(void) tee_fputs("<TD>", PAGER);
3228
safe_put_field(cur[i],lengths[i]);
3229
(void) tee_fputs("</TD>", PAGER);
3231
(void) tee_fputs("</TR>", PAGER);
3233
(void) tee_fputs("</TABLE>", PAGER);
3238
print_table_data_xml(DRIZZLE_RES *result)
3241
const DRIZZLE_FIELD *fields;
3243
drizzle_field_seek(result,0);
3245
tee_fputs("<?xml version=\"1.0\"?>\n\n<resultset statement=\"", PAGER);
3246
xmlencode_print(glob_buffer->str, glob_buffer->length);
3247
tee_fputs("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
3250
fields = drizzle_fetch_fields(result);
3251
while ((cur = drizzle_fetch_row(result)))
3253
if (interrupted_query)
3255
uint32_t *lengths=drizzle_fetch_lengths(result);
3256
(void) tee_fputs("\n <row>\n", PAGER);
3257
for (uint i=0; i < drizzle_num_fields(result); i++)
3259
tee_fprintf(PAGER, "\t<field name=\"");
3260
xmlencode_print(fields[i].name, (uint) strlen(fields[i].name));
3263
tee_fprintf(PAGER, "\">");
3264
xmlencode_print(cur[i], lengths[i]);
3265
tee_fprintf(PAGER, "</field>\n");
3268
tee_fprintf(PAGER, "\" xsi:nil=\"true\" />\n");
3270
(void) tee_fputs(" </row>\n", PAGER);
3272
(void) tee_fputs("</resultset>\n", PAGER);
3277
3166
print_table_data_vertically(DRIZZLE_RES *result)
3279
3168
DRIZZLE_ROW cur;
3354
static const char *array_value(const char **array, char key)
3356
for (; *array; array+= 2)
3364
xmlencode_print(const char *src, uint length)
3367
tee_fputs("NULL", PAGER);
3370
for (const char *p = src; *p && length; length--)
3373
if ((t = array_value(xmlmeta, *p++)))
3374
tee_fputs(t, PAGER);
3376
tee_putc(*p, PAGER);
3383
3244
safe_put_field(const char *pos,ulong length)