insertUpdate() can now handle a second array for the update component, or nothing, so it'll

re-use the insert array for the update component
This commit is contained in:
Sergey Tsalkov
2011-09-23 21:29:40 -07:00
parent 5050205e58
commit 80cc78edcd
2 changed files with 74 additions and 5 deletions

View File

@@ -248,7 +248,57 @@ class BasicTest extends SimpleTest {
$this->assert(count($result) === 1);
$this->assert($result[0]['height'] === '10.371');
DB::query("UPDATE accounts SET age=age-1 WHERE age=%i", 16);
DB::insertUpdate('accounts', array(
'id' => 2, //duplicate primary key
'username' => 'blahblahdude',
'age' => 233,
'height' => 199.194
));
$result = DB::query("SELECT * FROM accounts WHERE age = %i", 233);
$this->assert(count($result) === 1);
$this->assert($result[0]['height'] === '199.194');
$this->assert($result[0]['username'] === 'blahblahdude');
DB::insertUpdate('accounts', array(
'id' => 2, //duplicate primary key
'username' => 'gonesoon',
'password' => 'something',
'age' => 61,
'height' => 199.194
), array(
'age' => 74,
));
$result = DB::query("SELECT * FROM accounts WHERE age = %i", 74);
$this->assert(count($result) === 1);
$this->assert($result[0]['height'] === '199.194');
$this->assert($result[0]['username'] === 'blahblahdude');
$multiples[] = array(
'id' => 3, //duplicate primary key
'username' => 'gonesoon',
'password' => 'something',
'age' => 61,
'height' => 199.194
);
$multiples[] = array(
'id' => 1, //duplicate primary key
'username' => 'gonesoon',
'password' => 'something',
'age' => 61,
'height' => 199.194
);
DB::insertUpdate('accounts', $multiples, array('age' => 914));
$this->assert(DB::affectedRows() === 4);
$result = DB::query("SELECT * FROM accounts WHERE age=914 ORDER BY id ASC");
$this->assert(count($result) === 2);
$this->assert($result[0]['username'] === 'Abe');
$this->assert($result[1]['username'] === 'Charlie\'s Friend');
DB::query("UPDATE accounts SET age=15, username='Bart' WHERE age=%i", 74);
$this->assert(DB::affectedRows() === 1);
}