MDP
MDP

Reputation: 4287

SQLite creates double column _id

I'm creating a very simple table inside my android app database. Something weird happened, but I can't find my error.

When I analize the database of my android app, inside my table there are 2 column _id, as you can see in the image enter image description here

here you can see the class that "handle" the database.

public class ContactsDAO extends SQLiteOpenHelper {

    public ContactsDAO(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DB_NAME, factory, DB_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        try {
            String createQuery = "CREATE TABLE my_contact(_id integer primary key autoincrement, contact_uri text)";
            sqLiteDatabase.execSQL(createQuery);
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1){}

  public void add(MyContact myContact){
        ContentValues contentValues = new ContentValues();
        contentValues.put(contact_uri, "uriiiiiiiii");
        SQLiteDatabase database = this.getWritableDatabase();
        database.insert(my_contact, null, contentValues);
        database.close();
    }
}

Thank in advance.

SOLUTION

As the user CL. says, it's an error of the tool. If I check the tables using adb the table is correct, as you can see in this image

enter image description here

Upvotes: 1

Views: 284

Answers (1)

CL.
CL.

Reputation: 180290

It is not possible to have two columns with the same name.

The database is fine. The display in that "Developer Tools" window is wrong.

Upvotes: 4

Related Questions