Lol, that's standard 'problem' with multiple non-synchronized DB.
Download and start DhamenDAO android SQLite java class generator. Enter your database and package information. Select the tables required to generate android java classes. Copy generated files to your project. Configure the database manager. Just enjoy the. ( 1 ) Create your SQLite database using your favourite SQLite database manager.
- Sep 06, 2019 SQLite FAQ: How do I create an autoincrement field in SQLite? You define a SQLite autoincrement field (also known in other databases as a serial, identity, or primary key field) with this syntax: id INTEGER PRIMARY KEY SQLite autoincrement field in a table.
- Nov 13, 2014 Generator for SQLite Use in Android. Rate this: 5.00 (4 votes). (' + PEOPLEID + ' INTEGER PRIMARY KEY. Thank you for this application. It has saved my time a lot. I have one suggestion. The code generated the function names in capital letters like (setNAME) instead of that it should use camel casing like setName.
First of all - if you want to be able to create any unique objects at API, as well as at multiple mobile devices side, you need to have:
- YourModelUniqueApi1:1 table + YourModelTempLocal table
OR: - YourModel table with two ID's colum - LocalID (any autoincrement/autogenerated/guid ID, and it would be PRIMARY KEY at mobile side) + COMPLETELLY UNIQUE ID column (based on objects ID's at API side).
LocalID is used only at mobile app side, and it's not used by API side.
Sqlite Primary Key Unique
When your object is local only (hasn't been synchronized with API yet), it should have only LocalID filled, and ID 0. When your object has been synchronized with API, ID should match API object ID.
Get Generated Primary Key Sqlite Android 2017
Sqlite Change Primary Key
You can implement it with your way - to check next available ID every time, because you have multiple mobile devices, and you have objects at API side with ID's 1, 2, 3, 4, 5, you can in the same moment, try to create new object at TWO DIFFERENT mobile devices with ID 6, which would lead conflict at API side later on.