pushtorefresh / storio

Reactive API for SQLiteDatabase and ContentResolver.
Apache License 2.0
2.55k stars 182 forks source link

Queries using "WHERE field IN (value1, value2)" #474

Closed tadas-subonis closed 9 years ago

tadas-subonis commented 9 years ago

Hi,

Is there a support for such queries or an example of that?

Thanks

artem-zinnatullin commented 9 years ago

Yep, just like in SQLiteDatabase:

storIOSQLite
  .get()
  .listOfObjects(Tweet.class)
  .withQuery(Query.builder()
    .table("tweets")
    .where(TweetTableMeta.COLUMN_ID + " IN (?,?,?)")
    .whereArgs(1, 2, 3)
    .build())
  .prepare()
  .createObservable()
  .subscribe(tweets -> ...)
tadas-subonis commented 9 years ago

Hmm... In my case a number of arguments (number of entries in a list varies that I use for IN condition) is a variable so I guess I'll have to stick with RawQuery :/

On Thu, Jul 30, 2015 at 7:39 PM, Artem Zinnatullin <notifications@github.com

wrote:

Yep, just like in SQLiteDatabase:

storIOSQLite .get() .listOfObjects(Tweet.class) .withQuery(Query.builder() .table("tweets") .where(TweetTableMeta.COLUMN_ID + " IN (?,?,?)") .whereArgs(1, 2, 3) .build()) .prepare() .createObservable() .subscribe(tweets -> ...)

— Reply to this email directly or view it on GitHub https://github.com/pushtorefresh/storio/issues/474#issuecomment-126396935 .

Kind Regards, Tadas Šubonis

artem-zinnatullin commented 9 years ago

Just write func that generates ?,?,? string and use args :)

artem-zinnatullin commented 9 years ago

@tadas-subonis can we close this issue?

tadas-subonis commented 9 years ago

Well, it would be nice to have more streamlined support for that but I guess we can close this at the moment :)

Thanks!

On Thu, Jul 30, 2015 at 8:36 PM, Artem Zinnatullin <notifications@github.com

wrote:

@tadas-subonis https://github.com/tadas-subonis can we close this issue?

— Reply to this email directly or view it on GitHub https://github.com/pushtorefresh/storio/issues/474#issuecomment-126412868 .

Kind Regards, Tadas Šubonis

artem-zinnatullin commented 9 years ago

Okay, we'll think about it and comment here.

artem-zinnatullin commented 9 years ago

@tadas-subonis PTAL at #485, today I needed WHERE IN (?,?,?) too and decided to add it to the StorIO :)

artem-zinnatullin commented 9 years ago

@tadas-subonis with StorIO 1.2.0 you can use Queries.placeholders(numberOfPlaceholders) to generate ?,?,?.

For example:

List<Author> authors;

storIOSQLite
  .get()
  .listOfObjects(Tweet.class)
  .withQuery(Query.builder()
    .table("tweets")
    .where("author IN (" + placeholders(authors.size()) +  ")")
    .whereArgs(authors.toArray())
    .build())
  .prepare()
  .createObservable()
tadas-subonis commented 9 years ago

Nice! Thanks :)

On Fri, Aug 7, 2015 at 6:54 PM, Artem Zinnatullin notifications@github.com wrote:

@tadas-subonis https://github.com/tadas-subonis with StorIO 1.2.0 you can use Queries.placeholders(numberOfPlaceholders) to generate ?,?,?.

For example:

List authors;

storIOSQLite .get() .listOfObjects(Tweet.class) .withQuery(Query.builder() .table("tweets") .where("author IN (" + placeholders(authors.size()) + ")") .whereArgs(authors.toArray()) .build()) .prepare() .createObservable()

— Reply to this email directly or view it on GitHub https://github.com/pushtorefresh/storio/issues/474#issuecomment-128745728 .

Kind Regards, Tadas Šubonis