package com.example.memosystem.util;

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

//alt +回车
public class DBUtil extends SQLiteOpenHelper {


    private static final String DATABASE_NAME="db_memo.db";//数据库名字

    public static SQLiteDatabase db=null;//用他来操作数据库


    private static final int DATABASE_VERSION=3;//每一次对数据库脚本的更新都需要将这个数字进行加1



    public DBUtil(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION,null);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {//数据库初始化加载的代码

        db.execSQL("PRAGMA foreign_keys = false");
        db.execSQL("drop table if exists d_admin");//如果这个表存在则删除
        db.execSQL("CREATE TABLE d_admin (s_id  varchar(20) primary key," +
                " s_pwd varchar(20)," +
                " s_name varchar(20)," +
                " s_sex varchar(20)," +
                " s_phone varchar(20)," +
                " s_age varchar(20) )");
        db.execSQL("INSERT INTO d_admin VALUES('root','123456','小铭','男','5696331','18')");
        //-------------管理员 表
        //编号  标题   内容  时间
        db.execSQL("drop table if exists d_record");//如果这个表存在则删除
        db.execSQL("CREATE TABLE d_record (s_id  varchar(50) primary key," +
                " s_title varchar(20)," +
                " s_con text," +
                " s_uid varchar(20)," +//用户ID
                " s_time varchar(20) )");
        db.execSQL("INSERT INTO d_record VALUES('1','记录一下今天的生活','今天吃了好多零食，看了很多电视剧.','root','2023年9月10日 上午 12：56')");
       // db.execSQL("PRAGMA foreign_keys = true");


    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {//数据库变动则执行
        onCreate(sqLiteDatabase);

    }
}
