Google 数据存储从 select 获取的结果不一致
Google data store inconsistent result fetch from select
我非常需要 GDS 和 PHP-GDS 库方面的帮助。
我正在使用出色的 php-gds 库从 google appengine 外部获取数据。到目前为止,图书馆工作正常。
我的问题是我从 GDS 获取的数据 returns 不一致的结果,我不知道可能是什么问题。
请看下面的代码:
<?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.
?>
请帮忙。此外,当我 运行 在云控制台中执行完全相同的查询时,我得到了正确的实体计数。 (希望这对某人有帮助)
UPDATE
我最终使用了游标。新代码如下:
<?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.
?>
尝试使用游标而不是偏移量。在此处查看游标的讨论(包括 PHP 中的示例):
https://cloud.google.com/datastore/docs/concepts/queries#datastore-cursor-paging-php
我非常需要 GDS 和 PHP-GDS 库方面的帮助。
我正在使用出色的 php-gds 库从 google appengine 外部获取数据。到目前为止,图书馆工作正常。
我的问题是我从 GDS 获取的数据 returns 不一致的结果,我不知道可能是什么问题。
请看下面的代码:
<?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.
?>
请帮忙。此外,当我 运行 在云控制台中执行完全相同的查询时,我得到了正确的实体计数。 (希望这对某人有帮助)
UPDATE
我最终使用了游标。新代码如下:
<?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.
?>
尝试使用游标而不是偏移量。在此处查看游标的讨论(包括 PHP 中的示例): https://cloud.google.com/datastore/docs/concepts/queries#datastore-cursor-paging-php