Пример #1
0
 /**
  * Returns a merge/upsert (i.e. insert or update) SQL query when supported by the database.
  *
  * @return string|null The SQL string or null when not supported
  */
 protected function getMergeSql()
 {
     $platform = $this->connection->getDatabasePlatform();
     if ($platform instanceof MySqlPlatform) {
         return "INSERT INTO {$this->table} (id, data, time) VALUES (:id, :data, :time) " . "ON DUPLICATE KEY UPDATE data = VALUES(data), time = CASE WHEN time = :time THEN (VALUES(time) + INTERVAL 1 SECOND) ELSE VALUES(time) END";
     } elseif ($platform instanceof SqlitePlatform) {
         return "INSERT OR REPLACE INTO {$this->table} (id, data, time) VALUES (:id, :data, :time)";
     }
 }
Пример #2
0
 /**
  * Deletes an entity.
  *
  * @param  object $entity
  * @throws \InvalidArgumentException
  */
 public function delete($entity)
 {
     $metadata = $this->getMetadata($entity);
     $identifier = $metadata->getIdentifier(true);
     if ($value = $metadata->getValue($entity, $identifier, true)) {
         $this->trigger(Events::DELETING, $metadata, [$entity]);
         $this->connection->delete($metadata->getTable(), [$identifier => $value]);
         $this->trigger(Events::DELETED, $metadata, [$entity]);
         $metadata->setValue($entity, $identifier, null, true);
     } else {
         throw new \InvalidArgumentException("Can't remove entity with empty identifier value.");
     }
 }
Пример #3
0
 /**
  * @deprecated to be removed in Pagekit 1.0
  */
 protected function createTable()
 {
     $util = $this->connection->getUtility();
     if ($util->tableExists($this->config['table']) === false) {
         $util->createTable($this->config['table'], function ($table) {
             $table->addColumn('id', 'string', ['length' => 255]);
             $table->addColumn('user_id', 'integer', ['unsigned' => true, 'length' => 10, 'default' => 0]);
             $table->addColumn('access', 'datetime', ['notnull' => false]);
             $table->addColumn('status', 'smallint');
             $table->addColumn('data', 'json_array', ['notnull' => false]);
             $table->setPrimaryKey(['id']);
         });
     }
 }
Пример #4
0
 /**
  * Creates the "select" SQL string from the query parts.
  *
  * @return string
  */
 protected function getSQLForSelect()
 {
     extract($this->parts);
     $query = sprintf('SELECT %s FROM ' . $from, $select ? implode(', ', $select) : '*');
     foreach ($join as $j) {
         $query .= sprintf(' %s JOIN %s ON %s', strtoupper($j['type']), $j['table'], (string) $j['condition']);
     }
     if ($where) {
         $query .= ' WHERE ' . $where;
     }
     if ($group) {
         $query .= ' GROUP BY ' . implode(', ', $group);
     }
     if ($having) {
         $query .= ' HAVING ' . $having;
     }
     if ($order) {
         $query .= ' ORDER BY ' . implode(', ', $order);
     }
     return $limit === null && $offset === null ? $query : $this->connection->getDatabasePlatform()->modifyLimitQuery($query, $limit, $offset);
 }
Пример #5
0
 /**
  * Replaces the table prefix placeholder with actual one.
  *
  * @param  string $query
  * @return string
  */
 protected function replacePrefix($query)
 {
     return $this->connection->replacePrefix($query);
 }
 /**
  * {@inheritdoc}
  */
 public function collect()
 {
     $driver = $this->connection->getDriver()->getName();
     return array_replace(compact('driver'), parent::collect());
 }