237
236
static char *get_arg(char *line, bool get_next_arg);
238
237
static void init_username(void);
239
238
static void add_int_to_prompt(int toadd);
240
static int get_result_width(MYSQL_RES *res);
241
static int get_field_disp_length(MYSQL_FIELD * field);
239
static int get_result_width(DRIZZLE_RES *res);
240
static int get_field_disp_length(DRIZZLE_FIELD * field);
243
242
/* A structure which contains information on the commands this program
244
243
can understand. */
246
const char *name; /* User printable name of the function. */
247
char cmd_char; /* msql command character */
245
const char *name; /* User printable name of the function. */
246
char cmd_char; /* msql command character */
248
247
int (*func)(DYNAMIC_STRING *str,char *); /* Function to call to do the job. */
249
bool takes_params; /* Max parameters for command */
250
const char *doc; /* Documentation for this function. */
248
bool takes_params; /* Max parameters for command */
249
const char *doc; /* Documentation for this function. */
259
258
{ "delimiter", 'd', com_delimiter, 1,
260
259
"Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." },
261
260
{ "ego", 'G', com_ego, 0,
262
"Send command to mysql server, display result vertically."},
263
{ "exit", 'q', com_quit, 0, "Exit mysql. Same as quit."},
264
{ "go", 'g', com_go, 0, "Send command to mysql server." },
261
"Send command to drizzle server, display result vertically."},
262
{ "exit", 'q', com_quit, 0, "Exit drizzle. Same as quit."},
263
{ "go", 'g', com_go, 0, "Send command to drizzle server." },
265
264
{ "help", 'h', com_help, 1, "Display this help." },
266
265
{ "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
267
266
{ "notee", 't', com_notee, 0, "Don't write into outfile." },
268
267
{ "pager", 'P', com_pager, 1,
269
268
"Set PAGER [to_pager]. Print the query results via PAGER." },
270
269
{ "print", 'p', com_print, 0, "Print current command." },
271
{ "prompt", 'R', com_prompt, 1, "Change your mysql prompt."},
272
{ "quit", 'q', com_quit, 0, "Quit mysql." },
270
{ "prompt", 'R', com_prompt, 1, "Change your drizzle prompt."},
271
{ "quit", 'q', com_quit, 0, "Quit drizzle." },
273
272
{ "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
274
273
{ "source", '.', com_source, 1,
275
274
"Execute an SQL script file. Takes a file name as an argument."},
1010
1007
static bool add_line(DYNAMIC_STRING *buffer,char *line,char *in_string,
1011
1008
bool *ml_comment);
1012
1009
static void remove_cntrl(DYNAMIC_STRING *buffer);
1013
static void print_table_data(MYSQL_RES *result);
1014
static void print_table_data_html(MYSQL_RES *result);
1015
static void print_table_data_xml(MYSQL_RES *result);
1016
static void print_tab_data(MYSQL_RES *result);
1017
static void print_table_data_vertically(MYSQL_RES *result);
1010
static void print_table_data(DRIZZLE_RES *result);
1011
static void print_table_data_html(DRIZZLE_RES *result);
1012
static void print_table_data_xml(DRIZZLE_RES *result);
1013
static void print_tab_data(DRIZZLE_RES *result);
1014
static void print_table_data_vertically(DRIZZLE_RES *result);
1018
1015
static void print_warnings(void);
1019
1016
static ulong start_timer(void);
1020
1017
static void end_timer(ulong start_time,char *buff);
1021
static void mysql_end_timer(ulong start_time,char *buff);
1018
static void drizzle_end_timer(ulong start_time,char *buff);
1022
1019
static void nice_time(double sec,char *buff,bool part_second);
1023
extern sig_handler mysql_end(int sig);
1020
extern sig_handler drizzle_end(int sig);
1024
1021
extern sig_handler handle_sigint(int sig);
1025
1022
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1026
1023
static sig_handler window_resize(int sig);
1093
if (mysql_server_init(embedded_server_arg_count, embedded_server_args,
1094
(char**) embedded_server_groups))
1097
free_defaults(defaults_argv);
1101
1090
completion_hash_init(&ht, 128);
1102
1091
init_alloc_root(&hash_mem_root, 16384, 0);
1103
bzero((char*) &mysql, sizeof(mysql));
1092
bzero((char*) &drizzle, sizeof(drizzle));
1104
1093
if (sql_connect(current_host,current_db,current_user,opt_password,
1107
quick= 1; // Avoid history
1096
quick= 1; // Avoid history
1108
1097
status.exit_status= 1;
1111
1100
if (!status.batch)
1112
ignore_errors=1; // Don't abort monitor
1101
ignore_errors=1; // Don't abort monitor
1114
1103
if (opt_sigint_ignore)
1115
1104
signal(SIGINT, SIG_IGN);
1117
1106
signal(SIGINT, handle_sigint); // Catch SIGINT to clean up
1118
signal(SIGQUIT, mysql_end); // Catch SIGQUIT to clean up
1107
signal(SIGQUIT, drizzle_end); // Catch SIGQUIT to clean up
1120
1109
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1121
1110
/* Readline will call this if it installs a handler */
1133
1122
/* this is a slight abuse of the DYNAMIC_STRING interface. deal. */
1134
1123
sprintf(glob_buffer->str,
1135
1124
"Your Drizzle connection id is %u\nServer version: %s\n",
1136
mysql_thread_id(&mysql), server_version_string(&mysql));
1125
drizzle_thread_id(&drizzle), server_version_string(&drizzle));
1137
1126
put_info(glob_buffer->str, INFO_INFO, 0, 0);
1138
1127
dynstr_set(glob_buffer, NULL);
1140
1129
initialize_readline(my_progname);
1141
1130
if (!status.batch && !quick && !opt_html && !opt_xml)
1143
/* read-history from file, default ~/.mysql_history*/
1132
/* read-history from file, default ~/.drizzle_history*/
1144
1133
if (getenv("MYSQL_HISTFILE"))
1145
1134
histfile= strdup(getenv("MYSQL_HISTFILE"));
1146
1135
else if (getenv("HOME"))
1148
1137
histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1149
+ (uint) strlen("/.mysql_history")+2,
1138
+ (uint) strlen("/.drizzle_history")+2,
1152
sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
1141
sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
1153
1142
char link_name[FN_REFLEN];
1154
1143
if (my_readlink(link_name, histfile, 0) == 0 &&
1155
1144
strncmp(link_name, "/dev/null", 10) == 0)
1157
/* The .mysql_history file is a symlink to /dev/null, don't use it */
1146
/* The .drizzle_history file is a symlink to /dev/null, don't use it */
1158
1147
my_free(histfile, MYF(MY_ALLOW_ZERO_PTR));
1237
1226
sig_handler handle_sigint(int sig)
1239
1228
char kill_buffer[40];
1240
MYSQL *kill_mysql= NULL;
1229
DRIZZLE *kill_drizzle= NULL;
1242
1231
/* terminate if no query being executed, or we already tried interrupting */
1243
1232
if (!executing_query || interrupted_query) {
1247
kill_mysql= mysql_init(kill_mysql);
1248
if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
1249
"", opt_mysql_port, opt_mysql_unix_port,0))
1236
kill_drizzle= drizzle_create(kill_drizzle);
1237
if (!drizzle_connect(kill_drizzle,current_host, current_user, opt_password,
1238
"", opt_drizzle_port, opt_drizzle_unix_port,0))
1254
1243
/* kill_buffer is always big enough because max length of %lu is 15 */
1255
sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u", mysql_thread_id(&mysql));
1256
mysql_real_query(kill_mysql, kill_buffer, strlen(kill_buffer));
1257
mysql_close(kill_mysql);
1244
sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u", drizzle_thread_id(&drizzle));
1245
drizzle_real_query(kill_drizzle, kill_buffer, strlen(kill_buffer));
1246
drizzle_close(kill_drizzle);
1258
1247
tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
1260
1249
interrupted_query= 1;
1287
1276
(char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1289
1278
{"no-auto-rehash", 'A',
1290
"No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
1279
"No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of DRIZZLE and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
1291
1280
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1292
1281
{"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1293
1282
"Automatically switch to vertical output mode if the result is wider than the terminal width.",
1328
1317
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1330
1319
{"named-commands", 'G',
1331
"Enable named commands. Named commands mean this program's internal commands; see mysql> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default.",
1320
"Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default.",
1332
1321
(char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1334
1323
{"no-named-commands", 'g',
1384
1373
"/etc/services, "
1386
1375
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
1387
(char**) &opt_mysql_port,
1388
(char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1389
{"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
1376
(char**) &opt_drizzle_port,
1377
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1378
{"prompt", OPT_PROMPT, "Set the drizzle prompt to this value.",
1390
1379
(char**) ¤t_prompt, (char**) ¤t_prompt, 0, GET_STR_ALLOC,
1391
1380
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1392
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
1381
{"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
1393
1382
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1395
1384
"Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file.",
1402
1391
{"silent", 's', "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,
1404
1393
{"socket", 'S', "Socket file to use for connection.",
1405
(char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR_ALLOC,
1394
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR_ALLOC,
1406
1395
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1407
1396
{"table", 't', "Output in table format.", (char**) &output_tables,
1408
1397
(char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
2340
2328
/* hash Drizzle functions (to be implemented) */
2342
2330
/* hash all database names */
2343
if (mysql_query(&mysql,"show databases") == 0)
2331
if (drizzle_query(&drizzle,"show databases") == 0)
2345
if (!(databases = mysql_store_result(&mysql)))
2346
put_info(mysql_error(&mysql),INFO_INFO,0,0);
2333
if (!(databases = drizzle_store_result(&drizzle)))
2334
put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
2349
while ((database_row=mysql_fetch_row(databases)))
2337
while ((database_row=drizzle_fetch_row(databases)))
2351
2339
char *str=strdup_root(&hash_mem_root, (char*) database_row[0]);
2353
2341
add_word(&ht,(char*) str);
2355
mysql_free_result(databases);
2343
drizzle_free_result(databases);
2358
2346
/* hash all table names */
2359
if (mysql_query(&mysql,"show tables")==0)
2347
if (drizzle_query(&drizzle,"show tables")==0)
2361
if (!(tables = mysql_store_result(&mysql)))
2362
put_info(mysql_error(&mysql),INFO_INFO,0,0);
2349
if (!(tables = drizzle_store_result(&drizzle)))
2350
put_info(drizzle_error(&drizzle),INFO_INFO,0,0);
2365
if (mysql_num_rows(tables) > 0 && !opt_silent && write_info)
2353
if (drizzle_num_rows(tables) > 0 && !opt_silent && write_info)
2367
2355
tee_fprintf(stdout, "\
2368
2356
Reading table information for completion of table and column names\n \
2369
2357
You can turn off this feature to get a quicker startup with -A\n\n");
2371
while ((table_row=mysql_fetch_row(tables)))
2359
while ((table_row=drizzle_fetch_row(tables)))
2373
2361
char *str=strdup_root(&hash_mem_root, (char*) table_row[0]);
2381
2369
/* hash all field names, both with the table prefix and without it */
2382
if (!tables) /* no tables */
2370
if (!tables) /* no tables */
2386
mysql_data_seek(tables,0);
2374
drizzle_data_seek(tables,0);
2387
2375
if (!(field_names= (char ***) alloc_root(&hash_mem_root,sizeof(char **) *
2388
(uint) (mysql_num_rows(tables)+1))))
2376
(uint) (drizzle_num_rows(tables)+1))))
2390
mysql_free_result(tables);
2378
drizzle_free_result(tables);
2394
while ((table_row=mysql_fetch_row(tables)))
2382
while ((table_row=drizzle_fetch_row(tables)))
2396
if ((fields=mysql_list_fields(&mysql,(const char*) table_row[0],NullS)))
2384
if ((fields=drizzle_list_fields(&drizzle,(const char*) table_row[0],NullS)))
2398
num_fields=mysql_num_fields(fields);
2386
num_fields=drizzle_num_fields(fields);
2399
2387
if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,
2400
2388
sizeof(char *) *
2401
2389
(num_fields*2+1))))
2403
mysql_free_result(fields);
2391
drizzle_free_result(fields);
2406
2394
field_names[i][num_fields*2]= '\0';
2408
while ((sql_field=mysql_fetch_field(fields)))
2396
while ((sql_field=drizzle_fetch_field(fields)))
2410
2398
sprintf(buf,"%.64s.%.64s",table_row[0],sql_field->name);
2411
2399
field_names[i][j] = strdup_root(&hash_mem_root,buf);
2807
2795
print_table_data(result);
2808
2796
sprintf(buff,"%ld %s in set",
2809
(long) mysql_num_rows(result),
2810
(long) mysql_num_rows(result) == 1 ? "row" : "rows");
2797
(long) drizzle_num_rows(result),
2798
(long) drizzle_num_rows(result) == 1 ? "row" : "rows");
2812
if (mysql_errno(&mysql))
2813
error= put_error(&mysql);
2800
if (drizzle_errno(&drizzle))
2801
error= put_error(&drizzle);
2816
else if (mysql_affected_rows(&mysql) == ~(uint64_t) 0)
2804
else if (drizzle_affected_rows(&drizzle) == ~(uint64_t) 0)
2817
2805
strmov(buff,"Query OK");
2819
2807
sprintf(buff,"Query OK, %ld %s affected",
2820
(long) mysql_affected_rows(&mysql),
2821
(long) mysql_affected_rows(&mysql) == 1 ? "row" : "rows");
2808
(long) drizzle_affected_rows(&drizzle),
2809
(long) drizzle_affected_rows(&drizzle) == 1 ? "row" : "rows");
2823
2811
pos=strend(buff);
2824
if ((warnings= mysql_warning_count(&mysql)))
2812
if ((warnings= drizzle_warning_count(&drizzle)))
2833
2821
strmov(pos, time_buff);
2834
2822
put_info(buff,INFO_RESULT,0,0);
2835
if (mysql_info(&mysql))
2836
put_info(mysql_info(&mysql),INFO_RESULT,0,0);
2837
put_info("",INFO_RESULT,0,0); // Empty row
2823
if (drizzle_info(&drizzle))
2824
put_info(drizzle_info(&drizzle),INFO_RESULT,0,0);
2825
put_info("",INFO_RESULT,0,0); // Empty row
2839
if (result && !mysql_eof(result)) /* Something wrong when using quick */
2840
error= put_error(&mysql);
2827
if (result && !drizzle_eof(result)) /* Something wrong when using quick */
2828
error= put_error(&drizzle);
2841
2829
else if (unbuffered)
2842
2830
fflush(stdout);
2843
mysql_free_result(result);
2844
} while (!(err= mysql_next_result(&mysql)));
2831
drizzle_free_result(result);
2832
} while (!(err= drizzle_next_result(&drizzle)));
2846
error= put_error(&mysql);
2834
error= put_error(&drizzle);
3009
print_table_data(MYSQL_RES *result)
2997
print_table_data(DRIZZLE_RES *result)
3000
DRIZZLE_FIELD *field;
3013
3001
bool *num_flag;
3014
3002
DYNAMIC_STRING *separator=
3015
3003
(DYNAMIC_STRING *)my_malloc(sizeof(DYNAMIC_STRING), MYF(0));
3016
3004
init_dynamic_string(separator, "", 256, 256);
3018
num_flag=(bool*) my_malloc(sizeof(bool)*mysql_num_fields(result),
3006
num_flag=(bool*) my_malloc(sizeof(bool)*drizzle_num_fields(result),
3020
3008
if (column_types_flag)
3022
3010
print_field_types(result);
3023
if (!mysql_num_rows(result))
3011
if (!drizzle_num_rows(result))
3025
mysql_field_seek(result,0);
3013
drizzle_field_seek(result,0);
3027
3015
dynstr_append(separator, "+");
3028
while ((field = mysql_fetch_field(result)))
3016
while ((field = drizzle_fetch_field(result)))
3030
3018
uint length= column_names ? field->name_length : 0;
3247
print_table_data_xml(MYSQL_RES *result)
3235
print_table_data_xml(DRIZZLE_RES *result)
3250
MYSQL_FIELD *fields;
3238
DRIZZLE_FIELD *fields;
3252
mysql_field_seek(result,0);
3240
drizzle_field_seek(result,0);
3254
3242
tee_fputs("<?xml version=\"1.0\"?>\n\n<resultset statement=\"", PAGER);
3255
3243
xmlencode_print(glob_buffer->str, glob_buffer->length);
3256
3244
tee_fputs("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">",
3259
fields = mysql_fetch_fields(result);
3260
while ((cur = mysql_fetch_row(result)))
3247
fields = drizzle_fetch_fields(result);
3248
while ((cur = drizzle_fetch_row(result)))
3262
3250
if (interrupted_query)
3264
uint32_t *lengths=mysql_fetch_lengths(result);
3252
uint32_t *lengths=drizzle_fetch_lengths(result);
3265
3253
(void) tee_fputs("\n <row>\n", PAGER);
3266
for (uint i=0; i < mysql_num_fields(result); i++)
3254
for (uint i=0; i < drizzle_num_fields(result); i++)
3268
3256
tee_fprintf(PAGER, "\t<field name=\"");
3269
3257
xmlencode_print(fields[i].name, (uint) strlen(fields[i].name));
3297
3285
field->max_length=length;
3300
mysql_field_seek(result,0);
3301
for (uint row_count=1; (cur= mysql_fetch_row(result)); row_count++)
3288
drizzle_field_seek(result,0);
3289
for (uint row_count=1; (cur= drizzle_fetch_row(result)); row_count++)
3303
3291
if (interrupted_query)
3305
mysql_field_seek(result,0);
3293
drizzle_field_seek(result,0);
3306
3294
tee_fprintf(PAGER,
3307
3295
"*************************** %d. row ***************************\n", row_count);
3308
for (uint off=0; off < mysql_num_fields(result); off++)
3296
for (uint off=0; off < drizzle_num_fields(result); off++)
3310
field= mysql_fetch_field(result);
3298
field= drizzle_fetch_field(result);
3311
3299
tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
3312
3300
tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
3903
sql_real_connect(char *host,char *database,char *user,char *password,
3891
sql_connect(char *host,char *database,char *user,char *password,
3909
mysql_close(&mysql);
3897
drizzle_close(&drizzle);
3899
drizzle_create(&drizzle);
3912
3900
if (opt_connect_timeout)
3914
3902
uint timeout=opt_connect_timeout;
3915
mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT,
3903
drizzle_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
3916
3904
(char*) &timeout);
3918
3906
if (opt_compress)
3919
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
3907
drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NullS);
3920
3908
if (opt_secure_auth)
3921
mysql_options(&mysql, MYSQL_SECURE_AUTH, (char *) &opt_secure_auth);
3909
drizzle_options(&drizzle, DRIZZLE_SECURE_AUTH, (char *) &opt_secure_auth);
3922
3910
if (using_opt_local_infile)
3923
mysql_options(&mysql,MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
3911
drizzle_options(&drizzle,DRIZZLE_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
3924
3912
if (opt_protocol)
3925
mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
3913
drizzle_options(&drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
3926
3914
if (safe_updates)
3928
3916
char init_command[100];
3929
3917
sprintf(init_command,
3930
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3918
"SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3931
3919
",SQL_MAX_JOIN_SIZE=%"PRIu32,
3932
select_limit, max_join_size);
3933
mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
3920
select_limit, max_join_size);
3921
drizzle_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
3935
3923
if (default_charset_used)
3936
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
3937
if (!mysql_real_connect(&mysql, host, user, password,
3938
database, opt_mysql_port, opt_mysql_unix_port,
3924
drizzle_options(&drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
3925
if (!drizzle_connect(&drizzle, host, user, password,
3926
database, opt_drizzle_port, opt_drizzle_unix_port,
3939
3927
connect_flag | CLIENT_MULTI_STATEMENTS))
3942
(mysql_errno(&mysql) != CR_CONN_HOST_ERROR &&
3943
mysql_errno(&mysql) != CR_CONNECTION_ERROR))
3930
(drizzle_errno(&drizzle) != CR_CONN_HOST_ERROR &&
3931
drizzle_errno(&drizzle) != CR_CONNECTION_ERROR))
3945
(void) put_error(&mysql);
3933
(void) put_error(&drizzle);
3946
3934
(void) fflush(stdout);
3947
return ignore_errors ? -1 : 1; // Abort
3935
return ignore_errors ? -1 : 1; // Abort
3949
return -1; // Retryable
3937
return -1; // Retryable
3952
mysql.reconnect= debug_info_flag; // We want to know if this happens
3940
drizzle.reconnect= debug_info_flag; // We want to know if this happens
3953
3941
build_completion_hash(opt_rehash, 1);
3959
sql_connect(char *host,char *database,char *user,char *password,uint silent)
3966
if ((error=sql_real_connect(host,database,user,password,wait_flag)) >= 0)
3970
tee_fputs("\n", stderr);
3971
(void) fflush(stderr);
3976
return ignore_errors ? -1 : 1;
3977
if (!message && !silent)
3980
tee_fputs("Waiting",stderr); (void) fflush(stderr);
3982
(void) sleep(wait_time);
3985
putc('.',stderr); (void) fflush(stderr);
3994
3947
com_status(DYNAMIC_STRING *buffer __attribute__((unused)),
3995
3948
char *line __attribute__((unused)))
3997
3950
const char *status_str;
3953
DRIZZLE_RES *result;
4002
3955
tee_puts("--------------", stdout);
4003
usage(1); /* Print version */
3956
usage(1); /* Print version */
4006
tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
3959
tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",drizzle_thread_id(&drizzle));
4008
3961
Don't remove "limit 1",
4009
3962
it is protection againts SQL_SELECT_LIMIT=0
4011
if (!mysql_query(&mysql,"select DATABASE(), USER() limit 1") &&
4012
(result=mysql_use_result(&mysql)))
3964
if (!drizzle_query(&drizzle,"select DATABASE(), USER() limit 1") &&
3965
(result=drizzle_use_result(&drizzle)))
4014
MYSQL_ROW cur=mysql_fetch_row(result);
3967
DRIZZLE_ROW cur=drizzle_fetch_row(result);
4017
3970
tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
4018
3971
tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
4020
mysql_free_result(result);
3973
drizzle_free_result(result);
4022
3975
tee_puts("SSL:\t\t\tNot in use", stdout);
4037
3990
tee_fprintf(stdout, "Current pager:\t\t%s\n", pager);
4038
3991
tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : "");
4039
3992
tee_fprintf(stdout, "Using delimiter:\t%s\n", delimiter);
4040
tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&mysql));
4041
tee_fprintf(stdout, "Protocol version:\t%d\n", mysql_get_proto_info(&mysql));
4042
tee_fprintf(stdout, "Connection:\t\t%s\n", mysql_get_host_info(&mysql));
4043
if ((id= mysql_insert_id(&mysql)))
3993
tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&drizzle));
3994
tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_get_proto_info(&drizzle));
3995
tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_get_host_info(&drizzle));
3996
if ((id= drizzle_insert_id(&drizzle)))
4044
3997
tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
4046
3999
/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
4047
if (!mysql_query(&mysql,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
4048
(result=mysql_use_result(&mysql)))
4000
if (!drizzle_query(&drizzle,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
4001
(result=drizzle_use_result(&drizzle)))
4050
MYSQL_ROW cur=mysql_fetch_row(result);
4003
DRIZZLE_ROW cur=drizzle_fetch_row(result);
4053
4006
tee_fprintf(stdout, "Server characterset:\t%s\n", cur[2] ? cur[2] : "");
4055
4008
tee_fprintf(stdout, "Client characterset:\t%s\n", cur[0] ? cur[0] : "");
4056
4009
tee_fprintf(stdout, "Conn. characterset:\t%s\n", cur[1] ? cur[1] : "");
4058
mysql_free_result(result);
4011
drizzle_free_result(result);
4062
4015
/* Probably pre-4.1 server */
4063
4016
tee_fprintf(stdout, "Client characterset:\t%s\n", charset_info->csname);
4064
tee_fprintf(stdout, "Server characterset:\t%s\n", mysql.charset->csname);
4017
tee_fprintf(stdout, "Server characterset:\t%s\n", drizzle.charset->csname);
4067
if (strstr(mysql_get_host_info(&mysql),"TCP/IP") || ! mysql.unix_socket)
4068
tee_fprintf(stdout, "TCP port:\t\t%d\n", mysql.port);
4020
if (strstr(drizzle_get_host_info(&drizzle),"TCP/IP") || ! drizzle.unix_socket)
4021
tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle.port);
4070
tee_fprintf(stdout, "UNIX socket:\t\t%s\n", mysql.unix_socket);
4071
if (mysql.net.compress)
4023
tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle.unix_socket);
4024
if (drizzle.net.compress)
4072
4025
tee_fprintf(stdout, "Protocol:\t\tCompressed\n");
4074
if ((status_str= mysql_stat(&mysql)) && !mysql_error(&mysql)[0])
4027
if ((status_str= drizzle_stat(&drizzle)) && !drizzle_error(&drizzle)[0])
4077
4030
const char *pos= strchr(status_str,' ');
4112
4065
if (buf[0] == '\0')
4114
4067
char *bufp = buf;
4068
DRIZZLE_RES *result;
4117
bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
4070
bufp= strnmov(buf, drizzle_get_server_info(con), sizeof buf);
4119
4072
/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
4120
if (!mysql_query(con, "select @@version_comment limit 1") &&
4121
(result = mysql_use_result(con)))
4073
if (!drizzle_query(con, "select @@version_comment limit 1") &&
4074
(result = drizzle_use_result(con)))
4123
MYSQL_ROW cur = mysql_fetch_row(result);
4076
DRIZZLE_ROW cur = drizzle_fetch_row(result);
4124
4077
if (cur && cur[0])
4126
4079
bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
4128
mysql_free_result(result);
4081
drizzle_free_result(result);
4131
4084
/* str*nmov doesn't guarantee NUL-termination */
4525
4479
my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
4526
4480
my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
4529
if (!mysql_query(&mysql,"select USER()") &&
4530
(result=mysql_use_result(&mysql)))
4482
DRIZZLE_RES *result;
4483
if (!drizzle_query(&drizzle,"select USER()") &&
4484
(result=drizzle_use_result(&drizzle)))
4532
MYSQL_ROW cur=mysql_fetch_row(result);
4486
DRIZZLE_ROW cur=drizzle_fetch_row(result);
4533
4487
full_username= strdup(cur[0]);
4534
4488
part_username= strdup(strtok(cur[0],"@"));
4535
(void) mysql_fetch_row(result); // Read eof
4489
(void) drizzle_fetch_row(result); // Read eof
4539
static int com_prompt(DYNAMIC_STRING *buffer __attribute__((__unused__)), char *line)
4493
static int com_prompt(DYNAMIC_STRING *buffer __attribute__((__unused__)),
4541
4496
char *ptr=strchr(line, ' ');
4542
4497
prompt_counter = 0;