Error executing delete in Sqlite database

Asked

Viewed 233 times

3

I’m having a problem with my project Android. When I execute a delete at the bank sqlite, I get as return the following log message:

W/FileUtils: Failed to chmod(/storage/sdcard/Cardapio Digital/Database/dbcardapio.sqlite): 
android.system.ErrnoException: chmod failed: EPERM (Operation not permitted)

public class Pedidosdao {

Context context;
variaveis v;
SQLiteDatabase db;


public PedidosDao(Context context, variaveis v) {
    this.v = v;
    this.context = context;
}

public void deletaItem(int codigo){
    db = context.openOrCreateDatabase(v.getPathBanco(),Context.MODE_WORLD_WRITEABLE,null);

    try{

        db.execSQL("DELETE FROM PEDIDOS WHERE ID = "+codigo+" ");

    }catch(Exception e){
        e.printStackTrace();
    }
    db.close();
}
  • Ask the question what code you’re using.

1 answer

4

I think the code is wrong. vc ta put double quotes on top of double quotes without single quotes(let’s say he needs to understand that it’s a string).......

Try it this way:

db.execSQL("DELETE FROM PEDIDOS WHERE ID = '"+codigo+"';");

or else:

db.execSQL("DELETE FROM PEDIDOS WHERE ID = "+codigo);


Editing:
The error description seems to indicate that some permission is missing. Try putting these lines in your manifest.xml:

"android.permission.WRITE_EXTERNAL_STORAGE"
  • I don’t see why to make a mistake... I actually created my "DELETES" in the way I described. Today I no longer use it like this, I do DELETE in a different way, following a url that explains it better: https://stackoverflow.com/questions/7510219/deleting-row-in-sqlite-in-android

  • the error seems to refer to permissions, my manifest is all ok, has permissions, I can record records and read the records, when I delete shows me the log : W/Fileutils: Failed to chmod(/Storage/sdcard/Cardapio Digital/Database/dbcardapio.sqlite): android.system.Errnoexception: chmod failed: EPERM)

  • @Andreguedes I think the problem is in the way you are trying to delete the database data, I believe that is not the recommended way. If you want me to post an answer in the form recommended by the documentation, but you’ll have to change a lot of how you’ve been doing things so far.

Browser other questions tagged

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