on second thought, we won't have insertMany() and replaceMany(), but insert() and replace()
will figure out which one you mean this means that a minor undocumented feature, being able to insert an array and have it automatically serialized, can't exist anymore
This commit is contained in:
23
db.class.php
23
db.class.php
@@ -145,10 +145,16 @@ class DB
|
||||
call_user_func_array('DB::queryNull', $args);
|
||||
}
|
||||
|
||||
public static function insertOrReplace($which, $table, $datas, $many) {
|
||||
public static function insertOrReplace($which, $table, $datas) {
|
||||
$datas = unserialize(serialize($datas)); // break references within array
|
||||
$keys = null;
|
||||
if (! $many) $datas = array($datas);
|
||||
|
||||
if (isset($datas[0]) && is_array($datas[0])) {
|
||||
$many = true;
|
||||
} else {
|
||||
$datas = array($datas);
|
||||
$many = false;
|
||||
}
|
||||
|
||||
foreach ($datas as $data) {
|
||||
if (! $keys) {
|
||||
@@ -165,7 +171,6 @@ class DB
|
||||
if (is_object($datum) && ($datum instanceof MeekroDBEval)) {
|
||||
$datum = $datum->text;
|
||||
} else {
|
||||
if (is_array($datum)) $datum = serialize($datum);
|
||||
$datum = (is_int($datum) ? $datum : "'" . DB::escape($datum) . "'");
|
||||
}
|
||||
$insert_values[] = $datum;
|
||||
@@ -183,19 +188,11 @@ class DB
|
||||
}
|
||||
|
||||
public static function insert($table, $data) {
|
||||
return DB::insertOrReplace('INSERT', $table, $data, false);
|
||||
}
|
||||
|
||||
public static function insertMany($table, $data) {
|
||||
return DB::insertOrReplace('INSERT', $table, $data, true);
|
||||
return DB::insertOrReplace('INSERT', $table, $data);
|
||||
}
|
||||
|
||||
public static function replace($table, $data) {
|
||||
return DB::insertOrReplace('REPLACE', $table, $data, false);
|
||||
}
|
||||
|
||||
public static function replaceMany($table, $data) {
|
||||
return DB::insertOrReplace('REPLACE', $table, $data, true);
|
||||
return DB::insertOrReplace('REPLACE', $table, $data);
|
||||
}
|
||||
|
||||
public static function delete() {
|
||||
|
||||
@@ -190,7 +190,7 @@ class BasicTest extends SimpleTest {
|
||||
'height' => 190.194
|
||||
);
|
||||
|
||||
DB::insertMany('accounts', $ins);
|
||||
DB::insert('accounts', $ins);
|
||||
$this->assert(DB::affectedRows() === 2);
|
||||
|
||||
$rows = DB::query("SELECT * FROM accounts WHERE height=%d ORDER BY age ASC", 190.194);
|
||||
|
||||
Reference in New Issue
Block a user