Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subqueries don't work when using requery-kotlin dependency #905

Open
zwieback opened this issue Dec 2, 2019 · 0 comments
Open

Subqueries don't work when using requery-kotlin dependency #905

zwieback opened this issue Dec 2, 2019 · 0 comments
Labels

Comments

@zwieback
Copy link

zwieback commented Dec 2, 2019

Hi, @npurushe !

Thank you for this very nice library!

When I use a io.requery:requery dependency, the following query:

val sumInNativeCurrency: Long? =
    data.select(
        NamedNumericExpression.ofLong("t_native.value").sum().`as`("native_sum")
    )
    .from(
        data
            .select(Operation.VALUE.`as`("value"))
            .join(ExchangeRate::class.java)
            .on(ExchangeRate.CURRENCY_ID.eq(currencyId))
            .and(ExchangeRate.ID.eq(Operation.EXCHANGE_RATE_ID))
            .where(Operation.ACCOUNT_ID.eq(accountId))
            .`as`("t_native")
    )
    .get().first().get("native_sum")

where data is ReactiveEntityStore

Generates the following SQL:

select sum(t_native.value) as native_sum from (select a._value as value from operation a inner join exchange_rate b on b.currency_id = ? and b.id = a.exchange_rate_id where a.account_id = ?) t_native

But when I use io.requery:requery-kotlin dependency with minor changes (in the JOIN clause):

val sumInNativeCurrency: Long? =
    data.select(
        NamedNumericExpression.ofLong("t_native.value").sum().`as`("native_sum")
    )
    .from(
        data
            .select(Operation.VALUE.`as`("value"))
            .join(ExchangeRate::class)
            .on(ExchangeRate.CURRENCY_ID.eq(currencyId))
            .and(ExchangeRate.ID.eq(Operation.EXCHANGE_RATE_ID))
            .where(Operation.ACCOUNT_ID.eq(accountId))
            .`as`("t_native")
    )
    .get().first().get("native_sum")

where data is KotlinReactiveEntityStore

FROM clause isn't generated and throws the following error:

Caused by: android.database.sqlite.SQLiteException: incomplete input (code 1): , while compiling: select sum(t_native._value) as native_sum from
        at io.requery.android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at io.requery.android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:937)
        at io.requery.android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:540)
        at io.requery.android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:598)
        at io.requery.android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:60)
        at io.requery.android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:41)
        at io.requery.android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
        at io.requery.android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1456)
        at io.requery.android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1398)
        at io.requery.android.sqlitex.SqlitexStatement.executeQuery(SqlitexStatement.kt:55)
        	... 70 more

I am using dependencies with version 1.6.1

@npurushe npurushe added the bug label Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants