2015-04-01 71 views
0

我有一个在Azure SQL数据库中正常工作的查询,但我试图在我的Android应用程序中使用它,但无法使其正常工作。这是为了找到任何重叠的时间预订。下面是一些虚拟的数据,到达的SQL查询和离开都是整数:将SQL查询转换为Android Azure移动服务查询

Select * from bourguestMob.tableObjectBookings 
where tabObjID = 28 
and day = 30 
and month = 3 
and year = 2015 
and ((arrival <= 1600 and depart > 1600) 
or (arrival< 1800 and depart >= 1800)); 

使用移动服务提供的,我必须使用查询,就像这样:

tableObjectBookingsTable.where().field("tabObjID").eq(tables.get(i).getId()) 
.and().field("day").eq(day).and().field("month").eq(month).and().field("year").eq(year) 
.and().field("arrival").lt(intTime).or().field("arrival").eq(intTime).and().field("depart").gt(intTime) 

这就是我有部分,但我认为查询的某些部分需要嵌套才能正确评估。

回答

0

我想你想要的是改变你的查询的结尾看起来像这样:

.and(field("arrival").lt(intTime).or() 
    .field("arrival").eq(intTime).and().field("depart").gt(intTime)) 

它帮助我一下OData的字符串来检查,如果你得到它的权利,来看看这里对于一些复杂查询的样本:

https://github.com/Azure/azure-mobile-services/blob/master/sdk/android/test/sdk.testapp.tests/src/com/microsoft/windowsazure/mobileservices/sdk/testapp/test/MobileServiceQueryTests.java#L724