本文整理汇总了PHP中Doctrine\DBAL\Query\QueryBuilder::select方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::select方法的具体用法?PHP QueryBuilder::select怎么用?PHP QueryBuilder::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Query\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBeforeGetList
/**
* @dataProvider beforeGetListHarness
*/
public function testBeforeGetList($query, $expectedQuery, $expectedParams)
{
$this->queryBuilder->select('o.*')->from('posts', 'o');
$request = new Request($query);
$queryBuilder = $this->postDecorator->beforeGetList($this->queryBuilder, $request);
$this->assertEquals($expectedQuery, (string) $queryBuilder);
$this->assertEquals($expectedParams, $queryBuilder->getParameters());
}
示例2: setUp
protected function setUp()
{
if ($this->isDoctrineDbalNotAvailable()) {
$this->markTestSkipped('Doctrine DBAL is not available');
}
$conn = $this->getConnection();
$this->createSchema($conn);
$this->insertData($conn);
$this->qb = new QueryBuilder($conn);
$this->qb->select('p.*')->from('posts', 'p');
}
示例3: testPaginationWithDoctrineDbalAdapter
public function testPaginationWithDoctrineDbalAdapter()
{
$cqb = clone $this->qb;
$records = $this->qb->select('*')->from('sample', 'sample');
$cqb->select('*')->from('sample', 'sample')->setMaxResults(20)->setFirstResult(60);
$expected = $cqb->execute()->fetchAll();
/*var_dump($this->qb->execute()->fetchAll());
exit;*/
$paginatorClass = new Paginator();
$paginator = $paginatorClass->page(4)->perPage(20)->make($records);
$this->assertEquals(90, $paginator->total(), 'Failed asserting pagination total.');
$this->assertEquals($expected, $paginator->records(), 'Failed asserting pagination records.');
}
示例4: __construct
/**
* @param QueryBuilder $qb
* @param callable|null $countQueryBuilderModifier
*/
public function __construct(QueryBuilder $qb, callable $countQueryBuilderModifier = null)
{
$this->qb = $qb;
$this->countQueryBuilderModifier = $countQueryBuilderModifier ?: function (QueryBuilder $qb) {
return $qb->select('COUNT(*)');
};
}
示例5: selectDoesNotQuoteStarPlaceholder
/**
* @test
*/
public function selectDoesNotQuoteStarPlaceholder()
{
$this->connection->quoteIdentifier('aField')->shouldBeCalled()->willReturnArgument(0);
$this->connection->quoteIdentifier('*')->shouldNotBeCalled();
$this->concreteQueryBuilder->select(Argument::exact('aField'), Argument::exact('*'))->shouldBeCalled()->willReturn($this->subject);
$this->subject->select('aField', '*');
}
示例6: getFilteredCountQuery
/**
* Build the count of filtered query
*
* @return QueryBuilder
*/
public function getFilteredCountQuery()
{
$this->buildFilteredQuery();
$this->currentQueryBuilder->select('COUNT(DISTINCT ' . $this->getDistinct() . ')');
$this->currentQueryBuilder->resetQueryPart('orderBy');
return $this->currentQueryBuilder;
}
示例7: testSetQueryBuilder02
public function testSetQueryBuilder02()
{
$contain = $this->testConstruct02();
$queryBuilder = new QueryBuilder($this->getConnection());
$queryBuilder->select('*')->from('table', 't');
$contain->setQueryBuilder($queryBuilder);
return $contain;
}
示例8: getDataProvider
protected function getDataProvider()
{
if (!$this->provider) {
$builder = new QueryBuilder(Connection::get());
$builder->select('*')->from('test_users');
$this->provider = new DoctrineDataProvider($builder);
}
return $this->provider;
}
示例9: testItShouldWorksWithParametersInTheOrX
public function testItShouldWorksWithParametersInTheOrX()
{
$qb = new QueryBuilder($this->connection);
$qb->select('p.id')->from('posts', 'p')->setParameter('status', 'odd');
$aclFilter = new DoctrineDbalAclFilter($qb);
$aclFilter->setAclSchema($this->aclSchema);
$aclFilter->apply('p', 'id', 'post-', ['user-1'], 1, ['status = :status']);
$this->assertEquals(['status' => 'odd', 'acl_prefix' => 'post-', 'acl_identifiers' => ['user-1'], 'acl_mask' => 1], $qb->getParameters());
}
示例10: loadUserByUsername
/**
* Load user by username
*
* @param string $username
* @return User
* @throws \Exception
*/
public function loadUserByUsername($username)
{
$qb = new QueryBuilder($this->db);
$stmt = $qb->select('username, password, roles')->from('users', 'u')->where('u.username = :username')->andWhere('u.active = 1')->setParameter('username', $username)->execute();
if (!($user = $stmt->fetchObject())) {
throw new \Exception(sprintf('User "%s" not found.', $username));
}
return new User($user->username, $user->password, explode(',', $user->roles), true, true, true, true);
}
示例11: setUp
public function setUp()
{
$builder = new QueryBuilder(Connection::get());
$builder->select('*')->from('test_users');
$this->data = $builder->execute()->fetchAll(\PDO::FETCH_OBJ);
$this->operations = new OperationCollection();
$this->service = new DoctrineProcessingService(new DoctrineProcessorResolver(), $this->operations, $builder);
$this->totalCount = (new QueryBuilder(Connection::get()))->select('count(*)')->from('test_users')->execute()->fetchColumn();
self::assertTrue($this->totalCount > 0);
}
示例12: loadRoles
/**
* Load roles at RBAC creation.
*
* @param Event $e
* @return array
*/
public function loadRoles(Event $e)
{
$builder = new QueryBuilder($this->connection);
$options = $this->options;
$builder->select("role.{$options->getNameColumn()} AS name, parent.{$options->getNameColumn()} AS parent")->from($options->getTable(), 'role')->leftJoin('role', $options->getTable(), 'parent', "role.{$options->getJoinColumn()} = parent.{$options->getIdColumn()}");
$result = $builder->execute();
$roles = array();
foreach ($result as $row) {
$parentName = isset($row['parent']) ? $row['parent'] : 0;
unset($row['parent']);
$roles[$parentName][] = $row['name'];
}
$this->recursiveRoles($e->getRbac(), $roles);
}
示例13: shouldPaginateSimpleDoctrineQuery
/**
* @test
*/
function shouldPaginateSimpleDoctrineQuery()
{
$this->populate();
$p = new Paginator();
$qb = new QueryBuilder($this->em->getConnection());
$qb->select('*')->from('Article', 'a');
$view = $p->paginate($qb, 1, 2);
$this->assertEquals(1, $view->getCurrentPageNumber());
$this->assertEquals(2, $view->getItemNumberPerPage());
$this->assertEquals(4, $view->getTotalItemCount());
$items = $view->getItems();
$this->assertEquals(2, count($items));
$this->assertEquals('summer', $items[0]['title']);
$this->assertEquals('winter', $items[1]['title']);
}
示例14: _build
/**
* 初始化数据构造器
*
* @param int $type 要执行的SQL类型
* @return $this
*/
protected function _build($type)
{
switch ($type) {
case Db::SELECT:
$this->_dbBuilder = $this->_db->createQueryBuilder()->select();
break;
case Db::UPDATE:
$this->_dbBuilder = $this->_db->createQueryBuilder()->update($this->_tableName, $this->_objectName);
break;
case Db::DELETE:
$this->_dbBuilder = $this->_db->createQueryBuilder()->delete($this->_tableName);
}
$selectList = [];
foreach ($this->_dbPending as $method) {
$name = $method['name'];
$args = $method['args'];
// 如果是select,那么暂时先不执行
if ($name == 'select') {
$selectList = Arr::merge($selectList, $args);
continue;
}
$this->_dbApplied[$name] = $name;
call_user_func_array([$this->_dbBuilder, $name], $args);
}
$this->_dbBuilder->select($selectList);
return $this;
}
示例15: testCreatePositionalParameter
public function testCreatePositionalParameter()
{
$qb = new QueryBuilder($this->conn);
$qb->select('u.*')->from('users', 'u')->where($qb->expr()->eq('u.name', $qb->createPositionalParameter(10, \PDO::PARAM_INT)));
$this->assertEquals('SELECT u.* FROM users u WHERE u.name = ?', (string) $qb);
$this->assertEquals(10, $qb->getParameter(1));
}