2
I’m trying to manipulate an internal database with the following code:
sql = "CREATE TABLE IF NOT EXISTS tipo ([codigo] integer autoincrement,nome text not null);";
bancoDados.execSQL(sql);
sql = "INSERT INTO \"tipo\" VALUES(1,\"ESTADUAL\");";
bancoDados.execSQL(sql);
sql = "INSERT INTO \"tipo\" VALUES(2,\"MUNICIPAL\");";
bancoDados.execSQL(sql);
sql = "INSERT INTO \"tipo\" VALUES(3,\"PRIVADA\");";
bancoDados.execSQL(sql);
sql = "INSERT INTO \"tipo\" VALUES(4,\"FEDERAL\");";
The mistake I’m having is this::
03-23 20:22:26.419: E/Database(368):
Failure 19 (PRIMARY KEY must be unique) on 0x92ba0 when executing
'INSERT INTO "tipo" VALUES(1,"ESTADUAL");'
I already tried some things: take the number I myself was entering (for being with an autoincrement), but did not give and continued the same mistake... Someone knows what’s wrong?
In INSERT you either put the list of fields (omitting the code field that will be generated automatically) or you have to enter the value of all fields (which you did not do in the first INSERT). Clean your table and redo the Inserts in a single way. To check what has been included run a SELECT * FROM "type" .
– user4552