add delete() function -- mostly for completeness with insert(), update(), etc
This commit is contained in:
@@ -172,6 +172,15 @@ class DB
|
||||
return DB::insertOrReplace('REPLACE', $table, $data);
|
||||
}
|
||||
|
||||
public static function delete() {
|
||||
$args = func_get_args();
|
||||
$table = self::formatTableName(array_shift($args));
|
||||
$where = array_shift($args);
|
||||
$buildquery = "DELETE FROM $table WHERE $where";
|
||||
array_unshift($args, $buildquery);
|
||||
call_user_func_array('DB::queryNull', $args);
|
||||
}
|
||||
|
||||
public static function sqleval($text) {
|
||||
return new MeekroDBEval($text);
|
||||
}
|
||||
|
||||
@@ -155,6 +155,24 @@ class BasicTest extends SimpleTest {
|
||||
$this->assert(DB::affectedRows() === 1);
|
||||
}
|
||||
|
||||
function test_4_2_delete() {
|
||||
DB::insert('accounts', array(
|
||||
'username' => 'gonesoon',
|
||||
'password' => 'something',
|
||||
'age' => 61,
|
||||
'height' => 199.194
|
||||
));
|
||||
|
||||
$ct = DB::queryFirstField("SELECT COUNT(*) FROM accounts WHERE username=%s AND height=%d", 'gonesoon', 199.194);
|
||||
$this->assert(intval($ct) === 1);
|
||||
|
||||
DB::delete('accounts', 'username=%s AND age=%i AND height=%d', 'gonesoon', '61', '199.194');
|
||||
$this->assert(DB::affectedRows() === 1);
|
||||
|
||||
$ct = DB::queryFirstField("SELECT COUNT(*) FROM accounts WHERE username=%s AND height=%d", 'gonesoon', '199.194');
|
||||
$this->assert(intval($ct) === 0);
|
||||
}
|
||||
|
||||
function test_5_error_handler() {
|
||||
global $error_callback_worked;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user