Ejemplo n.º 1
0
 public function processUpdate(DatabaseLayer\Update $thing)
 {
     // SELECTORS
     if (count($thing->getTables()) > 1) {
         throw new Exception("Active Record Cannot update into more than one table at a time!");
     }
     $tables = $thing->getTables();
     $table = end($tables);
     $updates = array();
     foreach ($thing->getData() as $key => $value) {
         $key = trim($key, "\"");
         if (is_object($value) || is_array($value)) {
             $value = JsonPrettyPrinter::Json($value);
         }
         $value_slashed = addslashes($value);
         if ($value === null) {
             $updates[] = "\"{$key}\" = NULL";
         } else {
             $updates[] = "\"{$key}\" = \"{$value_slashed}\"";
         }
     }
     $selector = "UPDATE {$table->getName()} ";
     $data = "SET " . implode(", ", $updates);
     $conditions = $this->processConditions($thing);
     $query = "{$selector}\n{$data}\n{$conditions}";
     //header("Content-type: text/plain"); echo $query; exit;
     $result = $this->query($query);
     return $result->errorCode() == "00000" ? true : false;
 }