Example #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;
 }
Example #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;
 }
Example #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();
 }
Example #4
0
 public function testFindAll()
 {
     $this->repository->findAll()->count();
     $this->assertEquals("SELECT number FROM `dummy`", $this->adapter->getDriver()->getLastQuery());
 }
Example #5
0
 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());
 }
Example #6
0
 public function testSchemaGeneratorDependency()
 {
     $this->assertTrue(is_array($this->adapter->getSchema()));
 }