我已经构建了一个将Log4Net日志写入名为LogTable的SimpleDB表/域的appender。我现在正在尝试编写一个Windows服务,它将删除此表中的旧记录。绝对正在创建AmazonSimpleDB客户端,手动运行时的查询会返回记录。但是,当通过单元测试执行代码时,不会返回任何结果。表格和列名称区分大小写是正确的。
using (AmazonSimpleDB simpleDbClient = AWSClientFactory.CreateAmazonSimpleDBClient(accessKey, secretKey))
{
String selectExpression = String.Format("select * from LogTable where Timestamp < '{0:o}'", purgeDate);
SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
SelectResponse selectResponse = simpleDbClient.Select(selectRequestAction);
if (selectResponse.IsSetSelectResult())
{
BatchDeleteAttributesRequest deleteRequest = new BatchDeleteAttributesRequest().WithDomainName("LogTable");
deleteRequest.Item = new List<DeleteableItem>();
SelectResult selectResult = selectResponse.SelectResult;
foreach (Item item in selectResult.Item)
{
deleteRequest.Item.Add(new DeleteableItem { ItemName = item.Name });
}
if (deleteRequest.Item.Count > 0)
{
simpleDbClient.BatchDeleteAttributes(deleteRequest);
}
logger.InfoFormat("Success - {0} log records deleted from LogTable", deleteRequest.Item.Count);
}
}
真的很感激这方面的一些帮助。
答案 0 :(得分:0)
只会返回满足表达式的记录,因此请确保您的查询正确无误。简单的选择查询返回什么?试试这个并检查 -
select * from LogTable
如果您没有获得任何点击,请指定区域终点。
如果它返回,请确保您指定的条件匹配。
已编辑:
请尝试运行此代码,并使用您的域所属的link指定区域终点。
AmazonSimpleDBConfig theConfig = new AmazonSimpleDBConfig();
theConfig.ServiceURL = myEndpoint; //where myEndPoint is the region endpoint you are interested in
AmazonSimpleDBClient simpleDbClient= new AmazonSimpleDBClient(myKey, mySecretKey, theConfig);
String selectExpression = "select * from LogTable";
SelectRequest selectRequestAction = new SelectRequest();
selectRequestAction.SelectExpression = selectExpression;
selectRequestAction.NextToken = null;
SelectResponse selectResponse = simpleDbClient.Select(selectRequestAction);
SelectResult selectResult = selectResponse.SelectResult;
List<Item> itemList = selectResult.Item;