Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55228 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12154 invoked from network); 5 Sep 2011 14:53:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Sep 2011 14:53:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=ulf.wendel@oracle.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ulf.wendel@oracle.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain oracle.com from 141.146.126.227 cause and error) X-PHP-List-Original-Sender: ulf.wendel@oracle.com X-Host-Fingerprint: 141.146.126.227 acsinet15.oracle.com Received: from [141.146.126.227] ([141.146.126.227:44015] helo=acsinet15.oracle.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/E7-64330-762E46E4 for ; Mon, 05 Sep 2011 10:53:28 -0400 Received: from rtcsinet22.oracle.com (rtcsinet22.oracle.com [66.248.204.30]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p85ErMir020505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 Sep 2011 14:53:24 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by rtcsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p85ErLcl023625 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 5 Sep 2011 14:53:21 GMT Received: from abhmt108.oracle.com (abhmt108.oracle.com [141.146.116.60]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p85ErFWQ029158 for ; Mon, 5 Sep 2011 09:53:15 -0500 Received: from [192.168.2.116] (/91.58.121.228) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 05 Sep 2011 07:53:15 -0700 Message-ID: <4E64E25E.3080102@oracle.com> Date: Mon, 05 Sep 2011 16:53:18 +0200 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 MIME-Version: 1.0 To: internals@lists.php.net References: <4E611027.6000103@sugarcrm.com> In-Reply-To: <4E611027.6000103@sugarcrm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: rtcsinet22.oracle.com [66.248.204.30] X-CT-RefId: str=0001.0A090204.4E64E264.0199,ss=1,re=0.000,fgs=0 Subject: Re: [PHP-DEV] mysqli tests breaking From: ulf.wendel@oracle.com (Ulf Wendel) This is the one and only mysqlnd-libmysql difference of some practical relevance. I consider it at least questionable if libmysql is correct. If it was to be decided that mysqlnd is wrong, it is probably like five lines of code in mysqlnd to change, if need be. Am 02.09.2011 19:19, schrieb Stas Malyshev: > API vs. SQL LAST_INSERT_ID() [ext/mysqli/tests/mysqli_last_insert_id.phpt] > The reason is that this test relies on LAST_INSERT_ID() being reset on > SELECT. I have not observed such behavior neither via PHP not talking to > Mysql server directly from CLI interface, so I have no idea why this > test assumes such behavior. Personal observation and memory may not be the best reference here. What the test does is: DROP TABLE IF EXISTS test CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY) Engine=MyISAM INSERT INTO test(id) VALUES (1); printf("insert id for INSERT is: %d\n", mysqli_insert_id(link)); SELECT 1 FROM DUAL printf("insert id for SELECT is: %d\n", mysqli_insert_id(link)); Libmysql will print: insert id for INSERT is: 1 insert id for SELECT is: 1 Mysqlnd will print: insert id for INSERT is: 1 insert id for SELECT is: 0 At the end of the day, we are discussing C library differences again, thus we can consult the C API reference: "Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement. Use this function after you have performed an INSERT statement into a table that contains an AUTO_INCREMENT field, or have used INSERT or UPDATE to set a column value with LAST_INSERT_ID(expr).", http://dev.mysql.com/doc/refman/5.6/en/mysql-insert-id.html The test is using the function not after an INSERT but after a SELECT. The documentation continues: "The return value of mysql_insert_id() is always zero unless explicitly updated under one of the following conditions: - [...] INSERT - [...] INSERT multi-row ... MySQL version dependent - [...} INSERT...SELECT and [...] - [...] INSERT...SELECT and [...]" Followed by: "mysql_insert_id() returns 0 if the previous statement does not use an AUTO_INCREMENT value. If you need to save the value for later, be sure to call mysql_insert_id() immediately after the statement that generates the value." I read: - "The return value of mysql_insert_id() is always zero unless explicitly updated under one of the following conditions" - "If you need to save the value for later, be sure to call mysql_insert_id() immediately after the statement that generates the value." If people like, we can call this mysqlnd interpretation a bug. In any case, I find no reference in the documentation that the value must NOT to be reset upon SELECT. Searching bugs.php.net gives one related case: https://bugs.php.net/bug.php?id=54190 Unfortunately, Andrey did not write down the MySQL bug he refers to. However, back in March he wrote something that makes be believe he interprets the manual similar to how I do: "mysqli calls internally "SHOW WARNINGS" to fetch the warnings from the server. The SHOW statement should reset insert_id in libmysql, but it does not." To sum up: - debatable issue - edge case going beyond primary use of function - edge case not explicitly covered by the documentation - five lines(?) to change, if need be - quick check: no bug report on bugs.php.net against mysqlnd Ulf