summaryrefslogtreecommitdiff
path: root/client/mysql.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysql.cc')
-rw-r--r--client/mysql.cc134
1 files changed, 54 insertions, 80 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 55fb7700cc4..9ce3139c56f 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -81,7 +81,7 @@ extern "C" {
#endif
#undef bcmp // Fix problem with new readline
-#if defined( __WIN__) || defined(OS2)
+#if defined( __WIN__)
#include <conio.h>
#elif !defined(__NETWARE__)
#include <readline/readline.h>
@@ -101,7 +101,7 @@ extern "C" {
#define cmp_database(cs,A,B) strcmp((A),(B))
#endif
-#if !defined( __WIN__) && !defined( OS2) && !defined(__NETWARE__) && (!defined(HAVE_mit_thread) || !defined(THREAD))
+#if !defined( __WIN__) && !defined(__NETWARE__) && !defined(THREAD)
#define USE_POPEN
#endif
@@ -136,8 +136,7 @@ static my_bool info_flag=0,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;
-static volatile int executing_query= 0, interrupted_query= 0;
+ show_warnings= 0, executing_query= 0, interrupted_query= 0;
static ulong opt_max_allowed_packet, opt_net_buffer_length;
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
static my_string opt_mysql_unix_port=0;
@@ -339,8 +338,7 @@ 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);
-
+static sig_handler handle_sigint(int sig);
int main(int argc,char *argv[])
{
@@ -422,7 +420,7 @@ int main(int argc,char *argv[])
if (opt_sigint_ignore)
signal(SIGINT, SIG_IGN);
else
- signal(SIGINT, mysql_sigint); // Catch SIGINT to clean up
+ signal(SIGINT, handle_sigint); // Catch SIGINT to clean up
signal(SIGQUIT, mysql_end); // Catch SIGQUIT to clean up
/*
@@ -490,28 +488,6 @@ int main(int argc,char *argv[])
#endif
}
-sig_handler mysql_sigint(int sig)
-{
- char kill_buffer[40];
- MYSQL *kill_mysql= NULL;
-
- signal(SIGINT, mysql_sigint);
-
- /* terminate if no query being executed, or we already tried interrupting */
- if (!executing_query || interrupted_query++)
- mysql_end(sig);
-
- kill_mysql= mysql_init(kill_mysql);
- if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
- "", opt_mysql_port, opt_mysql_unix_port,0))
- mysql_end(sig);
- /* kill_buffer is always big enough because max length of %lu is 15 */
- sprintf(kill_buffer, "KILL /*!50000 QUERY */ %lu", mysql_thread_id(&mysql));
- mysql_real_query(kill_mysql, kill_buffer, strlen(kill_buffer));
- mysql_close(kill_mysql);
- tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
-}
-
sig_handler mysql_end(int sig)
{
mysql_close(&mysql);
@@ -555,6 +531,35 @@ sig_handler mysql_end(int sig)
}
+/*
+ This function handles sigint calls
+ If query is in process, kill query
+ no query in process, terminate like previous behavior
+ */
+sig_handler handle_sigint(int sig)
+{
+ char kill_buffer[40];
+ MYSQL *kill_mysql= NULL;
+
+ /* terminate if no query being executed, or we already tried interrupting */
+ if (!executing_query || interrupted_query)
+ mysql_end(sig);
+
+ kill_mysql= mysql_init(kill_mysql);
+ if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
+ "", opt_mysql_port, opt_mysql_unix_port,0))
+ mysql_end(sig);
+
+ /* kill_buffer is always big enough because max length of %lu is 15 */
+ sprintf(kill_buffer, "KILL /*!50000 QUERY */ %lu", mysql_thread_id(&mysql));
+ mysql_real_query(kill_mysql, kill_buffer, strlen(kill_buffer));
+ mysql_close(kill_mysql);
+ tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
+
+ interrupted_query= 1;
+}
+
+
static struct my_option my_long_options[] =
{
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
@@ -993,7 +998,7 @@ static int get_options(int argc, char **argv)
static int read_and_execute(bool interactive)
{
-#if defined(OS2) || defined(__NETWARE__)
+#if defined(__NETWARE__)
char linebuffer[254];
String buffer;
#endif
@@ -1030,9 +1035,7 @@ static int read_and_execute(bool interactive)
if (opt_outfile && glob_buffer.is_empty())
fflush(OUTFILE);
- interrupted_query= 0;
-
-#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
+#if defined( __WIN__) || defined(__NETWARE__)
tee_fputs(prompt, stdout);
#if defined(__NETWARE__)
line=fgets(linebuffer, sizeof(linebuffer)-1, stdin);
@@ -1043,7 +1046,7 @@ static int read_and_execute(bool interactive)
if (p != NULL)
*p = '\0';
}
-#elif defined(__WIN__)
+#else defined(__WIN__)
if (!tmpbuf.is_alloced())
tmpbuf.alloc(65535);
tmpbuf.length(0);
@@ -1059,32 +1062,12 @@ static int read_and_execute(bool interactive)
*/
} while (tmpbuf.alloced_length() <= clen);
line= buffer.c_ptr();
-#else /* OS2 */
- buffer.length(0);
- /* _cgets() expects the buffer size - 3 as the first byte */
- linebuffer[0]= (char) sizeof(linebuffer) - 3;
- do
- {
- line= _cgets(linebuffer);
- buffer.append(line, (unsigned char)linebuffer[1]);
- /*
- If _cgets() gets an input line that is linebuffer[0] bytes
- long, the next call to _cgets() will return immediately with
- linebuffer[1] == 0, and it does the same thing for input that
- is linebuffer[0]-1 bytes long. So it appears that even though
- _cgets() replaces the newline (which is two bytes on Window) with
- a nil, it still needs the space in the linebuffer for it. This is,
- naturally, undocumented.
- */
- } while ((unsigned char)linebuffer[0] <=
- (unsigned char)linebuffer[1] + 1);
- line= buffer.c_ptr();
#endif /* __NETWARE__ */
#else
if (opt_outfile)
fputs(prompt, OUTFILE);
line= readline(prompt);
-#endif /* defined( __WIN__) || defined(OS2) || defined(__NETWARE__) */
+#endif /* defined( __WIN__) || defined(__NETWARE__) */
/*
When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
@@ -1136,7 +1119,7 @@ static int read_and_execute(bool interactive)
}
}
-#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
+#if defined( __WIN__) || defined(__NETWARE__)
buffer.free();
#endif
#if defined( __WIN__)
@@ -2000,6 +1983,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
uint error= 0;
int err= 0;
+ interrupted_query= 0;
if (!status.batch)
{
old_buffer= *buffer; // Save for edit command
@@ -2035,9 +2019,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
}
timer=start_timer();
-
executing_query= 1;
-
error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length());
#ifdef HAVE_READLINE
@@ -2051,8 +2033,8 @@ com_go(String *buffer,char *line __attribute__((unused)))
if (error)
{
- buffer->length(0); // Remove query on error
executing_query= 0;
+ buffer->length(0); // Remove query on error
return error;
}
error=0;
@@ -2065,7 +2047,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql))
{
executing_query= 0;
- return put_error(&mysql);
+ return put_error(&mysql);
}
}
else
@@ -2074,7 +2056,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
if (error)
{
executing_query= 0;
- return error;
+ return error;
}
}
@@ -2136,9 +2118,6 @@ com_go(String *buffer,char *line __attribute__((unused)))
fflush(stdout);
mysql_free_result(result);
} while (!(err= mysql_next_result(&mysql)));
-
- executing_query= 0;
-
if (err >= 1)
error= put_error(&mysql);
@@ -2153,6 +2132,7 @@ com_go(String *buffer,char *line __attribute__((unused)))
(mysql.server_status & SERVER_STATUS_DB_DROPPED))
get_current_db();
+ executing_query= 0;
return error; /* New command follows */
}
@@ -2368,6 +2348,8 @@ print_table_data(MYSQL_RES *result)
while ((cur= mysql_fetch_row(result)))
{
+ if (interrupted_query)
+ break;
ulong *lengths= mysql_fetch_lengths(result);
(void) tee_fputs("| ", PAGER);
mysql_field_seek(result, 0);
@@ -2376,11 +2358,9 @@ print_table_data(MYSQL_RES *result)
const char *buffer;
uint data_length;
uint field_max_length;
- bool right_justified;
uint visible_length;
uint extra_padding;
- /* If this column may have a null value, use "NULL" for empty. */
if (cur[off] == NULL)
{
buffer= "NULL";
@@ -2474,6 +2454,8 @@ print_table_data_html(MYSQL_RES *result)
}
while ((cur = mysql_fetch_row(result)))
{
+ if (interrupted_query)
+ break;
ulong *lengths=mysql_fetch_lengths(result);
(void) tee_fputs("<TR>", PAGER);
for (uint i=0; i < mysql_num_fields(result); i++)
@@ -2503,6 +2485,8 @@ print_table_data_xml(MYSQL_RES *result)
fields = mysql_fetch_fields(result);
while ((cur = mysql_fetch_row(result)))
{
+ if (interrupted_query)
+ break;
ulong *lengths=mysql_fetch_lengths(result);
(void) tee_fputs("\n <row>\n", PAGER);
for (uint i=0; i < mysql_num_fields(result); i++)
@@ -2537,6 +2521,8 @@ print_table_data_vertically(MYSQL_RES *result)
mysql_field_seek(result,0);
for (uint row_count=1; (cur= mysql_fetch_row(result)); row_count++)
{
+ if (interrupted_query)
+ break;
mysql_field_seek(result,0);
tee_fprintf(PAGER,
"*************************** %d. row ***************************\n", row_count);
@@ -3506,9 +3492,6 @@ void tee_fprintf(FILE *file, const char *fmt, ...)
NETWARE_YIELD;
va_start(args, fmt);
(void) vfprintf(file, fmt, args);
-#ifdef OS2
- fflush( file);
-#endif
va_end(args);
if (opt_outfile)
@@ -3524,9 +3507,6 @@ void tee_fputs(const char *s, FILE *file)
{
NETWARE_YIELD;
fputs(s, file);
-#ifdef OS2
- fflush( file);
-#endif
if (opt_outfile)
fputs(s, OUTFILE);
}
@@ -3537,9 +3517,6 @@ void tee_puts(const char *s, FILE *file)
NETWARE_YIELD;
fputs(s, file);
fputs("\n", file);
-#ifdef OS2
- fflush( file);
-#endif
if (opt_outfile)
{
fputs(s, OUTFILE);
@@ -3550,14 +3527,11 @@ void tee_puts(const char *s, FILE *file)
void tee_putc(int c, FILE *file)
{
putc(c, file);
-#ifdef OS2
- fflush( file);
-#endif
if (opt_outfile)
putc(c, OUTFILE);
}
-#if defined( __WIN__) || defined( OS2) || defined(__NETWARE__)
+#if defined( __WIN__) || defined(__NETWARE__)
#include <time.h>
#else
#include <sys/times.h>
@@ -3569,7 +3543,7 @@ void tee_putc(int c, FILE *file)
static ulong start_timer(void)
{
-#if defined( __WIN__) || defined( OS2) || defined(__NETWARE__)
+#if defined( __WIN__) || defined(__NETWARE__)
return clock();
#else
struct tms tms_tmp;