mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 15:06:06 +00:00
find by query sth
This commit is contained in:
@@ -33,6 +33,7 @@ use \Espo\Core\Exceptions\Error;
|
||||
|
||||
class EntityManager
|
||||
{
|
||||
const STH_COLLECTION = 'sthCollection';
|
||||
|
||||
protected $pdo;
|
||||
|
||||
|
||||
@@ -227,11 +227,17 @@ class RDB extends \Espo\ORM\Repository
|
||||
return null;
|
||||
}
|
||||
|
||||
public function findByQuery($sql)
|
||||
public function findByQuery(string $sql, ?string $collectionType = null)
|
||||
{
|
||||
$dataArr = $this->getMapper()->selectByQuery($this->seed, $sql);
|
||||
|
||||
$collection = new EntityCollection($dataArr, $this->entityType, $this->entityFactory);
|
||||
if (!$collectionType) {
|
||||
$collection = new EntityCollection($dataArr, $this->entityType, $this->entityFactory);
|
||||
} else if ($collectionType === \Espo\ORM\EntityManager::STH_COLLECTION) {
|
||||
$collection = $this->getEntityManager()->createSthCollection($this->entityType);
|
||||
$collection->setQuery($sql);
|
||||
}
|
||||
|
||||
$this->reset();
|
||||
|
||||
return $collection;
|
||||
|
||||
@@ -39,6 +39,8 @@ class SthCollection implements \IteratorAggregate
|
||||
|
||||
private $sth = null;
|
||||
|
||||
private $sql = null;
|
||||
|
||||
public function __construct(string $entityType, EntityManager $entityManager = null, array $selectParams = [])
|
||||
{
|
||||
$this->selectParams = $selectParams;
|
||||
@@ -51,9 +53,18 @@ class SthCollection implements \IteratorAggregate
|
||||
$this->selectParams = $selectParams;
|
||||
}
|
||||
|
||||
public function setQuery(?string $sql)
|
||||
{
|
||||
$this->sql = $sql;
|
||||
}
|
||||
|
||||
public function executeQuery()
|
||||
{
|
||||
$sql = $this->entityManager->getQuery()->createSelectQuery($this->entityType, $this->selectParams);
|
||||
if ($this->sql) {
|
||||
$sql = $this->sql;
|
||||
} else {
|
||||
$sql = $this->entityManager->getQuery()->createSelectQuery($this->entityType, $this->selectParams);
|
||||
}
|
||||
$sth = $this->entityManager->getPdo()->prepare($sql);
|
||||
$sth->execute();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user