iOS Question iSQLiteLight insert a new record between existing ones ?

MitchBu

Well-Known Member
Licensed User
I am adapting the code from Klaus example "iSQLiteLight Three simple SQLite projects" to my own need : a spreadsheet like display with 7 columns.

It works very nicely, so I am confident I will be able to used this in my current check register project.

The only feature I miss is to insert a record between existing ones.

Say I want to insert a new record between record 4 and 5. How will I proceed ?

Thank you in advance.

 

klaus

Expert
Licensed User
There is no Insert method in these examples because these are simple database demonstration programs.
In a database, when you insert a new entry it is added into the database and the internal rowID is automatically incremented.
What you want to do is a display problem not directly related to the database.
You could use your own ID column for filtering and sorting, but it is up to you to manage it.
Then, when you read the database you can filter and sort almost whatever you want for the display.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Thank you Klaus.

So, basically, what I have to do is to manipulate the ID field ?

For instance, if I want to insert a record between4 and 5, I renumber all records from 5 on, by incrementing 1, and I set the inserted one as ID = 5, right ?

Besides your booklets, would you have any suggestion for a book or web site that teaches SQLite ?
 
Upvote 0

klaus

Expert
Licensed User
Upvote 0

aeric

Expert
Licensed User
For instance, if I want to insert a record between4 and 5, I renumber all records from 5 on, by incrementing 1, and I set the inserted one as ID = 5, right ?
I recommend you just leave the auto increment field. Add another column for e.g. SortID or SequenceNo and then follow the steps you mentioned above, renumbering of ID 5 onwards by increment 1. Then use this field after ORDER BY in your SQL query.
 
Upvote 0

klaus

Expert
Licensed User
I recommend you just leave the auto increment field. Add another column for e.g. SortID or SequenceNo
This is what I meant.
Thank you for clarifying it.
I don't use any auto incremented ID column, I use the internal rowid for this.
 
Upvote 0
Top