169
169
connected= false, opt_raw_data= false, unbuffered= false,
170
170
output_tables= false, opt_rehash= true, skip_updates= false,
171
171
safe_updates= false, one_database= false,
172
opt_compress= false, opt_shutdown= false, opt_ping= false,
173
173
vertical= false, line_numbers= true, column_names= true,
174
174
opt_nopager= true, opt_outfile= false, named_cmds= false,
175
175
tty_password= false, opt_nobeep= false, opt_reconnect= true,
1020
1020
static void window_resize(int sig);
1024
Shutdown the server that we are currently connected to.
1031
static bool server_shutdown(void)
1033
drizzle_result_st result;
1034
drizzle_return_t ret;
1038
printf("shutting down drizzled");
1039
if (opt_drizzle_port > 0)
1040
printf(" on port %d", opt_drizzle_port);
1044
if (drizzle_shutdown(&con, &result, DRIZZLE_SHUTDOWN_DEFAULT,
1045
&ret) == NULL || ret != DRIZZLE_RETURN_OK)
1047
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1049
fprintf(stderr, "shutdown failed; error: '%s'",
1050
drizzle_result_error(&result));
1051
drizzle_result_free(&result);
1055
fprintf(stderr, "shutdown failed; error: '%s'",
1056
drizzle_con_error(&con));
1061
drizzle_result_free(&result);
1070
Ping the server that we are currently connected to.
1077
static bool server_ping(void)
1079
drizzle_result_st result;
1080
drizzle_return_t ret;
1082
if (drizzle_ping(&con, &result, &ret) != NULL && ret == DRIZZLE_RETURN_OK)
1085
printf("drizzled is alive\n");
1089
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1091
fprintf(stderr, "ping failed; error: '%s'",
1092
drizzle_result_error(&result));
1093
drizzle_result_free(&result);
1097
fprintf(stderr, "drizzled won't answer to ping, error: '%s'",
1098
drizzle_con_error(&con));
1102
drizzle_result_free(&result);
1107
Execute command(s) specified by the user.
1109
@param error error status of command execution.
1110
If an error had occurred, this variable will be set
1111
to 1 whereas on success, it shall be set to 0. This
1112
value will be supplied to the exit() function used
1116
false no commands were executed
1118
true at least one command was executed
1120
static bool execute_commands(int *error)
1122
bool executed= false;
1127
if (server_ping() == false)
1134
if (server_shutdown() == false)
1023
1141
int main(int argc,char *argv[])
1100
if (status.batch && !status.line_buff &&
1101
!(status.line_buff=batch_readline_init(opt_max_input_line+512,stdin)))
1103
free_defaults(defaults_argv);
1107
1219
memset(&drizzle, 0, sizeof(drizzle));
1108
1220
if (sql_connect(current_host,current_db,current_user,opt_password,
1112
1224
status.exit_status= 1;
1113
1225
drizzle_end(-1);
1229
if (execute_commands(&command_error) != false)
1231
/* we've executed a command so exit before we go into readline mode */
1232
free_defaults(defaults_argv);
1234
exit(command_error);
1237
if (status.batch && !status.line_buff)
1239
status.line_buff =batch_readline_init(opt_max_input_line+512, stdin);
1240
if (status.line_buff == NULL)
1242
free_defaults(defaults_argv);
1115
1248
if (!status.batch)
1116
1249
ignore_errors=1; // Don't abort monitor
1388
1521
{"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
1389
1522
(char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1523
{"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
1524
(char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1390
1525
{"silent", 's', N_("Be more silent. Print results with a tab as separator, each row on new line."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
1392
1527
{"socket", 'S', N_("Socket file to use for connection."),
1443
1578
{"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
1444
1579
(char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
1445
1580
0, 0, 0, 0, 0, 0},
1581
{"ping", OPT_PING, N_("Ping the server to check if it's alive."),
1582
(char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1446
1583
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}