Release the open source code for the previous period:
Ardbconfig
On the IOS, provide a database table structure update mechanism, ensure that the user in any version of the installer, the Database structure to ensure adapter.
(on iOS, a mechanism for updating the database table structure ensures that the database structure is guaranteed to fit regardless of the version from which the user installs the program.) )
Such as: User A's database version is V1, User B is v2, User C has not installed the app; now that all users install and run the latest app (the database version is V3), user A's database will be upgraded in a "v1->v2->v3" order, and User B's database will "v2-> V3 "Sequential upgrade, User C's database will be" V1->V2->V3 "sequential upgrade.
Source: Https://github.com/longjun3000/ARDBConfig
How do I use it?
1, the first time to create a project, a new database (database version 1):
(1) Create a new class that inherits from "Rldbconfigbase", such as "Dbconfiglogic".
(2) Add int type read-only property "Dbversion", implement Get method and return 1;
(3) Add the Override parent class method "OnCreate" and write the first SQL and code to create the data table structure within the method.
(4) When the program starts (such as "APPDELEGATE.M"), instantiate the "Dbconfiglogic" class and Invoke the "Checkdatabase" method, you can complete the initialization of the database action.
2, the app in a version of the database structure needs to be changed (database version up to 2):
(1) On the basis of step 1, the return value of the Modify "Dbversion" Property method is returned 2.
(2) On the basis of step 1, add overwrite the parent class method "Onupgrade", using the Model code in "Onupgrade" in this article, just modify the code in switch.
(3) If you need to do some subsequent data processing after the database structure upgrade is complete, you can add the method "Didchecked" that overrides the parent class to write the code for the database operation.
(4) When the program starts (such as "APPDELEGATE.M"), instantiate the "Dbconfiglogic" class and Invoke the "Checkdatabase" method, you can complete the initialization of the database and upgrade action.
Open source code for the database table structure update mechanism for iOS