2

I'm exploring source code of google io schedule app in education purposes. And I've noted an interesting thing.

In ScheduleProvider they use two id field. For example you can see that in table of blocks they use well known BaseColumns._ID and another BlocksColumns.BLOCK_ID column.

    db.execSQL("CREATE TABLE " + Tables.BLOCKS + " ("
            + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + BlocksColumns.BLOCK_ID + " TEXT NOT NULL," // BlocksColumns.BLOCK_ID == "block_id"
            + BlocksColumns.BLOCK_TITLE + " TEXT NOT NULL,"
            + BlocksColumns.BLOCK_START + " INTEGER NOT NULL,"
            + BlocksColumns.BLOCK_END + " INTEGER NOT NULL,"
            + BlocksColumns.BLOCK_TYPE + " TEXT,"
            + BlocksColumns.BLOCK_SUBTITLE + " TEXT,"
            + "UNIQUE (" + BlocksColumns.BLOCK_ID + ") ON CONFLICT REPLACE)");

So my question is: Why do they need two columns for id?

I have one assumption. I think they don't want to refuse to standard tools like SimpleCursorAdapter so they created '_id' column. But they also want to do lots of joins without name conflicts so they created '%table%_id' column for each table. Am I right? If so I have another question. How they generate unique '%table%_id' for each new row?


EDIT:

I am asking not only for those who explored this code but also for experienced android programmers who probably came across the same scheme.

Atef Hares
  • 4,715
  • 3
  • 29
  • 61
Nolan
  • 1,060
  • 1
  • 11
  • 34
  • This is resonable. As you can see there is only one primary key. They might using it for any other purpose, – RajSharma Jul 07 '15 at 05:29

0 Answers0