本文整理汇总了PHP中Nette\Database\Context::queryArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::queryArgs方法的具体用法?PHP Context::queryArgs怎么用?PHP Context::queryArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Context
的用法示例。
在下文中一共展示了Context::queryArgs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
protected function fetch(SqlBuilder $builder, $hasJoin, array $values)
{
$primaryKey = $this->targetRepository->getMapper()->getStorageReflection()->getStoragePrimaryKey()[0];
$builder->addWhere($primaryKey, $values);
$builder->addSelect(($hasJoin ? 'DISTINCT ' : '') . $builder->getTableName() . '.*');
$result = $this->context->queryArgs($builder->buildSelectQuery(), $builder->getParameters());
$entities = [];
while ($data = $result->fetch()) {
$entity = $this->targetRepository->hydrateEntity((array) $data);
$entities[$entity->id] = $entity;
}
return new EntityContainer($entities);
}
示例2: getTimeData
/**
* Spusti vytvoreny SQL dotaz se zadanymi parametry
*
* @param string[] $par_where Pole filtru zadane uzivatelem.
* @param string[] $par_order Pole s tridicimi kriterii zadane uzivatelem.
* @param string[] $columns Pole pozadovanych sloupců.
* @param string[] $table Nazev tabulky.
* @param string[] $limit Maximalni velikost vysledku dotazu.
*
* @return array Vybrane radky z tabulky
* @return NULL Nebyly zvoleny vyberova ani tridici kriteria
*/
public function getTimeData($par_where, $par_order, $columns, $table, $limit)
{
$this->par_where = $par_where;
$this->par_order = $par_order;
$this->columns = $columns;
$this->table = $table;
$this->limit = $limit;
if (count($this->par_where, COUNT_RECURSIVE) > 1) {
$this->where = "sm_time.id_event = sm_event.id AND sm_time.id_swimmer = sm_swimmer.id AND ";
}
$this->createSelect();
$this->createWhere();
$this->createOrderBy();
$this->createParVal();
$this->createCommand();
//nebyly zvoleny vyberova ani tridici kriteria
if ($this->select === NULL) {
return NULL;
}
if (count($this->par_where, COUNT_RECURSIVE) <= 1) {
$this->select = substr_replace($this->select, " WHERE sm_time.id_event = sm_event.id AND sm_time.id_swimmer = sm_swimmer.id ", strpos($this->select, "ORDER") - 1, 0);
}
if ($this->limit !== NULL) {
$this->select = $this->select . " LIMIT " . $this->limit;
}
$data = $this->database->queryArgs($this->select, $this->parval);
$this->select = "SELECT\n";
$this->where = "";
$this->order = "";
$this->table = "";
return $data;
}
示例3: remove
public function remove(IEntity $parent, array $remove)
{
$this->mapperOne->beginTransaction();
$list = $this->buildList($parent, $remove);
$builder = new SqlBuilder($this->joinTable, $this->context);
$builder->addWhere(array_keys(reset($list)), $list);
$this->context->queryArgs($builder->buildDeleteQuery(), $builder->getParameters());
}
示例4: execute
protected function execute()
{
$builder = clone $this->builder;
$builder->addSelect(($this->distinct ? 'DISTINCT ' : '') . $builder->getTableName() . '.*');
$result = $this->context->queryArgs($builder->buildSelectQuery(), $builder->getParameters());
$this->result = [];
while ($data = $result->fetch()) {
$this->result[] = $this->repository->hydrateEntity((array) $data);
}
}
示例5: update
/**
* Updates all rows in result set.
* Joins in UPDATE are supported only in MySQL
* @param array|\Traversable ($column => $value)
* @return int number of affected rows
*/
public function update($data)
{
if ($data instanceof \Traversable) {
$data = iterator_to_array($data);
} elseif (!is_array($data)) {
throw new Nette\InvalidArgumentException();
}
if (!$data) {
return 0;
}
return $this->context->queryArgs($this->sqlBuilder->buildUpdateQuery(), array_merge(array($data), $this->sqlBuilder->getParameters()))->getRowCount();
}
示例6: createOrUpdate
/**
* Insert row in database or update existing one.
*
* @param array
* @return \Nette\Database\Table\ActiveRow automatically found based on first "column => value" pair in $values
*/
public function createOrUpdate(array $values)
{
$pairs = array();
foreach ($values as $key => $value) {
$pairs[] = "`{$key}` = ?";
// warning: SQL injection possible if $values infected!
}
$pairs = implode(', ', $pairs);
$values = array_values($values);
$this->db->queryArgs('INSERT INTO `' . $this->tableName . '` SET ' . $pairs . ' ON DUPLICATE KEY UPDATE ' . $pairs, array_merge($values, $values));
return $this->findOneBy(func_get_arg(0));
}
示例7: setUpdateAsDone
/**
* Mark given file as done in database updates table.
* @param string $filename
* @throws \Exception
*/
private function setUpdateAsDone($filename)
{
if (!$this->isUpdateTableCreated($this->db, $this->dbUpdateTable)) {
$this->createUpdateTable();
}
$matches = array();
if (!preg_match("/(\\d{4}-\\d{2}-\\d{2})_(\\d{2}-\\d{2}-\\d{2})/", $filename, $matches)) {
throw new \Exception("Filename '{$filename}' is not in valid format.");
}
list(, $date, $time) = $matches;
$this->db->queryArgs("REPLACE INTO `{$this->dbUpdateTable}` (created_at) VALUES (?)", array($date . " " . strtr($time, "-", ":")));
}
示例8: fetchCounts
private function fetchCounts(SqlBuilder $builder, array $values)
{
$targetStoragePrimaryKey = $this->targetMapper->getStorageReflection()->getStoragePrimaryKey()[0];
$builder = clone $builder;
$table = $builder->getTableName();
$builder->addSelect("{$table}.{$this->joinStorageKey}");
$builder->addSelect("COUNT({$table}.{$targetStoragePrimaryKey}) AS count");
$builder->addWhere("{$table}.{$this->joinStorageKey}", $values);
$builder->setGroup("{$table}.{$this->joinStorageKey}");
$builder->setOrder([], []);
$result = $this->context->queryArgs($builder->buildSelectQuery(), $builder->getParameters());
$counts = [];
foreach ($result->fetchAll() as $row) {
$counts[$row->{$this->joinStorageKey}] = $row['count'];
}
return $counts;
}