summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorTatiana A. Nurnberg <azundris@mysql.com>2009-03-23 05:21:45 +0100
committerTatiana A. Nurnberg <azundris@mysql.com>2009-03-23 05:21:45 +0100
commitaeb9747a95dd77c983d58f553637812c99507753 (patch)
treef5252fb21d5ea7c6e6f19beba5ee34903fc4ee47 /client
parent4093dcfb03e3f39bdfc7c65bea866a070bf3d11d (diff)
parentde750af17dee6b2e7cbcb77b5fa03cd81560d9a2 (diff)
downloadmariadb-git-aeb9747a95dd77c983d58f553637812c99507753.tar.gz
auto-merge
Diffstat (limited to 'client')
-rw-r--r--client/my_readline.h2
-rw-r--r--client/mysql.cc45
-rw-r--r--client/mysql_upgrade.c2
-rw-r--r--client/mysqladmin.cc2
-rw-r--r--client/mysqlbinlog.cc16
-rw-r--r--client/mysqlcheck.c9
-rw-r--r--client/mysqldump.c70
-rw-r--r--client/mysqlmanager-pwgen.c5
-rw-r--r--client/mysqltest.c78
-rw-r--r--client/readline.cc46
-rw-r--r--client/sql_string.cc21
11 files changed, 176 insertions, 120 deletions
diff --git a/client/my_readline.h b/client/my_readline.h
index 47be7fa9294..32d6da4c626 100644
--- a/client/my_readline.h
+++ b/client/my_readline.h
@@ -29,5 +29,5 @@ typedef struct st_line_buffer
extern LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file);
extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, my_string str);
-extern char *batch_readline(LINE_BUFFER *buffer);
+extern char *batch_readline(LINE_BUFFER *buffer, bool *truncated);
extern void batch_readline_end(LINE_BUFFER *buffer);
diff --git a/client/mysql.cc b/client/mysql.cc
index e035cee16f9..983d7719c3c 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -112,6 +112,8 @@ extern "C" {
#define PROMPT_CHAR '\\'
#define DEFAULT_DELIMITER ";"
+#define MAX_BATCH_BUFFER_SIZE (1024L * 1024L)
+
typedef struct st_status
{
int exit_status;
@@ -243,7 +245,7 @@ static COMMANDS commands[] = {
{ "connect",'r', com_connect,1,
"Reconnect to the server. Optional arguments are db and host." },
{ "delimiter", 'd', com_delimiter, 1,
- "Set statement delimiter. NOTE: Takes the rest of the line as new delimiter." },
+ "Set statement delimiter." },
#ifdef USE_POPEN
{ "edit", 'e', com_edit, 0, "Edit command with $EDITOR."},
#endif
@@ -1035,7 +1037,7 @@ static void fix_history(String *final_command);
static COMMANDS *find_command(char *name,char cmd_name);
static bool add_line(String &buffer,char *line,char *in_string,
- bool *ml_comment);
+ bool *ml_comment, bool truncated);
static void remove_cntrl(String &buffer);
static void print_table_data(MYSQL_RES *result);
static void print_table_data_html(MYSQL_RES *result);
@@ -1117,7 +1119,7 @@ int main(int argc,char *argv[])
exit(1);
}
if (status.batch && !status.line_buff &&
- !(status.line_buff=batch_readline_init(opt_max_allowed_packet+512,stdin)))
+ !(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin)))
{
free_defaults(defaults_argv);
my_end(0);
@@ -1197,7 +1199,7 @@ int main(int argc,char *argv[])
#endif
sprintf(buff, "%s",
#ifndef NOT_YET
- "Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n");
+ "Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n");
#else
"Type 'help [[%]function name[%]]' to get help on usage of function.\n");
#endif
@@ -1226,7 +1228,7 @@ sig_handler mysql_sigint(int sig)
goto err;
/* 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_real_query(kill_mysql, kill_buffer, (uint) strlen(kill_buffer));
mysql_close(kill_mysql);
tee_fprintf(stdout, "Query aborted by Ctrl+C\n");
@@ -1766,13 +1768,14 @@ static int read_and_execute(bool interactive)
ulong line_number=0;
bool ml_comment= 0;
COMMANDS *com;
+ bool truncated= 0;
status.exit_status=1;
for (;;)
{
if (!interactive)
{
- line=batch_readline(status.line_buff);
+ line=batch_readline(status.line_buff, &truncated);
/*
Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
Editors like "notepad" put this marker in
@@ -1891,7 +1894,7 @@ static int read_and_execute(bool interactive)
#endif
continue;
}
- if (add_line(glob_buffer,line,&in_string,&ml_comment))
+ if (add_line(glob_buffer,line,&in_string,&ml_comment, truncated))
break;
}
/* if in batch mode, send last query even if it doesn't end with \g or go */
@@ -1977,7 +1980,7 @@ static COMMANDS *find_command(char *name,char cmd_char)
static bool add_line(String &buffer,char *line,char *in_string,
- bool *ml_comment)
+ bool *ml_comment, bool truncated)
{
uchar inchar;
char buff[80], *pos, *out;
@@ -2222,8 +2225,23 @@ static bool add_line(String &buffer,char *line,char *in_string,
}
if (out != line || !buffer.is_empty())
{
- *out++='\n';
uint length=(uint) (out-line);
+
+ if (!truncated &&
+ (length < 9 ||
+ my_strnncoll (charset_info,
+ (uchar *)line, 9, (const uchar *) "delimiter", 9)))
+ {
+ /*
+ Don't add a new line in case there's a DELIMITER command to be
+ added to the glob buffer (e.g. on processing a line like
+ "<command>;DELIMITER <non-eof>") : similar to how a new line is
+ not added in the case when the DELIMITER is the first command
+ entered with an empty glob buffer.
+ */
+ *out++='\n';
+ length++;
+ }
if (buffer.length() + length >= buffer.alloced_length())
buffer.realloc(buffer.length()+length+IO_SIZE);
if ((!*ml_comment || preserve_comments) && buffer.append(line, length))
@@ -2832,7 +2850,7 @@ com_charset(String *buffer __attribute__((unused)), char *line)
param= get_arg(buff, 0);
if (!param || !*param)
{
- return put_info("Usage: \\C char_setname | charset charset_name",
+ return put_info("Usage: \\C charset_name | charset charset_name",
INFO_ERROR, 0);
}
new_cs= get_charset_by_csname(param, MY_CS_PRIMARY, MYF(MY_WME));
@@ -3449,7 +3467,7 @@ static void print_warnings()
/* Get the warnings */
query= "show warnings";
- mysql_real_query_for_lazy(query, strlen(query));
+ mysql_real_query_for_lazy(query, (uint) strlen(query));
mysql_store_result_for_lazy(&result);
/* Bail out when no warnings */
@@ -3872,7 +3890,7 @@ static int com_source(String *buffer, char *line)
return put_info(buff, INFO_ERROR, 0);
}
- if (!(line_buff=batch_readline_init(opt_max_allowed_packet+512,sql_file)))
+ if (!(line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, sql_file)))
{
my_fclose(sql_file,MYF(0));
return put_info("Can't initialize batch_readline", INFO_ERROR, 0);
@@ -4329,7 +4347,8 @@ server_version_string(MYSQL *con)
MYSQL_ROW cur = mysql_fetch_row(result);
if (cur && cur[0])
{
- bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
+ bufp = strxnmov(bufp, (uint) (sizeof buf - (bufp - buf)), " ", cur[0],
+ NullS);
}
mysql_free_result(result);
}
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c
index 74e8c9dd577..e3500c81fb9 100644
--- a/client/mysql_upgrade.c
+++ b/client/mysql_upgrade.c
@@ -429,7 +429,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
MYF(MY_WME))) < 0)
die("Failed to create temporary file for defaults");
- if (my_write(fd, query, strlen(query),
+ if (my_write(fd, query, (uint) strlen(query),
MYF(MY_FNABP | MY_WME)))
{
my_close(fd, MYF(0));
diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc
index 54f67c5df2d..24b95be8626 100644
--- a/client/mysqladmin.cc
+++ b/client/mysqladmin.cc
@@ -844,7 +844,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
bool old= (find_type(argv[0], &command_typelib, 2) ==
ADMIN_OLD_PASSWORD);
#ifdef __WIN__
- uint pw_len= strlen(pw);
+ uint pw_len= (uint) strlen(pw);
if (pw_len > 1 && pw[0] == '\'' && pw[pw_len-1] == '\'')
printf("Warning: single quotes were not trimmed from the password by"
" your command\nline client, as you might have expected.\n");
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index f0a4c8d2abf..ed072902730 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -105,7 +105,7 @@ static MYSQL* safe_connect();
class Load_log_processor
{
char target_dir_name[FN_REFLEN];
- int target_dir_name_len;
+ size_t target_dir_name_len;
/*
When we see first event corresponding to some LOAD DATA statement in
@@ -275,7 +275,7 @@ File Load_log_processor::prepare_new_file_for_old_format(Load_log_event *le,
File file;
fn_format(filename, le->fname, target_dir_name, "", 1);
- len= strlen(filename);
+ len= (uint) strlen(filename);
tail= filename + len;
if ((file= create_unique_file(filename,tail)) < 0)
@@ -284,7 +284,7 @@ File Load_log_processor::prepare_new_file_for_old_format(Load_log_event *le,
return -1;
}
- le->set_fname_outside_temp_buf(filename,len+strlen(tail));
+ le->set_fname_outside_temp_buf(filename,len+(uint) strlen(tail));
return file;
}
@@ -369,7 +369,7 @@ int Load_log_processor::process_first_event(const char *bname, uint blen,
uint file_id,
Create_file_log_event *ce)
{
- uint full_len= target_dir_name_len + blen + 9 + 9 + 1;
+ size_t full_len= target_dir_name_len + blen + 9 + 9 + 1;
int error= 0;
char *fname, *ptr;
File file;
@@ -403,7 +403,7 @@ int Load_log_processor::process_first_event(const char *bname, uint blen,
}
if (ce)
- ce->set_fname_outside_temp_buf(fname, strlen(fname));
+ ce->set_fname_outside_temp_buf(fname, (uint) strlen(fname));
if (my_write(file, (byte*)block, block_len, MYF(MY_WME|MY_NABP)))
error= -1;
@@ -416,7 +416,7 @@ int Load_log_processor::process_first_event(const char *bname, uint blen,
int Load_log_processor::process(Create_file_log_event *ce)
{
const char *bname= ce->fname + dirname_length(ce->fname);
- uint blen= ce->fname_len - (bname-ce->fname);
+ uint blen= (uint) (ce->fname_len - (bname-ce->fname));
return process_first_event(bname, blen, ce->block, ce->block_len,
ce->file_id, ce);
@@ -864,7 +864,7 @@ static my_time_t convert_str_to_timestamp(const char* str)
long dummy_my_timezone;
my_bool dummy_in_dst_time_gap;
/* We require a total specification (date AND time) */
- if (str_to_datetime(str, strlen(str), &l_time, 0, &was_cut) !=
+ if (str_to_datetime(str, (uint) strlen(str), &l_time, 0, &was_cut) !=
MYSQL_TIMESTAMP_DATETIME || was_cut)
{
fprintf(stderr, "Incorrect date and time argument: %s\n", str);
@@ -1109,7 +1109,7 @@ could be out of memory");
int4store(buf, (uint32)start_position);
int2store(buf + BIN_LOG_HEADER_SIZE, binlog_flags);
- size_s tlen = strlen(logname);
+ size_t tlen= strlen(logname);
if (tlen > UINT_MAX)
{
fprintf(stderr,"Log name too long\n");
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index 513d1974ed0..15922e672a6 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -328,7 +328,7 @@ static int get_options(int *argc, char ***argv)
if (!what_to_do)
{
- int pnlen = strlen(my_progname);
+ size_t pnlen= strlen(my_progname);
if (pnlen < 6) /* name too short */
what_to_do = DO_CHECK;
@@ -414,7 +414,8 @@ static int process_selected_tables(char *db, char **table_names, int tables)
space is for more readable output in logs and in case of error
*/
char *table_names_comma_sep, *end;
- int i, tot_length = 0;
+ size_t tot_length= 0;
+ int i= 0;
for (i = 0; i < tables; i++)
tot_length+= fixed_name_length(*(table_names + i)) + 2;
@@ -430,7 +431,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
*end++= ',';
}
*--end = 0;
- handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1);
+ handle_request_for_tables(table_names_comma_sep + 1, (uint) (tot_length - 1));
my_free(table_names_comma_sep, MYF(0));
}
else
@@ -452,7 +453,7 @@ static uint fixed_name_length(const char *name)
else if (*p == '.')
extra_length+= 2;
}
- return (p - name) + extra_length;
+ return (uint) ((p - name) + extra_length);
}
diff --git a/client/mysqldump.c b/client/mysqldump.c
index ced34f16212..a9d2788de05 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2009 Sun Microsystems, Inc.
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
@@ -662,7 +662,7 @@ static void free_table_ent(char *key)
byte* get_table_key(const char *entry, uint *length,
my_bool not_used __attribute__((unused)))
{
- *length= strlen(entry);
+ *length= (uint) strlen(entry);
return (byte*) entry;
}
@@ -778,7 +778,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
opt_set_charset= 0;
opt_compatible_mode_str= argument;
opt_compatible_mode= find_set(&compatible_mode_typelib,
- argument, strlen(argument),
+ argument, (uint) strlen(argument),
&err_ptr, &err_len);
if (err_len)
{
@@ -791,7 +791,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
uint size_for_sql_mode= 0;
const char **ptr;
for (ptr= compatible_mode_names; *ptr; ptr++)
- size_for_sql_mode+= strlen(*ptr);
+ size_for_sql_mode+= (uint) strlen(*ptr);
size_for_sql_mode+= sizeof(compatible_mode_names)-1;
DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode);
}
@@ -1039,7 +1039,7 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
"SET SESSION character_set_results = '%s'",
(const char *) cs_name);
- return mysql_real_query(mysql, query_buffer, query_length);
+ return mysql_real_query(mysql, query_buffer, (uint) query_length);
}
@@ -1129,7 +1129,8 @@ static int connect_to_db(char *host, char *user,char *passwd)
DB_error(&mysql_connection, "when trying to connect");
DBUG_RETURN(1);
}
- if (mysql_get_server_version(&mysql_connection) < 40100)
+ if ((mysql_get_server_version(&mysql_connection) < 40100) ||
+ (opt_compatible_mode & 3))
{
/* Don't dump SET NAMES with a pre-4.1 server (bug#7997). */
opt_set_charset= 0;
@@ -1371,7 +1372,8 @@ static void print_xml_tag(FILE * xml_file, const char* sbeg,
fputs(attribute_name, xml_file);
fputc('\"', xml_file);
- print_quoted_xml(xml_file, attribute_value, strlen(attribute_value));
+ print_quoted_xml(xml_file, attribute_value,
+ (uint) strlen(attribute_value));
fputc('\"', xml_file);
attribute_name= va_arg(arg_list, char *);
@@ -1411,7 +1413,7 @@ static void print_xml_null_tag(FILE * xml_file, const char* sbeg,
fputs("<", xml_file);
fputs(stag_atr, xml_file);
fputs("\"", xml_file);
- print_quoted_xml(xml_file, sval, strlen(sval));
+ print_quoted_xml(xml_file, sval, (uint) strlen(sval));
fputs("\" xsi:nil=\"true\" />", xml_file);
fputs(line_end, xml_file);
check_io(xml_file);
@@ -1509,7 +1511,7 @@ static uint dump_routines_for_db(char *db)
DBUG_ENTER("dump_routines_for_db");
DBUG_PRINT("enter", ("db: '%s'", db));
- mysql_real_escape_string(mysql, db_name_buff, db, strlen(db));
+ mysql_real_escape_string(mysql, db_name_buff, db, (uint) strlen(db));
/* nice comments */
if (opt_comments)
@@ -1601,13 +1603,13 @@ static uint dump_routines_for_db(char *db)
Allocate memory for new query string: original string
from SHOW statement and version-specific comments.
*/
- query_str= alloc_query_str(strlen(row[2]) + 23);
+ query_str= alloc_query_str((uint) strlen(row[2]) + 23);
query_str_tail= strnmov(query_str, row[2],
- definer_begin - row[2]);
+ (uint) (definer_begin - row[2]));
query_str_tail= strmov(query_str_tail, "*/ /*!50020");
query_str_tail= strnmov(query_str_tail, definer_begin,
- definer_end - definer_begin);
+ (uint) (definer_end - definer_begin));
query_str_tail= strxmov(query_str_tail, "*/ /*!50003",
definer_end, NullS);
}
@@ -1857,11 +1859,11 @@ static uint get_table_structure(char *table, char *db, char *table_type,
row= mysql_fetch_row(result);
- fprintf(sql_file,
- "SET @saved_cs_client = @@character_set_client;\n"
- "SET character_set_client = utf8;\n"
+ fprintf(sql_file, (opt_compatible_mode & 3) ? "%s;\n" :
+ "/*!40101 SET @saved_cs_client = @@character_set_client */;\n"
+ "/*!40101 SET character_set_client = utf8 */;\n"
"%s;\n"
- "SET character_set_client = @saved_cs_client;\n",
+ "/*!40101 SET character_set_client = @saved_cs_client */;\n",
row[1]);
check_io(sql_file);
@@ -2216,7 +2218,7 @@ static void dump_triggers_for_table(char *table,
char host_name_str[HOSTNAME_LENGTH + 1];
char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3];
- parse_user(row[7], strlen(row[7]), user_name_str, &user_name_len,
+ parse_user(row[7], (uint) strlen(row[7]), user_name_str, &user_name_len,
host_name_str, &host_name_len);
fprintf(sql_file,
@@ -3054,7 +3056,7 @@ static int dump_all_tables_in_db(char *database)
while ((table= getTableName(0)))
{
char *end= strmov(afterdot, table);
- if (include_table(hash_key, end - hash_key))
+ if (include_table(hash_key, (uint) (end - hash_key)))
{
dump_table(table,database);
my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
@@ -3103,6 +3105,11 @@ static my_bool dump_all_views_in_db(char *database)
char *table;
uint numrows;
char table_buff[NAME_LEN*2+3];
+ char hash_key[2*NAME_LEN+2]; /* "db.tablename" */
+ char *afterdot;
+
+ afterdot= strmov(hash_key, database);
+ *afterdot++= '.';
if (init_dumping(database, init_dumping_views))
return 1;
@@ -3112,10 +3119,15 @@ static my_bool dump_all_views_in_db(char *database)
{
DYNAMIC_STRING query;
init_dynamic_string_checked(&query, "LOCK TABLES ", 256, 1024);
- for (numrows= 0 ; (table= getTableName(1)); numrows++)
+ for (numrows= 0 ; (table= getTableName(1)); )
{
- dynstr_append_checked(&query, quote_name(table, table_buff, 1));
- dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
+ char *end= strmov(afterdot, table);
+ if (include_table((uchar*) hash_key,end - hash_key))
+ {
+ numrows++;
+ dynstr_append_checked(&query, quote_name(table, table_buff, 1));
+ dynstr_append_checked(&query, " READ /*!32311 LOCAL */,");
+ }
}
if (numrows && mysql_real_query(mysql, query.str, query.length-1))
DB_error(mysql, "when using LOCK TABLES");
@@ -3129,7 +3141,11 @@ static my_bool dump_all_views_in_db(char *database)
/* We shall continue here, if --force was given */
}
while ((table= getTableName(0)))
- get_view_structure(table, database);
+ {
+ char *end= strmov(afterdot, table);
+ if (include_table((uchar*) hash_key, end - hash_key))
+ get_view_structure(table, database);
+ }
if (opt_xml)
{
fputs("</database>\n", md_result_file);
@@ -3199,7 +3215,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
DBUG_ENTER("dump_selected_tables");
if (init_dumping(db, init_dumping_tables))
- return 1;
+ DBUG_RETURN(1);
init_alloc_root(&root, 8192, 0);
if (!(dump_tables= pos= (char**) alloc_root(&root, tables * sizeof(char *))))
@@ -3561,7 +3577,8 @@ char check_if_ignore_table(const char *table_name, char *table_type)
If these two types, we do want to skip dumping the table
*/
if (!opt_no_data &&
- (!strcmp(table_type,"MRG_MyISAM") || !strcmp(table_type,"MRG_ISAM")))
+ (!strcmp(table_type,"MRG_MyISAM") || !strcmp(table_type,"MRG_ISAM") ||
+ !strcmp(table_type,"FEDERATED")))
result= IGNORE_DATA;
}
mysql_free_result(res);
@@ -3622,7 +3639,7 @@ static char *primary_key_fields(const char *table_name)
do
{
quoted_field= quote_name(row[4], buff, 0);
- result_length+= strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
+ result_length+= (uint) strlen(quoted_field) + 1; /* + 1 for ',' or \0 */
} while ((row= mysql_fetch_row(res)) && atoi(row[3]) > 1);
}
@@ -3682,7 +3699,8 @@ static int replace(DYNAMIC_STRING *ds_str,
return 1;
init_dynamic_string_checked(&ds_tmp, "",
ds_str->length + replace_len, 256);
- dynstr_append_mem_checked(&ds_tmp, ds_str->str, start - ds_str->str);
+ dynstr_append_mem_checked(&ds_tmp, ds_str->str,
+ (uint) (start - ds_str->str));
dynstr_append_mem_checked(&ds_tmp, replace_str, replace_len);
dynstr_append_checked(&ds_tmp, start + search_len);
dynstr_set_checked(ds_str, ds_tmp.str);
diff --git a/client/mysqlmanager-pwgen.c b/client/mysqlmanager-pwgen.c
index 7a857c59743..568358b1cda 100644
--- a/client/mysqlmanager-pwgen.c
+++ b/client/mysqlmanager-pwgen.c
@@ -134,7 +134,6 @@ void get_pass(char* pw, int len)
int main(int argc, char** argv)
{
FILE* fp;
- my_MD5_CTX context;
uchar digest[16];
char pw[17];
uint i;
@@ -147,9 +146,7 @@ int main(int argc, char** argv)
if (!(fp=fopen(outfile,"w")))
die("Could not open '%s'(errno=%d)",outfile,errno);
get_pass(pw,sizeof(pw)-1);
- my_MD5Init(&context);
- my_MD5Update(&context,(uchar*) pw,sizeof(pw)-1);
- my_MD5Final(digest,&context);
+ MY_MD5_HASH(digest,(uchar*) pw,sizeof(pw)-1);
fprintf(fp,"%s:",user);
for (i=0;i<sizeof(digest);i++)
fprintf(fp,"%02x",digest[i]);
diff --git a/client/mysqltest.c b/client/mysqltest.c
index d7fbb6f1f18..64b9f4a5a16 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -801,7 +801,7 @@ void check_command_args(struct st_command *command,
ptr++;
if (ptr > start)
{
- init_dynamic_string(arg->ds, 0, ptr-start, 32);
+ init_dynamic_string(arg->ds, 0, (uint) (ptr - start), 32);
do_eval(arg->ds, start, ptr, FALSE);
}
else
@@ -1156,16 +1156,16 @@ void warning_msg(const char *fmt, ...)
len= my_snprintf(buff, sizeof(buff), "in included file %s ",
cur_file->file_name);
dynstr_append_mem(&ds_warning_messages,
- buff, len);
+ buff, (uint) len);
}
len= my_snprintf(buff, sizeof(buff), "at line %d: ",
start_lineno);
dynstr_append_mem(&ds_warning_messages,
- buff, len);
+ buff, (uint) len);
}
len= my_vsnprintf(buff, sizeof(buff), fmt, args);
- dynstr_append_mem(&ds_warning_messages, buff, len);
+ dynstr_append_mem(&ds_warning_messages, buff, (uint) len);
dynstr_append(&ds_warning_messages, "\n");
va_end(args);
@@ -1185,7 +1185,7 @@ void log_msg(const char *fmt, ...)
len= my_vsnprintf(buff, sizeof(buff)-1, fmt, args);
va_end(args);
- dynstr_append_mem(&ds_res, buff, len);
+ dynstr_append_mem(&ds_res, buff, (uint) len);
dynstr_append(&ds_res, "\n");
DBUG_VOID_RETURN;
@@ -1222,7 +1222,7 @@ void cat_file(DYNAMIC_STRING* ds, const char* filename)
/* Add fake newline instead of cr and output the line */
*p= '\n';
p++; /* Step past the "fake" newline */
- dynstr_append_mem(ds, start, p-start);
+ dynstr_append_mem(ds, start, (uint) (p - start));
p++; /* Step past the "fake" newline */
start= p;
}
@@ -1230,7 +1230,7 @@ void cat_file(DYNAMIC_STRING* ds, const char* filename)
p++;
}
/* Output any chars that migh be left */
- dynstr_append_mem(ds, start, p-start);
+ dynstr_append_mem(ds, start, (uint) (p - start));
}
my_close(fd, MYF(0));
}
@@ -1770,9 +1770,9 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val,
int val_alloc_len;
VAR *tmp_var;
if (!name_len && name)
- name_len = strlen(name);
+ name_len = (uint) strlen(name);
if (!val_len && val)
- val_len = strlen(val) ;
+ val_len = (uint) strlen(val) ;
val_alloc_len = val_len + 16; /* room to grow */
if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
+ name_len+1, MYF(MY_WME))))
@@ -1815,7 +1815,7 @@ VAR* var_from_env(const char *name, const char *def_val)
if (!(tmp = getenv(name)))
tmp = def_val;
- v = var_init(0, name, strlen(name), tmp, strlen(tmp));
+ v = var_init(0, name, (uint) strlen(name), tmp, (uint) strlen(tmp));
my_hash_insert(&var_hash, (byte*)v);
return v;
}
@@ -1864,7 +1864,7 @@ VAR* var_get(const char *var_name, const char **var_name_end, my_bool raw,
{
sprintf(v->str_val, "%d", v->int_val);
v->int_dirty = 0;
- v->str_val_len = strlen(v->str_val);
+ v->str_val_len = (uint) strlen(v->str_val);
}
if (var_name_end)
*var_name_end = var_name ;
@@ -1927,7 +1927,7 @@ void var_set(const char *var_name, const char *var_name_end,
{
sprintf(v->str_val, "%d", v->int_val);
v->int_dirty= 0;
- v->str_val_len= strlen(v->str_val);
+ v->str_val_len= (uint) strlen(v->str_val);
}
my_snprintf(buf, sizeof(buf), "%.*s=%.*s",
v->name_len, v->name,
@@ -2006,7 +2006,7 @@ void var_query_set(VAR *var, const char *query, const char** query_end)
++query;
/* Eval the query, thus replacing all environment variables */
- init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
+ init_dynamic_string(&ds_query, 0, (uint) ((end - query) + 32), 256);
do_eval(&ds_query, query, end, FALSE);
if (mysql_real_query(mysql, ds_query.str, ds_query.length))
@@ -2223,7 +2223,7 @@ void eval_expr(VAR *v, const char *p, const char **p_end)
struct st_command command;
memset(&command, 0, sizeof(command));
command.query= (char*)p;
- command.first_word_len= len;
+ command.first_word_len= (uint) len;
command.first_argument= command.query + len;
command.end= (char*)*p_end;
var_set_query_get_value(&command, v);
@@ -2413,7 +2413,7 @@ static int replace(DYNAMIC_STRING *ds_str,
return 1;
init_dynamic_string(&ds_tmp, "",
ds_str->length + replace_len, 256);
- dynstr_append_mem(&ds_tmp, ds_str->str, start - ds_str->str);
+ dynstr_append_mem(&ds_tmp, ds_str->str, (uint) (start - ds_str->str));
dynstr_append_mem(&ds_tmp, replace_str, replace_len);
dynstr_append(&ds_tmp, start + search_len);
dynstr_set(ds_str, ds_tmp.str);
@@ -2468,7 +2468,7 @@ void do_exec(struct st_command *command)
if (builtin_echo[0] && strncmp(cmd, "echo", 4) == 0)
{
/* Replace echo with our "builtin" echo */
- replace(&ds_cmd, "echo", 4, builtin_echo, strlen(builtin_echo));
+ replace(&ds_cmd, "echo", 4, builtin_echo, (uint) strlen(builtin_echo));
}
#ifdef __WIN__
@@ -4627,7 +4627,7 @@ void do_delimiter(struct st_command* command)
die("Can't set empty delimiter");
strmake(delimiter, p, sizeof(delimiter) - 1);
- delimiter_length= strlen(delimiter);
+ delimiter_length= (uint) strlen(delimiter);
DBUG_PRINT("exit", ("delimiter: %s", delimiter));
command->last_argument= p + delimiter_length;
@@ -4753,9 +4753,11 @@ int read_line(char *buf, int size)
}
else if ((c == '{' &&
(!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
- (uchar*) buf, min(5, p - buf), 0) ||
+ (uchar*) buf, min(5, (uint) (p - buf)),
+ 0) ||
!my_strnncoll_simple(charset_info, (const uchar*) "if", 2,
- (uchar*) buf, min(2, p - buf), 0))))
+ (uchar*) buf, min(2, (uint) (p - buf)),
+ 0))))
{
/* Only if and while commands can be terminated by { */
*p++= c;
@@ -5117,7 +5119,7 @@ int read_command(struct st_command** command_ptr)
command->first_argument= p;
command->end= strend(command->query);
- command->query_len= (command->end - command->query);
+ command->query_len= (uint) (command->end - command->query);
parser.read_lines++;
DBUG_RETURN(0);
}
@@ -6459,7 +6461,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
else
{
query = command->query;
- query_len = strlen(query);
+ query_len = (uint) strlen(query);
}
/*
@@ -6520,7 +6522,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
*/
view_created= 1;
query= (char*)"SELECT * FROM mysqltest_tmp_v";
- query_len = strlen(query);
+ query_len = (uint) strlen(query);
/*
Collect warnings from create of the view that should otherwise
@@ -6568,7 +6570,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
sp_created= 1;
query= (char*)"CALL mysqltest_tmp_sp()";
- query_len = strlen(query);
+ query_len = (uint) strlen(query);
}
dynstr_free(&query_str);
}
@@ -6661,7 +6663,7 @@ void init_re_comp(my_regex_t *re, const char* str)
if (err)
{
char erbuf[100];
- int len= my_regerror(err, re, erbuf, sizeof(erbuf));
+ size_t len= my_regerror(err, re, erbuf, sizeof(erbuf));
die("error %s, %d/%d `%s'\n",
re_eprint(err), len, (int)sizeof(erbuf), erbuf);
}
@@ -6717,7 +6719,7 @@ int match_re(my_regex_t *re, char *str)
{
char erbuf[100];
- int len= my_regerror(err, re, erbuf, sizeof(erbuf));
+ size_t len= my_regerror(err, re, erbuf, sizeof(erbuf));
die("error %s, %d/%d `%s'\n",
re_eprint(err), len, (int)sizeof(erbuf), erbuf);
}
@@ -7579,7 +7581,7 @@ void replace_strings_append(REPLACE *rep, DYNAMIC_STRING* ds,
if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string)
{
/* No match found */
- dynstr_append_mem(ds, start, from - start - 1);
+ dynstr_append_mem(ds, start, (uint) (from - start - 1));
DBUG_PRINT("exit", ("Found no more string to replace, appended: %s", start));
DBUG_VOID_RETURN;
}
@@ -7590,11 +7592,11 @@ void replace_strings_append(REPLACE *rep, DYNAMIC_STRING* ds,
rep_str->from_offset, rep_str->replace_string));
/* Append part of original string before replace string */
- dynstr_append_mem(ds, start, (from - rep_str->to_offset) - start);
+ dynstr_append_mem(ds, start, (uint) ((from - rep_str->to_offset) - start));
/* Append replace string */
dynstr_append_mem(ds, rep_str->replace_string,
- strlen(rep_str->replace_string));
+ (uint) strlen(rep_str->replace_string));
if (!*(from-=rep_str->from_offset) && rep_pos->found != 2)
{
@@ -7689,7 +7691,7 @@ struct st_replace_regex* init_replace_regex(char* expr)
char* buf,*expr_end;
char* p;
char* buf_p;
- uint expr_len= strlen(expr);
+ size_t expr_len= strlen(expr);
char last_c = 0;
struct st_regex reg;
@@ -7866,7 +7868,7 @@ void free_replace_regex()
*/
#define SECURE_REG_BUF if (buf_len < need_buf_len) \
{ \
- int off= res_p - buf; \
+ size_t off= res_p - buf; \
buf= (char*)my_realloc(buf,need_buf_len,MYF(MY_WME+MY_FAE)); \
res_p= buf + off; \
buf_len= need_buf_len; \
@@ -7898,7 +7900,7 @@ int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
char *res_p,*str_p,*str_end;
buf_len= *buf_len_p;
- len= strlen(string);
+ len= (uint) strlen(string);
str_end= string + len;
/* start with a buffer of a reasonable size that hopefully will not
@@ -7950,7 +7952,7 @@ int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
we need at least what we have so far in the buffer + the part
before this match
*/
- need_buf_len= (res_p - buf) + (int) subs[0].rm_so;
+ need_buf_len= (uint) (res_p - buf) + (int) subs[0].rm_so;
/* on this pass, calculate the memory for the result buffer */
while (expr_p < replace_end)
@@ -8040,8 +8042,8 @@ int reg_replace(char** buf_p, int* buf_len_p, char *pattern,
}
else /* no match this time, just copy the string as is */
{
- int left_in_str= str_end-str_p;
- need_buf_len= (res_p-buf) + left_in_str;
+ size_t left_in_str= str_end-str_p;
+ need_buf_len= (uint) ((res_p-buf) + left_in_str);
SECURE_REG_BUF
memcpy(res_p,str_p,left_in_str);
res_p += left_in_str;
@@ -8708,7 +8710,7 @@ void replace_dynstr_append_mem(DYNAMIC_STRING *ds,
if (!multi_reg_replace(glob_replace_regex, (char*)val))
{
val= glob_replace_regex->buf;
- len= strlen(val);
+ len= (uint) strlen(val);
}
}
@@ -8725,7 +8727,7 @@ void replace_dynstr_append_mem(DYNAMIC_STRING *ds,
/* Append zero-terminated string to ds, with optional replace */
void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val)
{
- replace_dynstr_append_mem(ds, val, strlen(val));
+ replace_dynstr_append_mem(ds, val, (uint) strlen(val));
}
/* Append uint to ds, with optional replace */
@@ -8733,7 +8735,7 @@ void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val)
{
char buff[22]; /* This should be enough for any int */
char *end= longlong10_to_str(val, buff, 10);
- replace_dynstr_append_mem(ds, buff, end - buff);
+ replace_dynstr_append_mem(ds, buff, (uint) (end - buff));
}
@@ -8771,7 +8773,7 @@ void dynstr_append_sorted(DYNAMIC_STRING* ds, DYNAMIC_STRING *ds_input)
while (*start && *start != '\n')
start++;
start++; /* Skip past \n */
- dynstr_append_mem(ds, ds_input->str, start - ds_input->str);
+ dynstr_append_mem(ds, ds_input->str, (uint) (start - ds_input->str));
/* Insert line(s) in array */
while (*start)
diff --git a/client/readline.cc b/client/readline.cc
index ad42ed2ee10..726d9cd9415 100644
--- a/client/readline.cc
+++ b/client/readline.cc
@@ -24,7 +24,7 @@ static bool init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,
ulong max_size);
static bool init_line_buffer_from_string(LINE_BUFFER *buffer,my_string str);
static uint fill_buffer(LINE_BUFFER *buffer);
-static char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length);
+static char *intern_read_line(LINE_BUFFER *buffer, ulong *out_length, bool *truncated);
LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
@@ -42,12 +42,13 @@ LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
}
-char *batch_readline(LINE_BUFFER *line_buff)
+char *batch_readline(LINE_BUFFER *line_buff, bool *truncated)
{
char *pos;
ulong out_length;
+ DBUG_ASSERT(truncated != NULL);
- if (!(pos=intern_read_line(line_buff,&out_length)))
+ if (!(pos=intern_read_line(line_buff,&out_length, truncated)))
return 0;
if (out_length && pos[out_length-1] == '\n')
if (--out_length && pos[out_length-1] == '\r') /* Remove '\n' */
@@ -149,6 +150,14 @@ static uint fill_buffer(LINE_BUFFER *buffer)
read_count=(buffer->bufread - bufbytes)/IO_SIZE;
if ((read_count*=IO_SIZE))
break;
+ if (buffer->bufread * 2 > buffer->max_size)
+ {
+ /*
+ So we must grow the buffer but we cannot due to the max_size limit.
+ Return 0 w/o setting buffer->eof to signal this condition.
+ */
+ return 0;
+ }
buffer->bufread *= 2;
if (!(buffer->buffer = (char*) my_realloc(buffer->buffer,
buffer->bufread+1,
@@ -172,11 +181,15 @@ static uint fill_buffer(LINE_BUFFER *buffer)
DBUG_PRINT("fill_buff", ("Got %d bytes", read_count));
- /* Kludge to pretend every nonempty file ends with a newline. */
- if (!read_count && bufbytes && buffer->end[-1] != '\n')
+ if (!read_count)
{
- buffer->eof = read_count = 1;
- *buffer->end = '\n';
+ buffer->eof = 1;
+ /* Kludge to pretend every nonempty file ends with a newline. */
+ if (bufbytes && buffer->end[-1] != '\n')
+ {
+ read_count = 1;
+ *buffer->end = '\n';
+ }
}
buffer->end_of_line=(buffer->start_of_line=buffer->buffer)+bufbytes;
buffer->end+=read_count;
@@ -186,7 +199,7 @@ static uint fill_buffer(LINE_BUFFER *buffer)
-char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length)
+char *intern_read_line(LINE_BUFFER *buffer, ulong *out_length, bool *truncated)
{
char *pos;
uint length;
@@ -200,14 +213,23 @@ char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length)
pos++;
if (pos == buffer->end)
{
- if ((uint) (pos - buffer->start_of_line) < buffer->max_size)
+ /*
+ fill_buffer() can return 0 either on EOF in which case we abort
+ or when the internal buffer has hit the size limit. In the latter case
+ return what we have read so far and signal string truncation.
+ */
+ if (!(length=fill_buffer(buffer)) || length == (uint) -1)
{
- if (!(length=fill_buffer(buffer)) || length == (uint) -1)
- DBUG_RETURN(0);
- continue;
+ if (buffer->eof)
+ DBUG_RETURN(0);
}
+ else
+ continue;
pos--; /* break line here */
+ *truncated= 1;
}
+ else
+ *truncated= 0;
buffer->end_of_line=pos+1;
*out_length=(ulong) (pos + 1 - buffer->eof - buffer->start_of_line);
DBUG_RETURN(buffer->start_of_line);
diff --git a/client/sql_string.cc b/client/sql_string.cc
index 9d887ff031c..4967538ad3b 100644
--- a/client/sql_string.cc
+++ b/client/sql_string.cc
@@ -71,25 +71,22 @@ bool String::realloc(uint32 alloc_length)
char *new_ptr;
if (alloced)
{
- if ((new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME))))
- {
- Ptr=new_ptr;
- Alloced_length=len;
- }
- else
- return TRUE; // Signal error
+ if (!(new_ptr= (char*) my_realloc(Ptr,len,MYF(MY_WME))))
+ return TRUE; // Signal error
}
else if ((new_ptr= (char*) my_malloc(len,MYF(MY_WME))))
{
+ if (str_length > len - 1)
+ str_length= 0;
if (str_length) // Avoid bugs in memcpy on AIX
memcpy(new_ptr,Ptr,str_length);
new_ptr[str_length]=0;
- Ptr=new_ptr;
- Alloced_length=len;
alloced=1;
}
else
return TRUE; // Signal error
+ Ptr= new_ptr;
+ Alloced_length= len;
}
Ptr[alloc_length]=0; // This make other funcs shorter
return FALSE;
@@ -125,7 +122,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
str_charset=cs;
if (decimals >= NOT_FIXED_DEC)
{
- uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME
+ uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME
return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
}
#ifdef HAVE_FCONVERT
@@ -468,7 +465,7 @@ bool String::append(const char *s,uint32 arg_length)
bool String::append(const char *s)
{
- return append(s, strlen(s));
+ return append(s, (uint) strlen(s));
}
@@ -677,7 +674,7 @@ void String::qs_append(const char *str, uint32 len)
void String::qs_append(double d)
{
char *buff = Ptr + str_length;
- str_length+= my_sprintf(buff, (buff, "%.14g", d));
+ str_length+= my_sprintf(buff, (buff, "%.15g", d));
}
void String::qs_append(double *d)