Android: In-depth study of SQLite instances (I) Business-type SQLite Version Management

Source: Internet
Author: User
Tags name database

Written in front of, this article Reprinted from http://www.eoeandroid.com/thread-81911-1-1.html

Package EOE. demo; import android. content. context; import android. database. SQLite. sqlitedatabase; import android. database. SQLite. sqliteopenhelper;/*** database version control class * sqliteopenhelper is a database version control superclass **/public class mangerdatabase extends sqliteopenhelper {Private Static final string name = "shool "; private Static final int version = 2; /***** @ Param context information * @ Param name database name * @ Param cursorfactory factory cursor factory * @ Param version database version * initialize data parameters */Public mangerdatabase (context) {// call the superclass constructor super (context, name, null, version );} /*** if no database exists, create a table structure and overwrite the superclass Creation Method * in the superclass, this method is an oncreate method which only has the method body but does not implement the body. when the user executes a call to obtain the user database management, the instance has already executed * This method exists in a superclass and is executed by getwritabledatabase () */@ overridepublic void oncreate (sqlitedatabase dB) called by this method mongodb.exe csql ("create table person (personid integer primary key autoincrement, name varchar (20), age integer, xxx integer) ");} /*** execute update. If the table exists, perform the update operation. * oldversion Old Version Number * newversio New Version Number * onupgrade creation method. The instance has been executed when the user executes the call to obtain the user database management. * the method exists in the superclass and is composed of getwritabledatabase () */@ overridepublic void onupgrade (sqlitedatabase dB, int oldversion, int newversion) called in this method {// Delete db.exe csql ("Drop table if exists person") first "); // call the method to execute the oncreate (db );}}
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.