dblayer: return the primarykey value after an insert. If it is not an autoincrement, return the provided value
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3922 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -95,7 +95,7 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
"where"=>"\$'\"",
|
"where"=>"\$'\"",
|
||||||
"with space"=>"with space"));
|
"with space"=>"with space"));
|
||||||
// SQLite start at 1, MySQL start at 0...
|
// SQLite start at 1, MySQL start at 0...
|
||||||
$this->assertLessThanOrEqual ($res, 1);
|
$this->assertSame ($res, "gr ou\"p");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_read1 ()
|
public function test_read1 ()
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class test_userssql extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$userssql = new userssql ("sqlite:///tmp/database.db");
|
$userssql = new userssql ("sqlite:///tmp/database.db");
|
||||||
$res = $userssql->adduser ("toto@toto.com", "Toto", "Toto2");
|
$res = $userssql->adduser ("toto@toto.com", "Toto", "Toto2");
|
||||||
$this->assertSame ($res, "1");
|
$this->assertSame ($res, "toto@toto.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_listusers2 ()
|
public function test_listusers2 ()
|
||||||
|
|||||||
11
dblayer.php
11
dblayer.php
@@ -675,7 +675,16 @@ class dblayer
|
|||||||
echo "dblayer execute exception : ".$e->getMessage()."\n";
|
echo "dblayer execute exception : ".$e->getMessage()."\n";
|
||||||
exit;
|
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);
|
$lastID = call_user_func ($this->hookpostinsertFunc, $dataOK, $lastID);
|
||||||
return $lastID;
|
return $lastID;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user