public function delete() { $update = new DatabaseLayer\Update($this->_table); $update->setData(['deleted' => 'Yes']); $update->condition($this->getIDField(), $this->getId()); $update->condition('sequence', $this->sequence); $update->execute(); #echo "Deleting {$this->_table} with id = {$this->getId()}, sequence = {$this->sequence}\n"; $this->reload(); return $this; }
/** * @expectedException \Thru\ActiveRecord\DatabaseLayer\Exception * @expectedExceptionMessage Active Record Cannot update into more than one table at a time! */ public function testUpdateIntoTwoTablesFails() { $update = new DatabaseLayer\Update("test_models"); $update->setTables(array("tm" => new DatabaseLayer\Table("test_models"), "tmb" => new DatabaseLayer\Table("test_model_bad"))); $update->execute(); }
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; }