Inheritance: use trait dibi\Strict
Example #1
0
 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @param  string
  * @return void
  * @throws DuplicateNameException
  */
 public function add($username, $password, $role = 'guest')
 {
     try {
         $this->db->insert(self::TABLE_NAME, [self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_ROLE => $role])->execute();
     } catch (Nette\Database\UniqueConstraintViolationException $e) {
         throw new DuplicateNameException();
     }
 }
Example #2
0
 protected function query($sql)
 {
     if (!is_array($sql)) {
         $sql = [$sql];
     }
     foreach ($sql as $query) {
         $this->dibiConnection->nativeQuery($query);
     }
 }
Example #3
0
 /**
  * This will detect all columns of the table and divides it to $this->columns array and $this->numbered collection of objects.
  * @return void|NULL
  */
 public function detectColumns()
 {
     $fields = $this->connection->query("SELECT * FROM `{$this->name}` %ofs", 0, "%lmt", 1);
     if (count($fields) == 0) {
         throw new \Sakura\SakuraNoRowException("There is no row in table `{$this->name}`.");
     }
     $columns = array();
     foreach ($fields as $v) {
         foreach ($v as $key => $value) {
             $columns[] = $key;
         }
     }
     unset($fields);
     $numberedSet = $this->detectNumbered($columns);
     if ($numberedSet == False) {
         $this->columns = $columns;
         return NULL;
     }
     foreach ($numberedSet as $findName => $numbered) {
         foreach ($columns as $key => $column) {
             $numberMaybe = ltrim($column, $findName);
             if (is_numeric($numberMaybe)) {
                 $number = intval($numberMaybe);
                 if ($number >= $numbered['min'] and $number <= $numbered['max']) {
                     unset($columns[$key]);
                 }
             }
         }
         $this->addNumbered($findName, $findName, $numbered['max'], $numbered['min']);
     }
     // reset to the first founded numbered colums
     $this->activeNumbered = key($this->numbered);
     $this->columns = $columns;
 }
Example #4
0
 /**
  * It generates basic Dibi\Fluent SQL for getting one node.
  * @return Dibi\Fluent
  */
 public function selectNodeSqlFactory($selectId = False)
 {
     $DF = new Fluent($this->connection);
     if ($selectId) {
         $DF = $this->connection->select("`" . $this->table->getAlias() . "`.`{$this->id}`");
     } else {
         $DF = $this->connection->select(False);
     }
     return $DF->from('`' . $this->table->getName() . '` AS `' . $this->table->getAlias() . '`');
 }
Example #5
0
 /**
  * @return IAdapter
  */
 public function getAdapter()
 {
     if (!$this->adapter) {
         $driver = ucfirst(strtolower($this->connection->getConfig('driver')));
         switch ($driver) {
             case IAdapter::DRIVER_MYSQL:
             case IAdapter::DRIVER_MYSQLI:
                 $class = 'Joseki\\Migration\\Database\\Adapters\\MysqlAdapter';
                 break;
             case IAdapter::DRIVER_SQLSRV:
                 $class = 'Joseki\\Migration\\Database\\Adapters\\SqlsrvAdapter';
                 break;
             default:
                 // fallback
                 $class = self::$defaultAdapter;
                 break;
         }
         $this->adapter = new $class($this->connection, $this->table);
     }
     return $this->adapter;
 }
Example #6
0
 /**
  * @param $name
  * @param $params
  */
 public function saveContent($name, $params)
 {
     $names = $this->decodeNames($name);
     $locale = isset($params->locale) ? $params->locale : '';
     $rowId = $this->connection->select('id')->from(self::TABLE)->where(['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale])->fetchSingle();
     $content = isset($params->content) ? $params->content : '';
     if ($rowId) {
         // update
         $this->connection->update(self::TABLE, ['content' => $content])->where(['id' => $rowId])->execute();
     } else {
         // new
         $this->connection->insert(self::TABLE, ['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale, 'content' => $content])->execute();
     }
     $this->findContentAndFillCache($names->namespace, '', '');
 }
Example #7
0
 public function escapeIdentifier($value)
 {
     return $this->conn->getDriver()->escapeIdentifier($value);
 }
Example #8
0
 public function log(AbstractMigration $migration, $timestamp)
 {
     $datetime = new \DateTime();
     $this->connection->insert($this->table, ['version' => $migration->getVersion(), 'executed' => $datetime->setTimestamp($timestamp)])->execute();
 }
Example #9
0
 /**
  * @return mixed
  */
 private function getPrimaryKey()
 {
     $primaryKey = $this->db->getDatabaseInfo()->getTable($this->tableName)->getPrimaryKey()->getColumns();
     return $primaryKey[0]->name;
 }
Example #10
0
 public function getMapData($xMax, $xMin, $yMax, $yMin)
 {
     return $this->database->select('*')->from($this->table)->where('x <= %i', $xMax)->where('x >= %i', $xMin)->where('y <= %i', $yMax)->where('y >= %i', $yMin)->fetchAll();
 }