androiddatabaseentityandroid-roomr-tree

Is it possible to use Android Room Database to create an R*Tree table?


I would like to continue using Room, but I see no way to create an Entity that uses rtree. There is @FTS3 and @FTS4 annotations but nothing for RTree that I see. Is it possible to create an Entity using R-Tree?

I was attempting to do a migration with this code, but I still wouldn't have the Entity for Room...

val TABLE_CREATE = "CREATE VIRTUAL TABLE if not exists my_table_name USING rtree(" +
       "row_id," +          // Primary key
       "minX, maxX," +      // Minimum and maximum X coordinate
       "minY, maxY" +       // Minimum and maximum Y coordinate
");"
db.execSQL(TABLE_CREATE)

Solution

  • I believe that currently it is not possible to use RTree's in Room.

    To use RTree you would need an SQLite distribution that is compiled with the option -DSQLITE_ENABLE_RTREE=1.

    Room is an abstract layer over the SQLite that is distributed with the Android device and, I believe, does not have RTree enabled (if it were then I would guess that @RTree annotation would then be available).

    e.g. on API 31 if you try to use you get :-

    E/SQLiteLog: (1) statement aborts at 28: [CREATE VIRTUAL TABLE rtree1 USING rtree(id,minX,maxX,minY,maxY);] no such module: rtree
    

    i.e. rtree is not enabled.