dtol41388 2016-12-14 11:26
浏览 46
已采纳

Google数据存储从select中获取不一致的结果

I seriously need help with GDS and PHP-GDS Library.

I am doing a fetch from outside google appengine using the fantastic php-gds library. So far the library works fine.

My problem is that my data fetch from GDS returns inconsistent results and I have no idea what the issue might be.

Please see code below:

    <?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.
    ?>

Please help. Also when I run the exact same query in the cloud console I get the right entity count. (Hope this helps someone)

UPDATE

I ended up using cursors. New code below:

<?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.
?>
  • 写回答

1条回答 默认 最新

  • dongluobei9359 2016-12-15 19:29
    关注

    Try using a cursor instead of an offset. See the discussion of cursors (including samples in PHP) here: https://cloud.google.com/datastore/docs/concepts/queries#datastore-cursor-paging-php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?