package com.itheima.redbaby.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.itheima.redbaby.util.Logger;
public class SQLConnection extends SQLiteOpenHelper {
private static final String TAG = "SQLConnection";
public static final String DATABASE_NAME = "redbaby.db"; // 数据库名称
public static final int DATABASE_VERSION = 2;// 数据库版本
public SQLConnection(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
/**
* 演示数据 程序锁数据表
*/
String applock = "create table applock (packename varchar(200))";
db.execSQL(applock);
Logger.d(TAG, applock);
/**
* 地址表
*/
String pub_cant = "create table pub_cant (cant_code nvarchar(6) NOT NULL PRIMARY KEY, cant_name nvarchar(60) NULL," +
"super_code nvarchar(6) NULL)";
db.execSQL(pub_cant);
intData(db);
Logger.d(TAG, pub_cant);
/**
* 浏览记录表
*/
String productHistory = "create table productHistory (id integer, name varchar(200), pic archar(200), marketprice integer, price integer, comment_count integer, time integer)";
db.execSQL(productHistory);
Logger.d(TAG, productHistory);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists applock");
db.execSQL("drop table if exists pub_cant");
db.execSQL("drop table if exists productHistory");
onCreate(db);
}
private void intData(SQLiteDatabase db) {
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110000','北京市','CN')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110100','市辖区','110000')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110101','东城区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110102','西城区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110103','崇文区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110104','宣武区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110105','朝阳区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110106','丰台区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110107','石景山区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110108','海淀区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110109','门头沟区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110111','房山区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110112','通州区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110113','顺义区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110114','昌平区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110115','大兴区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110116','怀柔区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110117','平谷区','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110118','密云县','110100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110200','县','110000')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('110229','延庆县','110200')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120000','天津市','CN')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120100','市辖区','120000')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120101','和平区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120102','河东区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120103','河西区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120104','南开区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120105','河北区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120106','红桥区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120107','塘沽区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120108','汉沽区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120109','大港区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120110','东丽区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120111','西青区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120112','津南区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120113','北辰区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120114','武清区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120115','宝坻区','120100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120200','县','120000')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120221','宁河县','120200')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120223','静海县','120200')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('120225','蓟县','120200')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130000','河北省','CN')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130100','石家庄市','130000')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130102','长安区','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130103','桥东区','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130104','桥西区','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130105','新华区','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130107','井陉矿区','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130108','裕华区','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130121','井陉县','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130123','正定县','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130124','栾城县','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130125','行唐县','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130126','灵寿县','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130127','高邑县','130100')");
db.execSQL("insert into pub_cant (cant_code,cant_name,super_code) values ('130128','深泽县','130100')");
db.execSQL("insert