Reading cursor columns

Consider the following lines:

final int id = cursor.getInt(cursor.getColumnIndexOrThrow
(StockUpdateTable.Columns.ID));

These and the rest are responsible for fetching the data from the cursor. First of all, it looks up the index of the column by the name using the following:

cursor.getColumnIndexOrThrow(StockUpdateTable.Columns.ID)

Then, the actual value is retrieved using this:

cursor.getInt(...);

For the readers who are unfamiliar with SQLite, the values in the Cursor object are encoded by index and that index represents a column from where the data was retrieved. However, we can look up the index for the column automatically by calling cursor.getColumnIndexOrThrow(), where the name for the column is supplied by the constant from the StockUpdateTable table.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.72.176