package com.example.orangesale_02;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;

import androidx.annotation.Nullable;

public class MyDatabaseHelper extends SQLiteOpenHelper {
    public MyDatabaseHelper(@Nullable Context context)
    {
        super(context,"orange",null,1);
    }
    @Override
    public void onCreate(SQLiteDatabase db)
    {
        String sql="create table orange_user(id integer primary key autoincrement,username varchar(50),password varchar(50),sex varchar(50),city varchar(50))";
        db.execSQL(sql);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
public void insertUser(SQLiteDatabase sqLiteDatabase,String username,String password,String sex,String city)
{
    ContentValues contentValues=new ContentValues();
    contentValues.put("username",username);
    contentValues.put("password",password);
    contentValues.put("sex",sex);
    contentValues.put("city",city);
    sqLiteDatabase.insert("orange_user",null,contentValues);
    sqLiteDatabase.close();
}
public Bundle queryUserInfo(SQLiteDatabase sqLiteDatabase,Bundle bundle)
{

    String username=bundle.getString("username");
    Cursor cursor =sqLiteDatabase.rawQuery("select *from orange_user where username=?",new String[]{username});
    if(cursor!=null)
    {
        while(cursor.moveToNext())
        {
            bundle.putString("sex",cursor.getString(3));
            bundle.putString("city",cursor.getString(4));
        }
    }
    cursor.close();
    sqLiteDatabase.close();
    return bundle;
}


}

