1 https://rt.cpan.org/Public/Bug/Display.html?id=108000 |
|
2 https://bugs.mysql.com/bug.php?id=78778 |
|
3 |
|
4 The fix will be available in next DBD::mysql stable release |
|
5 |
|
6 commit 85459c2f43243e41841180e554e4ef142d95d56b |
|
7 Author: Michiel Beijen <[email protected]> |
|
8 Date: Mon Aug 1 08:10:33 2016 +0200 |
|
9 |
|
10 $dbh->{mysql_insertid} is cleared after SELECT |
|
11 |
|
12 Apparently, on t/31insertid.t, there is one test that fails when |
|
13 compiled against libmysqlclient 5.7 or up; issuing a SELECT statement |
|
14 on the same database handle that previously executed an INSERT clears |
|
15 $dbh->{mysql_insertid}, while previously this was retained. |
|
16 (https://rt.cpan.org/Ticket/Display.html?id=108000) |
|
17 |
|
18 --- a/Changes |
|
19 +++ b/Changes |
|
20 @@ -1,3 +1,10 @@ |
|
21 +2016-08-01 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.035_01) |
|
22 +* Apparently, on t/31insertid.t, there is one test that fails when compiled |
|
23 + against libmysqlclient 5.7 or up; issuing a SELECT statement on the same |
|
24 + database handle that previously executed an INSERT clears |
|
25 + $dbh->{mysql_insertid}, while previously this was retained. |
|
26 + (https://rt.cpan.org/Ticket/Display.html?id=108000) |
|
27 + |
|
28 2016-07-09 Patrick Galbraith, Michiel Beijen, DBI/DBD community (4.035) |
|
29 * Add DBI back to configure_requires, fix by miyagawa. |
|
30 |
|
31 diff --git a/lib/DBD/mysql.pm b/lib/DBD/mysql.pm |
|
32 index 069e882..4830b9d 100644 |
|
33 --- a/lib/DBD/mysql.pm |
|
34 +++ b/lib/DBD/mysql.pm |
|
35 @@ -1733,10 +1733,14 @@ have impact on the I<max_length> attribute. |
|
36 |
|
37 =item mysql_insertid |
|
38 |
|
39 -MySQL has the ability to choose unique key values automatically. If this |
|
40 -happened, the new ID will be stored in this attribute. An alternative |
|
41 -way for accessing this attribute is via $dbh->{'mysql_insertid'}. |
|
42 -(Note we are using the $dbh in this case!) |
|
43 +If the statement you executed performs an INSERT, and there is an AUTO_INCREMENT |
|
44 +column in the table you inserted in, this attribute holds the value stored into |
|
45 +the AUTO_INCREMENT column, if that value is automatically generated, by |
|
46 +storing NULL or 0 or was specified as an explicit value. |
|
47 + |
|
48 +Typically, you'd access the value via $sth->{mysql_insertid}. The value can |
|
49 +also be accessed via $dbh->{mysql_insertid} but this can easily |
|
50 +produce incorrect results in case one database handle is shared. |
|
51 |
|
52 =item mysql_is_blob |
|
53 |
|
54 diff --git a/t/31insertid.t b/t/31insertid.t |
|
55 index 18a6d3b..f00c5a4 100644 |
|
56 --- a/t/31insertid.t |
|
57 +++ b/t/31insertid.t |
|
58 @@ -16,7 +16,7 @@ if ($@) { |
|
59 plan skip_all => |
|
60 "no database connection"; |
|
61 } |
|
62 -plan tests => 18; |
|
63 +plan tests => 19; |
|
64 |
|
65 ok $dbh->do('SET @@auto_increment_offset = 1'); |
|
66 ok $dbh->do('SET @@auto_increment_increment = 1'); |
|
67 @@ -38,7 +38,8 @@ ok defined $sth; |
|
68 |
|
69 ok $sth->execute("Jochen"); |
|
70 |
|
71 -is $dbh->{'mysql_insertid'}, 1, "insert id == $dbh->{mysql_insertid}"; |
|
72 +is $sth->{mysql_insertid}, 1, "insert id == $sth->{mysql_insertid}"; |
|
73 +is $dbh->{mysql_insertid}, 1, "insert id == $dbh->{mysql_insertid}"; |
|
74 |
|
75 ok $sth->execute("Patrick"); |
|
76 |
|
77 @@ -53,12 +54,15 @@ ok ($max_id= $sth2->fetch()); |
|
78 |
|
79 ok defined $max_id; |
|
80 |
|
81 -cmp_ok $sth->{'mysql_insertid'}, '==', $max_id->[0], "sth insert id $sth->{'mysql_insertid'} == max(id) $max_id->[0] in dbd_mysql_t31"; |
|
82 - |
|
83 -cmp_ok $dbh->{'mysql_insertid'}, '==', $max_id->[0], "dbh insert id $dbh->{'mysql_insertid'} == max(id) $max_id->[0] in dbd_mysql_t31"; |
|
84 +SKIP: { |
|
85 + skip 'using libmysqlclient 5.7 or up we now have an empty dbh insertid', |
|
86 + 1, if $dbh->{mysql_clientversion} >= 50700; |
|
87 + cmp_ok $dbh->{mysql_insertid}, '==', $max_id->[0], |
|
88 + "dbh insert id $dbh->{'mysql_insertid'} == max(id) $max_id->[0] in dbd_mysql_t31"; |
|
89 +} |
|
90 +cmp_ok $sth->{mysql_insertid}, '==', $max_id->[0], |
|
91 + "sth insert id $sth->{'mysql_insertid'} == max(id) $max_id->[0] in dbd_mysql_t31"; |
|
92 |
|
93 ok $sth->finish(); |
|
94 - |
|
95 ok $sth2->finish(); |
|
96 - |
|
97 ok $dbh->disconnect(); |
|
98 |
|