Autoincremet on Sqlite is not working on Android

Asked

Viewed 81 times

2

Autoincrement is not working on my Sqlite tables.

Table:

db.execSQL("create table usuario(_idUsuario integer primary key autoincrement, nome text not null, email text not null, senha text not null)");

Insert:

public String insertUsuario(Usuario usuario) {
    db = dbHelper.getWritableDatabase();
    long resultado;

    ContentValues values = new ContentValues();

    values.put("nome", usuario.getNome());
    values.put("email", usuario.getEmail());
    values.put("senha", usuario.getSenha());

    resultado = db.insert("usuario", null, values);

    if (resultado == -1) {
        return "Usuário não foi criado!";
    } else {
        return "Usuário foi criado com sucesso";
    }
}

I enter the values through the code below:

 usuario.setNome(cadNome);
 usuario.setEmail(cadEmail);
 usuario.setSenha(cadSenha);
 DBControle db = new DBControle(getApplicationContext());

 String a = db.insertUsuario(usuario);

Any user that is created is with id = 0. What I am doing wrong?

Show 1 more comment

1 answer

0

Create id column only as _id. Autoincrement is done automatically Something like:

db.execSQL("create table usuario(_id integer primary key, nome text not null, email text not null, senha text not null)");

Browser other questions tagged

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