pushtorefresh / storio

Reactive API for SQLiteDatabase and ContentResolver.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make a query to update multiple rows by different values

nikiJava opened this issue · comments

As I mention in title, what I have to use to update multiple rows by different values?
For example, I have table like this:

 class Language {
        private String name;
        private int status;
    }

I want to change status of one of the languages to 0, and in another - to 2, using one Query (UpdateQuery or something else).

Originnally I wanted to use two UpdateQuery instances - the one reset language to 0, the second - set 2 in another row, but did not find how to concatenate PutResults of those querries.

Thanks!

Hi, @nikiJava !
I think using 2 different queries for 2 different values is the right way.
Don't you use storIO.put().objects(Collection) or storIO.put().contentValueses(Iterable) to put them?
In common case one of values may already exist in db unlike another. So the first PutResult will be for update, and the second for insertion.
And you can combine it with PutResults like this

Guys, I'm gonna use one custom PutResolver to perform operation, that was mention in my first comment in the issue - change status of one of the languages to 0, and in another - to 2. So, how can I merge that PutResults from two different operation, cause method performPut have to return PutResult, but not a PutResults.

PutResolver should be used to map single object into contentValues.
So if you want to put two object you can use storIO.put().objects(Collection)
Will it applicable in your case?

Language l1 = new Language("en", 0);
Language l2 = new Language("ru", 2);
PutResults results = storIO.put()
   .objects(list(l1, l2))
   .prepare()
   .executeAsBlocking();
Log.d("English put result: ", results.results().get("en").wasInserted() + "");

Closing. Feel free to reopen if storIO.put().objects(Collection) doesn't work in your case