mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Merge MySQL->MariaDB
* Finished Monty and Jani's merge * Some InnoDB tests still fail (because it's old xtradb code run against newer testsuite). They are expected to go after mergning with the latest xtradb.
This commit is contained in:
164
client/mysql.cc
164
client/mysql.cc
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2000-2008 MySQL AB
|
||||
/* Copyright (C) 2000-2009 MySQL AB & Monty Program Ab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -115,7 +115,7 @@ extern "C" {
|
||||
#define PROMPT_CHAR '\\'
|
||||
#define DEFAULT_DELIMITER ";"
|
||||
|
||||
#define MAX_BATCH_BUFFER_SIZE (1024L * 1024L)
|
||||
#define MAX_BATCH_BUFFER_SIZE (1024L * 1024L * 1024L)
|
||||
|
||||
typedef struct st_status
|
||||
{
|
||||
@@ -143,7 +143,8 @@ static my_bool ignore_errors=0,wait_flag=0,quick=0,
|
||||
tty_password= 0, opt_nobeep=0, opt_reconnect=1,
|
||||
default_charset_used= 0, opt_secure_auth= 0,
|
||||
default_pager_set= 0, opt_sigint_ignore= 0,
|
||||
show_warnings= 0, executing_query= 0, interrupted_query= 0;
|
||||
show_warnings= 0, executing_query= 0, interrupted_query= 0,
|
||||
ignore_spaces= 0;
|
||||
static my_bool debug_info_flag, debug_check_flag, batch_abort_on_error;
|
||||
static my_bool column_types_flag;
|
||||
static my_bool preserve_comments= 0;
|
||||
@@ -169,6 +170,8 @@ static const char *xmlmeta[] = {
|
||||
"<", "<",
|
||||
">", ">",
|
||||
"\"", """,
|
||||
/* Turn \0 into a space. Why not �? That's not valid XML or HTML. */
|
||||
"\0", " ",
|
||||
0, 0
|
||||
};
|
||||
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
|
||||
@@ -248,7 +251,7 @@ typedef struct {
|
||||
|
||||
static COMMANDS commands[] = {
|
||||
{ "?", '?', com_help, 1, "Synonym for `help'." },
|
||||
{ "clear", 'c', com_clear, 0, "Clear command."},
|
||||
{ "clear", 'c', com_clear, 0, "Clear the current input statement."},
|
||||
{ "connect",'r', com_connect,1,
|
||||
"Reconnect to the server. Optional arguments are db and host." },
|
||||
{ "delimiter", 'd', com_delimiter, 1,
|
||||
@@ -1183,7 +1186,12 @@ int main(int argc,char *argv[])
|
||||
histfile= 0;
|
||||
}
|
||||
}
|
||||
if (histfile)
|
||||
|
||||
/* We used to suggest setting MYSQL_HISTFILE=/dev/null. */
|
||||
if (histfile && strncmp(histfile, "/dev/null", 10) == 0)
|
||||
histfile= NULL;
|
||||
|
||||
if (histfile && histfile[0])
|
||||
{
|
||||
if (verbose)
|
||||
tee_fprintf(stdout, "Reading history-file %s\n",histfile);
|
||||
@@ -1218,7 +1226,8 @@ sig_handler mysql_end(int sig)
|
||||
{
|
||||
mysql_close(&mysql);
|
||||
#ifdef HAVE_READLINE
|
||||
if (!status.batch && !quick && !opt_html && !opt_xml && histfile)
|
||||
if (!status.batch && !quick && !opt_html && !opt_xml &&
|
||||
histfile && histfile[0])
|
||||
{
|
||||
/* write-history */
|
||||
if (verbose)
|
||||
@@ -1349,7 +1358,7 @@ static struct my_option my_long_options[] =
|
||||
{"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
|
||||
(uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
||||
#endif
|
||||
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit .",
|
||||
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
|
||||
(uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
|
||||
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"debug-info", 'T', "Print some debug info at exit.", (uchar**) &debug_info_flag,
|
||||
@@ -1376,8 +1385,9 @@ static struct my_option my_long_options[] =
|
||||
{"no-named-commands", 'g',
|
||||
"Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead.",
|
||||
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"ignore-spaces", 'i', "Ignore space after function names.", 0, 0, 0,
|
||||
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
{"ignore-spaces", 'i', "Ignore space after function names.",
|
||||
(uchar**) &ignore_spaces, (uchar**) &ignore_spaces, 0, GET_BOOL, NO_ARG, 0, 0,
|
||||
0, 0, 0, 0},
|
||||
{"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
|
||||
(uchar**) &opt_local_infile,
|
||||
(uchar**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
||||
@@ -1801,6 +1811,10 @@ static int get_options(int argc, char **argv)
|
||||
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
|
||||
if (debug_check_flag)
|
||||
my_end_arg= MY_CHECK_ERROR;
|
||||
|
||||
if (ignore_spaces)
|
||||
connect_flag|= CLIENT_IGNORE_SPACE;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -1974,7 +1988,7 @@ static COMMANDS *find_command(char *name,char cmd_char)
|
||||
*/
|
||||
if (strstr(name, "\\g") || (strstr(name, delimiter) &&
|
||||
!(strlen(name) >= 9 &&
|
||||
!my_strnncoll(charset_info,
|
||||
!my_strnncoll(&my_charset_latin1,
|
||||
(uchar*) name, 9,
|
||||
(const uchar*) "delimiter",
|
||||
9))))
|
||||
@@ -1995,8 +2009,7 @@ static COMMANDS *find_command(char *name,char cmd_char)
|
||||
{
|
||||
if (commands[i].func &&
|
||||
(((name &&
|
||||
!my_strnncoll(charset_info,
|
||||
(uchar*) name, len,
|
||||
!my_strnncoll(&my_charset_latin1, (uchar*) name, len,
|
||||
(uchar*) commands[i].name, len) &&
|
||||
!commands[i].name[len] &&
|
||||
(!end || (end && commands[i].takes_params)))) ||
|
||||
@@ -2300,8 +2313,10 @@ extern "C" char **new_mysql_completion (const char *text, int start, int end);
|
||||
*/
|
||||
|
||||
#if defined(USE_NEW_READLINE_INTERFACE)
|
||||
static int fake_magic_space(int, int);
|
||||
extern "C" char *no_completion(const char*,int)
|
||||
#elif defined(USE_LIBEDIT_INTERFACE)
|
||||
static int fake_magic_space(const char *, int);
|
||||
extern "C" int no_completion(const char*,int)
|
||||
#else
|
||||
extern "C" char *no_completion()
|
||||
@@ -2378,6 +2393,18 @@ static int not_in_history(const char *line)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#if defined(USE_NEW_READLINE_INTERFACE)
|
||||
static int fake_magic_space(int, int)
|
||||
#else
|
||||
static int fake_magic_space(const char *, int)
|
||||
#endif
|
||||
{
|
||||
rl_insert(1, ' ');
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void initialize_readline (char *name)
|
||||
{
|
||||
/* Allow conditional parsing of the ~/.inputrc file. */
|
||||
@@ -2387,12 +2414,15 @@ static void initialize_readline (char *name)
|
||||
#if defined(USE_NEW_READLINE_INTERFACE)
|
||||
rl_attempted_completion_function= (rl_completion_func_t*)&new_mysql_completion;
|
||||
rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
|
||||
|
||||
rl_add_defun("magic-space", (rl_command_func_t *)&fake_magic_space, -1);
|
||||
#elif defined(USE_LIBEDIT_INTERFACE)
|
||||
#ifdef HAVE_LOCALE_H
|
||||
setlocale(LC_ALL,""); /* so as libedit use isprint */
|
||||
#endif
|
||||
rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;
|
||||
rl_completion_entry_function= &no_completion;
|
||||
rl_add_defun("magic-space", (Function*)&fake_magic_space, -1);
|
||||
#else
|
||||
rl_attempted_completion_function= (CPPFunction*)&new_mysql_completion;
|
||||
rl_completion_entry_function= &no_completion;
|
||||
@@ -2730,7 +2760,7 @@ static int com_server_help(String *buffer __attribute__((unused)),
|
||||
{
|
||||
MYSQL_ROW cur;
|
||||
const char *server_cmd= buffer->ptr();
|
||||
char cmd_buf[100];
|
||||
char cmd_buf[100 + 1];
|
||||
MYSQL_RES *result;
|
||||
int error;
|
||||
|
||||
@@ -3306,6 +3336,9 @@ print_table_data(MYSQL_RES *result)
|
||||
uint visible_length;
|
||||
uint extra_padding;
|
||||
|
||||
if (off)
|
||||
(void) tee_fputs(" ", PAGER);
|
||||
|
||||
if (cur[off] == NULL)
|
||||
{
|
||||
buffer= "NULL";
|
||||
@@ -3340,7 +3373,7 @@ print_table_data(MYSQL_RES *result)
|
||||
else
|
||||
tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, FALSE);
|
||||
}
|
||||
tee_fputs(" | ", PAGER);
|
||||
tee_fputs(" |", PAGER);
|
||||
}
|
||||
(void) tee_fputs("\n", PAGER);
|
||||
}
|
||||
@@ -3391,9 +3424,12 @@ print_table_data_html(MYSQL_RES *result)
|
||||
{
|
||||
while((field = mysql_fetch_field(result)))
|
||||
{
|
||||
tee_fprintf(PAGER, "<TH>%s</TH>", (field->name ?
|
||||
(field->name[0] ? field->name :
|
||||
" ") : "NULL"));
|
||||
tee_fputs("<TH>", PAGER);
|
||||
if (field->name && field->name[0])
|
||||
xmlencode_print(field->name, field->name_length);
|
||||
else
|
||||
tee_fputs(field->name ? " " : "NULL", PAGER);
|
||||
tee_fputs("</TH>", PAGER);
|
||||
}
|
||||
(void) tee_fputs("</TR>", PAGER);
|
||||
}
|
||||
@@ -3406,7 +3442,7 @@ print_table_data_html(MYSQL_RES *result)
|
||||
for (uint i=0; i < mysql_num_fields(result); i++)
|
||||
{
|
||||
(void) tee_fputs("<TD>", PAGER);
|
||||
safe_put_field(cur[i],lengths[i]);
|
||||
xmlencode_print(cur[i], lengths[i]);
|
||||
(void) tee_fputs("</TD>", PAGER);
|
||||
}
|
||||
(void) tee_fputs("</TR>", PAGER);
|
||||
@@ -3477,11 +3513,29 @@ print_table_data_vertically(MYSQL_RES *result)
|
||||
mysql_field_seek(result,0);
|
||||
tee_fprintf(PAGER,
|
||||
"*************************** %d. row ***************************\n", row_count);
|
||||
|
||||
ulong *lengths= mysql_fetch_lengths(result);
|
||||
|
||||
for (uint off=0; off < mysql_num_fields(result); off++)
|
||||
{
|
||||
field= mysql_fetch_field(result);
|
||||
tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
|
||||
tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
|
||||
if (cur[off])
|
||||
{
|
||||
unsigned int i;
|
||||
const char *p;
|
||||
|
||||
for (i= 0, p= cur[off]; i < lengths[off]; i+= 1, p+= 1)
|
||||
{
|
||||
if (*p == '\0')
|
||||
tee_putc((int)' ', PAGER);
|
||||
else
|
||||
tee_putc((int)*p, PAGER);
|
||||
}
|
||||
tee_putc('\n', PAGER);
|
||||
}
|
||||
else
|
||||
tee_fprintf(PAGER, "NULL\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3548,7 +3602,7 @@ xmlencode_print(const char *src, uint length)
|
||||
tee_fputs("NULL", PAGER);
|
||||
else
|
||||
{
|
||||
for (const char *p = src; *p && length; *p++, length--)
|
||||
for (const char *p = src; length; *p++, length--)
|
||||
{
|
||||
const char *t;
|
||||
if ((t = array_value(xmlmeta, *p)))
|
||||
@@ -3568,7 +3622,12 @@ safe_put_field(const char *pos,ulong length)
|
||||
else
|
||||
{
|
||||
if (opt_raw_data)
|
||||
tee_fputs(pos, PAGER);
|
||||
{
|
||||
unsigned long i;
|
||||
/* Can't use tee_fputs(), it stops with NUL characters. */
|
||||
for (i= 0; i < length; i++, pos++)
|
||||
tee_putc(*pos, PAGER);
|
||||
}
|
||||
else for (const char *end=pos+length ; pos != end ; pos++)
|
||||
{
|
||||
#ifdef USE_MB
|
||||
@@ -4269,41 +4328,36 @@ com_status(String *buffer __attribute__((unused)),
|
||||
MYSQL_RES *result;
|
||||
LINT_INIT(result);
|
||||
|
||||
if (mysql_real_query_for_lazy(
|
||||
C_STRING_WITH_LEN("select DATABASE(), USER() limit 1")))
|
||||
return 0;
|
||||
|
||||
tee_puts("--------------", stdout);
|
||||
usage(1); /* Print version */
|
||||
if (connected)
|
||||
tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
|
||||
/*
|
||||
Don't remove "limit 1",
|
||||
it is protection againts SQL_SELECT_LIMIT=0
|
||||
*/
|
||||
if (mysql_store_result_for_lazy(&result))
|
||||
{
|
||||
tee_fprintf(stdout, "\nConnection id:\t\t%lu\n",mysql_thread_id(&mysql));
|
||||
/*
|
||||
Don't remove "limit 1",
|
||||
it is protection againts SQL_SELECT_LIMIT=0
|
||||
*/
|
||||
if (!mysql_query(&mysql,"select DATABASE(), USER() limit 1") &&
|
||||
(result=mysql_use_result(&mysql)))
|
||||
MYSQL_ROW cur=mysql_fetch_row(result);
|
||||
if (cur)
|
||||
{
|
||||
MYSQL_ROW cur=mysql_fetch_row(result);
|
||||
if (cur)
|
||||
{
|
||||
tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
|
||||
tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
|
||||
tee_fprintf(stdout, "Current user:\t\t%s\n", cur[1]);
|
||||
}
|
||||
mysql_free_result(result);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
if ((status_str= mysql_get_ssl_cipher(&mysql)))
|
||||
tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
|
||||
status_str);
|
||||
else
|
||||
#endif /* HAVE_OPENSSL */
|
||||
tee_puts("SSL:\t\t\tNot in use", stdout);
|
||||
}
|
||||
if ((status_str= mysql_get_ssl_cipher(&mysql)))
|
||||
tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
|
||||
status_str);
|
||||
else
|
||||
{
|
||||
vidattr(A_BOLD);
|
||||
tee_fprintf(stdout, "\nNo connection\n");
|
||||
vidattr(A_NORMAL);
|
||||
return 0;
|
||||
}
|
||||
#endif /* HAVE_OPENSSL */
|
||||
tee_puts("SSL:\t\t\tNot in use", stdout);
|
||||
|
||||
if (skip_updates)
|
||||
{
|
||||
vidattr(A_BOLD);
|
||||
@@ -4322,8 +4376,14 @@ com_status(String *buffer __attribute__((unused)),
|
||||
tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
|
||||
|
||||
/* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
|
||||
if (!mysql_query(&mysql,"select @@character_set_client, @@character_set_connection, @@character_set_server, @@character_set_database limit 1") &&
|
||||
(result=mysql_use_result(&mysql)))
|
||||
if (mysql_real_query_for_lazy(C_STRING_WITH_LEN(
|
||||
"select @@character_set_client, @@character_set_connection, "
|
||||
"@@character_set_server, @@character_set_database limit 1")))
|
||||
{
|
||||
if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)
|
||||
return 0;
|
||||
}
|
||||
if (mysql_store_result_for_lazy(&result))
|
||||
{
|
||||
MYSQL_ROW cur=mysql_fetch_row(result);
|
||||
if (cur)
|
||||
|
Reference in New Issue
Block a user