package com.example.iot_controlhost.utils.old;

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

public class DataBaseUtil {
    DBOpenHelper dbsqLiteOpenHelper;
    SQLiteDatabase db;
    public DataBaseUtil(Context context){
        dbsqLiteOpenHelper = new DBOpenHelper(context,"database.db",null,22);
        db = dbsqLiteOpenHelper.getWritableDatabase();
    }
    public SQLiteDatabase InitDataBase()
    {
        return db;
    }

    /**
     * 查询
     * @param table 表名
     * @param columns 指定要查询的列，如果为空，返回所有
     * @param selection 查询条件 ，可以用占位符？
     * @param selectionArgs  where对应的条件值
     * @param groupBy 指定分组方式
     * @param having 指定having条件
     * @param orderBy 指定having条件
     * @return
     */
    public Cursor Query(String table, String[] columns, String selection, String[]
            selectionArgs, String groupBy, String having, String orderBy){
        Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
        return cursor;
    }

    public Cursor Select(String sql){
        Cursor cursor = db.rawQuery(sql,null);
        return cursor;
    }

    public void close(){
        db.close();
    }

}