예제 #1
0
 /**
  * Delete entity
  *
  * @throws \Rio\Exception
  */
 public function delete()
 {
     $query = sprintf("DELETE FROM `{$this->table}` WHERE %s = %s", $this->primary, $this->adapter->getDriver()->quote($this->uid, $this->properties[$this->primary]['type']));
     $statement = $this->adapter->getDriver()->query($query);
     if ($statement->rowsAffected() === 0) {
         throw new Exception('Failed to delete entity "' . CamelCase::to($this->table) . ' #' . $this->uid . '"');
     }
     $this->modified = null;
     $this->uid = null;
 }
예제 #2
0
 /**
  * Translate single filter definition into SQL-like query constraint
  *
  * @param array $filter
  * @return string
  */
 protected function translateFilter(array $filter)
 {
     $type = ' = ';
     if (is_array($filter['value'])) {
         $type = ' IN ';
         $values = [];
         foreach ($filter['value'] as $value) {
             $values[] = $this->adapter->getDriver()->quote($value, $this->schema['properties'][$filter['column']]['type']);
         }
         $value = '(' . implode(', ', $values) . ')';
     } else {
         $value = $this->adapter->getDriver()->quote($filter['value'], $this->schema['properties'][$filter['column']]['type']);
     }
     return $filter['column'] . $type . $value;
 }
예제 #3
0
 /**
  * @template Schema/Update.phtml
  * @return string
  */
 public function updateAction()
 {
     $hash = hash('crc32', serialize($this->adapter->getSchema()));
     $hashCurrent = $hash;
     $this->view->set('current', $hash);
     do {
         $update = ROOT . sprintf($this->registry->get('database.schema'), $hash);
         if (file_exists($update)) {
             try {
                 $this->adapter->getDriver()->query(file_get_contents($update));
             } catch (\Exception $e) {
                 $update = false;
             }
         } else {
             $update = false;
         }
         $hash = hash('crc32', serialize($this->adapter->getSchema()));
     } while (false !== $update && $hash !== $hashCurrent);
     return $this->view->set('new', $hash)->render();
 }
예제 #4
0
 public function testFindAll()
 {
     $this->repository->findAll()->count();
     $this->assertEquals("SELECT number FROM `dummy`", $this->adapter->getDriver()->getLastQuery());
 }
예제 #5
0
파일: DummyTest.php 프로젝트: poliander/rio
 public function testGettingRelatedRepository()
 {
     $entity = new Dummy($this->adapter);
     $entity->setName('random lastname')->getFamily()->count();
     $this->assertEquals("SELECT number FROM `dummy` WHERE (name = 'random lastname')", $this->adapter->getDriver()->getLastQuery());
 }
예제 #6
0
 public function testSchemaGeneratorDependency()
 {
     $this->assertTrue(is_array($this->adapter->getSchema()));
 }