1

Kindly understand my question first

I am using this code to update C_P table in db, who have a trigger on it, which is going to insert any new value in my queuelist table. My database instance is singleton.

  1. when I insert by using this

    "queueListDatabase.dbAccess().insertTask(queueList)"
    

observer on changed call so my observer is working fine.

  1. I have implemented a trigger in room like this

    " db.execSQL("CREATE TRIGGER if not exists CONTROL_PARAM_TRIGGER" +
                                         " AFTER UPDATE " +
                                         "ON C_P" +
                                         " BEGIN " +
                                         " INSERT INTO QueueList(title, description) 
    values('CONTROL_PARAM', new.order_sku_limit||' '||new.cmnum||' '||new.avnum); " +
                                         " END;");"
    

Trigger is also working fine, like when ever I have called

  String queryUpdate="Update CONTROL_PARAM Set abc= 'xyz'";
  queueListDatabase.getOpenHelper().getWritableDatabase().execSQL(queryUpdate) 

it update in C_P and also inserting in QueueList; but it wont fire the onchange method of observer. if I check value after execSQL query, Value is inserted in QueueList table.

P.S : Kindly understand this I can not use dao @RawQuery(writing raw query in db interface) because queries are coming from server.(Kindly suggest me alternate solution if anyone have it)

Here my code for observer

  roomObserver = new Observer<List<QueueList>>() {
        @Override
        public void onChanged(@Nullable List<QueueList> periods) {
            if (periods != null && periods.size()>0) {
                Log.e("dbValue", periods.size() + "");
            }
        }

    };

    queueListDatabase.dbAccess().fetchAllTasks().observe(this,roomObserver);

Kindly suggest my any link or solution I have already check multiple solution (Link are mentioned below), but they does not meet the requirement.

Android ROOM - LiveData not triggered when using custom insert query

Room - LiveData observer does not trigger when database is updated

Insert on Room DB does not trigger Observer on Activity

Observer not triggered on room database change

Room : LiveData from Dao will trigger Observer.onChanged on every Update, even if the LiveData value has no change

Room - LiveData not triggered

Android Room : LiveData callback of update insert?

Android ROOM - LiveData not triggered when using custom insert query

Notify observers when executing a custom sql query ROOM

Room - LiveData observer does not trigger when database is updated

https://developer.android.com/reference/android/arch/persistence/room/RawQuery

Ebad Ahmed
  • 63
  • 1
  • 1
  • 6
  • If anyone found same problem, I have found a solution use this line instance.getInvalidationTracker().refreshVersionsAsync(); after executing "excSQL" line queueListDatabase.getOpenHelper().getWritableDatabase().execSQL(queryUpdate) – Ebad Ahmed Mar 04 '21 at 12:32

0 Answers0