mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
Merge with 4.0.11
BitKeeper/etc/gone: auto-union BitKeeper/etc/logging_ok: auto-union Makefile.am: Auto merged bdb/os/os_handle.c: Auto merged client/mysqladmin.c: Auto merged client/mysqlcheck.c: Auto merged client/mysqldump.c: Auto merged client/mysqltest.c: Auto merged extra/resolveip.c: Auto merged include/Makefile.am: Auto merged include/config-win.h: Auto merged include/my_base.h: Auto merged include/my_global.h: Auto merged include/my_pthread.h: Auto merged include/my_sys.h: Auto merged include/mysql.h: Auto merged innobase/btr/btr0cur.c: Auto merged innobase/os/os0file.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged libmysql/Makefile.am: Auto merged libmysql/Makefile.shared: Auto merged libmysql/manager.c: Auto merged libmysqld/libmysqld.c: Auto merged myisam/ft_static.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_open.c: Auto merged myisam/mi_test3.c: Auto merged myisam/myisamdef.h: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/func_group.result: Auto merged mysql-test/r/func_math.result: Auto merged mysql-test/r/handler.result: Auto merged mysql-test/r/query_cache.result: Auto merged mysql-test/r/select_found.result: Auto merged mysql-test/r/union.result: Auto merged mysql-test/t/backup.test: Auto merged mysql-test/t/bigint.test: Auto merged mysql-test/t/binary.test: Auto merged mysql-test/t/count_distinct.test: Auto merged mysql-test/t/func_crypt.test: Auto merged mysql-test/t/func_group.test: Auto merged mysql-test/t/grant_cache.test: Auto merged mysql-test/t/handler.test: Auto merged mysql-test/t/query_cache.test: Auto merged mysql-test/t/rpl000015.test: Auto merged mysql-test/t/rpl000017.test: Auto merged mysys/default.c: Auto merged mysys/my_getwd.c: Auto merged mysys/my_init.c: Auto merged sql/Makefile.am: Auto merged sql/des_key_file.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_myisam.cc: Auto merged sql/ha_myisammrg.cc: Auto merged sql/handler.cc: Auto merged sql/hostname.cc: Auto merged sql/item.cc: Auto merged sql/item_create.h: Auto merged sql/item_func.h: Auto merged sql/item_strfunc.cc: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/lex.h: Auto merged sql/net_serv.cc: Auto merged sql/opt_sum.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.cc: Auto merged sql/slave.h: Auto merged sql/sql_acl.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.h: Auto merged sql/sql_show.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_udf.cc: Auto merged sql-bench/crash-me.sh: Auto merged sql-bench/server-cfg.sh: Auto merged sql-bench/test-insert.sh: Auto merged sql/share/english/errmsg.txt: Auto merged sql/table.cc: Auto merged Docs/manual.texi: Use remote version client/mysql.cc: Merge configure.in: Merge libmysql/libmysql.c: Merge libmysqld/lib_sql.cc: Merge myisam/ft_stopwords.c: Merge myisam/myisamchk.c: Merge mysql-test/r/bigint.result: Merge mysql-test/r/group_by.result: Merge mysql-test/r/rpl000009.result: Merge mysql-test/t/group_by.test: Merge mysql-test/t/rpl000009.test: Merge mysql-test/t/rpl_rotate_logs.test: Merge mysys/Makefile.am: Merge mysys/charset.c: Merge sql/item.h: Merge sql/item_cmpfunc.cc: Merge sql/item_cmpfunc.h: Merge sql/item_create.cc: Merge sql/item_func.cc: Merge sql/item_strfunc.h: Merge sql/log.cc: Merge sql/mysql_priv.h: Merge sql/mysqld.cc: Merge sql/protocol.cc: Merge sql/slave.cc: Merge sql/sql_class.h: Merge sql/sql_db.cc: Merge sql/sql_handler.cc: Merge sql/sql_parse.cc: Merge sql/sql_select.cc: Merge sql/sql_yacc.yy: Merge
This commit is contained in:
162
client/mysql.cc
162
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)
|
||||
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 (glob_buffer.is_empty())
|
||||
fflush(OUTFILE);
|
||||
fputs(glob_buffer.is_empty() ? construct_prompt() :
|
||||
!in_string ? " -> " :
|
||||
in_string == '\'' ?
|
||||
" '> " : " \"> ", OUTFILE);
|
||||
}
|
||||
line=readline((char*) (glob_buffer.is_empty() ? construct_prompt() :
|
||||
char *prompt= (char*) (glob_buffer.is_empty() ? construct_prompt() :
|
||||
!in_string ? " -> " :
|
||||
in_string == '\'' ?
|
||||
" '> " : " \"> "));
|
||||
#endif
|
||||
" '> " : " \"> ");
|
||||
if (opt_outfile && glob_buffer.is_empty())
|
||||
fflush(OUTFILE);
|
||||
|
||||
#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
|
||||
tee_fputs(prompt, stdout);
|
||||
#ifdef __NETWARE__
|
||||
line=fgets(linebuffer, sizeof(linebuffer)-1, stdin);
|
||||
/* Remove the '\n' */
|
||||
{
|
||||
char *p = strrchr(line, '\n');
|
||||
if (p != NULL)
|
||||
*p = '\0';
|
||||
}
|
||||
#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':
|
||||
|
Reference in New Issue
Block a user