Open-source code for an iOS database table structure update mechanism

Source: Internet
Author: User

Open-source code for an iOS database table structure update mechanism

Release the open-source code some time ago:

ARDBConfig

On the iOS, provide a database table structure update mechanisms, ensure that the user in any version of the installer, the database structure to ensure adapter.

(On iOS, a database table structure update mechanism is provided to ensure that the user installs the program regardless of the version from which the database structure is adapted .)


For example, user A's database version is v1, user B is v2, and user C has never installed an App. Now, after all users install and run the latest App (the database version is v3, user A's database will be upgraded in sequence from v1 to v2 to v3, and user B's database will be upgraded in sequence from v2 to v3, user C's database will be upgraded in the "v1-> v2-> v3" order.

 

 





How to use it?

1. When creating a project for the first time and creating a database (the database version is 1 ):
(1) create a new class that inherits from "RLDBConfigBase", such as "DBConfigLogic ".
(2) Add the int type read-only attribute "dbVersion" to implement the get method and return 1;
(3) add and overwrite the "onCreate" method of the parent class, and write the SQL and code for creating the data table structure for the first time in the method.
(4) When a program is started (such as "AppDelegate. m"), instantiate the "DBConfigLogic" class and call the "checkDatabase" method to complete database initialization.

2. When the database structure of an App version needs to be changed (the database version is upgraded to 2 ):
(1) based on step 1, modify the return value of the "dbVersion" attribute method to return 2.
(2) On the basis of step 1, add the override parent class method "onUpgrade". Use the demonstration code in "onUpgrade" in this article to modify the code in the switch.
(3) If You Need To perform subsequent data processing after the database structure is upgraded, you can add the method "didChecked" that overwrites the parent class and write the database operation code.
(4) When a program is started (such as "AppDelegate. m"), instantiate the "DBConfigLogic" class and call the "checkDatabase" method to complete database initialization and upgrade.

 

Related Article

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.