【发布时间】:2016-12-14 11:26:00
【问题描述】:
我非常需要 GDS 和 PHP-GDS 库方面的帮助。
我正在使用出色的 php-gds 库从外部 google appengine 进行获取。到目前为止,图书馆工作正常。
我的问题是我从 GDS 获取的数据返回不一致的结果,我不知道问题可能是什么。
请看下面的代码:
<?php
//...
//...
$offset = 0;
do{
$query = "SELECT * FROM `KIND` order by _URI ASC limit 300 offset ".$offset;
$tableList=[];
$tableList = $this->obj_store->fetchAll($query);
$offset += count($tableList);
$allTables[] = $tableList;
$totalRecords = $offset;
}while(!empty($tableList));
echo $totalRecords; // i expect total records to be equal to the number of entities in the KIND.
// but the results are inconsistent. In some cases, it is correct
// but in most cases it is far less than the total records.
// I could have a KIND with 750 entities and only 721 will be returned in total.
// I could have a KIND with 900 entities and all entities will be returned.
// I could have a KIND with 4000 entities and only 1200 will be returned.
?>
请帮忙。此外,当我在云控制台中运行完全相同的查询时,我得到了正确的实体计数。 (希望这对某人有帮助)
更新
我最终使用了游标。新代码如下:
<?php
$query = "SELECT * FROM `KIND`";
$tableList=[];
$queryInit = $this->obj_store->query($query);
do{
$page = $this->obj_store->fetchPage(300);// fetch page.
$tableList = am($tableList,$page); //merge with existing records.
$this->obj_store->setCursor($this->obj_store->getCursor());//set next cursor to previous last cursor
}while(!empty($page)); //as long as page result is not empty.
?>
【问题讨论】:
-
如果您查询的部分/全部实体是最近创建的,那么由于最终的一致性,这是预期的行为:cloud.google.com/datastore/docs/articles/…
-
感谢 Dan,但在我查询的 KIND 中实际上没有最近创建的实体。我会继续寻找。
标签: php google-app-engine google-cloud-storage google-cloud-datastore