/** * Quries tables in the given storage account. * * @param Models\QueryTablesOptions|string|Models\Filter $options Could be * optional parameters, table prefix or filter to apply. * * @return Models\QueryTablesResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179405.aspx */ public function queryTables($options = null) { $method = Resources::HTTP_GET; $headers = array(); $postParams = array(); $queryParams = array(); $statusCode = Resources::STATUS_OK; $path = 'Tables'; if (is_null($options)) { $options = new QueryTablesOptions(); } else { if (is_string($options)) { $prefix = $options; $options = new QueryTablesOptions(); $options->setPrefix($prefix); } else { if ($options instanceof Filter) { $filter = $options; $options = new QueryTablesOptions(); $options->setFilter($filter); } } } $query = $options->getQuery(); $next = $options->getNextTableName(); $prefix = $options->getPrefix(); $timeout = $options->getTimeout(); if (!empty($prefix)) { // Append Max char to end '{' is 1 + 'z' in AsciiTable ==> upperBound // is prefix + '{' $prefixFilter = Filter::applyAnd(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant($prefix, EdmType::STRING)), Filter::applyLe(Filter::applyPropertyName('TableName'), Filter::applyConstant($prefix . '{', EdmType::STRING))); if (is_null($query)) { $query = new Models\Query(); } if (is_null($query->getFilter())) { // use the prefix filter if the query filter is null $query->setFilter($prefixFilter); } else { // combine and use the prefix filter if the query filter exists $combinedFilter = Filter::applyAnd($query->getFilter(), $prefixFilter); $query->setFilter($combinedFilter); } } $queryParams = $this->_addOptionalQuery($queryParams, $query); $this->addOptionalQueryParam($queryParams, Resources::QP_NEXT_TABLE_NAME, $next); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout); // One can specify the NextTableName option to get table entities starting // from the specified name. However, there appears to be an issue in the // Azure Table service where this does not engage on the server unless // $filter appears in the URL. The current behavior is to just ignore the // NextTableName options, which is not expected or easily detectable. if (array_key_exists(Resources::QP_NEXT_TABLE_NAME, $queryParams) && !array_key_exists(Resources::QP_FILTER, $queryParams)) { $queryParams[Resources::QP_FILTER] = Resources::EMPTY_STRING; } $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $tables = $this->_atomSerializer->parseTableEntries($response->getBody()); return QueryTablesResult::create($response->getHeader(), $tables); }