Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Barkov committed Dec 30, 2016
2 parents 09615ca + 970f17c commit b6aa3d2
Show file tree
Hide file tree
Showing 918 changed files with 41,459 additions and 18,010 deletions.
1 change: 1 addition & 0 deletions CREDITS
Expand Up @@ -10,6 +10,7 @@ Visma http://visma.com (2015 - 2016)
Acronis http://acronis.com (2016)
Nexedi https://www.nexedi.com (2016)
Automattic https://automattic.com (2014 - 2016)
Tencent Game DBA http://tencentdba.com/about (2016)
Verkkokauppa.com https://www.verkkokauppa.com (2015 - 2016)
Virtuozzo https://virtuozzo.com (2016)

Expand Down
56 changes: 30 additions & 26 deletions client/mysql.cc
Expand Up @@ -245,7 +245,8 @@ static void end_pager();
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);
enum get_arg_mode { CHECK, GET, GET_NEXT};
static char *get_arg(char *line, get_arg_mode mode);
static void init_username();
static void add_int_to_prompt(int toadd);
static int get_result_width(MYSQL_RES *res);
Expand Down Expand Up @@ -2257,7 +2258,7 @@ static COMMANDS *find_command(char *name)
if (!my_strnncoll(&my_charset_latin1, (uchar*) name, len,
(uchar*) commands[i].name, len) &&
(commands[i].name[len] == '\0') &&
(!end || commands[i].takes_params))
(!end || (commands[i].takes_params && get_arg(name, CHECK))))
{
index= i;
break;
Expand Down Expand Up @@ -3175,7 +3176,7 @@ com_charset(String *buffer __attribute__((unused)), char *line)
char buff[256], *param;
CHARSET_INFO * new_cs;
strmake_buf(buff, line);
param= get_arg(buff, 0);
param= get_arg(buff, GET);
if (!param || !*param)
{
return put_info("Usage: \\C charset_name | charset charset_name",
Expand Down Expand Up @@ -4260,12 +4261,12 @@ com_connect(String *buffer, char *line)
#ifdef EXTRA_DEBUG
tmp[1]= 0;
#endif
tmp= get_arg(buff, 0);
tmp= get_arg(buff, GET);
if (tmp && *tmp)
{
my_free(current_db);
current_db= my_strdup(tmp, MYF(MY_WME));
tmp= get_arg(buff, 1);
tmp= get_arg(buff, GET_NEXT);
if (tmp)
{
my_free(current_host);
Expand Down Expand Up @@ -4368,7 +4369,7 @@ com_delimiter(String *buffer __attribute__((unused)), char *line)
char buff[256], *tmp;

strmake_buf(buff, line);
tmp= get_arg(buff, 0);
tmp= get_arg(buff, GET);

if (!tmp || !*tmp)
{
Expand Down Expand Up @@ -4399,7 +4400,7 @@ com_use(String *buffer __attribute__((unused)), char *line)

bzero(buff, sizeof(buff));
strmake_buf(buff, line);
tmp= get_arg(buff, 0);
tmp= get_arg(buff, GET);
if (!tmp || !*tmp)
{
put_info("USE must be followed by a database name", INFO_ERROR);
Expand Down Expand Up @@ -4484,23 +4485,22 @@ com_nowarnings(String *buffer __attribute__((unused)),
}

/*
Gets argument from a command on the command line. If get_next_arg is
not defined, skips the command and returns the first argument. The
line is modified by adding zero to the end of the argument. If
get_next_arg is defined, then the function searches for end of string
first, after found, returns the next argument and adds zero to the
end. If you ever wish to use this feature, remember to initialize all
items in the array to zero first.
Gets argument from a command on the command line. If mode is not GET_NEXT,
skips the command and returns the first argument. The line is modified by
adding zero to the end of the argument. If mode is GET_NEXT, then the
function searches for end of string first, after found, returns the next
argument and adds zero to the end. If you ever wish to use this feature,
remember to initialize all items in the array to zero first.
*/

char *get_arg(char *line, my_bool get_next_arg)
static char *get_arg(char *line, get_arg_mode mode)
{
char *ptr, *start;
my_bool quoted= 0, valid_arg= 0;
bool short_cmd= false;
char qtype= 0;

ptr= line;
if (get_next_arg)
if (mode == GET_NEXT)
{
for (; *ptr; ptr++) ;
if (*(ptr + 1))
Expand All @@ -4511,7 +4511,7 @@ char *get_arg(char *line, my_bool get_next_arg)
/* skip leading white spaces */
while (my_isspace(charset_info, *ptr))
ptr++;
if (*ptr == '\\') // short command was used
if ((short_cmd= *ptr == '\\')) // short command was used
ptr+= 2;
else
while (*ptr &&!my_isspace(charset_info, *ptr)) // skip command
Expand All @@ -4524,24 +4524,28 @@ char *get_arg(char *line, my_bool get_next_arg)
if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
{
qtype= *ptr;
quoted= 1;
ptr++;
}
for (start=ptr ; *ptr; ptr++)
{
if (*ptr == '\\' && ptr[1]) // escaped character
if ((*ptr == '\\' && ptr[1]) || // escaped character
(!short_cmd && qtype && *ptr == qtype && ptr[1] == qtype)) // quote
{
// Remove the backslash
strmov_overlapp(ptr, ptr+1);
// Remove (or skip) the backslash (or a second quote)
if (mode != CHECK)
strmov_overlapp(ptr, ptr+1);
else
ptr++;
}
else if ((!quoted && *ptr == ' ') || (quoted && *ptr == qtype))
else if (*ptr == (qtype ? qtype : ' '))
{
*ptr= 0;
qtype= 0;
if (mode != CHECK)
*ptr= 0;
break;
}
}
valid_arg= ptr != start;
return valid_arg ? start : NullS;
return ptr != start && !qtype ? start : NullS;
}


Expand Down
12 changes: 11 additions & 1 deletion client/mysqlbinlog.cc
Expand Up @@ -1267,6 +1267,9 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
goto err;
break;
}
case START_ENCRYPTION_EVENT:
glob_description_event->start_decryption((Start_encryption_log_event*)ev);
/* fall through */
default:
print_skip_replication_statement(print_event_info, ev);
ev->print(result_file, print_event_info);
Expand Down Expand Up @@ -2839,9 +2842,16 @@ int main(int argc, char** argv)
}


uint dummy1() { return 1; }
struct encryption_service_st encryption_handler=
{
0, 0, 0, 0, 0, 0, 0
(uint(*)(uint))dummy1,
(uint(*)(uint, uint, uchar*, uint*))dummy1,
(uint(*)(uint, uint))dummy1,
(int (*)(void*, const uchar*, uint, const uchar*, uint, int, uint, uint))dummy1,
(int (*)(void*, const uchar*, uint, uchar*, uint*))dummy1,
(int (*)(void*, uchar*, uint*))dummy1,
(uint (*)(uint, uint, uint))dummy1
};

/*
Expand Down
60 changes: 43 additions & 17 deletions client/mysqldump.c
Expand Up @@ -577,9 +577,7 @@ static int dump_all_tablespaces();
static int dump_tablespaces_for_tables(char *db, char **table_names, int tables);
static int dump_tablespaces_for_databases(char** databases);
static int dump_tablespaces(char* ts_where);
static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
...);

static void print_comment(FILE *, my_bool, const char *, ...);

/*
Print the supplied message if in verbose mode
Expand Down Expand Up @@ -657,6 +655,30 @@ static void short_usage(FILE *f)
}


/** returns a string fixed to be safely printed inside a -- comment
that is, any new line in it gets prefixed with --
*/
static const char *fix_for_comment(const char *ident)
{
static char buf[1024];
char c, *s= buf;

while ((c= *s++= *ident++))
{
if (s >= buf + sizeof(buf) - 10)
{
strmov(s, "...");
break;
}
if (c == '\n')
s= strmov(s, "-- ");
}

return buf;
}


static void write_header(FILE *sql_file, char *db_name)
{
if (opt_xml)
Expand All @@ -679,8 +701,8 @@ static void write_header(FILE *sql_file, char *db_name)
DUMP_VERSION, MYSQL_SERVER_VERSION, SYSTEM_TYPE,
MACHINE_TYPE);
print_comment(sql_file, 0, "-- Host: %s Database: %s\n",
current_host ? current_host : "localhost",
db_name ? db_name : "");
fix_for_comment(current_host ? current_host : "localhost"),
fix_for_comment(db_name ? db_name : ""));
print_comment(sql_file, 0,
"-- ------------------------------------------------------\n"
);
Expand Down Expand Up @@ -2252,7 +2274,8 @@ static uint dump_events_for_db(char *db)

/* nice comments */
print_comment(sql_file, 0,
"\n--\n-- Dumping events for database '%s'\n--\n", db);
"\n--\n-- Dumping events for database '%s'\n--\n",
fix_for_comment(db));

/*
not using "mysql_query_with_error_report" because we may have not
Expand Down Expand Up @@ -2464,7 +2487,8 @@ static uint dump_routines_for_db(char *db)

/* nice comments */
print_comment(sql_file, 0,
"\n--\n-- Dumping routines for database '%s'\n--\n", db);
"\n--\n-- Dumping routines for database '%s'\n--\n",
fix_for_comment(db));

/*
not using "mysql_query_with_error_report" because we may have not
Expand Down Expand Up @@ -2760,11 +2784,11 @@ static uint get_table_structure(char *table, char *db, char *table_type,
if (strcmp (table_type, "VIEW") == 0) /* view */
print_comment(sql_file, 0,
"\n--\n-- Temporary table structure for view %s\n--\n\n",
result_table);
fix_for_comment(result_table));
else
print_comment(sql_file, 0,
"\n--\n-- Table structure for table %s\n--\n\n",
result_table);
fix_for_comment(result_table));

if (opt_drop)
{
Expand Down Expand Up @@ -3008,7 +3032,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,

print_comment(sql_file, 0,
"\n--\n-- Table structure for table %s\n--\n\n",
result_table);
fix_for_comment(result_table));
if (opt_drop)
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table);
if (!opt_xml)
Expand Down Expand Up @@ -3717,21 +3741,21 @@ static void dump_table(char *table, char *db)
{
print_comment(md_result_file, 0,
"\n--\n-- Dumping data for table %s\n--\n",
result_table);
fix_for_comment(result_table));

dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM ");
dynstr_append_checked(&query_string, result_table);

if (where)
{
print_comment(md_result_file, 0, "-- WHERE: %s\n", where);
print_comment(md_result_file, 0, "-- WHERE: %s\n", fix_for_comment(where));

dynstr_append_checked(&query_string, " WHERE ");
dynstr_append_checked(&query_string, where);
}
if (order_by)
{
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", order_by);
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", fix_for_comment(order_by));

dynstr_append_checked(&query_string, " ORDER BY ");
dynstr_append_checked(&query_string, order_by);
Expand Down Expand Up @@ -4241,7 +4265,7 @@ static int dump_tablespaces(char* ts_where)
if (first)
{
print_comment(md_result_file, 0, "\n--\n-- Logfile group: %s\n--\n",
row[0]);
fix_for_comment(row[0]));

fprintf(md_result_file, "\nCREATE");
}
Expand Down Expand Up @@ -4310,7 +4334,8 @@ static int dump_tablespaces(char* ts_where)
first= 1;
if (first)
{
print_comment(md_result_file, 0, "\n--\n-- Tablespace: %s\n--\n", row[0]);
print_comment(md_result_file, 0, "\n--\n-- Tablespace: %s\n--\n",
fix_for_comment(row[0]));
fprintf(md_result_file, "\nCREATE");
}
else
Expand Down Expand Up @@ -4514,7 +4539,8 @@ static int init_dumping(char *database, int init_func(char*))
char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);

print_comment(md_result_file, 0,
"\n--\n-- Current Database: %s\n--\n", qdatabase);
"\n--\n-- Current Database: %s\n--\n",
fix_for_comment(qdatabase));

/* Call the view or table specific function */
init_func(qdatabase);
Expand Down Expand Up @@ -5774,7 +5800,7 @@ static my_bool get_view_structure(char *table, char* db)

print_comment(sql_file, 0,
"\n--\n-- Final view structure for view %s\n--\n\n",
result_table);
fix_for_comment(result_table));

/* Table might not exist if this view was dumped with --tab. */
fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", opt_quoted_table);
Expand Down
30 changes: 21 additions & 9 deletions client/mysqltest.cc
Expand Up @@ -1731,11 +1731,11 @@ int cat_file(DYNAMIC_STRING* ds, const char* filename)
while((len= my_read(fd, (uchar*)&buff,
sizeof(buff)-1, MYF(0))) > 0)
{
char *p= buff, *start= buff;
while (p < buff+len)
char *p= buff, *start= buff,*end=buff+len;
while (p < end)
{
/* Convert cr/lf to lf */
if (*p == '\r' && *(p+1) && *(p+1)== '\n')
if (*p == '\r' && p+1 < end && *(p+1)== '\n')
{
/* Add fake newline instead of cr and output the line */
*p= '\n';
Expand Down Expand Up @@ -3373,10 +3373,6 @@ void do_exec(struct st_command *command)
#endif
#endif

/* exec command is interpreted externally and will not take newlines */
while(replace(&ds_cmd, "\n", 1, " ", 1) == 0)
;

DBUG_PRINT("info", ("Executing '%s' as '%s'",
command->first_argument, ds_cmd.str));

Expand All @@ -3395,16 +3391,32 @@ void do_exec(struct st_command *command)
ds_result= &ds_sorted;
}

#ifdef _WIN32
/* Workaround for CRT bug, MDEV-9409 */
_setmode(fileno(res_file), O_BINARY);
#endif

while (fgets(buf, sizeof(buf), res_file))
{
int len = (int)strlen(buf);
#ifdef _WIN32
/* Strip '\r' off newlines. */
if (len > 1 && buf[len-2] == '\r' && buf[len-1] == '\n')
{
buf[len-2] = '\n';
buf[len-1] = 0;
len--;
}
#endif
if (disable_result_log)
{
buf[strlen(buf)-1]=0;
if (len)
buf[len-1] = 0;
DBUG_PRINT("exec_result",("%s", buf));
}
else
{
replace_dynstr_append(ds_result, buf);
replace_dynstr_append_mem(ds_result, buf, len);
}
}
error= pclose(res_file);
Expand Down

0 comments on commit b6aa3d2

Please sign in to comment.