package com.yyrh.ui.userlist;


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

public class DatabaseHelper extends SQLiteOpenHelper {
	private Context context;
	 private static SQLiteDatabase db;

    public DatabaseHelper(Context context) {
        super(context, "yyrhsdk", null, 1);
        this.context=context;
        db=this.getReadableDatabase();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    	
       
        db.execSQL("create table user(uid varchar(100) primary key , name varchar(100), pwd varchar(100),login_token varchar(200),time varchar(100))");
        
    }

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

    public static void addColumn(String column, String table, Context context){

        String update_sql = "alter table "+ table + " add column "+column + " varchar";
        DatabaseHelper.excuteSql(context,update_sql);

    }
	public static void updateSqlPwd(String uname, String newPwd, Context context){
		DatabaseHelper dbHelper = new DatabaseHelper(context);
		String update_sql = "update user set time = '" + System.currentTimeMillis()+"',pwd = '"+newPwd + "' where name = '" + uname + "'";
		try {
			db.execSQL(update_sql);
		} catch (Exception e) {
			
		}
		db.close();

	}
	public static void excuteSql(Context context, String sql){

        DatabaseHelper dbHelper = new DatabaseHelper(context);
        SQLiteDatabase db = null;
        db = dbHelper.getReadableDatabase();
        try {
            db.execSQL(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        db.close();
    }

}
