BUG : dblayer : don't raise an exception when re-inserting unique record
dblayer : add more unit tests git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1850 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -259,4 +259,50 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
$this->assertThat($res, $this->lessThanOrEqual(2));
|
||||
}
|
||||
|
||||
// Test the unique feature
|
||||
public function test_insert3 ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "users";
|
||||
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
|
||||
"groupmember"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
// Unique simple in insert
|
||||
$db->unique = array ("user");
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $db->insert (array ("user"=>"Us ou\"r",
|
||||
"groupmember"=>"NEW GROUP",
|
||||
"where"=>"\$'\"",
|
||||
"with space"=>"with space"));
|
||||
}
|
||||
|
||||
public function test_insert4 ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "users";
|
||||
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
|
||||
"groupmember"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
// Unique multiple in insert
|
||||
$db->unique = array (array ("user", "groupmember"));
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $db->insert (array ("user"=>"Us ou\"r",
|
||||
"groupmember"=>"NEW GROUP",
|
||||
"where"=>"\$'\"",
|
||||
"with space"=>"with space"));
|
||||
}
|
||||
}
|
||||
|
||||
12
dblayer.php
12
dblayer.php
@@ -398,7 +398,7 @@ class dblayer extends PDO
|
||||
}
|
||||
// If there is only the primary key, there is no chance to have a
|
||||
// conflict
|
||||
if ($updatekey !== false && count ($select) >= 2)
|
||||
if ($updatekey === false && count ($select) >= 2)
|
||||
{
|
||||
$rc = $this->read ($select, array ($this->primary));
|
||||
if (count ($rc) > 0)
|
||||
@@ -580,7 +580,15 @@ class dblayer extends PDO
|
||||
throw new Exception ("TO BE DEVELOPPED : ".$this->fields[$key][0], 500);
|
||||
}
|
||||
|
||||
$st->execute ();
|
||||
try
|
||||
{
|
||||
$st->execute ();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo "dblayer execute exception : ".$e->getMessage()."\n";
|
||||
exit;
|
||||
}
|
||||
return $this->db->lastInsertId();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user