diff options
Diffstat (limited to 'client/mysql.cc')
-rw-r--r-- | client/mysql.cc | 102 |
1 files changed, 57 insertions, 45 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 6c4245fcd90..697f4d54ab3 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -58,6 +58,7 @@ static char *server_version= NULL; #define MAX_SERVER_ARGS 64 #include "sql_string.h" +#include "client_metadata.h" extern "C" { #if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H) @@ -211,7 +212,7 @@ static CHARSET_INFO *charset_info= &my_charset_latin1; #include "sslopt-vars.h" -const char *default_dbug_option="d:t:o,/tmp/mysql.trace"; +const char *default_dbug_option="d:t:o,/tmp/mariadb.trace"; void tee_fprintf(FILE *file, const char *fmt, ...); void tee_fputs(const char *s, FILE *file); @@ -221,7 +222,7 @@ static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool) /* The names of functions that actually do the manipulation. */ static int get_options(int argc,char **argv); extern "C" my_bool get_one_option(int optid, const struct my_option *opt, - char *argument); + const char *argument); static int com_quit(String *str,char*), com_go(String *str,char*), com_ego(String *str,char*), com_print(String *str,char*), @@ -1083,8 +1084,8 @@ inline bool is_delimiter_command(char *name, ulong len) only name(first DELIMITER_NAME_LEN bytes) is checked. */ return (len >= DELIMITER_NAME_LEN && - !my_strnncoll(&my_charset_latin1, (uchar*) name, DELIMITER_NAME_LEN, - (uchar *) DELIMITER_NAME, DELIMITER_NAME_LEN)); + !my_charset_latin1.strnncoll(name, DELIMITER_NAME_LEN, + DELIMITER_NAME, DELIMITER_NAME_LEN)); } /** @@ -1123,10 +1124,10 @@ int main(int argc,char *argv[]) charset_index= get_command_index('C'); delimiter_index= get_command_index('d'); delimiter_str= delimiter; - default_prompt = my_strdup(getenv("MYSQL_PS1") ? + default_prompt = my_strdup(PSI_NOT_INSTRUMENTED, getenv("MYSQL_PS1") ? getenv("MYSQL_PS1") : "\\N [\\d]> ",MYF(MY_WME)); - current_prompt = my_strdup(default_prompt,MYF(MY_WME)); + current_prompt = my_strdup(PSI_NOT_INSTRUMENTED, default_prompt,MYF(MY_WME)); prompt_counter=0; aborted= 0; sf_leaking_memory= 1; /* no memory leak reports yet */ @@ -1194,7 +1195,7 @@ int main(int argc,char *argv[]) sf_leaking_memory= 0; glob_buffer.realloc(512); completion_hash_init(&ht, 128); - init_alloc_root(&hash_mem_root, "hash", 16384, 0, MYF(0)); + init_alloc_root(PSI_NOT_INSTRUMENTED, &hash_mem_root, 16384, 0, MYF(0)); if (sql_connect(current_host,current_db,current_user,opt_password, opt_silent)) { @@ -1236,12 +1237,11 @@ int main(int argc,char *argv[]) { /* read-history from file, default ~/.mysql_history*/ if (getenv("MYSQL_HISTFILE")) - histfile=my_strdup(getenv("MYSQL_HISTFILE"),MYF(MY_WME)); + histfile=my_strdup(PSI_NOT_INSTRUMENTED, getenv("MYSQL_HISTFILE"),MYF(MY_WME)); else if (getenv("HOME")) { - histfile=(char*) my_malloc((uint) strlen(getenv("HOME")) - + (uint) strlen("/.mysql_history")+2, - MYF(MY_WME)); + histfile=(char*) my_malloc(PSI_NOT_INSTRUMENTED, + strlen(getenv("HOME")) + strlen("/.mysql_history")+2, MYF(MY_WME)); if (histfile) sprintf(histfile,"%s/.mysql_history",getenv("HOME")); char link_name[FN_REFLEN]; @@ -1263,8 +1263,8 @@ int main(int argc,char *argv[]) if (verbose) tee_fprintf(stdout, "Reading history-file %s\n",histfile); read_history(histfile); - if (!(histfile_tmp= (char*) my_malloc((uint) strlen(histfile) + 5, - MYF(MY_WME)))) + if (!(histfile_tmp= (char*) my_malloc(PSI_NOT_INSTRUMENTED, + strlen(histfile) + 5, MYF(MY_WME)))) { fprintf(stderr, "Couldn't allocate memory for temp histfile!\n"); exit(1); @@ -1724,10 +1724,9 @@ static void usage(int version) my_bool -get_one_option(int optid, const struct my_option *opt __attribute__((unused)), - char *argument) +get_one_option(const struct my_option *opt, const char *argument, const char *) { - switch(optid) { + switch(opt->id) { case OPT_CHARSETS_DIR: strmake_buf(mysql_charsets_dir, argument); charsets_dir = mysql_charsets_dir; @@ -1806,7 +1805,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), } if (embedded_server_arg_count == MAX_SERVER_ARGS-1 || !(embedded_server_args[embedded_server_arg_count++]= - my_strdup(argument, MYF(MY_FAE)))) + my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE)))) { put_info("Can't use server argument", INFO_ERROR); return 0; @@ -1834,7 +1833,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), status.add_to_history= 0; if (!status.line_buff) ignore_errors= 0; // do it for the first -e only - if (!(status.line_buff= batch_readline_command(status.line_buff, argument))) + if (!(status.line_buff= batch_readline_command(status.line_buff, + (char*) argument))) return 1; break; case 'o': @@ -1848,10 +1848,15 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), argument= (char*) ""; // Don't require password if (argument) { - char *start= argument; + /* + One should not really change the argument, but we make an + exception for passwords + */ + char *start= (char*) argument; my_free(opt_password); - opt_password= my_strdup(argument, MYF(MY_FAE)); - while (*argument) *argument++= 'x'; // Destroy argument + opt_password= my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE)); + while (*argument) + *(char*)argument++= 'x'; // Destroy argument if (*start) start[1]=0 ; tty_password= 0; @@ -1913,7 +1918,7 @@ static int get_options(int argc, char **argv) tmp= (char *) getenv("MYSQL_HOST"); if (tmp) - current_host= my_strdup(tmp, MYF(MY_WME)); + current_host= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME)); pagpoint= getenv("PAGER"); if (!((char*) (pagpoint))) @@ -1955,7 +1960,7 @@ static int get_options(int argc, char **argv) { skip_updates= 0; my_free(current_db); - current_db= my_strdup(*argv, MYF(MY_WME)); + current_db= my_strdup(PSI_NOT_INSTRUMENTED, *argv, MYF(MY_WME)); } if (tty_password) opt_password= get_tty_password(NullS); @@ -2259,8 +2264,8 @@ static COMMANDS *find_command(char *name) */ for (uint i= 0; commands[i].func; i++) { - if (!my_strnncoll(&my_charset_latin1, (uchar*) name, len, - (uchar*) commands[i].name, len) && + if (!my_charset_latin1.strnncoll((uchar*) name, len, + (uchar*) commands[i].name, len) && (commands[i].name[len] == '\0') && (!end || (commands[i].takes_params && get_arg(name, CHECK)))) { @@ -2311,7 +2316,7 @@ static bool add_line(String &buffer, char *line, size_t line_length, #ifdef USE_MB // Accept multi-byte characters as-is int length; - if (use_mb(charset_info) && + if (charset_info->use_mb() && (length= my_ismbchar(charset_info, pos, end_of_line))) { if (!*ml_comment || preserve_comments) @@ -2986,7 +2991,7 @@ static void get_current_db() { MYSQL_ROW row= mysql_fetch_row(res); if (row && row[0]) - current_db= my_strdup(row[0], MYF(MY_WME)); + current_db= my_strdup(PSI_NOT_INSTRUMENTED, row[0], MYF(MY_WME)); mysql_free_result(res); } } @@ -3253,9 +3258,8 @@ com_go(String *buffer,char *line __attribute__((unused))) (void) com_print(buffer,0); if (skip_updates && - (buffer->length() < 4 || my_strnncoll(charset_info, - (const uchar*)buffer->ptr(),4, - (const uchar*)"SET ",4))) + (buffer->length() < 4 || charset_info->strnncoll((const uchar*)buffer->ptr(),4, + (const uchar*)"SET ",4))) { (void) put_info("Ignoring query to other database",INFO_INFO); return 0; @@ -3526,13 +3530,16 @@ print_field_types(MYSQL_RES *result) while ((field = mysql_fetch_field(result))) { + Client_field_metadata metadata(field); + BinaryStringBuffer<128> data_type_metadata_str; + metadata.print_data_type_related_attributes(&data_type_metadata_str); tee_fprintf(PAGER, "Field %3u: `%s`\n" "Org_field: `%s`\n" "Catalog: `%s`\n" "Database: `%s`\n" "Table: `%s`\n" "Org_table: `%s`\n" - "Type: %s\n" + "Type: %s%s%.*s%s\n" "Collation: %s (%u)\n" "Length: %lu\n" "Max_length: %lu\n" @@ -3541,6 +3548,9 @@ print_field_types(MYSQL_RES *result) ++i, field->name, field->org_name, field->catalog, field->db, field->table, field->org_table, fieldtype2str(field->type), + data_type_metadata_str.length() ? " (" : "", + data_type_metadata_str.length(), data_type_metadata_str.ptr(), + data_type_metadata_str.length() ? ")" : "", get_charset_name(field->charsetnr), field->charsetnr, field->length, field->max_length, field->decimals, fieldflags2str(field->flags)); @@ -3625,9 +3635,8 @@ print_table_data(MYSQL_RES *result) while (MYSQL_FIELD *field= mysql_fetch_field(result)) { size_t name_length= (uint) strlen(field->name); - size_t numcells= charset_info->cset->numcells(charset_info, - field->name, - field->name + name_length); + size_t numcells= charset_info->numcells(field->name, + field->name + name_length); size_t display_length= field->max_length + name_length - numcells; tee_fprintf(PAGER, " %-*s |",(int) MY_MIN(display_length, MAX_COLUMN_LENGTH), @@ -3676,7 +3685,7 @@ print_table_data(MYSQL_RES *result) We need to find how much screen real-estate we will occupy to know how many extra padding-characters we should send with the printing function. */ - size_t visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length); + size_t visible_length= charset_info->numcells(buffer, buffer + data_length); extra_padding= (uint) (data_length - visible_length); if (opt_binhex && is_binary_field(field)) @@ -4023,7 +4032,7 @@ safe_put_field(const char *pos,ulong length) { #ifdef USE_MB int l; - if (use_mb(charset_info) && + if (charset_info->use_mb() && (l = my_ismbchar(charset_info, pos, end))) { while (l--) @@ -4333,12 +4342,12 @@ com_connect(String *buffer, char *line) if (tmp && *tmp) { my_free(current_db); - current_db= my_strdup(tmp, MYF(MY_WME)); + current_db= my_strdup(PSI_NOT_INSTRUMENTED, tmp, MYF(MY_WME)); tmp= get_arg(buff, GET_NEXT); if (tmp) { my_free(current_host); - current_host=my_strdup(tmp,MYF(MY_WME)); + current_host=my_strdup(PSI_NOT_INSTRUMENTED, tmp,MYF(MY_WME)); } } else @@ -4523,7 +4532,7 @@ com_use(String *buffer __attribute__((unused)), char *line) return put_error(&mysql); } my_free(current_db); - current_db=my_strdup(tmp,MYF(MY_WME)); + current_db=my_strdup(PSI_NOT_INSTRUMENTED, tmp,MYF(MY_WME)); #ifdef HAVE_READLINE if (select_db > 1) build_completion_hash(opt_rehash, 1); @@ -4643,7 +4652,10 @@ static char *get_arg(char *line, get_arg_mode mode) string, and the "dialog" plugin will free() it. */ -MYSQL_PLUGIN_EXPORT +extern "C" +#ifdef _MSC_VER +__declspec(dllexport) +#endif char *mysql_authentication_dialog_ask(MYSQL *mysql, int type, const char *prompt, char *buf, int buf_len) @@ -4932,7 +4944,7 @@ server_version_string(MYSQL *con) /* version, space, comment, \0 */ size_t len= strlen(mysql_get_server_info(con)) + strlen(cur[0]) + 2; - if ((server_version= (char *) my_malloc(len, MYF(MY_WME)))) + if ((server_version= (char *) my_malloc(PSI_NOT_INSTRUMENTED, len, MYF(MY_WME)))) { char *bufp; bufp = strmov(server_version, mysql_get_server_info(con)); @@ -4949,7 +4961,7 @@ server_version_string(MYSQL *con) */ if (server_version == NULL) - server_version= my_strdup(mysql_get_server_info(con), MYF(MY_WME)); + server_version= my_strdup(PSI_NOT_INSTRUMENTED, mysql_get_server_info(con), MYF(MY_WME)); } return server_version ? server_version : ""; @@ -5351,8 +5363,8 @@ static void init_username() (result=mysql_use_result(&mysql))) { MYSQL_ROW cur=mysql_fetch_row(result); - full_username=my_strdup(cur[0],MYF(MY_WME)); - part_username=my_strdup(strtok(cur[0],"@"),MYF(MY_WME)); + full_username=my_strdup(PSI_NOT_INSTRUMENTED, cur[0],MYF(MY_WME)); + part_username=my_strdup(PSI_NOT_INSTRUMENTED, strtok(cur[0],"@"),MYF(MY_WME)); (void) mysql_fetch_row(result); // Read eof } } @@ -5363,7 +5375,7 @@ static int com_prompt(String *buffer __attribute__((unused)), char *ptr=strchr(line, ' '); prompt_counter = 0; my_free(current_prompt); - current_prompt=my_strdup(ptr ? ptr+1 : default_prompt,MYF(MY_WME)); + current_prompt=my_strdup(PSI_NOT_INSTRUMENTED, ptr ? ptr+1 : default_prompt,MYF(MY_WME)); if (!ptr) tee_fprintf(stdout, "Returning to default PROMPT of %s\n", default_prompt); else |