Open source code for the database table structure update mechanism for iOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.