Author: uwendel
Date: 2008-04-07 12:14:32 +0200 (Mon, 07 Apr 2008)
New Revision: 1396
Modified:
trunk/tests/ext/pdo_mysql/pdo_mysql_mantis_370.phpt
Log:
Checking lastInsertID() once more and changing test.
Modified: trunk/tests/ext/pdo_mysql/pdo_mysql_mantis_370.phpt
===================================================================
--- trunk/tests/ext/pdo_mysql/pdo_mysql_mantis_370.phpt 2008-04-04 15:56:45 UTC (rev 1395)
+++ trunk/tests/ext/pdo_mysql/pdo_mysql_mantis_370.phpt 2008-04-07 10:14:32 UTC (rev 1396)
@@ -1,5 +1,5 @@
--TEST--
-Mantis #365 (Wrong SQLSTATE - II) - remove test after fix!
+Mantis #370 (lastInsertId()) - remove test after fix!
--SKIPIF--
<?php
require_once('skipif.inc');
@@ -9,27 +9,51 @@
?>
--FILE--
<?php
- require_once('mysql_pdo_test.inc');
-
+ require_once('mysql_pdo_test.inc');
$db = MySQLPDOTest::factory();
+ $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
$db->exec('DROP TABLE IF EXISTS test');
- $db->exec(sprintf('CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY, col1
CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE));
+ $db->exec(sprintf('CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY)
ENGINE=MyISAM'));
- $db->exec('INSERT INTO test(id, col1) VALUES (100, "a")');
- var_dump($db->lastInsertId());
+ // First insert
+ $db->exec('INSERT INTO test(id) VALUES (100)');
+ printf("First Insert -> LAST_INSERT_ID should be 100, got %d\n",
$db->lastInsertId());
- $db->exec('INSERT INTO test(id, col1) VALUES (100, "a")');
- var_dump($db->lastInsertId());
+ // Duplicate key
+ $db->exec('INSERT INTO test(id) VALUES (100)');
+ printf("Duplicate Key -> LAST_INSERT_ID should be 0, got %d\n",
$db->lastInsertId());
- $db->exec('INSERT INTO test(id, col1) VALUES (101, "b")');
- var_dump($db->lastInsertId());
+ // Next insert without PK conflict
+ $db->exec('INSERT INTO test(id) VALUES (101)');
+ printf("No PK conflicht -> LAST_INSERT_ID should be 101, got %d\n",
$db->lastInsertId());
+ $stmt = $db->query('SELECT * FROM test');
+ var_dump($stmt->fetchAll());
+ $stmt->fetch();
+
+ $db->exec(sprintf('DROP TABLE IF EXISTS test'));
print "done!";
--EXPECTF--
-string(3) "100"
+First Insert -> LAST_INSERT_ID should be 100, got 100
Warning: PDO::exec(): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate
entry '100' for key 'PRIMARY' in %s on line %d
-string(3) "100"
-string(3) "101"
+Duplicate Key -> LAST_INSERT_ID should be 0, got 100
+No PK conflicht -> LAST_INSERT_ID should be 101, got 101
+array(2) {
+ [0]=>
+ array(2) {
+ ["id"]=>
+ string(3) "100"
+ [0]=>
+ string(3) "100"
+ }
+ [1]=>
+ array(2) {
+ ["id"]=>
+ string(3) "101"
+ [0]=>
+ string(3) "101"
+ }
+}
done!
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r1396 - trunk/tests/ext/pdo_mysql | uwendel | 7 Apr 2008 |