You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.example.picture_share;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
import androidx.annotation.Nullable;
public class Database extends SQLiteOpenHelper {
private static final String dbname="mydb";
private Context mContext;
public Database(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
mContext=context;
}
public Database(Context context){
super(context,"mydb",null,1);
mContext=context;
}
@Override
public void onCreate(SQLiteDatabase db) {
//创建一个用户表包括所有用户里面有id密码用户名和头像
db.execSQL("create table if not exists users"+
"(id text primary key," +
"password text not null,"+
"name text ,"+
"touxiang blob)");
//创建一个图片表,存储图片,图片的id详细信息以及发布的用户id和图片
db.execSQL("create table if not exists picturestable"+
"(idnum text ,"+
"details text,"+
"usrerid text,"+
"pictures blob)");
//创建一个收藏点赞表存放图片id个人账号
db.execSQL("create table if not exists personlikes"+
"(idnum text ,"+
"usrerid text)");
Toast.makeText(mContext,"数据库创建成功", Toast.LENGTH_SHORT).show();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}