diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 158 | ||||
-rw-r--r-- | client/mysqladmin.c | 8 | ||||
-rw-r--r-- | client/mysqlcheck.c | 42 | ||||
-rw-r--r-- | client/mysqldump.c | 2 | ||||
-rw-r--r-- | client/mysqltest.c | 18 |
5 files changed, 142 insertions, 86 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index cef31b46b2c..574dc7c45cc 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -40,7 +40,7 @@ #include <signal.h> #include <violite.h> -const char *VER= "13.3"; +const char *VER= "13.4"; /* Don't try to make a nice table if the data is too big */ #define MAX_COLUMN_LENGTH 1024 @@ -79,7 +79,7 @@ extern "C" { #undef bcmp // Fix problem with new readline #if defined( __WIN__) || defined(OS2) #include <conio.h> -#else +#elif !defined(__NETWARE__) #include <readline/readline.h> #define HAVE_READLINE #endif @@ -97,6 +97,10 @@ extern "C" { #define cmp_database(A,B) strcmp((A),(B)) #endif +#if !defined( __WIN__) && !defined( OS2) && !defined(__NETWARE__) && (!defined(HAVE_mit_thread) || !defined(THREAD)) +#define USE_POPEN +#endif + #include "completion_hash.h" #define PROMPT_CHAR '\\' @@ -176,12 +180,12 @@ static int com_quit(String *str,char*), com_connect(String *str,char*), com_status(String *str,char*), com_use(String *str,char*), com_source(String *str, char*), com_rehash(String *str, char*), com_tee(String *str, char*), - com_notee(String *str, char*), com_shell(String *str, char *), + com_notee(String *str, char*), com_prompt(String *str, char*); -#ifndef __WIN__ +#ifdef USE_POPEN static int com_nopager(String *str, char*), com_pager(String *str, char*), - com_edit(String *str,char*); + com_edit(String *str,char*), com_shell(String *str, char *); #endif static int read_lines(bool execute_commands); @@ -192,7 +196,7 @@ 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 int init_tee(char *); +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); @@ -216,18 +220,18 @@ static COMMANDS commands[] = { { "clear", 'c', com_clear, 0, "Clear command."}, { "connect",'r', com_connect,1, "Reconnect to the server. Optional arguments are db and host." }, -#ifndef __WIN__ +#ifdef USE_POPEN { "edit", 'e', com_edit, 0, "Edit command with $EDITOR."}, #endif { "ego", 'G', com_ego, 0, "Send command to mysql server, display result vertically."}, { "exit", 'q', com_quit, 0, "Exit mysql. Same as quit."}, { "go", 'g', com_go, 0, "Send command to mysql server." }, -#ifndef __WIN__ +#ifdef USE_POPEN { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." }, #endif { "notee", 't', com_notee, 0, "Don't write into outfile." }, -#ifndef __WIN__ +#ifdef USE_POPEN { "pager", 'P', com_pager, 1, "Set PAGER [to_pager]. Print the query results via PAGER." }, #endif @@ -238,7 +242,7 @@ static COMMANDS commands[] = { { "source", '.', com_source, 1, "Execute a SQL script file. Takes a file name as an argument."}, { "status", 's', com_status, 0, "Get status information from the server."}, -#ifndef __WIN__ +#ifdef USE_POPEN { "system", '!', com_shell, 1, "Execute a system shell command."}, #endif { "tee", 'T', com_tee, 1, @@ -309,8 +313,8 @@ int main(int argc,char *argv[]) current_prompt = my_strdup(default_prompt,MYF(MY_WME)); prompt_counter=0; - strmov(outfile, "\0"); // no (default) outfile, unless given at least once - strmov(pager, "stdout"); // the default, if --pager wasn't given + outfile[0]=0; // no (default) outfile + strmov(pager, "stdout"); // the default, if --pager wasn't given { char *tmp=getenv("PAGER"); if (tmp) @@ -505,7 +509,7 @@ static struct my_option my_long_options[] = NO_ARG, 1, 0, 0, 0, 0, 0}, {"skip-line-numbers", 'L', "Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#ifndef __WIN__ +#ifdef USE_POPEN {"no-pager", OPT_NOPAGER, "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -526,7 +530,7 @@ static struct my_option my_long_options[] = {"one-database", 'o', "Only update the default database. This is useful for skipping updates to other database in the update log.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#ifndef __WIN__ +#ifdef USE_POPEN {"pager", OPT_PAGER, "Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, @@ -640,7 +644,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), end_tee(); } else - opt_outfile= init_tee(argument); + init_tee(argument); break; case OPT_NOTEE: printf("WARNING: option deprecated; use --disable-tee instead.\n"); @@ -803,7 +807,7 @@ static int get_options(int argc, char **argv) static int read_lines(bool execute_commands) { -#if defined( __WIN__) || defined(OS2) +#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__) char linebuffer[254]; #endif char *line; @@ -824,30 +828,33 @@ static int read_lines(bool execute_commands) } else { -#if defined( __WIN__) || defined(OS2) + char *prompt= (char*) (glob_buffer.is_empty() ? construct_prompt() : + !in_string ? " -> " : + in_string == '\'' ? + " '> " : " \"> "); if (opt_outfile && glob_buffer.is_empty()) fflush(OUTFILE); - tee_fputs(glob_buffer.is_empty() ? construct_prompt() : - !in_string ? " -> " : - in_string == '\'' ? - " '> " : " \"> ",stdout); - linebuffer[0]=(char) sizeof(linebuffer); - line=_cgets(linebuffer); -#else - if (opt_outfile) + +#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__) + tee_fputs(prompt, stdout); +#ifdef __NETWARE__ + line=fgets(linebuffer, sizeof(linebuffer)-1, stdin); + /* Remove the '\n' */ { - if (glob_buffer.is_empty()) - fflush(OUTFILE); - fputs(glob_buffer.is_empty() ? construct_prompt() : - !in_string ? " -> " : - in_string == '\'' ? - " '> " : " \"> ", OUTFILE); + char *p = strrchr(line, '\n'); + if (p != NULL) + *p = '\0'; } - line=readline((char*) (glob_buffer.is_empty() ? construct_prompt() : - !in_string ? " -> " : - in_string == '\'' ? - " '> " : " \"> ")); -#endif +#else + linebuffer[0]= (char) sizeof(linebuffer); + line= _cgets(linebuffer); +#endif /* __NETWARE__ */ +#else + if (opt_outfile) + fputs(prompt, OUTFILE); + line= readline(prompt); +#endif /* defined( __WIN__) || defined(OS2) || defined(__NETWARE__) */ + if (opt_outfile) fprintf(OUTFILE, "%s\n", line); } @@ -1682,7 +1689,7 @@ com_go(String *buffer,char *line __attribute__((unused))) static void init_pager() { -#if !defined( __WIN__) && !defined( OS2) && (!defined(HAVE_mit_thread) || !defined(THREAD)) +#ifdef USE_POPEN if (!opt_nopager) { if (!(PAGER= popen(pager, "w"))) @@ -1698,30 +1705,35 @@ static void init_pager() static void end_pager() { -#if !defined( __WIN__) && !defined( OS2) && !(defined(HAVE_mit_thread) && defined(THREAD)) +#ifdef USE_POPEN if (!opt_nopager) pclose(PAGER); #endif } -static int init_tee(char* newfile) +static void init_tee(const char *file_name) { FILE* new_outfile; - if (!(new_outfile= my_fopen(newfile, O_APPEND | O_WRONLY, MYF(MY_WME)))) - return 0; if (opt_outfile) end_tee(); + if (!(new_outfile= my_fopen(file_name, O_APPEND | O_WRONLY, MYF(MY_WME)))) + { + tee_fprintf(stdout, "Error logging to file '%s'\n", file_name); + return; + } OUTFILE = new_outfile; - strmake(outfile,newfile,FN_REFLEN-1); - tee_fprintf(stdout, "Logging to file '%s'\n", outfile); - return 1; + strmake(outfile, file_name, FN_REFLEN-1); + tee_fprintf(stdout, "Logging to file '%s'\n", file_name); + opt_outfile= 1; + return; } static void end_tee() { my_fclose(OUTFILE, MYF(0)); + OUTFILE= 0; opt_outfile= 0; return; } @@ -1761,6 +1773,9 @@ print_table_data(MYSQL_RES *result) MYSQL_ROW cur; MYSQL_FIELD *field; bool *num_flag; +#ifdef __NETWARE__ + uint lines= 0; +#endif num_flag=(bool*) my_alloca(sizeof(bool)*mysql_num_fields(result)); if (info_flag) @@ -1816,16 +1831,24 @@ print_table_data(MYSQL_RES *result) length, str); } (void) tee_fputs("\n", PAGER); +#ifdef __NETWARE__ + // on a long result the screen could hog the cpu + if ((lines++ & 1023) == 0) pthread_yield(); +#endif } tee_puts(separator.c_ptr(), PAGER); my_afree((gptr) num_flag); } + static void print_table_data_html(MYSQL_RES *result) { - MYSQL_ROW cur; - MYSQL_FIELD *field; + MYSQL_ROW cur; + MYSQL_FIELD *field; +#ifdef __NETWARE__ + uint lines= 0; +#endif mysql_field_seek(result,0); (void) tee_fputs("<TABLE BORDER=1><TR>", PAGER); @@ -1850,6 +1873,10 @@ print_table_data_html(MYSQL_RES *result) (void) tee_fputs("</TD>", PAGER); } (void) tee_fputs("</TR>", PAGER); +#ifdef __NETWARE__ + // on a long result the screen could hog the cpu + if ((lines++ & 1023) == 0) pthread_yield(); +#endif } (void) tee_fputs("</TABLE>", PAGER); } @@ -1883,6 +1910,10 @@ print_table_data_xml(MYSQL_RES *result) " ") : "NULL")); } (void) tee_fputs(" </row>\n", PAGER); +#ifdef __NETWARE__ + // on a long result the screen could hog the cpu + if ((lines++ & 1023) == 0) pthread_yield(); +#endif } (void) tee_fputs("</resultset>\n", PAGER); } @@ -1915,6 +1946,10 @@ print_table_data_vertically(MYSQL_RES *result) tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name); tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL"); } +#ifdef __NETWARE__ + // on a long result the screen could hog the cpu + if ((row_count & 1023) == 0) pthread_yield(); +#endif } } @@ -2056,11 +2091,7 @@ com_tee(String *buffer, char *line __attribute__((unused))) printf("No outfile specified!\n"); return 0; } - opt_outfile= init_tee(file_name); - if (opt_outfile) - tee_fprintf(stdout, "Logging to file '%s'\n", outfile); - else - tee_fprintf(stdout, "Error logging to file '%s'\n",file_name); + init_tee(file_name); return 0; } @@ -2079,7 +2110,7 @@ com_notee(String *buffer __attribute__((unused)), Sorry, this command is not available in Windows. */ -#ifndef __WIN__ +#ifdef USE_POPEN static int com_pager(String *buffer, char *line __attribute__((unused))) { @@ -2090,9 +2121,9 @@ com_pager(String *buffer, char *line __attribute__((unused))) /* Skip space from file name */ while (my_isspace(system_charset_info,*line)) line++; - if (!(param = strchr(line, ' '))) // if pager was not given, use the default + if (!(param= strchr(line, ' '))) // if pager was not given, use the default { - if (!strlen(default_pager)) + if (!default_pager[0]) { tee_fprintf(stdout, "Default pager wasn't set, using stdout.\n"); opt_nopager=1; @@ -2136,7 +2167,7 @@ com_nopager(String *buffer __attribute__((unused)), Sorry, you can't send the result to an editor in Win32 */ -#ifndef __WIN__ +#ifdef USE_POPEN static int com_edit(String *buffer,char *line __attribute__((unused))) { @@ -2184,6 +2215,10 @@ static int com_quit(String *buffer __attribute__((unused)), char *line __attribute__((unused))) { +#ifdef __NETWARE__ + // let the screen auto close on a normal shutdown + setscreenmode(SCR_AUTOCLOSE_ON_EXIT); +#endif status.exit_status=0; return 1; } @@ -2199,7 +2234,7 @@ com_rehash(String *buffer __attribute__((unused)), } -#ifndef __WIN__ +#ifdef USE_POPEN static int com_shell(String *buffer, char *line __attribute__((unused))) { @@ -2588,7 +2623,7 @@ com_status(String *buffer __attribute__((unused)), tee_fprintf(stdout, "\nAll updates ignored to this database\n"); vidattr(A_NORMAL); } -#ifndef __WIN__ +#ifdef USE_POPEN tee_fprintf(stdout, "Current pager:\t\t%s\n", pager); tee_fprintf(stdout, "Using outfile:\t\t'%s'\n", opt_outfile ? outfile : ""); #endif @@ -2763,7 +2798,7 @@ void tee_putc(int c, FILE *file) putc(c, OUTFILE); } -#if defined( __WIN__) || defined( OS2) +#if defined( __WIN__) || defined( OS2) || defined(__NETWARE__) #include <time.h> #else #include <sys/times.h> @@ -2775,7 +2810,7 @@ void tee_putc(int c, FILE *file) static ulong start_timer(void) { -#if defined( __WIN__) || defined( OS2) +#if defined( __WIN__) || defined( OS2) || defined(__NETWARE__) return clock(); #else struct tms tms_tmp; @@ -2876,7 +2911,10 @@ static const char* construct_prompt() ! mysql.unix_socket) add_int_to_prompt(mysql.port); else - processed_prompt.append(strrchr(mysql.unix_socket,'/')+1); + { + char *pos=strrchr(mysql.unix_socket,'/'); + processed_prompt.append(pos ? pos+1 : mysql.unix_socket); + } #endif break; case 'U': diff --git a/client/mysqladmin.c b/client/mysqladmin.c index 2fc77552d5f..cba137d54c6 100644 --- a/client/mysqladmin.c +++ b/client/mysqladmin.c @@ -25,8 +25,8 @@ #include <sys/stat.h> #include <mysql.h> -#define ADMIN_VERSION "8.39" -#define MAX_MYSQL_VAR 128 +#define ADMIN_VERSION "8.40" +#define MAX_MYSQL_VAR 256 #define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */ #define MAX_TRUNC_LENGTH 3 @@ -1016,7 +1016,7 @@ static void print_relative_row(MYSQL_RES *result, MYSQL_ROW cur, uint row) printf("| %-*s|", (int) field->max_length + 1, cur[0]); field = mysql_fetch_field(result); - tmp = cur[1] ? strtoull(cur[1], NULL, 0) : (ulonglong) 0; + tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0; printf(" %-*s|\n", (int) field->max_length + 1, llstr((tmp - last_values[row]), buff)); last_values[row] = tmp; @@ -1034,7 +1034,7 @@ static void print_relative_row_vert(MYSQL_RES *result __attribute__((unused)), if (!row) putchar('|'); - tmp = cur[1] ? strtoull(cur[1], NULL, 0) : (ulonglong) 0; + tmp = cur[1] ? strtoull(cur[1], NULL, 10) : (ulonglong) 0; printf(" %-*s|", ex_val_max_len[row] + 1, llstr((tmp - last_values[row]), buff)); diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index f9719f05bf3..cd67a2c7522 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -16,7 +16,7 @@ /* By Jani Tolonen, 2001-04-20, MySQL Development Team */ -#define CHECK_VERSION "2.4.2" +#define CHECK_VERSION "2.4.3" #include "client_priv.h" #include <m_ctype.h> @@ -167,6 +167,7 @@ static void dbDisconnect(char *host); static void DBerror(MYSQL *mysql, const char *when); static void safe_exit(int error); static void print_result(); +static char *fix_table_name(char *dest, char *src); int what_to_do = 0; static void print_version(void) @@ -390,7 +391,8 @@ static int process_selected_tables(char *db, char **table_names, int tables) for (end = table_names_comma_sep + 1; tables > 0; tables--, table_names++) { - end = strxmov(end, " `", *table_names, "`,", NullS); + end= fix_table_name(end, *table_names); + *end++= ','; } *--end = 0; handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1); @@ -403,6 +405,22 @@ static int process_selected_tables(char *db, char **table_names, int tables) } /* process_selected_tables */ +static char *fix_table_name(char *dest, char *src) +{ + char *db_sep; + + *dest++= '`'; + if ((db_sep= strchr(src, '.'))) + { + dest= strmake(dest, src, (uint) (db_sep - src)); + dest= strmov(dest, "`.`"); + src= db_sep + 1; + } + dest= strxmov(dest, src, "`", NullS); + return dest; +} + + static int process_all_tables_in_db(char *database) { MYSQL_RES *res; @@ -437,7 +455,8 @@ static int process_all_tables_in_db(char *database) } for (end = tables + 1; (row = mysql_fetch_row(res)) ;) { - end = strxmov(end, " `", row[0], "`,", NullS); + end= fix_table_name(end, row[0]); + *end++= ','; } *--end = 0; if (tot_length) @@ -468,6 +487,7 @@ static int use_db(char *database) static int handle_request_for_tables(char *tables, uint length) { char *query, *end, options[100], message[100]; + uint query_length= 0; const char *op = 0; options[0] = 0; @@ -498,11 +518,21 @@ static int handle_request_for_tables(char *tables, uint length) if (!(query =(char *) my_malloc((sizeof(char)*(length+110)), MYF(MY_WME)))) return 1; if (opt_all_in_1) + { /* No backticks here as we added them before */ - sprintf(query, "%s TABLE %s %s", op, tables, options); + query_length= my_sprintf(query, + (query, "%s TABLE %s %s", op, tables, options)); + } else - sprintf(query, "%s TABLE `%s` %s", op, tables, options); - if (mysql_query(sock, query)) + { + char *ptr; + + ptr= strmov(strmov(query, op), " TABLE "); + ptr= fix_table_name(ptr, tables); + ptr= strxmov(ptr, " ", options, NullS); + query_length= (uint) (ptr - query); + } + if (mysql_real_query(sock, query, query_length)) { sprintf(message, "when executing '%s TABLE ... %s'", op, options); DBerror(sock, message); diff --git a/client/mysqldump.c b/client/mysqldump.c index 5eabce9b038..0d5b1edc89a 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -375,7 +375,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), tty_password=1; break; case 'r': - if (!(md_result_file = my_fopen(argument, O_WRONLY | O_BINARY, + if (!(md_result_file = my_fopen(argument, O_WRONLY | FILE_BINARY, MYF(MY_WME)))) exit(1); break; diff --git a/client/mysqltest.c b/client/mysqltest.c index c938ec5eec0..f417018dbb7 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -684,7 +684,7 @@ int open_file(const char* name) if (*cur_file && cur_file == file_stack_end) die("Source directives are nesting too deep"); - if (!(*(cur_file+1) = my_fopen(buff, O_RDONLY | O_BINARY, MYF(MY_WME)))) + if (!(*(cur_file+1) = my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME)))) die(NullS); cur_file++; *++lineno=1; @@ -692,18 +692,6 @@ int open_file(const char* name) return 0; } -static void my_sleep(ulong m_seconds) -{ -#ifndef OS2 - struct timeval t; - t.tv_sec= m_seconds / 1000000L; - t.tv_usec= m_seconds % 1000000L; - select(0,0,0,0,&t); /* sleep */ -#else - DosSleep(m_seconds/1000+1); -#endif -} - /* ugly long name, but we are following the convention */ int do_wait_for_slave_to_stop(struct st_query* q __attribute__((unused))) @@ -1925,7 +1913,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), argument= buff; } fn_format(buff, argument, "", "", 4); - if (!(*++cur_file = my_fopen(buff, O_RDONLY | O_BINARY, MYF(MY_WME)))) + if (!(*++cur_file = my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME)))) die("Could not open %s: errno = %d", argument, errno); break; } @@ -2611,7 +2599,7 @@ static int read_server_arguments(const char* name) embedded_server_arg_count=1; embedded_server_args[0]= (char*) ""; /* Progname */ } - if (!(file=my_fopen(buff, O_RDONLY | O_BINARY, MYF(MY_WME)))) + if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME)))) return 1; while (embedded_server_arg_count < MAX_SERVER_ARGS && (str=fgets(argument,sizeof(argument), file))) |