Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to the <a href="http://developer.android.com/guide/topics/providers/content-provider-basics.html" rel="noreferrer">Android Developer Guide</a>,</p> <blockquote> <p>Note: A provider isn't required to have a primary key, and it isn't required to use _ID as the column name of a primary key if one is present. However, if you want to bind data from a provider to a ListView, one of the column names has to be _ID. This requirement is explained in more detail in the section Displaying query results.</p> </blockquote> <p>The Guide continues on to explain the basics of why you need a unique value provided by the <code>primary key</code>,</p> <blockquote> <p>Table data should always have a "primary key" column that the provider maintains as a unique numeric value for each row. You can use this value to link the row to related rows in other tables (using it as a "foreign key"). Although you can use any name for this column, using BaseColumns._ID is the best choice, <strong>because linking the results of a provider query to a ListView requires one of the retrieved columns to have the name _ID.</strong> [emphasis mine]</p> </blockquote> <p>To answer your questions in the order that you provided them:</p> <ol> <li>Having the <code>_ID</code> Column is a best practice for versatility. It doesn't have to be displayed, but works terrific as the primary key (and foreign key!) Required for cursors and queries. <ul> <li>Having it identified by BaseColumns automatically identifies this column as the primary key, unique (obviously), and instructs it to autoincrement.</li> <li>Presumably, implementing BaseColumns is easier than typing out these properties for your private fields.</li> </ul></li> <li><code>_COUNT</code> <a href="http://developer.android.com/reference/android/provider/BaseColumns.html#_COUNT" rel="noreferrer">is just the count of the number of rows in a directory.</a> If your table's rows are being deleted and added, there is no reason to believe that an item's <code>_ID</code> integer has anything to do with when it was added or its sort properties. In other words, <code>last_insert_rowid()</code> <strong>DOES NOT EQUAL</strong> <code>Count()</code>. The _COUNT column just provides a way to show how many results are returned on a query, IN EVERY LINE of that query. For a visual reference, see <a href="http://www.linuxtopia.org/online_books/android/devguide/guide/topics/providers/content-providers.html" rel="noreferrer">linuxtopia.org</a></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload