本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::createQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::createQuery方法的具体用法?PHP EntityManagerInterface::createQuery怎么用?PHP EntityManagerInterface::createQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::createQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testImportExport
/**
* @medium
*/
public function testImportExport()
{
$sourceStorage = new LocalFileStorage(new \SplFileInfo(__DIR__ . '/../../../metadata/testfiles/100.csv'), new CsvFormat());
$targetStorage = new DoctrineStorage(self::$em, 'TestEntities\\Address');
$this->assertEquals(new StorageInfo(['name' => 'SELECT o FROM TestEntities\\Address o', 'count' => 0, 'type' => 'DQL Query']), $targetStorage->info());
$importer = Importer::build($targetStorage);
$importConfiguration = new ImportConfiguration();
$importRun = $importConfiguration->toRun();
$import = Import::build($importer, $sourceStorage, $importRun);
$eventDispatcher = new EventDispatcher();
$importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
$importRunner->run($import);
$entities = self::$em->getRepository('TestEntities\\Address')->findAll();
//import worked
$this->assertEquals(100, count($entities));
$exportFile = '/tmp/doctrine_test.csv';
@unlink($exportFile);
$sourceStorage = new DoctrineStorage(self::$em, null, self::$em->createQuery("SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'"));
$this->assertEquals(new StorageInfo(['name' => "SELECT A FROM TestEntities\\Address A WHERE A.zip LIKE '2%'", 'count' => 10, 'type' => 'DQL Query']), $sourceStorage->info());
$targetStorage = new LocalFileStorage(new \SplFileInfo($exportFile), new CsvFormat());
$importer = Importer::build($targetStorage);
$importConfiguration = new ImportConfiguration();
$importRun = $importConfiguration->toRun();
$import = Import::build($importer, $sourceStorage, $importRun);
$eventDispatcher = new EventDispatcher();
$importRunner = new ImportRunner(new DefaultWorkflowFactory($eventDispatcher));
$importRunner->run($import);
$this->assertFileExists($exportFile);
$this->assertEquals(11, count(file($exportFile)));
//+header
$this->assertEquals(10, $import->getRun()->toArray()['statistics']['processed']);
}
示例2: startJobs
/**
* {@inheritdoc}
*/
public function startJobs(ProjectInterface $project)
{
$query = 'UPDATE Worldia\\Bundle\\TextmasterBundle\\Entity\\Job j ' . 'SET j.status = :status ' . 'WHERE j.projectId = :projectId ';
$q = $this->entityManager->createQuery($query)->setParameter('status', JobInterface::STATUS_STARTED)->setParameter('projectId', $project->getId());
$q->execute();
$this->entityManager->clear();
}
示例3: fillData
private function fillData()
{
self::$data = [];
$q = $this->entityManager->createQuery("select partial c.{id,name,value} from ItBlaster\\SingleConfigBundle\\Entity\\Config c");
$res = $q->execute(null, Query::HYDRATE_ARRAY);
foreach ($res as $k => $v) {
self::$data[$v['name']] = $v['value'];
}
}
示例4: it_performs_a_fulltext_query
public function it_performs_a_fulltext_query(EntityManagerInterface $entityManager, AbstractQuery $query, $result = [])
{
$entityManager->createQuery(Argument::any())->shouldBeCalled()->willReturn($query);
$query->setParameter(Argument::any(), Argument::any())->shouldBeCalled()->willReturn($query);
$query->getResult()->shouldBeCalled()->willReturn($result);
$this->query('black', $entityManager)->shouldBeArray();
}
示例5: uniqueNameExists
/**
* @param $fileName
* @return bool
*/
protected function uniqueNameExists($fileName, EntityManagerInterface $em)
{
$dql = "SELECT COUNT(image) FROM EDVFileBundle:EdImage AS image WHERE image.hashString = :name";
$query = $em->createQuery($dql)->setParameters(array('name' => $fileName));
$result = $query->getSingleScalarResult();
return $result > 0;
}
示例6: import
/**
* @param Supplier $supplier
* @param EntityManagerInterface $entityManager
* @return null
*/
public function import(Supplier $supplier, EntityManagerInterface $entityManager)
{
$params = array('input/webpage/url' => $this->url, '_user' => $this->importIoConfig['user_id'], '_apikey' => $this->importIoConfig['api_key']);
$result = $this->DataSource->query($this->importIoConfig['connectorGuid'], $params);
if ($result = json_decode($result)) {
// delete all supplier products
$entityManager->createQuery('DELETE ProductBundle:Product p WHERE p.supplier = :supplier')->setParameter('supplier', $supplier)->execute();
$this->createProducts($entityManager, $supplier, $result);
}
}
示例7: existsAnyShipmentOption
public function existsAnyShipmentOption()
{
$query = $this->entityManager->createQuery('SELECT 1 FROM ShoPHP\\Shipment\\ShipmentPersonalPoint');
$query->setMaxResults(1);
if (count($query->getResult()) > 0) {
return true;
}
$query = $this->entityManager->createQuery('SELECT 1 FROM ShoPHP\\Shipment\\ShipmentCollectionPoint');
$query->setMaxResults(1);
if (count($query->getResult()) > 0) {
return true;
}
$query = $this->entityManager->createQuery('SELECT 1 FROM ShoPHP\\Shipment\\ShipmentTransportCompany');
$query->setMaxResults(1);
if (count($query->getResult()) > 0) {
return true;
}
return false;
}
示例8: clearDb
protected function clearDb()
{
// We can't rely on FK delete cascade as long as we're using sqlite for
// tests. Doctrine doesn't enable FK support for it.
$this->em->createQuery('delete from common\\entities\\Outpost')->execute();
$this->em->createQuery('delete from common\\entities\\CelestialBody')->execute();
$this->em->createQuery('delete from common\\entities\\System')->execute();
$this->em->createQuery('delete from common\\entities\\Galaxy')->execute();
$this->em->createQuery('delete from common\\entities\\CelestialBodyTypeSpecs')->execute();
$this->em->createQuery('delete from common\\entities\\Universe')->execute();
$this->em->createQuery('delete from common\\entities\\User')->execute();
$this->em->flush();
}
示例9: getQuery
/**
* Constructs a Query instance from the current specifications of the builder.
*
* <code>
* $qb = $em->createQueryBuilder()
* ->select('u')
* ->from('User', 'u');
* $q = $qb->getQuery();
* $results = $q->execute();
* </code>
*
* @return Query
*/
public function getQuery()
{
$parameters = clone $this->parameters;
$query = $this->_em->createQuery($this->getDQL())->setParameters($parameters)->setFirstResult($this->_firstResult)->setMaxResults($this->_maxResults);
if ($this->lifetime) {
$query->setLifetime($this->lifetime);
}
if ($this->cacheMode) {
$query->setCacheMode($this->cacheMode);
}
if ($this->cacheable) {
$query->setCacheable($this->cacheable);
}
if ($this->cacheRegion) {
$query->setCacheRegion($this->cacheRegion);
}
return $query;
}
示例10: getAll
/**
* @return Order[]|\Traversable
*/
public function getAll($limit, $offset)
{
$query = $this->entityManager->createQuery(sprintf('SELECT o FROM %s o', Order::class));
$query->setFirstResult($offset)->setMaxResults($limit);
return new Paginator($query);
}
示例11: __invoke
public function __invoke()
{
$query = $this->em->createQuery('SELECT b.title, COUNT(a) as authorsCount FROM AppBundle:Book b LEFT JOIN AppBundle:Author a WITH b MEMBER OF a.books');
return $query->getResult();
}
示例12: createQuery
/**
* {@inheritdoc}
*/
public function createQuery($dql = '')
{
return $this->wrapped->createQuery($dql);
}
示例13: queryEntity
private function queryEntity(EntityManagerInterface $em, $label)
{
$times = 100;
$size = 500;
$startPersist = microtime(true);
echo PHP_EOL . $label;
for ($i = 0; $i < $size; $i++) {
$em->persist(new Country("Country {$i}"));
}
$em->flush();
$em->clear();
printf("\n[%s] persist %s countries", number_format(microtime(true) - $startPersist, 6), $size);
$dql = 'SELECT c FROM Doctrine\\Tests\\Models\\Cache\\Country c WHERE c.name LIKE :name';
$startFind = microtime(true);
for ($i = 0; $i < $times; $i++) {
$em->createQuery($dql)->setParameter('name', "%Country%")->setCacheable(true)->getResult();
}
printf("\n[%s] select %s countries (%s times)", number_format(microtime(true) - $startFind, 6), $size, $times);
printf("\n%s\n", str_repeat('-', 50));
}
示例14: count
/**
* @return Integer
*/
public function count()
{
return $this->entityManager->createQuery("SELECT COUNT('e') FROM " . $this->getEntity() . " e")->getSingleScalarResult();
}
示例15: getResultsCount
/**
* Gets total results count.
*
* @param array $query
*
* @return int
*/
private function getResultsCount($query)
{
$queryObject = $this->entityManager->createQuery(str_replace('SELECT ' . $this->select, 'SELECT COUNT(p.id) cnt', $query['query']));
$queryObject->setParameters($query['parameters']);
return $queryObject->getSingleScalarResult();
}