$filter = " ( redemption_code eq '1001') ";
$result = $tableRestProxy->queryEntities("Redemptions", $filter);
$entities = $result->getEntities();
foreach($entities as $entity){
}
此Microsoft Azure存储查询工作完美,可从Redemptions表中返回数千条记录。你可以帮助我如何使用start和limit参数进行分页。
答案 0 :(得分:0)
您可以利用QueryEntitiesOptions进行查询和分页。通常,您可以使用setTop($top)从表中选择前(N)个实体,然后将queryEntities()
函数请求的$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
$options = new QueryEntitiesOptions();
$filter = " ( redemption_code eq '1001') ";
$options->setFilter($filter);
$options->setTop(100);
try {
$result = $tableRestProxy->queryEntities("Redemptions", $options);
} catch (ServiceException $e) {
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code . ": " . $error_message . "<br />";
}
//query next 100 entities
$nextRowKey = $result->getNextRowKey();
$nextPartitionKey = $result->getNextPartitionKey();
$options->setNextRowKey($nextRowKey);
$options->setNextPartitionKey($nextPartitionKey);
try {
$next_result = $tableRestProxy->queryEntities("Redemptions", $options);
} catch (ServiceException $e) {
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code . ": " . $error_message . "<br />";
}
属性用于下一个(N)实体。< / p>
以下是代码段:
setFilter
经过一系列测试后,如果过滤字符串不是setTop
,它会同时使用RowKey
和$filter
,我在{{1}中使用了自定义列}字符串,它工作正常。
但是当我同时使用RowKey
中的$filter
列和setTop
函数时,会引发您的问题。
我深入研究了源代码,发现$filter
字符串未设置为line 1008 of TableRestProxy.php _buildFilterExpressionRec()
,因为$queryParam
字符串没有输入匹配QueryStringFilter
instance处的任何条件stsm。
因此,您可以尝试利用{{3}}来设置过滤字符串。请尝试以下代码:
$filter
答案 1 :(得分:0)
您可以看到How to do queries and pagination for Azure Table Storage in PHP
的演示function queryPaginationEntitiesSample($tableClient, $tableName, $numPerPage, $page, $filter)
{
try {
$options = new QueryEntitiesOptions();
$options->setFilter(Filter::applyQueryString($filter));
if($page== 1){
$options->setTop($numPerPage);
$result = $tableClient->queryEntities($tableName, $options);
$entities = $result->getEntities();
}
else{
//skip $numPerPage * ($page-1) records
$options->setTop($numPerPage * ($page-1));
$options->setSelectFields(array('pk'));
$result = $tableClient->queryEntities($tableName, $options);
$nextRowKey = $result->getNextRowKey();
$nextPartitionKey = $result->getNextPartitionKey();
$options = new QueryEntitiesOptions();
$options->setFilter(Filter::applyQueryString($filter));
$options->setTop($numPerPage);
$options->setNextRowKey($nextRowKey);
$options->setNextPartitionKey($nextPartitionKey);
$result = $tableClient->queryEntities($tableName, $options);
$entities = $result->getEntities();
}
return $entities;
}
catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message.PHP_EOL;
return null;
}
}
示范如下: