/// <summary> /// get database trans /// </summary> /// <returns>IDbTransaction</returns> public static IDbTransaction getDBTS() { IDbConnection oIDbConnection = SQLiteHelper.CreateConnection(m_strDBName); IDbTransaction trans = oIDbConnection.BeginTransaction(); return(trans); }
/// <summary> /// query first cell /// </summary> /// <param name="sql">sql</param> /// <param name="parameters">parameters</param> /// <returns>object</returns> public static object execScalar(string sql, Dictionary <string, object> parameters) { using (IDbConnection conn = SQLiteHelper.CreateConnection(m_strDBName)) { return(execScalar(conn, sql, parameters)); } }
/// <summary> /// query dataset /// </summary> /// <param name="sql">sql</param> /// <param name="parameters">parameters</param> /// <returns>DataSet</returns> public static DataSet execDataset(string sql, Dictionary <string, object> parameters) { using (IDbConnection conn = SQLiteHelper.CreateConnection(m_strDBName)) { return(SQLiteHelper.ExecuteDataSet((SQLiteConnection)conn, sql, parameters)); } }
/// <summary> /// exec sql /// </summary> /// <param name="sql">sql</param> /// <param name="parameters">parameters</param> /// <returns>record count</returns> public static int execSQL(string sql, Dictionary <string, object> parameters) { using (IDbConnection conn = SQLiteHelper.CreateConnection(m_strDBName)) { return(SQLiteHelper.ExecuteNonQuery((SQLiteConnection)conn, sql, parameters)); } }
/// <summary> /// query datatable /// </summary> /// <param name="sql">sql</param> /// <param name="parameters">parameters</param> /// <returns>DataTable</returns> public static DataTable execDataTable(string sql, Dictionary <string, object> parameters) { DataTable dt = new DataTable(); using (IDbConnection conn = SQLiteHelper.CreateConnection(m_strDBName)) { using (IDataReader oIDataReader = SQLiteHelper.ExecuteReader((SQLiteConnection)conn, sql, parameters)) { dt.Load(oIDataReader); } } return(dt); }
/// <summary> /// create table /// </summary> /// <param name="strTableName">table name</param> /// <param name="strCreateTableSql">create table sql</param> /// <returns>true:create success</returns> public static bool createDT(string strTableName, string strCreateTableSql) { using (IDbConnection conn = SQLiteHelper.CreateConnection(m_strDBName)) { var strSelectSql = "SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = @TableName"; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("TableName", strTableName); object ob = SQLiteHelper.ExecuteScalar((SQLiteConnection)conn, strSelectSql, parameters); long tableCount = Convert.ToInt64(ob); if (tableCount == 0) { int iRes = SQLiteHelper.ExecuteNonQuery((SQLiteConnection)conn, strCreateTableSql, parameters); return(iRes > 0); } return(true); } }
/// <summary> /// exec trans /// </summary> /// <param name="oAction">SQLiteTransaction callback</param> public static void execQueryTrans(Action <SQLiteTransaction> oAction) { using (SQLiteConnection conn = SQLiteHelper.CreateConnection(m_strDBName)) { conn.Open(); DbTransaction trans = conn.BeginTransaction(); try { oAction((SQLiteTransaction)trans); trans.Commit(); } catch { trans.Rollback(); throw; } } }
/// <summary> /// get database connection /// </summary> /// <returns>IDbConnection</returns> public static IDbConnection getDBCC() { return(SQLiteHelper.CreateConnection(m_strDBName)); }