Skip to content

Commit e60acae

Browse files
committed
Merge 10.5 into 10.6
2 parents 32202c3 + 956bcf8 commit e60acae

File tree

8 files changed

+142
-92
lines changed

8 files changed

+142
-92
lines changed

client/mysql.cc

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ static my_bool ignore_errors=0,wait_flag=0,quick=0,
158158
default_pager_set= 0, opt_sigint_ignore= 0,
159159
auto_vertical_output= 0,
160160
show_warnings= 0, executing_query= 0,
161-
ignore_spaces= 0, opt_binhex= 0, opt_progress_reports;
161+
ignore_spaces= 0, opt_binhex= 0, opt_progress_reports,
162+
opt_print_query_on_error;
162163
static my_bool debug_info_flag, debug_check_flag, batch_abort_on_error;
163164
static my_bool column_types_flag;
164165
static my_bool preserve_comments= 0;
@@ -237,6 +238,7 @@ static int com_quit(String *str,char*),
237238
com_prompt(String *str, char*), com_delimiter(String *str, char*),
238239
com_warnings(String *str, char*), com_nowarnings(String *str, char*),
239240
com_sandbox(String *str, char*);
241+
static void print_query_to_stderr(String *buffer);
240242

241243
#ifdef USE_POPEN
242244
static int com_nopager(String *str, char*), com_pager(String *str, char*),
@@ -1662,6 +1664,10 @@ static struct my_option my_long_options[] =
16621664
#endif
16631665
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").", &opt_mysql_port,
16641666
&opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1667+
{"print-query-on-error", 0,
1668+
"Print the query if there was an error. Is only enabled in --batch mode if verbose is not set (as then the query would be printed anyway)",
1669+
&opt_print_query_on_error, &opt_print_query_on_error, 0, GET_BOOL, NO_ARG,
1670+
1, 0, 0, 0, 0, 0},
16651671
{"progress-reports", 0,
16661672
"Get progress reports for long running commands (like ALTER TABLE)",
16671673
&opt_progress_reports, &opt_progress_reports, 0, GET_BOOL, NO_ARG, 1, 0,
@@ -3114,6 +3120,11 @@ int mysql_real_query_for_lazy(const char *buf, size_t length)
31143120
int error;
31153121
if (!mysql_real_query(&mysql,buf,(ulong)length))
31163122
return 0;
3123+
if (opt_print_query_on_error)
3124+
{
3125+
String query(buf, length, charset_info);
3126+
(void) print_query_to_stderr(&query);
3127+
}
31173128
error= put_error(&mysql);
31183129
if (mysql_errno(&mysql) != CR_SERVER_GONE_ERROR || retry > 1 ||
31193130
!opt_reconnect)
@@ -3320,7 +3331,6 @@ static int com_charset(String *, char *line)
33203331
1 if fatal error
33213332
*/
33223333

3323-
33243334
static int com_go(String *buffer, char *)
33253335
{
33263336
char buff[200]; /* about 110 chars used so far */
@@ -3393,6 +3403,8 @@ static int com_go(String *buffer, char *)
33933403
{
33943404
if (!(result=mysql_use_result(&mysql)) && mysql_field_count(&mysql))
33953405
{
3406+
if (opt_print_query_on_error)
3407+
print_query_to_stderr(buffer);
33963408
error= put_error(&mysql);
33973409
goto end;
33983410
}
@@ -3446,7 +3458,11 @@ static int com_go(String *buffer, char *)
34463458
(long) mysql_num_rows(result) == 1 ? "row" : "rows");
34473459
end_pager();
34483460
if (mysql_errno(&mysql))
3461+
{
3462+
if (opt_print_query_on_error)
3463+
print_query_to_stderr(buffer);
34493464
error= put_error(&mysql);
3465+
}
34503466
}
34513467
}
34523468
else if (mysql_affected_rows(&mysql) == ~(ulonglong) 0)
@@ -3473,13 +3489,21 @@ static int com_go(String *buffer, char *)
34733489
put_info("",INFO_RESULT); // Empty row
34743490

34753491
if (result && !mysql_eof(result)) /* Something wrong when using quick */
3492+
{
3493+
if (opt_print_query_on_error)
3494+
print_query_to_stderr(buffer);
34763495
error= put_error(&mysql);
3496+
}
34773497
else if (unbuffered)
34783498
fflush(stdout);
34793499
mysql_free_result(result);
34803500
} while (!(err= mysql_next_result(&mysql)));
34813501
if (err >= 1)
3502+
{
3503+
if (opt_print_query_on_error)
3504+
print_query_to_stderr(buffer);
34823505
error= put_error(&mysql);
3506+
}
34833507

34843508
end:
34853509

@@ -4405,14 +4429,35 @@ static int com_shell(String *, char *line)
44054429
#endif
44064430

44074431

4408-
static int com_print(String *buffer,char *)
4432+
static void print_query(String *buffer, FILE *file)
44094433
{
4410-
tee_puts("--------------", stdout);
4411-
(void) tee_fputs(buffer->c_ptr(), stdout);
4434+
tee_puts("--------------", file);
4435+
(void) tee_fputs(buffer->c_ptr(), file);
44124436
if (!buffer->length() || (*buffer)[buffer->length()-1] != '\n')
4413-
tee_putc('\n', stdout);
4414-
tee_puts("--------------\n", stdout);
4415-
return 0; /* If empty buffer */
4437+
tee_putc('\n', file);
4438+
tee_puts("--------------\n", file);
4439+
}
4440+
4441+
4442+
/*
4443+
Print query to stderr in batch mode if verbose is not set
4444+
*/
4445+
4446+
static void print_query_to_stderr(String *buffer)
4447+
{
4448+
if ((status.batch || in_com_source) && !verbose)
4449+
{
4450+
fflush(stdout);
4451+
print_query(buffer, stderr);
4452+
fflush(stderr);
4453+
}
4454+
}
4455+
4456+
4457+
static int com_print(String *buffer,char *)
4458+
{
4459+
print_query(buffer, stdout);
4460+
return 0;
44164461
}
44174462

44184463

@@ -5154,8 +5199,9 @@ put_info(const char *str,INFO_TYPE info_type, uint error, const char *sqlstate)
51545199

51555200
static int put_error(MYSQL *con)
51565201
{
5157-
return put_info(mysql_error(con), INFO_ERROR, mysql_errno(con),
5158-
mysql_sqlstate(con));
5202+
DBUG_ENTER("put_error");
5203+
DBUG_RETURN(put_info(mysql_error(con), INFO_ERROR,
5204+
mysql_errno(con), mysql_sqlstate(con)));
51595205
}
51605206

51615207

client/mysql_upgrade.c

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
628628
{
629629
my_close(fd, MYF(MY_WME));
630630
my_delete(query_file_path, MYF(0));
631-
die("Failed to write to '%s'", query_file_path);
631+
die("Failed to write query to '%s'", query_file_path);
632632
}
633633
}
634634

@@ -637,7 +637,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
637637
{
638638
my_close(fd, MYF(MY_WME));
639639
my_delete(query_file_path, MYF(0));
640-
die("Failed to write to '%s'", query_file_path);
640+
die("Failed to write query to '%s'", query_file_path);
641641
}
642642

643643
ret= run_tool(mysql_path,
@@ -647,6 +647,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
647647
"--batch", /* Turns off pager etc. */
648648
force ? "--force": "--skip-force",
649649
opt_verbose >= 5 ? "--verbose" : "",
650+
"--print-query-on-error",
650651
ds_res || opt_silent ? "--silent": "",
651652
"<",
652653
query_file_path,
@@ -1085,18 +1086,6 @@ static char* get_line(char* line)
10851086
return line;
10861087
}
10871088

1088-
1089-
/* Print the current line to stderr */
1090-
static void print_line(char* line)
1091-
{
1092-
while (*line && *line != '\n')
1093-
{
1094-
fputc(*line, stderr);
1095-
line++;
1096-
}
1097-
fputc('\n', stderr);
1098-
}
1099-
11001089
static my_bool from_before_10_1()
11011090
{
11021091
my_bool ret= TRUE;
@@ -1315,16 +1304,21 @@ static int check_slave_repositories(void)
13151304

13161305
static int run_sql_fix_privilege_tables(void)
13171306
{
1318-
int found_real_errors= 0;
1307+
int found_real_errors= 0, query_started= 0;
13191308
const char **query_ptr;
1309+
const char *end;
13201310
DYNAMIC_STRING ds_script;
13211311
DYNAMIC_STRING ds_result;
1312+
DYNAMIC_STRING ds_query;
13221313
DBUG_ENTER("run_sql_fix_privilege_tables");
13231314

1324-
if (init_dynamic_string(&ds_script, "", 65536, 1024))
1315+
if (init_dynamic_string(&ds_script, "", 96*1024, 8196))
13251316
die("Out of memory");
13261317

1327-
if (init_dynamic_string(&ds_result, "", 512, 512))
1318+
if (init_dynamic_string(&ds_result, "", 1024, 1024))
1319+
die("Out of memory");
1320+
1321+
if (init_dynamic_string(&ds_query, "", 1024, 1024))
13281322
die("Out of memory");
13291323

13301324
verbose("Phase %d/%d: Running 'mysql_fix_privilege_tables'",
@@ -1353,22 +1347,46 @@ static int run_sql_fix_privilege_tables(void)
13531347
"Unknown column" and "Duplicate key name" since they just
13541348
indicate the system tables are already up to date
13551349
*/
1356-
char *line= ds_result.str;
1350+
const char *line= ds_result.str;
13571351
do
13581352
{
1353+
size_t length;
1354+
end= strchr(line, '\n');
1355+
if (!end)
1356+
end= strend(line);
1357+
else
1358+
end++; /* Include end \n */
1359+
length= (size_t) (end - line);
1360+
13591361
if (!is_expected_error(line))
13601362
{
13611363
/* Something unexpected failed, dump error line to screen */
13621364
found_real_errors++;
1363-
print_line(line);
1365+
if (ds_query.length)
1366+
fwrite(ds_query.str, sizeof(char), ds_query.length, stderr);
1367+
fwrite(line, sizeof(char), length, stderr);
1368+
query_started= 0;
13641369
}
13651370
else if (strncmp(line, "WARNING", 7) == 0)
13661371
{
1367-
print_line(line);
1372+
fwrite(line, sizeof(char), length, stderr);
1373+
query_started= 0;
13681374
}
1369-
} while ((line= get_line(line)) && *line);
1375+
else if (!strncmp(line, "--------------\n", 16))
1376+
{
1377+
/* mariadb separates query from the error with a line of '-' */
1378+
if (!query_started++)
1379+
ds_query.length= 0; /* Truncate */
1380+
else
1381+
query_started= 0; /* End of query */
1382+
}
1383+
else if (query_started)
1384+
{
1385+
dynstr_append_mem(&ds_query, line, length);
1386+
}
1387+
} while (*(line= end));
13701388
}
1371-
1389+
dynstr_free(&ds_query);
13721390
dynstr_free(&ds_result);
13731391
dynstr_free(&ds_script);
13741392
DBUG_RETURN(found_real_errors);

client/mysqldump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,7 @@ static void get_sequence_structure(const char *seq, const char *db)
29852985
row= mysql_fetch_row(result);
29862986
if (row[0])
29872987
{
2988-
fprintf(sql_file, "SELECT SETVAL(%s, %s, 0);\n", result_seq, row[0]);
2988+
fprintf(sql_file, "DO SETVAL(%s, %s, 0);\n", result_seq, row[0]);
29892989
}
29902990
// Sequences will not use inserts, so no need for REPLACE and LOCKS
29912991
mysql_free_result(result);

mysql-test/main/mysql.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ c int(11) YES NULL
137137
drop table t1;
138138
1
139139
1
140+
--------------
141+
use
142+
--------------
143+
140144
ERROR 1064 (42000) at line 3: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
141145
ERROR at line 1: USE must be followed by a database name
142146
1 +1
@@ -166,6 +170,10 @@ count(*)
166170
drop table t17583;
167171
Test connect without db- or host-name => reconnect
168172
Test connect with dbname only => new dbname, old hostname
173+
--------------
174+
connecttest
175+
--------------
176+
169177
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'connecttest' at line 1
170178
Test connect with _invalid_ dbname only => new invalid dbname, old hostname
171179
ERROR 1049 (42000) at line 1: Unknown database 'invalid'

mysql-test/main/mysqldump.result

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6326,14 +6326,6 @@ Table Create Table
63266326
s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
63276327
# Dump sequence without `--no-data`
63286328
# Restore from mysqldump
6329-
SETVAL(`s1`, 1101, 0)
6330-
1101
6331-
SETVAL(`s2`, 1201, 0)
6332-
1201
6333-
SETVAL(`s3`, 1301, 0)
6334-
1301
6335-
SETVAL(`s4`, 1401, 0)
6336-
1401
63376329
# Show create after restore
63386330
show create sequence d.s1;
63396331
Table Create Table
@@ -6352,14 +6344,6 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
63526344
100 200 300 400
63536345
# Dump sequence with `--no-data`
63546346
# Restore from mysqldump
6355-
SETVAL(`s1`, 1101, 0)
6356-
1101
6357-
SETVAL(`s2`, 1201, 0)
6358-
1201
6359-
SETVAL(`s3`, 1301, 0)
6360-
1301
6361-
SETVAL(`s4`, 1401, 0)
6362-
1401
63636347
# Show create after restore `--no-data`
63646348
show create sequence d.s1;
63656349
Table Create Table
@@ -6378,14 +6362,6 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
63786362
100 200 300 400
63796363
# Restore to different database than original
63806364
create database d2;
6381-
SETVAL(`s1`, 1101, 0)
6382-
1101
6383-
SETVAL(`s2`, 1201, 0)
6384-
1201
6385-
SETVAL(`s3`, 1301, 0)
6386-
1301
6387-
SETVAL(`s4`, 1401, 0)
6388-
1401
63896365
show create sequence d2.s1;
63906366
Table Create Table
63916367
s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
@@ -6413,9 +6389,11 @@ j integer
64136389
INSERT INTO t VALUES (1,1),(2,2),(3,3),(4,4);
64146390
# Dump database 1
64156391
# Restore from database 1 to database 2
6392+
--------------
6393+
INSERT INTO `t` VALUES (1,1),(2,2),(3,3),(4,4)
6394+
--------------
6395+
64166396
ERROR 1100 (HY000) at line 46: Table 'seq_t_i' was not locked with LOCK TABLES
6417-
SETVAL(`seq_t_i`, 1, 0)
6418-
1
64196397
DROP DATABASE IF EXISTS test1;
64206398
DROP DATABASE IF EXISTS test2;
64216399
#

0 commit comments

Comments
 (0)