square / sqlbrite

A lightweight wrapper around SQLiteOpenHelper which introduces reactive stream semantics to SQL operations.
https://square.github.io/sqlbrite/3.x/sqlbrite/
Apache License 2.0
4.57k stars 416 forks source link

QueryObservable with dynamic query [ Question ] #224

Closed rezastallone closed 6 years ago

rezastallone commented 6 years ago

Suppose i have this String query = "Select * from message where created_at > " + afterThisDate ; mDb.createQuery(Db.TABLE_NAME, query) ;

is there a way to update afterThisDate variable everytime this Observable emit new data because changes in database ?

rezastallone commented 6 years ago

i am gonna try solution for similar issue #28

JakeWharton commented 6 years ago

Yeah the solution here is switchMap. Give a Observable<Date> (or whatever date type) you should do switchMap(date -> db.createQuery(table, query, date).

Also make sure you're using ? and not string concatenation or you're opening yourself up to SQL injection.