From 0ed2837f3d16c469de3e013c1c16e050d03ed978 Mon Sep 17 00:00:00 2001 From: Sergey Tsalkov Date: Fri, 29 Apr 2011 01:48:27 -0400 Subject: [PATCH] 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 --- db.class.php | 23 ++++++++++------------- simpletest/BasicTest.php | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/db.class.php b/db.class.php index 5ee54f5..08dec1f 100644 --- a/db.class.php +++ b/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() { diff --git a/simpletest/BasicTest.php b/simpletest/BasicTest.php index 0ed914c..87a2392 100644 --- a/simpletest/BasicTest.php +++ b/simpletest/BasicTest.php @@ -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);