Open ValeriusGC opened 7 years ago
Perform get with RawQuery!
On Fri, Dec 16, 2016, 17:04 Valery Kulikov notifications@github.com wrote:
What is elegant and effective way to do that with StorIO?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pushtorefresh/storio/issues/737, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7B3Dhjp6vzRkku7FOTVQ0MzhIcQ1q0ks5rIppygaJpZM4LPN14 .
But how? Constructon like this
Integer i = storIoSqlite
.get()
.object(Integer.class)
.withQuery(RawQuery.builder()
.query("SELECT COUNT(*) FROM some_table WHERE some_field=some_value)
.build()
)
.prepare()
.executeAsBlocking();
fails with Caused by: java.lang.IllegalStateException: This type does not have type mapping: type = class java.lang.Integer,db was not touched by this operation, please add type mapping for this type
Can you please try something some like this?
try (Cursor cursor = storIOSqlite
.get()
.cursor()
.withQuery(RawQuery.builder()
.query("SELECT COUNT(*) FROM some_table WHERE some_field =?")
.args("some_value")
.build())
.prepare()
.executeAsBlocking()
) {
cursor.moveToFirst();
Assertions.assertThat(count).isEqualTo(cursor.getInt(0));
}```
You can't use `get().object` for objects without get resolver, so should use `get().cursor` or `get().numberOfResults()`
I really really have no idea how perform this primitive operation as COUNT with this sophisticated library. It is terrible to imagine how to implement min()/max()... or get some columns... \B-( As Metallica sang: "The Thing That Should Not Be"
What's the problem with cursor?
On Fri, Dec 16, 2016, 20:05 Valery Kulikov notifications@github.com wrote:
I really really have no idea how perform this primitive operation as COUNT with this sophisticated library. It is terrible to imagine how to implement min()/max()... or get some columns... \B-( As Metallica sang: "The Thing That Should Not Be"
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/pushtorefresh/storio/issues/737#issuecomment-267642661, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7B3GUXXGDBwD52Uysb1J9B1600CjnYks5rIsTWgaJpZM4LPN14 .
Thanks to @nikitin-da problem was gone. Maybe this solution should be in documentation.
What's the problem with cursor?
PR welcome :)
On Sat, Dec 17, 2016, 15:02 Valery Kulikov notifications@github.com wrote:
Thanks to @nikitin-da https://github.com/nikitin-da problem was gone. Maybe this solution should be in documentation.
What's the problem with cursor?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/pushtorefresh/storio/issues/737#issuecomment-267759133, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7B3IHAkO-O8u7EaOMttu-ghcJDJ2auks5rI89ogaJpZM4LPN14 .
well, ok. i`d make PR for sample or readme with this 'use case'. But i have another case: how can i perform complex update in one transaction, such as (pseudocode):
begin transaction
get COUNT
put operation on some table
put operation on another table
some ...
end transaction
Please help me with this. So then I combine all oof this in one PR
You can use storIOSQLite#lowLever
for this:
StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
lowLevel.beginTransaction();
try {
// code that should be execute inside single transaction
lowLevel.setTransactionSuccessful();
} finally {
lowLevel.endTransaction();
}
What is elegant and effective way to do that with StorIO?