protected function preQuery(Query &$query) { $scriptNameNode = new EqNode('scriptName', $this->scriptName); if ($query->getQuery()) { $query->setQuery(new AndNode([$scriptNameNode, $query->getQuery()])); } else { $query->setQuery($scriptNameNode); } }
public function setUp() { $this->queryObject = new Query(); $this->queryObject->setQuery(new AndNode([new AndNode([new EqNode('q', null), new NeNode('q', null), new LeNode('q', 'r'), new GeNode('q', 'u')]), new OrNode([new LtNode('q', 't'), new GtNode('q', 'y'), new InNode('q', ['a', 's', 'd', 'f', 'g'])])])); $this->queryObject->setSelect(new XSelectNode(['q', new AggregateFunctionNode('max', 'q'), new AggregateFunctionNode('min', 'q'), new AggregateFunctionNode('count', 'q')])); $this->queryObject->setSort(new SortNode(['q' => -1, 'w' => 1, 'e' => 1])); $this->queryObject->setLimit(new LimitNode(20, 30)); $this->rqlString = "and(and(eq(q,null()),ne(q,null()),le(q,r),ge(q,u)),or(lt(q,t),gt(q,y),in(q,(a,s,d,f,g))))"; $this->rqlString .= "&limit(20,30)"; $this->rqlString .= "&sort(-q,+w,e)"; $this->rqlString .= "&select(q,max(q),min(q),count(q))"; }
/** * @param AbstractQueryNode $query * @return $this */ public function addQuery(AbstractQueryNode $query) { $current = $this->query->getQuery(); if ($current === null) { $this->query->setQuery($query); } elseif ($current instanceof AndNode) { $current->addQuery($query); } else { $this->query->setQuery(new AndNode([$current, $query])); } return $this; }
/** * {@inheritdoc} * * {@inheritdoc} */ public function query(Query $query) { $selectSQL = $this->dbTable->getSql()->select(); $selectSQL = $this->setSelectColumns($selectSQL, $query); $fields = $selectSQL->getRawState(Select::COLUMNS); $props = []; if (isset($fields['props'])) { $props = $fields['props']; unset($fields['props']); $selectSQL->columns($fields); } $sql = $this->getSqlQuery($query); /** @var Adapter $adapter */ $adapter = $this->dbTable->getAdapter(); $rowSet = $adapter->query($sql, $adapter::QUERY_MODE_EXECUTE); $data = $rowSet->toArray(); if (!empty($props)) { foreach ($data as &$item) { /** @var $prop Prop */ foreach ($props as $key => $prop) { $linkedColumn = $prop->getLinkedColumn($this->getEntityName(), $key); $propQuery = new Query(); $propQuery->setQuery(new EqNode($linkedColumn, $item[$this->getIdentifier()])); $propData = $prop->query($propQuery); $item[$key] = $propData; } } } return $data; }
/** * Hop callback which called from Ticker * * @param $hopId * @param $ttl */ public function processHop($hopId, $ttl) { /** * One more reads active filters from DataStore and further use it ever tick */ $query = new Query(); $query->setQuery(new ScalarOperator\EqNode('active', 1)); $this->filters = $this->dataStore->query($query); }
public function getAll() { if ($this->notificationType === null) { throw new \Exception("Not set notification Type"); } $query = new Query(); $query->setQuery(new EqNode(AllNotificationDataStoreFactory::KEY_EBAY_NOTIFICATION_TYPE, $this->notificationType)); return $this->dataByType($this->dataStore->query($query)); }
public function test_updateTaskSchedule() { $this->_initTask(); $seconds = []; $currentTime = date('i'); for ($i = 0; $i < 2; $i++) { $seconds[] = new EqNode('minutes', $currentTime + $i); } $query = new Query(); $query->setQuery(new OrNode($seconds)); $this->task->setSchedule($query); $this->assertEquals('ky', $this->task->activate(UTCTime::getUTCTimestamp(0), 1)); }
public function provider_query() { $emptyQuery = new Query(); $queryWithAndNode = new Query(); $queryWithAndNode->setQuery(new AndNode([new LtNode('price', 23), new NeNode('icon', 'icon1.jpg')])); $queryWithSelect = new Query(); $queryWithSelect->setSelect(new SelectNode(['price', 'icon'])); $queryWithSort = new Query(); $queryWithSort->setSort(new SortNode(['price' => -1, 'icon' => +1])); $queryWithSelectProps = new Query(); $queryWithSelectProps->setSelect(new SelectNode([StoreCatalog::PROP_LINKED_URL_TABLE_NAME])); return array(array($emptyQuery, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg']), array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg'])), array($queryWithAndNode, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg']), array(['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'])), array($queryWithSelect, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon3.jpg']), array(['price' => '21', 'icon' => 'icon1.jpg'], ['price' => '22', 'icon' => 'icon2.jpg'], ['price' => '23', 'icon' => 'icon3.jpg'])), array($queryWithSort, array(['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon6.jpg'], ['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '22', 'icon' => 'icon3.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon5.jpg']), array(['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon5.jpg'], ['title' => 'Plate43-mainicon', 'price' => '23', 'icon' => 'icon6.jpg'], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg'], ['title' => 'Plate43-mainicon', 'price' => '22', 'icon' => 'icon3.jpg'], ['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg'])), array($queryWithSelectProps, array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com', 'alt' => 'Pot1'], ['url' => 'http://google.com1', 'alt' => 'Pot2']]], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com2', 'alt' => 'Pot3'], ['url' => 'http://google.com3', 'alt' => 'Pot4']]]), array(['title' => 'Plate41-mainicon', 'price' => '21', 'icon' => 'icon1.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com', 'alt' => 'Pot1'], ['url' => 'http://google.com1', 'alt' => 'Pot2']]], ['title' => 'Plate42-mainicon', 'price' => '22', 'icon' => 'icon2.jpg', StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com2', 'alt' => 'Pot3'], ['url' => 'http://google.com3', 'alt' => 'Pot4']]]))); }
/** * {@inheritdoc} * * {@inheritdoc} */ public function read($id) { $identifier = $this->getIdentifier(); $this->checkIdentifierType($id); $query = new Query(); $eqNode = new EqNode($identifier, $id); $query->setQuery($eqNode); $queryResult = $this->query($query); if (empty($queryResult)) { return null; } else { return $queryResult[0]; } }
public function canCreate(ContainerInterface $container, $requestedName) { if ($requestedName === self::KEY_CACHEABLE_NOTIFICATION_TYPE) { $this::$flag = true; return true; } else { /** @var DataStoresInterface $allNotification */ $allNotification = $container->get($this::KEY_ALL_NOTIFICATION); $query = new Query(); $query->setQuery(new EqNode(AllNotificationDataStoreFactory::KEY_EBAY_NOTIFICATION_TYPE, $requestedName)); $result = $allNotification->query($query); } return count($result) > 0; }
public function __construct(DataStoresInterface $cachingDbTable, $cdsId) { $this->cachingDbTable = $cachingDbTable; $query = new Query(); $query->setQuery(new EqNode($this->cdsIdentifierString, $cdsId)); $this->items = $this->cachingDbTable->query($query); foreach ($this->items as &$item) { $item[$this->cachingDbTable->getIdentifier()] = $item[$this->dataIdentifierString]; unset($item[$this->dataIdentifierString]); unset($item[$this->cdsIdentifierString]); $item = array_filter($item); foreach ($item as $key => $value) { switch ($key) { case in_array($key, $this->fieldType['int']): if (is_numeric($value)) { $item[$key] = (int) $value; } else { throw new \Exception('Can\'t parse to int value:' . $value . 'from field: ' . $key); } break; case in_array($key, $this->fieldType['float']): if (is_numeric($value)) { $item[$key] = (double) $value; } else { throw new \Exception('Can\'t parse to float value:' . $value . 'from field: ' . $key); } break; case in_array($key, $this->fieldType['string']): $item[$key] = (string) $value; break; default: throw new \Exception('Type not set for field: ' . $key); } } } parent::__construct(); }
/** * @param ServerRequestInterface $request * @param ResponseInterface $response * @return ResponseInterface * @throws \zaboy\rest\RestException * @internal param callable|null $next */ public function methodGetWithoutId(ServerRequestInterface $request, ResponseInterface $response) { /** @var Query $rqlQueryObject */ $rqlQueryObject = $request->getAttribute('Rql-Query-Object'); $rqlLimitNode = $rqlQueryObject->getLimit(); $headerLimit = $request->getAttribute('Limit'); if (!is_null($rqlLimitNode)) { if (isset($headerLimit)) { $limit = $rqlLimitNode->getLimit() > $headerLimit['limit'] ? $headerLimit['limit'] : $rqlLimitNode->getLimit(); if (isset($headerLimit['offset'])) { $offset = $headerLimit['offset']; $rqlOffset = $rqlLimitNode->getOffset(); if (!is_null($rqlOffset)) { $offset += $rqlOffset; } $newLimitNode = new LimitNode($limit, $offset); } else { $newLimitNode = new LimitNode($limit); } $rqlQueryObject->setLimit($newLimitNode); } } else { if ($headerLimit) { $limit = (int) $headerLimit['limit']; if (isset($headerLimit['offset'])) { $offset = (int) $headerLimit['offset']; $newLimitNode = new LimitNode($limit, $offset); } else { $newLimitNode = new LimitNode($limit); } $rqlQueryObject->setLimit($newLimitNode); } } $rowCountQuery = new Query(); $aggregate = new AggregateFunctionNode('count', $this->dataStore->getIdentifier()); $rowCountQuery->setSelect(new XSelectNode([$aggregate])); if ($rqlQueryObject->getQuery()) { $rowCountQuery->setQuery($rqlQueryObject->getQuery()); } if ($rqlLimitNode) { $rowCountQuery->setLimit($rqlLimitNode); } //TODO: count aggregate fn can't work with limit and offset. Bug!!! $rowset = $this->dataStore->query($rqlQueryObject); $this->request = $request->withAttribute('Response-Body', $rowset); $rowCountQuery = new Query(); $rowCountQuery->setSelect(new XSelectNode([new AggregateFunctionNode('count', $this->dataStore->getIdentifier())])); $rowCount = $this->dataStore->query($rowCountQuery); if (isset($rowCount[0][$this->dataStore->getIdentifier() . '->count'])) { //throw new RestException('Can not make Content-Range header in response'); $limitObject = $rqlQueryObject->getLimit(); $offset = !$limitObject ? 0 : $limitObject->getOffset(); $contentRange = 'items ' . $offset . '-' . ($offset + count($rowset) - 1) . '/' . $rowCount[0][$this->dataStore->getIdentifier() . '->count']; $response = $response->withHeader('Content-Range', $contentRange); } $response = $response->withStatus(200); return $response; }
public function testSelectAggregateFunction_Combo_True() { $this->_initObject(); $query = new Query(); $aggregateCount = new AggregateFunctionNode('count', 'id'); $aggregateMaxId = new AggregateFunctionNode('max', 'id'); $aggregateMinId = new AggregateFunctionNode('min', 'id'); $query->setLimit(new Node\LimitNode(2, 1)); $query->setQuery(new ScalarOperator\EqNode('fString', 'val2')); $query->setSelect(new XSelectNode([$aggregateCount, $aggregateMaxId, $aggregateMinId, "anotherId"])); $resp = $this->object->query($query); $this->assertEquals(1, count($resp)); $this->assertEquals(2, $resp[0]['id->count']); //$this->assertEquals(2, $resp[0]['count(id)']); $this->assertEquals(4, $resp[0]['id->max']); //$this->assertEquals(4, $resp[0]['max(id)']); $this->assertEquals(3, $resp[0]['id->min']); //$this->assertEquals(3, $resp[0]['min(id)']); $this->assertEquals(40, $resp[0]['anotherId']); //$this->assertEquals(40, $resp[0]['anotherId']); }
/** * * @see Iterator * @return array */ public function next() { $identifier = $this->dataStore->getIdentifier(); $query = new Query(); $selectNode = new Node\SelectNode([$identifier]); $query->setSelect($selectNode); $sortNode = new Node\SortNode([$identifier => 1]); $query->setSort($sortNode); $limitNode = new Node\LimitNode(1, 0); $query->setLimit($limitNode); $gtNode = new ScalarOperator\GtNode($identifier, $this->index); $query->setQuery($gtNode); $queryArray = $this->dataStore->query($query); $this->index = $queryArray === [] ? null : $queryArray[0][$identifier]; }
public function test_queryFilterTask() { /** @var \zaboy\scheduler\Scheduler\Scheduler $scheduler */ $scheduler = $this->container->get('scheduler'); $filterData = $scheduler->create(['rql' => 'eq(tp_seconds,0)', 'callback' => function () { return 'ky'; }, 'active' => 1]); $id = $filterData['id']; $query = new Query(); $query->setQuery(new EqNode('id', $id)); $items = $scheduler->query($query); $item = array_shift($items); $callback = $item['callback']; $this->assertEquals('ky', $callback()); }
/** * @dataProvider provider_Query_Where_Like_False */ public function testQuery_Where_Like_False($globString) { $this->_initObject(); $query = new Query(); $likeNode = new ScalarOperator\LikeNode('fString', new Glob($globString)); $query->setQuery($likeNode); $queryArray = $this->object->query($query); $this->assertEquals(0, count($queryArray)); }
protected function methodPatchWithId(Request $request, Response $response) { $cdsId = $request->getAttribute('Primary-Key-Value'); $cdsConf = $this->getCdsConf($cdsId); if (empty($cdsConf)) { throw new \Exception("this cds id not found"); } if ($cdsConf['query'] !== '') { $query = RqlParser::rqlDecode($cdsConf['query']); } else { $query = new Query(); } $data = $this->getData($cdsConf['script_name'], $query); $query = new Query(); $query->setQuery(new EqNode('cds_id', $cdsId)); $items = $this->cds->query($query); foreach ($items as $item) { $this->cds->delete($item['id']); } foreach ($data as &$item) { $item['cds_id'] = $cdsId; $item['data_id'] = $item['id']; unset($item['id']); } $this->cds->create($data); $this->cdsManagerStore->update(['id' => $cdsConf['id'], 'freshness_date' => (new \DateTime())->format("Y-m-d H:i:s")]); $request = $request->withAttribute('CDS-ID', $cdsId); $request = $request->withAttribute('Response-Body', ['cdsId' => $cdsId]); $response = $response->withStatus(200); return array($request, $response); }
protected function addTickLimit(Query $query, $timeStart, $step) { $field = $step < 1 ? 'id' : 'timestamp'; $andNode = new LogicOperator\AndNode([$query->getQuery(), new ScalarOperator\GeNode($field, $timeStart), new ScalarOperator\LtNode($field, $timeStart + $step)]); $query->setQuery($andNode); return $query; }
public function test__update_nested_rollback() { $this->__init(); $data = $this->object->create(['title' => 'title_1', 'price' => 100, StoreCatalog::PROP_LINKED_URL_TABLE_NAME => [['url' => 'http://google.com', 'alt' => 'Pot1'], ['url' => 'http://google.com2', 'alt' => 'Pot3']]]); $data[StoreCatalog::PROP_LINKED_URL_TABLE_NAME] = ['url' => 'http://google.com3', 'alt' => 'Pot4', 'ttt' => 'asd']; $data[StoreCatalog::PROP_LINKED_URL_TABLE_NAME] = ['url' => 'http://google.com-1', 'alt' => 'Pot1-1']; try { $this->object->update($data); } catch (DataStoreException $e) { $query = new Query(); $query->setQuery(new AndNode([new EqNode('url', 'http://google.com-1'), new EqNode('alt', 'Pot1-1')])); $prop = new Prop(new TableGateway(StoreCatalog::PROP_LINKED_URL_TABLE_NAME, $this->container->get('db'))); $result = $prop->query($query); $this->assertEquals(0, count($result)); return; } $this->fail("An expected exception has not been raised."); }
public function test_QueryEq() { $this->_initObject(); $query = new Query(); $eqNode = new ScalarOperator\EqNode('fString', 'val1'); $query->setQuery($eqNode); $this->assertEquals($this->_itemsArrayDelault[0], $this->object->query($query)[0]); }