diff --git a/backend/lib/Interpreter/Interpreter.php b/backend/lib/Interpreter/Interpreter.php index 70afa2b..b59d5d5 100644 --- a/backend/lib/Interpreter/Interpreter.php +++ b/backend/lib/Interpreter/Interpreter.php @@ -76,10 +76,8 @@ abstract class Interpreter implements InterpreterInterface { */ protected function getData($tuples = NULL, $groupBy = NULL) { // prepare sql - $parameters = array(':id' => $this->channel->getId()); - $sql['from'] = ' FROM data'; - $sql['where'] = ' WHERE channel_id = :id' . self::buildDateTimeFilterSQL($this->from, $this->to); + $sql['where'] = ' WHERE channel_id = ?' . self::buildDateTimeFilterSQL($this->from, $this->to); $sql['orderBy'] = ' ORDER BY timestamp ASC'; if ($groupBy && $sql['groupFields'] = self::buildGroupBySQL($groupBy)) { @@ -94,10 +92,10 @@ abstract class Interpreter implements InterpreterInterface { } // get total row count for grouping - $rowCount = $this->conn->fetchColumn($sql['rowCount'], $parameters, 0); + $rowCount = $this->conn->fetchColumn($sql['rowCount'], array($this->channel->getId()), 0); // query for data - $stmt = $this->conn->executeQuery('SELECT ' . $sql['fields'] . $sql['from'] . $sql['where'] . $sql['groupBy'] . $sql['orderBy'], $parameters); + $stmt = $this->conn->executeQuery('SELECT ' . $sql['fields'] . $sql['from'] . $sql['where'] . $sql['groupBy'] . $sql['orderBy'], array($this->channel->getId())); // return iterators if ($sql['groupBy'] || is_null($tuples) || $rowCount < $tuples) { diff --git a/backend/lib/Interpreter/SensorInterpreter.php b/backend/lib/Interpreter/SensorInterpreter.php index cf32d1c..00fb815 100644 --- a/backend/lib/Interpreter/SensorInterpreter.php +++ b/backend/lib/Interpreter/SensorInterpreter.php @@ -58,7 +58,8 @@ class SensorInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMin() { - return array_map('floatval', $this->conn->fetchAssoc('SELECT value, timestamp FROM data WHERE channel_id = ' . (int) $this->channel->getId() . parent::buildDateTimeFilterSQL($this->from, $this->to) . ' ORDER BY value ASC LIMIT 1')); + $min = $this->conn->fetchAssoc('SELECT value, timestamp FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to) . ' ORDER BY value ASC LIMIT 1', array($this->channel->getId())); + return ($min) ? array_map('floatval', $min) : NULL; } /** @@ -67,7 +68,8 @@ class SensorInterpreter extends Interpreter { * @return array (0 => timestamp, 1 => value) */ public function getMax() { - return array_map('floatval', $this->conn->fetchAssoc('SELECT value, timestamp FROM data WHERE channel_id = ' . (int) $this->channel->getId() . parent::buildDateTimeFilterSQL($this->from, $this->to) . ' ORDER BY value DESC LIMIT 1')); + $max = $this->conn->fetchAssoc('SELECT value, timestamp FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to) . ' ORDER BY value DESC LIMIT 1', array($this->channel->getId())); + return ($max) ? array_map('floatval', $max) : NULL; } /** @@ -76,7 +78,7 @@ class SensorInterpreter extends Interpreter { * @return float */ public function getAverage() { - return (float) $this->conn->fetchColumn('SELECT AVG(value) FROM data WHERE channel_id = ' . (int) $this->channel->getId() . parent::buildDateTimeFilterSQL($this->from, $this->to)); + return (float) $this->conn->fetchColumn('SELECT AVG(value) FROM data WHERE channel_id = ?' . parent::buildDateTimeFilterSQL($this->from, $this->to), array($this->channel->getId()), 0); } /**