【发布时间】:2014-11-07 15:28:00
【问题描述】:
我在 GAE:php 运行时上有一个应用程序,我正在使用 Google Cloud Datastore API 从我的 PHP 应用程序连接到 Datastore。
我的问题:
如何使用键查询我的数据库,类似于 Sql 中的"SELECT * FROM table_name WHERE id <= 1410611039"。
我的代码:(我看到人们正在使用这种查询字符串语法并且它适用于他们)
$gql_query = new Google_Service_Datastore_GqlQuery();
$gql_query->setQueryString("SELECT * FROM notification WHERE __key__ = KEY('notification', 1410611039)");
我得到的部分错误是
Fatal error: Uncaught exception ... (400) Disallowed literal: KEY...
我的数据存储控制台视图:
在我将 WHERE __key__ = KEY('notification', 1410611039) 附加到 query_string 之前,一切都很好。
【问题讨论】:
-
Cloud Datastore GQL 与 App Engine GQL 略有不同。不过,我不确定这里的确切问题:您是否尝试过不带引号的
notification? -
是的,我刚试过
notification不带引号,但仍然是同样的错误。不幸的是,没有关于如何制作 Gql 字符串的 Datastore API 指南。我认为KEY('kind', 'name/id')是一种制作数据存储密钥的方法,但它不能通过 API 工作。
标签: php google-app-engine gql google-cloud-datastore