diff --git a/Tests/dblayerComplet.php b/Tests/dblayerComplet.php index 2b175b8..2ef7005 100644 --- a/Tests/dblayerComplet.php +++ b/Tests/dblayerComplet.php @@ -95,7 +95,7 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase "where"=>"\$'\"", "with space"=>"with space")); // SQLite start at 1, MySQL start at 0... - $this->assertLessThanOrEqual ($res, 1); + $this->assertSame ($res, "gr ou\"p"); } public function test_read1 () diff --git a/Tests/userssqlTest.php b/Tests/userssqlTest.php index 4da7fe9..c0c4d5b 100644 --- a/Tests/userssqlTest.php +++ b/Tests/userssqlTest.php @@ -29,7 +29,7 @@ class test_userssql extends PHPUnit_Framework_TestCase { $userssql = new userssql ("sqlite:///tmp/database.db"); $res = $userssql->adduser ("toto@toto.com", "Toto", "Toto2"); - $this->assertSame ($res, "1"); + $this->assertSame ($res, "toto@toto.com"); } public function test_listusers2 () diff --git a/dblayer.php b/dblayer.php index dce25e9..5e486d3 100644 --- a/dblayer.php +++ b/dblayer.php @@ -675,7 +675,16 @@ class dblayer echo "dblayer execute exception : ".$e->getMessage()."\n"; exit; } - $lastID = self::$instance[$this->dsn]->lastInsertId(); + if (key_exists ($this->primary, $data) && + ! in_array ("autoincrement", $this->fields[$this->primary]) && + $data[$this->primary] !== null) + $lastID = $data[$this->primary]; + elseif (key_exists ($this->primary, $data) && + in_array ("autoincrement", $this->fields[$this->primary]) && + $data[$this->primary] !== null) + $lastID = $data[$this->primary]; + else + $lastID = self::$instance[$this->dsn]->lastInsertId(); $lastID = call_user_func ($this->hookpostinsertFunc, $dataOK, $lastID); return $lastID; }