package com.example.userdata;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class UserDatabaseHelper extends SQLiteOpenHelper{
	
	//用于创建SQLite数据库的SQL语言--字符串
	private static final String DB_CREATE = "CREATE TABLE " + UserDataManager.TABLE_NAME + " ("
			+ UserDataManager.ID + " integer primary key," + UserDataManager.USER_NAME + " varchar,"
			+ UserDataManager.USER_PWD + " varchar" + ");";//SQL语法语句
	
	public UserDatabaseHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}
	//初次生成数据库时才会被调用
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + UserDataManager.TABLE_NAME + ";");//创建表之前先验证该表是否已存在,若存在则放弃创建
		db.execSQL(DB_CREATE);//创建表
	}
	//数据库的版本发送变化时会被调用
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		onCreate(db);
	}
}