Skip to content

Commit 25cbb13

Browse files
author
Anushree Prakash B
committed
Merge branch 'mysql-5.7' into mysql-trunk
2 parents a247e87 + 06484ed commit 25cbb13

File tree

2 files changed

+94
-7
lines changed

2 files changed

+94
-7
lines changed

sql-common/client.cc

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ void read_ok_ex(MYSQL *mysql, ulong length)
737737
{
738738
size_t total_len, len;
739739
uchar *pos, *saved_pos;
740+
my_ulonglong affected_rows, insert_id;
740741
char *db;
741742

742743
struct charset_info_st *saved_cs;
@@ -750,14 +751,30 @@ void read_ok_ex(MYSQL *mysql, ulong length)
750751

751752
pos= mysql->net.read_pos + 1;
752753

753-
/* affected rows */
754-
mysql->affected_rows= net_field_length_ll(&pos);
755-
/* insert id */
756-
mysql->insert_id= net_field_length_ll(&pos);
754+
affected_rows = net_field_length_ll(&pos); /* affected rows */
755+
insert_id = net_field_length_ll(&pos); /* insert id */
757756

758-
DBUG_PRINT("info",("affected_rows: %lu insert_id: %lu",
759-
(ulong) mysql->affected_rows,
760-
(ulong) mysql->insert_id));
757+
/*
758+
The following check ensures that we skip the assignment for the
759+
above read fields (i.e. affected_rows and insert_id) wherein the
760+
EOF packets are deprecated and the server sends OK packet instead
761+
with a packet header of 0xFE (254) to identify it as an EOF packet.
762+
We ignore this assignment as the valid contents of EOF packet include
763+
packet marker, server status and warning count only. However, we would
764+
assign these values to the connection handle if it was an OK packet
765+
with a packet header of 0x00.
766+
*/
767+
768+
if (!((mysql->server_capabilities & CLIENT_DEPRECATE_EOF) &&
769+
mysql->net.read_pos[0] == 254))
770+
{
771+
mysql->affected_rows= affected_rows;
772+
mysql->insert_id= insert_id;
773+
774+
DBUG_PRINT("info",("affected_rows: %lu insert_id: %lu",
775+
(ulong) mysql->affected_rows,
776+
(ulong) mysql->insert_id));
777+
}
761778

762779
/* server status */
763780
mysql->server_status= uint2korr(pos);

testclients/mysql_client_test.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15526,6 +15526,75 @@ static void test_mysql_insert_id()
1552615526
myquery(rc);
1552715527
}
1552815528

15529+
/*
15530+
Test for bug#22028117: MYSQLCLIENT DOES NOT RETURN CORRECT
15531+
MYSQL_INSERT_ID VIA DATABASE HANDLE
15532+
*/
15533+
15534+
static void test_bug22028117()
15535+
{
15536+
my_ulonglong res;
15537+
int rc;
15538+
MYSQL_STMT *stmt;
15539+
15540+
myheader("test_bug22028117");
15541+
15542+
rc = mysql_query(mysql, "USE test");
15543+
myquery(rc);
15544+
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
15545+
myquery(rc);
15546+
rc= mysql_query(mysql, "CREATE TABLE t1 ("
15547+
"f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT,"
15548+
"f2 VARCHAR(255))");
15549+
myquery(rc);
15550+
res= mysql_insert_id(mysql);
15551+
DIE_UNLESS(res == 0);
15552+
15553+
rc= mysql_query(mysql, "INSERT INTO t1 (f2) VALUES ('a')");
15554+
myquery(rc);
15555+
res= mysql_insert_id(mysql);
15556+
DIE_UNLESS(res == 1);
15557+
15558+
rc= mysql_query(mysql, "INSERT INTO t1 (f2) VALUES ('b')");
15559+
myquery(rc);
15560+
res= mysql_insert_id(mysql);
15561+
DIE_UNLESS(res == 2);
15562+
15563+
/* Make sure that the value of insert_id is not lost after SELECT */
15564+
stmt= mysql_simple_prepare(mysql, "SELECT MAX(f1) FROM t1");
15565+
check_stmt(stmt);
15566+
rc= mysql_stmt_execute(stmt);
15567+
check_execute(stmt, rc);
15568+
rc= my_process_stmt_result(stmt);
15569+
DIE_UNLESS(rc == 1);
15570+
mysql_stmt_close(stmt);
15571+
15572+
res= mysql_insert_id(mysql);
15573+
DIE_UNLESS(res == 2);
15574+
/* insert_id will be reset to 0 after a new table is created */
15575+
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t2");
15576+
myquery(rc);
15577+
15578+
rc= mysql_query(mysql, "CREATE TABLE t2 ("
15579+
"f1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT,"
15580+
"f2 VARCHAR(255))");
15581+
myquery(rc);
15582+
res= mysql_insert_id(mysql);
15583+
DIE_UNLESS(res == 0);
15584+
15585+
/*
15586+
mysql_insert_id() should return expr when the INSERT query contains
15587+
last_insert_id(expr)
15588+
*/
15589+
rc= mysql_query(mysql, "INSERT INTO t1 (f1) VALUES (last_insert_id(100))");
15590+
myquery(rc);
15591+
res= mysql_insert_id(mysql);
15592+
DIE_UNLESS(res == 100);
15593+
15594+
rc= mysql_query(mysql, "DROP TABLE t1,t2");
15595+
myquery(rc);
15596+
}
15597+
1552915598
/*
1553015599
Bug#20152: mysql_stmt_execute() writes to MYSQL_TYPE_DATE buffer
1553115600
*/
@@ -21177,6 +21246,7 @@ static struct my_tests_st my_tests[]= {
2117721246
{ "test_bug22559575", test_bug22559575 },
2117821247
{ "test_bug24963580", test_bug24963580 },
2117921248
{ "test_mysql_binlog", test_mysql_binlog },
21249+
{ "test_bug22028117", test_bug22028117 },
2118021250
{ 0, 0 }
2118121251
};
2118221252

0 commit comments

Comments
 (0)