Android Database Upgrade instance, updated

Source: Internet
Author: User

Turn: http://www.open-open.com/lib/view/open1347440993944.html
Android applications may inevitably deal with SQLite. With the continuous upgrading of applications, the original database structure may no longer adapt to new features. At this time, the structure of the SQLite database needs to be upgraded. SQLite provides the alter table command, allowing you to rename or add new fields to an existing table, but cannot delete fields from the table.
You can only add fields at the end of the table. For example, you can add two fields to subpartition:
1 alter table subpartition add column activation blob;
2 alter table subpartition add column key blob;

In addition, if you encounter complex modification operations, such as data transfer while modifying, You can execute the following statement in a transaction to modify the table.
1. Change the table name to a temporary table.
Alter table subpartition Rename to _ temp _ subpartition;

2. Create a new table
Create Table subpartition (orderid varchar (32) Primary key, username varchar (32) Not null, productidvarchar (16) Not null );
  
3. Import Data
Insert into subpartition select orderid, "", productid from _ temp _ subpartition;
Or
Insert into subpartition () Select orderid, "", productid from _ temp _ subpartition;
* Note that double quotation marks (") are used to supplement data that does not exist.
  
4. delete a temporary table
Drop table _ temp _ subpartition;

The above four steps can be used to migrate the old database structure to the new database structure, and ensure that the data will not be lost due to the upgrade.
Of course, you can also create a temporary table to reduce fields.


Attached example: ormlitetest.zip

 

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.