The world's most popular open source database
#include "client_priv.h"#include <m_ctype.h>#include <stdarg.h>#include <my_dir.h>#include "my_readline.h"#include <signal.h>#include <violite.h>#include "sql_string.h"#include <readline/readline.h>#include "completion_hash.h"#include "sslopt-vars.h"#include "sslopt-longopts.h"#include <sslopt-case.h>#include <sys/times.h>Include dependency graph for mysql.cc:

Go to the source code of this file.
Classes | |
| struct | st_status |
| struct | COMMANDS |
| struct | _hist_entry |
Defines | |
| #define | __GNU_LIBRARY__ |
| #define | MAX_COLUMN_LENGTH 1024 |
| #define | HAVE_READLINE |
| #define | vidattr(A) {} |
| #define | cmp_database(cs, A, B) strcmp((A),(B)) |
| #define | USE_POPEN |
| #define | PROMPT_CHAR '\\' |
| #define | DEFAULT_DELIMITER ";" |
| #define | ff2s_check_flag(X) if (f & X ## _FLAG) { s=strmov(s, # X " "); f &= ~ X ## _FLAG; } |
Typedefs | |
| typedef st_status | STATUS |
| typedef enum enum_info_type | INFO_TYPE |
| typedef _hist_entry | HIST_ENTRY |
Enumerations | |
| enum | enum_info_type { INFO_INFO, INFO_ERROR, INFO_RESULT } |
Functions | |
| gptr | sql_alloc (unsigned size) |
| void | sql_element_free (void *ptr) |
| void | tee_fprintf (FILE *file, const char *fmt,...) |
| void | tee_fputs (const char *s, FILE *file) |
| void | tee_puts (const char *s, FILE *file) |
| void | tee_putc (int c, FILE *file) |
| static void | tee_print_sized_data (const char *, unsigned int, unsigned int, bool) |
| static int | get_options (int argc, char **argv) |
| static int | com_quit (String *str, char *) |
| static int | com_go (String *str, char *) |
| static int | com_ego (String *str, char *) |
| static int | com_print (String *str, char *) |
| static int | com_help (String *str, char *) |
| static int | com_clear (String *str, char *) |
| static int | com_connect (String *str, char *) |
| static int | com_status (String *str, char *) |
| static int | com_use (String *str, char *) |
| static int | com_source (String *str, char *) |
| static int | com_rehash (String *str, char *) |
| static int | com_tee (String *str, char *) |
| static int | com_notee (String *str, char *) |
| static int | com_charset (String *str, char *) |
| static int | com_prompt (String *str, char *) |
| static int | com_delimiter (String *str, char *) |
| static int | com_warnings (String *str, char *) |
| static int | com_nowarnings (String *str, char *) |
| static int | com_nopager (String *str, char *) |
| static int | com_pager (String *str, char *) |
| static int | com_edit (String *str, char *) |
| static int | com_shell (String *str, char *) |
| static int | read_and_execute (bool interactive) |
| static int | sql_connect (char *host, char *database, char *user, char *password, uint silent) |
| static int | put_info (const char *str, INFO_TYPE info, uint error=0, const char *sql_state=0) |
| static int | put_error (MYSQL *mysql) |
| static void | safe_put_field (const char *pos, ulong length) |
| static void | xmlencode_print (const char *src, uint length) |
| static void | init_pager () |
| static void | end_pager () |
| static void | init_tee (const char *) |
| static void | end_tee () |
| static const char * | construct_prompt () |
| static char * | get_arg (char *line, my_bool get_next_arg) |
| static void | init_username () |
| static void | add_int_to_prompt (int toadd) |
| int | add_history (const char *command) |
| int | read_history (const char *command) |
| int | write_history (const char *command) |
| HIST_ENTRY * | history_get (int num) |
| static int | not_in_history (const char *line) |
| static void | initialize_readline (char *name) |
| static void | fix_history (String *final_command) |
| static COMMANDS * | find_command (char *name, char cmd_name) |
| static bool | add_line (String &buffer, char *line, char *in_string, bool *ml_comment) |
| static void | remove_cntrl (String &buffer) |
| static void | print_table_data (MYSQL_RES *result) |
| static void | print_table_data_html (MYSQL_RES *result) |
| static void | print_table_data_xml (MYSQL_RES *result) |
| static void | print_tab_data (MYSQL_RES *result) |
| static void | print_table_data_vertically (MYSQL_RES *result) |
| static void | print_warnings (void) |
| static ulong | start_timer (void) |
| static void | end_timer (ulong start_time, char *buff) |
| static void | mysql_end_timer (ulong start_time, char *buff) |
| static void | nice_time (double sec, char *buff, bool part_second) |
| static sig_handler | mysql_end (int sig) |
| static sig_handler | mysql_sigint (int sig) |
| int | main (int argc, char *argv[]) |
| sig_handler | handle_sigint (int sig) |
| static void | usage (int version) |
| static my_bool | get_one_option (int optid, const struct my_option *opt __attribute__((unused)), char *argument) |
| static char * | new_command_generator (const char *text, int) |
| static char ** | new_mysql_completion (const char *text, int start, int end) |
| int | no_completion () |
| static char ** | new_mysql_completion (const char *text, int start __attribute__((unused)), int end __attribute__((unused))) |
| static void | build_completion_hash (bool rehash, bool write_info) |
| char * | index (const char *, int c) |
| char ** | rindex (const char *, int) |
| static int | reconnect (void) |
| static void | get_current_db () |
| int | mysql_real_query_for_lazy (const char *buf, int length) |
| int | mysql_store_result_for_lazy (MYSQL_RES **result) |
| static void | print_help_item (MYSQL_ROW *cur, int num_name, int num_cat, char *last_char) |
| static int | com_server_help (String *buffer __attribute__((unused)), char *line __attribute__((unused)), char *help_arg) |
| static int | com_help (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | com_clear (String *buffer, char *line __attribute__((unused))) |
| static int | com_charset (String *buffer __attribute__((unused)), char *line) |
| static int | com_go (String *buffer, char *line __attribute__((unused))) |
| static const char * | fieldtype2str (enum enum_field_types type) |
| static char * | fieldflags2str (uint f) |
| static void | print_field_types (MYSQL_RES *result) |
| static const char * | array_value (const char **array, char key) |
| static int | com_tee (String *buffer, char *line __attribute__((unused))) |
| static int | com_notee (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | com_pager (String *buffer, char *line __attribute__((unused))) |
| static int | com_nopager (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | com_edit (String *buffer, char *line __attribute__((unused))) |
| static int | com_quit (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | com_rehash (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | com_shell (String *buffer, char *line __attribute__((unused))) |
| static int | com_print (String *buffer, char *line __attribute__((unused))) |
| static int | com_delimiter (String *buffer __attribute__((unused)), char *line) |
| static int | com_use (String *buffer __attribute__((unused)), char *line) |
| static int | com_warnings (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | com_nowarnings (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| static int | sql_real_connect (char *host, char *database, char *user, char *password, uint silent) |
| static int | com_status (String *buffer __attribute__((unused)), char *line __attribute__((unused))) |
| gptr | sql_alloc (unsigned int Size) |
Variables | |
| const char * | VER = "14.12" |
| static HashTable | ht |
| static char ** | defaults_argv |
| static MYSQL | mysql |
| static my_bool | info_flag = 0 |
| static my_bool | ignore_errors = 0 |
| static my_bool | wait_flag = 0 |
| static my_bool | quick = 0 |
| static my_bool | connected = 0 |
| static my_bool | opt_raw_data = 0 |
| static my_bool | unbuffered = 0 |
| static my_bool | output_tables = 0 |
| static my_bool | rehash = 1 |
| static my_bool | skip_updates = 0 |
| static my_bool | safe_updates = 0 |
| static my_bool | one_database = 0 |
| static my_bool | opt_compress = 0 |
| static my_bool | using_opt_local_infile = 0 |
| static my_bool | vertical = 0 |
| static my_bool | line_numbers = 1 |
| static my_bool | column_names = 1 |
| static my_bool | opt_html = 0 |
| static my_bool | opt_xml = 0 |
| static my_bool | opt_nopager = 1 |
| static my_bool | opt_outfile = 0 |
| static my_bool | named_cmds = 0 |
| static my_bool | tty_password = 0 |
| static my_bool | opt_nobeep = 0 |
| static my_bool | opt_reconnect = 1 |
| static my_bool | default_charset_used = 0 |
| static my_bool | opt_secure_auth = 0 |
| static my_bool | default_pager_set = 0 |
| static my_bool | opt_sigint_ignore = 0 |
| static my_bool | show_warnings = 0 |
| static my_bool | executing_query = 0 |
| static my_bool | interrupted_query = 0 |
| static ulong | opt_max_allowed_packet |
| static ulong | opt_net_buffer_length |
| static uint | verbose = 0 |
| static uint | opt_silent = 0 |
| static uint | opt_mysql_port = 0 |
| static uint | opt_local_infile = 0 |
| static my_string | opt_mysql_unix_port = 0 |
| static int | connect_flag = CLIENT_INTERACTIVE |
| static char * | current_host |
| static char * | current_db |
| static char * | current_user = 0 |
| static char * | opt_password = 0 |
| static char * | current_prompt = 0 |
| static char * | delimiter_str = 0 |
| static char * | default_charset = (char*) MYSQL_DEFAULT_CHARSET_NAME |
| static char * | histfile |
| static char * | histfile_tmp |
| static String | glob_buffer |
| static String | old_buffer |
| static String | processed_prompt |
| static char * | full_username = 0 |
| static char * | part_username = 0 |
| static char * | default_prompt = 0 |
| static int | wait_time = 5 |
| static STATUS | status |
| static ulong | select_limit |
| static ulong | max_join_size |
| static ulong | opt_connect_timeout = 0 |
| static char | mysql_charsets_dir [FN_REFLEN+1] |
| static const char * | xmlmeta [] |
| static const char * | day_names [] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"} |
| static const char * | month_names [] |
| static char | default_pager [FN_REFLEN] |
| static char | pager [FN_REFLEN] |
| static char | outfile [FN_REFLEN] |
| static FILE * | PAGER |
| static FILE * | OUTFILE |
| static MEM_ROOT | hash_mem_root |
| static uint | prompt_counter |
| static char | delimiter [16] = DEFAULT_DELIMITER |
| static uint | delimiter_length = 1 |
| static uint | opt_protocol = 0 |
| static CHARSET_INFO * | charset_info = &my_charset_latin1 |
| const char * | default_dbug_option = "d:t:o,/tmp/mysql.trace" |
| static COMMANDS | commands [] |
| static const char * | load_default_groups [] = { "mysql","client",0 } |
| static const char * | server_default_groups [] |
| int | history_length |
| static struct my_option | my_long_options [] |
| #define DEFAULT_DELIMITER ";" |
Referenced by fieldflags2str().
| #define MAX_COLUMN_LENGTH 1024 |
| #define PROMPT_CHAR '\\' |
| #define vidattr | ( | A | ) | {} |
| typedef struct _hist_entry HIST_ENTRY |
| typedef enum enum_info_type INFO_TYPE |
| enum enum_info_type |
| int add_history | ( | const char * | command | ) |
Definition at line 1172 of file readline.c.
Referenced by add_line(), fix_history(), history_expand(), main(), read_and_execute(), read_history_range(), and readline_gets().
01173 { 01174 HistEvent ev; 01175 01176 if (h == NULL || e == NULL) 01177 rl_initialize(); 01178 01179 (void)history(h, &ev, H_ENTER, line); 01180 if (history(h, &ev, H_GETSIZE) == 0) 01181 history_length = ev.num; 01182 01183 return (!(history_length > 0)); /* return 0 if all is okay */ 01184 }
Here is the caller graph for this function:

| static void add_int_to_prompt | ( | int | toadd | ) | [static] |
Definition at line 3796 of file mysql.cc.
References String::append(), buffer, int10_to_str(), and processed_prompt.
Referenced by construct_prompt().
03797 { 03798 char buffer[16]; 03799 int10_to_str(toadd,buffer,10); 03800 processed_prompt.append(buffer); 03801 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1216 of file mysql.cc.
References add_history(), st_status::add_to_history, buffer, charset_info, com, com_delimiter(), com_go(), DBUG_ENTER, DBUG_RETURN, delimiter, delimiter_length, find_command(), INFO_ERROR, IO_SIZE, is_prefix(), my_ismbchar, my_isspace, my_strcasecmp, mysql, not_in_history(), NullS, pos(), put_info(), st_mysql::server_status, SERVER_STATUS_NO_BACKSLASH_ESCAPES, status, strend(), strlen(), and use_mb.
Referenced by read_and_execute().
01218 { 01219 uchar inchar; 01220 char buff[80], *pos, *out; 01221 COMMANDS *com; 01222 bool need_space= 0; 01223 DBUG_ENTER("add_line"); 01224 01225 if (!line[0] && buffer.is_empty()) 01226 DBUG_RETURN(0); 01227 #ifdef HAVE_READLINE 01228 if (status.add_to_history && line[0] && not_in_history(line)) 01229 add_history(line); 01230 #endif 01231 #ifdef USE_MB 01232 char *end_of_line=line+(uint) strlen(line); 01233 #endif 01234 01235 for (pos=out=line ; (inchar= (uchar) *pos) ; pos++) 01236 { 01237 if (my_isspace(charset_info,inchar) && out == line && 01238 buffer.is_empty()) 01239 continue; 01240 #ifdef USE_MB 01241 int length; 01242 if (use_mb(charset_info) && 01243 (length= my_ismbchar(charset_info, pos, end_of_line))) 01244 { 01245 if (!*ml_comment) 01246 { 01247 while (length--) 01248 *out++ = *pos++; 01249 pos--; 01250 } 01251 else 01252 pos+= length - 1; 01253 continue; 01254 } 01255 #endif 01256 if (!*ml_comment && inchar == '\\' && 01257 !(mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)) 01258 { 01259 // Found possbile one character command like \c 01260 01261 if (!(inchar = (uchar) *++pos)) 01262 break; // readline adds one '\' 01263 if (*in_string || inchar == 'N') // \N is short for NULL 01264 { // Don't allow commands in string 01265 *out++='\\'; 01266 *out++= (char) inchar; 01267 continue; 01268 } 01269 if ((com=find_command(NullS,(char) inchar))) 01270 { 01271 const String tmp(line,(uint) (out-line), charset_info); 01272 buffer.append(tmp); 01273 if ((*com->func)(&buffer,pos-1) > 0) 01274 DBUG_RETURN(1); // Quit 01275 if (com->takes_params) 01276 { 01277 for (pos++ ; 01278 *pos && (*pos != *delimiter || 01279 !is_prefix(pos + 1, delimiter + 1)) ; pos++) 01280 ; // Remove parameters 01281 if (!*pos) 01282 pos--; 01283 else 01284 pos+= delimiter_length - 1; // Point at last delim char 01285 } 01286 out=line; 01287 } 01288 else 01289 { 01290 sprintf(buff,"Unknown command '\\%c'.",inchar); 01291 if (put_info(buff,INFO_ERROR) > 0) 01292 DBUG_RETURN(1); 01293 *out++='\\'; 01294 *out++=(char) inchar; 01295 continue; 01296 } 01297 } 01298 else if (!*ml_comment && !*in_string && 01299 (*pos == *delimiter && is_prefix(pos + 1, delimiter + 1) || 01300 buffer.length() == 0 && (out - line) >= 9 && 01301 !my_strcasecmp(charset_info, line, "delimiter"))) 01302 { 01303 uint old_delimiter_length= delimiter_length; 01304 if (out != line) 01305 buffer.append(line, (uint) (out - line)); // Add this line 01306 if ((com= find_command(buffer.c_ptr(), 0))) 01307 { 01308 if (com->func == com_delimiter) 01309 { 01310 /* 01311 Delimiter wants the get rest of the given line as argument to 01312 allow one to change ';' to ';;' and back 01313 */ 01314 char *end= strend(pos); 01315 buffer.append(pos, (uint) (end - pos)); 01316 /* Ensure pos will point at \0 after the pos+= below */ 01317 pos= end - old_delimiter_length + 1; 01318 } 01319 if ((*com->func)(&buffer, buffer.c_ptr()) > 0) 01320 DBUG_RETURN(1); // Quit 01321 } 01322 else 01323 { 01324 if (com_go(&buffer, 0) > 0) // < 0 is not fatal 01325 DBUG_RETURN(1); 01326 } 01327 buffer.length(0); 01328 out= line; 01329 pos+= old_delimiter_length - 1; 01330 } 01331 else if (!*ml_comment && (!*in_string && (inchar == '#' || 01332 inchar == '-' && pos[1] == '-' && 01333 my_isspace(charset_info,pos[2])))) 01334 break; // comment to end of line 01335 else if (!*in_string && inchar == '/' && *(pos+1) == '*' && 01336 *(pos+2) != '!') 01337 { 01338 pos++; 01339 *ml_comment= 1; 01340 if (out != line) 01341 { 01342 buffer.append(line,(uint) (out-line)); 01343 out=line; 01344 } 01345 } 01346 else if (*ml_comment && inchar == '*' && *(pos + 1) == '/') 01347 { 01348 pos++; 01349 *ml_comment= 0; 01350 need_space= 1; 01351 } 01352 else 01353 { // Add found char to buffer 01354 if (inchar == *in_string) 01355 *in_string= 0; 01356 else if (!*ml_comment && !*in_string && 01357 (inchar == '\'' || inchar == '"' || inchar == '`')) 01358 *in_string= (char) inchar; 01359 if (!*ml_comment) 01360 { 01361 if (need_space && !my_isspace(charset_info, (char)inchar)) 01362 { 01363 *out++= ' '; 01364 need_space= 0; 01365 } 01366 *out++= (char) inchar; 01367 } 01368 } 01369 } 01370 if (out != line || !buffer.is_empty()) 01371 { 01372 *out++='\n'; 01373 uint length=(uint) (out-line); 01374 if (buffer.length() + length >= buffer.alloced_length()) 01375 buffer.realloc(buffer.length()+length+IO_SIZE); 01376 if (!(*ml_comment) && buffer.append(line,length)) 01377 DBUG_RETURN(1); 01378 } 01379 DBUG_RETURN(0); 01380 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static const char* array_value | ( | const char ** | array, | |
| char | key | |||
| ) | [static] |
Definition at line 2597 of file mysql.cc.
Referenced by xmlencode_print().
02598 { 02599 for (; *array; array+= 2) 02600 if (**array == key) 02601 return array[1]; 02602 return 0; 02603 }
Here is the caller graph for this function:

Definition at line 1597 of file mysql.cc.
References add_word(), alloc_root(), st_status::batch, buf, commands, completion_hash_clean(), completion_hash_exists(), current_db, DBUG_ENTER, DBUG_VOID_RETURN, free_root(), hash_mem_root, ht, INFO_INFO, MYF, mysql, mysql_data_seek(), mysql_error(), mysql_fetch_field(), mysql_fetch_row(), mysql_free_result(), mysql_list_fields(), mysql_num_fields(), mysql_num_rows(), mysql_query(), mysql_store_result(), st_mysql_field::name, COMMANDS::name, NAME_LEN, NullS, opt_silent, put_info(), quick, status, strdup_root(), strlen(), and tee_fprintf().
Referenced by com_rehash(), com_use(), and sql_real_connect().
01598 { 01599 COMMANDS *cmd=commands; 01600 MYSQL_RES *databases=0,*tables=0; 01601 MYSQL_RES *fields; 01602 static char ***field_names= 0; 01603 MYSQL_ROW database_row,table_row; 01604 MYSQL_FIELD *sql_field; 01605 char buf[NAME_LEN*2+2]; // table name plus field name plus 2 01606 int i,j,num_fields; 01607 DBUG_ENTER("build_completion_hash"); 01608 01609 if (status.batch || quick || !current_db) 01610 DBUG_VOID_RETURN; // We don't need completion in batches 01611 01612 /* hash SQL commands */ 01613 while (cmd->name) { 01614 add_word(&ht,(char*) cmd->name); 01615 cmd++; 01616 } 01617 if (!rehash) 01618 DBUG_VOID_RETURN; 01619 01620 /* Free old used memory */ 01621

