Update does not update

Asked

Viewed 186 times

0

The app works like this: An SMS is received, so the app checks if the number that sent this SMS is registered, if the app checks the first twenty characters of the message, which I call text (example: Light 1.........-LIG , or: Light 1.........-DSL). If this text exists then the app updates the message in the database, otherwise it inserts a new message. The problem is time to Update, not the error in the execution, however it does not update. below the update:

public Long atualiza (ReceiveOne receiveOne) {

    db = this.getWritableDatabase();

    ContentValues valores = new ContentValues();

    valores.put(RECEIVE_ONE_DATA, receiveOne.getReceiveOne());

    return (long) db.update(RECEIVE_ONE_NAME, valores, RECEIVE_ONE_KEY + " =?", new String[]{String.valueOf(receiveOne.getId())});

}

and below the code that calls the method:

receiveOne.setReceiveOne(smsBody.toString());

receiveOne.setId(db.questTextReceiverOne(smsBody));

db.atualiza(receiveOne);

The smsBody is the SMS received. the method questTextReceiverOne() checks the existence of the text and returns the id.

I tested several update and da methods in the same.

id = 0. //retorno do atualiza = 0

db = SQLiteDatabase: /data/data/com.example.usuario.infinium8/databases/SMS.

In the database I have only one message. The existing message is: led 1.........-LIG ai chega o SMS : led 1.........-DSL, como o texto led 1 - é igual ao que está no banco a mensagem vai para o update.

the updated method is in a Sqliteopenhelper and is called in a BroadcastReceiver.

  • The method db.update() returns the number of updated records, zero indicates that none was. To update a record you must pass a id that exists in DB. Check whether receiveOne.getId() returns a id existing.

  • Okay, so I need to make the questTextReceiverOne(); which is returning the list entry return me the id. I tried to make a list.get(data number in the list) that I don’t even do with delete.

  • So, to make this process by a button is simple, in this case I want to occur when the SMS arrives and then that ta, I can not pull the id, nor by getId(), I can only do this in the return of the Insert.

  • If the name (Led 1) is unique do the update using name instead of id.

  • Hmmm.. but how will I use the name in update?

  • It would be something like that: return (long) db.update(RECEIVE_ONE_NAME, valores, RECEIVE_ONE_NomeDoCampoNome + " =?", new String[]{receiveOne.getNome()});

  • AAAAAEE, I made a method that you enter with the String and it returns the id

Show 2 more comments

1 answer

1


the answer was to create a method in which I enter with the received sms, it checks the text and returns the database object:

public ReceiveOne quest_IdReceiverOne (String message) {

    int size = receiveOneSize();

    List<ReceiveOne> list = selectReceiverOne();

    ReceiveOne receiveOne = new ReceiveOne();

    for (int i = 0; i < size; i++) {

        String data = String.valueOf(list.get(i));

        if (data.substring(0, 19).equals(message.substring(0, 19)))
            return receiveOne = list.get(i);
    }

    return null;

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.