Space Conservation Library - CREATE VIEW

I need to use SQL VIEW in a query using the save space library.

Using Commonsware answer here I was able to run a raw SQL statement to create a view during database creation.

 Room.databaseBuilder(context, MyDatabase.class, DB_NAME)
            .addCallback(new RoomDatabase.Callback() {
                @Override
                public void onCreate(@NonNull SupportSQLiteDatabase db) {
                    super.onCreate(db);
                    db.execSQL("CREATE VIEW view_name " +
                            "AS SELECT [...] "
                    );
                }
            })
            .build();

VIEW is actually created in SQLite DB and works fine, but I can't reference it in my Dao @Query because I get a compile-time error:

Error: (100, 48) error: there is a problem with the query: SQLID_ERROR] SQL error or missing database (no such table: output_name)

Any idea on how to let Room know about my view or ignore the error?

+5
source share
1 answer

UPDATE 12/17/2018

2.1.0 Room SQLite: https://developer.android.com/training/data-storage/room/creating-views (. DD)

15/12/2017

, .

, Entity , .

. CommonsWare .

, Room.

, , : Entity , ( ), .

.

Room
    .databaseBuilder(context, DueDatabase.class, DB_NAME)
    .addCallback(new RoomDatabase.Callback() {
       @Override
       public void onCreate(@NonNull SupportSQLiteDatabase db) {
          super.onCreate(db);
          //Drop the fake table and create a view with the same name
          db.execSQL("DROP TABLE view_name");
          db.execSQL("CREATE VIEW view_name " +
                     "AS SELECT [...]"
          );
       }
    })
    .build();
+6

Source: https://habr.com/ru/post/1686495/


All Articles