美文网首页
本地Sqlite操作类:ISqliteService

本地Sqlite操作类:ISqliteService

作者: 玄鸡快跑 | 来源:发表于2016-10-09 18:09 被阅读0次

    功能:

    /// <summary>
    /// 创建Sqlite帮助类
    /// </summary>
    /// <param name="dbName">数据库路径</param>
    /// <returns></returns>
    SqliteUtil GetSqliteUtil(string dbName);
    /// <summary>
    /// 删除一个数据库文件
    /// 失败返回异常
    /// </summary>
    /// <param name="dbName"></param>
    /// <returns></returns>
    bool DeleteDBFile(string dbName);
    
    

    ISqliteService 功能:

    /// <summary>
    /// 创建Sqlite帮助类
    /// </summary>
    /// <param name="dbName">数据库路径</param>
    /// <returns></returns>
    SqliteUtil GetSqliteUtil(string dbName);
    /// <summary>
    /// 删除一个数据库文件
    /// 失败返回异常
    /// </summary>
    /// <param name="dbName"></param>
    /// <returns></returns>
    bool DeleteDBFile(string dbName);
    
    

    SqliteUtil 功能:

    /// <summary>
    /// 创建数据库,前提是数据库不存在的情况下
    /// </summary>
    /// <returns></returns>
    bool CreateDB(string sql);
    /// <summary>
    /// 判断数据库是否存在
    /// </summary>
    /// <returns></returns>
    bool DBIsExist();
    /// <summary>
    /// 创建数据表
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    bool SQLiteCreateTable(string sql);
    /// <summary>
    /// 获取数据表
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    DataTable GetDataTable(string sql);
    /// <summary>
    /// 查询操作
    /// </summary>
    /// <param name="sql">SQL语句,例如:SELECT * FROM `table` WHERE `id` = @id </param>
    /// <param name="parame">SQLiteParameter集合</param>
    /// <returns></returns>
    int ExecuteNonQuery(string sql, Dictionary<string, string> parame);
    /// <summary>
    /// 查询操作
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    int ExecuteNonQuery(string sql);
    /// <summary>
    /// 获取数据库符合要求的第一行第一个数据
    /// </summary>
    /// <param name="sql">SQL语句,例如:SELECT * FROM `table` WHERE `id` = @id </param>
    /// <param name="parame">SQLiteParameter集合</param>
    /// <returns></returns>
    string ExecuteScalar(string sql, Dictionary<string, string> parame);
    /// <summary>
    /// 获取数据库符合要求的第一行第一个数据
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    string ExecuteScalar(string sql);
    /// <summary>
    /// 批量执行数据库语句
    /// </summary>
    /// <param name="sqls">数据库语句集合</param>
    /// <returns></returns>
    bool ExecuteByTransaction(List<string> sqls);
    /// <summary>
    /// 更新数据库
    /// </summary>
    /// <param name="sql">UPDATE `table` SET `id` = @id </param>
    /// <param name="param">SQLiteParameter集合</param>
    /// <returns></returns>
    bool Update(String sql, Dictionary<String, String> param);
    /// <summary>
    /// 更新数据库
    /// </summary>
    /// <param name="tableName">表名</param>
    /// <param name="data">数据字段+对应SQLiteParameter 例如 :new Dictionary<string,string>(){{"id","@id"}} </param>
    /// <param name="where">判别条件 例如:`id`=@id AND `number`= @nubmer </param>
    /// <param name="param">SQLiteParameter集合</param>
    /// <returns></returns>
    bool Update(String tableName, Dictionary<String, String> data, String where,Dictionary<String, String> param);
    /// <summary>
    /// 删除数据
    /// </summary>
    /// <param name="sql">DELETE `table` WHERE `id` = @id </param>
    /// <param name="param">SQLiteParameter集合</param>
    /// <returns></returns>
    bool Delete(String sql, Dictionary<string, string> param);
    /// <summary>
    /// 删除数据
    /// </summary>
    /// <param name="tableName">表名</param>
    /// <param name="where">判别条件 例如:`id`=@id AND `number`= @nubmer </param>
    /// <param name="param">SQLiteParameter集合</param>
    /// <returns></returns>
    bool Delete(String tableName, String where ,Dictionary<string ,string > param);
    /// <summary>
    /// 插入数据
    /// </summary>
    /// <param name="sql">INSERT INTO `table`(ID,data) VALUES(@id,@data) </param>
    /// <param name="param">SQLiteParameter集合</param>
    /// <returns></returns>
    bool Insert(String sql, Dictionary<string, string> param);
    /// <summary>
    /// 插入数据
    /// </summary>
    /// <param name="tableName">表名</param>
    /// <param name="data">数据字段+对应SQLiteParameter 例如 :new Dictionary<string,string>(){{"id","@id"}} </param>
    /// <param name="param">SQLiteParameter集合</param>
    /// <returns></returns>
    bool Insert(String tableName, Dictionary<String, String> data,Dictionary <string ,string > param);
    
    

    使用教程:

     public void Start(IBundleContext context)
     {
          var sdkFactoryService = context.GetFirstOrDefaultService<SdkFactoryService>();
          ISqliteService _SqliteService = sdkFactoryService.GetSqliteService(context, token);
          _SqliteService.DeleteDBFile("test.db");  //删除数据库
          SqliteUtil sqlUtil = _SqliteService.GetSqliteUtil("test.db");  //获取数据库帮助类
    }
    

    相关文章

      网友评论

          本文标题:本地Sqlite操作类:ISqliteService

          本文链接:https://www.haomeiwen.com/subject/mzxmyttx.html