I've got a azure table storage, with some entities in it. Putting new entities is no problem. Updating existing entities is no problem either, that all works fine.
The following code hangs on the line: $result = $tableClient->retrieveEntities('users',"Name eq 'John Doe'",'partition1');
(somewhere on the bottom) It gives an http 500 error.
require_once("Microsoft/WindowsAzure/Storage/Table.php");
require_once("Microsoft/WindowsAzure/Storage/DynamicTableEntity.php");
$accountName = '***';
$accountKey = '*****';
$tableClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net',$accountName,$accountKey);
$tableClient->createTableIfNotExists('users');
$result = $tableClient->listTables();
foreach ($result as $table){
echo 'Table name is: ' . $table->Name . "\r\n<br />";
}
function setUser($accountName,$accountKey,$partitionName,$data) {
$tableClient = new Microsoft_WindowsAzure_Storage_Table('table.core.windows.net',$accountName,$accountKey);
$update = false;
if(isset($data['ID']) && $entity = $tableClient->retrieveEntityById('users',$partitionName,$data['ID'])){
$update = true;
unset($data['ID']);
} else {
$guid = substr(com_create_guid(),1,32);
$entity = new Microsoft_WindowsAzure_Storage_DynamicTableEntity($partitionName, $guid);
$entity->ID = $guid;
}
$keys = array_keys($data);
foreach($keys as $key){
$entity->$key = $data[$key];
}
if($update){
$tableClient->updateEntity('users',$entity,true);
} else {
$tableClient->insertEntity('users',$entity);
}
}
setUser($accountName,$accountKey,'partition1',array(Name => 'John Doe',Email => '[email protected]',Time => time()));
$result = $tableClient->retrieveEntities('users',"Name eq 'John Doe'",'partition1');
//$result = $tableClient->retrieveEntities('users');
foreach($result as $data) {
echo $data->ID;
echo ' - ';
echo $data->Name;
echo ' - ';
echo $data->Email;
echo ' - ';
echo $data->Time;
echo '<br />';
}
What I want to know is;
What am I doing wrong with the filter paramater? (When I comment out the line with the filter and uncomment the line below, it works fine).
How do I catch this error(and other similar errors), I tried a try { } catch { }, but that wasn't working. It resulted in the same HTTP 500 error.
try-catch - code:
try {
$result = $tableClient->retrieveEntities('users',"Name eq 'John Doe'",'partition1');
} catch (Microsoft_WindowsAzure_Exception $e) {
echo 'Caught exception: '.$e->getMessage();
}
partition1
as one of the arguments to the method. Could that be causing the problem. Try something like$tableClient->retrieveEntities('users',"PartitionKey eq 'partition1' and Name eq 'John Doe'")
and see if that fixes the problem. – Gaurav Mantri