question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[3.0.0-beta2] Index/IndexGroup not working

See original GitHub issue

I’ve followed the instructions. Here’s the relevant part of my table showing what I want to index:

@Table(
        database = SNOCRUDatabase.class,
        name = ChatterConversation.TABLE_NAME,
        indexGroups = {@IndexGroup(number = 1, name = "serverOrder")})
public class ChatterConversation extends BaseTable implements Serializable {


    @Index(indexGroups = 1)
    @Column long serverOrder = 0;


}

And then a query to get rows ordered by the index:

    @Override
    public List<ChatterConversation> getChatterConversationList() {
        chatterGateway.getChatterConversations(new GetChatterConversationsListResponseCallback());
        return SQLite.select()
                .from(ChatterConversation.class)
                .indexedBy(ChatterConversation_Table.index_serverOrder)
                .orderBy(ChatterConversation_Table.serverOrder, true)
                .queryList();
    }

Pretty straight forward and it all compiles. However pulling the database from my emulator shows that no index was created and of course I get an exception as soon as I run the query.

java.lang.RuntimeException: Unable to resume activity {com.phonegap.snocru.review/com.snocru.snocru.MainActivity}: android.database.sqlite.SQLiteException: no such index: serverOrder (code 1): , while compiling: SELECT * FROM `chatter_conversation`INDEXED BY `serverOrder` ORDER BY `serverOrder` ASC

If I yank the .indexedBy() call, It’ll run but there still is no index. Yes I’ve tried making the index name something other than the column name. What am I missing?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
brwskitimecommented, Mar 10, 2016

Why do you need a migration on a new table?? It should be part of the table creation. It’s also not consistent with unique index creation. Also tried this and it only runs the migration on a database upgrade. So new users/fresh install will still not get my index. This is broken IMO.

1reaction
agrosnercommented, Feb 5, 2016

just create a subclass of BaseMigration like so:

public class IndexPropertyMigration extends BaseMigration {

    private final IndexProperty indexProperty;

    public IndexPropertyMigration(IndexProperty indexProperty) {
        this.indexProperty = indexProperty;
    }

    @Override
    public void migrate(DatabaseWrapper database) {
        indexProperty.createIfNotExists(database);
    }
}

and subclass it with proper annotation:

@Migration(version = MyDatabase.VERSION, database = MyDatabase.class)
public class MyIndexPropertyMigration extends IndexPropertyMigration {

    private final IndexProperty indexProperty;

    public IndexPropertyMigration() {
        super(MyTable_Table.index_myIndexProperty);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found