Skip to content

[Bug] Using Limit and Offset causes SQL exception. #140

@wojciechsura

Description

@wojciechsura

I have the following code:

public Operation getLocalOperation(int mostRecentOperation, int skip) {

        try {

            Operation operation = databaseHelper.getOperationDao().queryBuilder()
                    .orderBy(Operation.ID_FIELD, true)
                    .offset((long)skip)
                    .where()
                    .isNull(Operation.FOREIGN_USER_FIELD)
                    .and()
                    .ge(Operation.ID_FIELD, mostRecentOperation)
                    .queryForFirst();

            return operation;

        } catch (SQLException e) {

            throw new RuntimeException("Cannot get local operation");
        }
    }

Running this code on Android 30 yields the following exception:

SELECT * FROM Operations WHERE (ForeignUserIS NULL ANDId>= 0) ORDER BYId OFFSET 0 LIMIT 1

However, the query fails with the following exception and cause:

Problems executing Android query: SELECT * FROM `Operations` WHERE (`ForeignUser` IS NULL AND `Id` >= 0) ORDER BY `Id` OFFSET 0 LIMIT 1
near "OFFSET": syntax error (code 1 SQLITE_ERROR[1]): , while compiling: SELECT * FROM `Operations` WHERE (`ForeignUser` IS NULL AND `Id` >= 0) ORDER BY `Id` OFFSET 0 LIMIT 1

I'm using com.j256.ormlite:ormlite-android:6.1 on Android 30 (Samsung Galaxy S9+).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions