Persistent Library Room COLLATE LOCALIZED query not working

I use the new Room Persistance Library , released during these years by Google I / O, and it works fine so far, but for some reason it is not possible to order the results using UNICODE or LOCALIZED . The only thing that works is NOCASE , which is useless in my case.

Is there any way to achieve this functionality?

@Dao
public interface ContactDao { 

    @Query("SELECT * FROM contact ORDER BY lastName COLLATE LOCALIZED")
    Flowable<List<Contact>> getAll();
}

If I build Query as above, I get an error:

Error:(21, 29) error: There is a problem with the query: [SQLITE_ERROR] 
SQL error or missing database (no such collation sequence: LOCALIZED)
+7
source share
3 answers

You must use this version of the room.

compile "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

Gradle Line

@ColumnInfo (collate = ColumnInfo.NOCASE)

+4

, LOCALIZED ( Room 1.0.0), (https://developer.android.com/reference/android/arch/persistence/room/ColumnInfo.html#LOCALIZED). https://issuetracker.google.com/issues/68925249, - , .

, , CommonsWare - CREATE. . - create, sqlite alter collate. , .

( Kotlin) - create statement :

@Database(entities = [(LocalityItem::class)], version = AppDatabase.DB_VERSION, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {

    abstract fun localityDao(): LocalityDao

    companion object {
        const val DB_NAME : String = "app_db"
        const val DB_VERSION : Int = 1

        private var INSTANCE: AppDatabase? = null

        private val CALLBACK: Callback = object : Callback() {
            override fun onCreate(db: SupportSQLiteDatabase) {
                db.execSQL("DROP TABLE `locality` ")
                db.execSQL("CREATE TABLE `locality` ("
                        + " `id` INTEGER,"
                        + " `type` INTEGER,"
                        + " `name` TEXT COLLATE LOCALIZED, "
                        + " `row_index` INTEGER,"
                        + " `col_index` INTEGER,"
                        + " PRIMARY KEY(`id`)"
                        + ")")
                db.execSQL("CREATE INDEX `index_locality_type` ON `locality` (`type`)")
                db.execSQL("CREATE INDEX `index_locality_name` ON `locality` (`name`)")
            }
        }

        fun getInstance(context : Context) : AppDatabase? {
            if (INSTANCE == null) {
                synchronized(AppDatabase::class) {
                    INSTANCE = Room.databaseBuilder(
                            context.applicationContext,
                            AppDatabase::class.java, DB_NAME)
                            .addCallback(CALLBACK)
                            .build()
                }
            }
            return INSTANCE
        }
    }
}
+1

COLLATE ,

@ColumnInfo(collate = NOCASE) var name: String

. COLLATE Query.

LOCALIZED Room

-1

All Articles