The DB device is such that it does not bind to ordinal rows, such as an array, and you cannot get write access to the first row in the table in the usual way. This is the architecture of the database and this may seem to be a problem, but in reality this is not the case, since the database works somewhat differently.
The identifier, although it is an auto-incrementing value, cannot serve as a sequential index, since when deleting records from a table, they are simply deleted and the identifiers of the rows following the deleted record do not change. That is, when the third record is deleted, the identifiers will have the following order: 0, 1, 3, 4 ... When adding an entry, the next in order identifier is assigned.
A separate column will not solve this problem either, since deleting it will happen the same as with ID, and rewriting all the values of this column with each deletion is extremely inefficient.
What to do. And the solution is simple - to update the record in the table, you first had to read it, the identifier of this record will be obtained accordingly, you need to save it, and when you update the record you just need to specify the same identifier.
If you need to get access to the first record by all means (although if you work correctly with the database, it is difficult for me to think of why this may be necessary and the way suffers from disadvantages), then you can use a crutch, which consists of the following:
- Make a selection in the cursor over the entire table.
- Set the cursor to the first position.
- Read this post ID
- Use the received ID to update the first entry.
It is worth noting that working with the database is a rather complicated discipline, which was singled out as a separate science - the DBMS and with a swoop you can only spoil everything. In order not to experience problems with this science and work with data stored in the database, this science should be studied.
As a start, I can offer a wonderful book that is very easy and interesting to read and gives a complete initial understanding of the discipline of the database. After reading it, you will discover a lot of interesting and not quite obvious when working with data in the database. The book is called: Bailey L. - Exploring SQL (O'Reilly Bestsellers) - 2012. - You can find it in the public domain. The book is about pure SQL and the organization of work with the database and the creation of its structure, but the application of the stated knowledge to a specific database, like SQLite, will not make any problems.
mSqLiteDatabase.update( "pts", values, DatabaseHelper._ID + " = ?", new String[] { 0 } );- pavlofffmSqLiteDatabase.update( "pts", values, DatabaseHelper._ID + " = ?", new String[] { Integer.toString(0) } );- Mr KlonwarmSqLiteDatabase.update( "pts", values, null, null); Displays exactly what I wrote down in values, but if you write_id = 0, or something, then for some reason it shows another DB cell - Mr Klonwar