From 1d797b306e7abde5d4debdf190fc2577b4e85853 Mon Sep 17 00:00:00 2001 From: Sergey Tsalkov Date: Sat, 14 Jun 2014 02:41:06 +0000 Subject: [PATCH] bugfix: insert/update type functions don't break when using a param_char other than % --- db.class.php | 14 ++++++++++---- simpletest/BasicTest.php | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/db.class.php b/db.class.php index 808037d..54e6d9e 100644 --- a/db.class.php +++ b/db.class.php @@ -299,7 +299,7 @@ class MeekroDB { $params = array_shift($args); $where = array_shift($args); - $query = "UPDATE %b SET %? WHERE " . $where; + $query = str_replace('%', $this->param_char, "UPDATE %b SET %? WHERE ") . $where; array_unshift($args, $params); array_unshift($args, $table); @@ -327,17 +327,23 @@ class MeekroDB { if (isset($options['update']) && is_array($options['update']) && $options['update'] && strtolower($which) == 'insert') { if (array_values($options['update']) !== $options['update']) { - return $this->query("INSERT INTO %b %lb VALUES %? ON DUPLICATE KEY UPDATE %?", $table, $keys, $values, $options['update']); + return $this->query( + str_replace('%', $this->param_char, "INSERT INTO %b %lb VALUES %? ON DUPLICATE KEY UPDATE %?"), + $table, $keys, $values, $options['update']); } else { $update_str = array_shift($options['update']); - $query_param = array("INSERT INTO %b %lb VALUES %? ON DUPLICATE KEY UPDATE $update_str", $table, $keys, $values); + $query_param = array( + str_replace('%', $this->param_char, "INSERT INTO %b %lb VALUES %? ON DUPLICATE KEY UPDATE ") . $update_str, + $table, $keys, $values); $query_param = array_merge($query_param, $options['update']); return call_user_func_array(array($this, 'query'), $query_param); } } - return $this->query("%l INTO %b %lb VALUES %?", $which, $table, $keys, $values); + return $this->query( + str_replace('%', $this->param_char, "%l INTO %b %lb VALUES %?"), + $which, $table, $keys, $values); } public function insert($table, $data) { return $this->insertOrReplace('INSERT', $table, $data); } diff --git a/simpletest/BasicTest.php b/simpletest/BasicTest.php index 913d439..4a9bebd 100644 --- a/simpletest/BasicTest.php +++ b/simpletest/BasicTest.php @@ -114,6 +114,8 @@ class BasicTest extends SimpleTest { $bart = DB::queryFirstRow("SELECT * FROM accounts WHERE age IN ###li AND height IN ###ld AND username IN ###ls", array(15, 25), array(10.371, 150.123), array('Bart', 'Barts')); $this->assert($bart['username'] === 'Bart'); + DB::insert('accounts', array('username' => 'f_u')); + DB::query("DELETE FROM accounts WHERE username=###s", 'f_u'); DB::$param_char = '%'; $charlie_password = DB::queryFirstField("SELECT password FROM accounts WHERE username IN %ls AND username = %s",