Android 5.0 API 21会出现此错误,但此代码可与Android API 33完美配合
我正在使用SimpleSQLiteQuery创建我的选择查询[![在此处输入图像描述
override fun getPropertyBySearch(
type: String,
city: String,
minSurface: Int,
maxSurface: Int,
minPrice: Int,
maxPrice: Int,
onTheMarketLessALastWeek: Boolean,
soldOn3LastMonth: Boolean,
min3photos: Boolean,
schools: Boolean,
shops: Boolean
): LiveData<List<RealEstateDatabase>> {
val iso = ISOChronology.getInstance()
val today = LocalDate(iso)
Log.e("today",today.toString())
val dateMinusThreeMonth = today.minusMonths(3)
val dateMinus1Week = today.minusDays(7)
Log.e("dateMinusThreeMonth",dateMinusThreeMonth.toString())
Log.e("dateMinus1Week",dateMinus1Week.toString())
val query = """SELECT * FROM RealEstateDatabase WHERE
('$type' ='' OR type LIKE '%$type%' ) AND
('$city' ='' OR city LIKE '%$city%' ) AND
($schools = false OR schoolsNear = $schools ) AND
($shops = false OR shopsNear = $shops ) AND
($min3photos = false OR count_photo >= 3 ) AND
($minSurface =0 AND $maxSurface = 0 OR area BETWEEN $minSurface AND $maxSurface ) AND
($minPrice =0 AND $maxPrice = 0 OR price BETWEEN $minPrice AND $maxPrice ) AND
($onTheMarketLessALastWeek = false OR dateOfEntry BETWEEN '$dateMinus1Week' AND '$today' ) AND
($soldOn3LastMonth = false OR dateOfSale BETWEEN '$dateMinusThreeMonth' AND '$today') """
Log.e("query", query)
return realEstateDao.getPropertyBySearch(SimpleSQLiteQuery(query))
}
这就是我们要讨论的table
@Entity
@Parcelize
data class RealEstateDatabase(
@PrimaryKey
var id: String,
var type: String? = null,
var price: Int? = null,
var area: Int? = null,
var numberRoom: String? = null,
var description: String? = null,
var numberAndStreet: String? = null,
var numberApartment: String? = null,
var city: String? = null,
var region: String? = null,
var postalCode: String? = null,
var country: String? = null,
var status: String? = null,
var dateOfEntry: String? = null,
var dateOfSale: String? = null,
var realEstateAgent: String? = null,
var lat: Double ?=null,
var lng: Double ?=null,
var hospitalsNear : Boolean = false,
var schoolsNear : Boolean = false,
var shopsNear : Boolean = false,
var parksNear : Boolean = false,
@ColumnInfo(name = "listPhotoWithText")
var listPhotoWithText : List<PhotoWithTextFirebase> ?=null,
var count_photo : Int? = listPhotoWithText?.size,
)
我没有解释这段代码在一个API上工作,而不是另一个,我倾向于我的sql lite查询的不兼容性,但我不确定或如何修复它
1条答案
按热度按时间woobm2wo1#
常量false(以及true)在SQLite 3.23.0版本中引入;依据:-
1.支持运算符IS TRUE、IS FALSE、IS NOT TRUE和IS NOT FALSE。
因此,根据,只有30+的android API支持使用true和false
相反,您可以使用0来代替false(非零,通常1表示true)。例如: