Ejemplo n.º 1
0
        /// <summary>
        /// 将IOperateSection转换为Sql语句执行
        /// </summary>
        /// <param name="db">数据库对象</param>
        /// <param name="sections"></param>
        /// <returns></returns>
        public static int BatchExecute(EDatabase db, params string[] sqls)
        {
            int nReturn      = 0;
            int nMaxSqlLenth = 8000 - 1;//最大的执行Sql语句的长度

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                StringBuilder sbSql = new StringBuilder();
                for (int i = 0; i < sqls.Length; i++)
                {
                    string strSql = sqls[i];

                    if (sbSql.Length + strSql.Length < nMaxSqlLenth)
                    {
                        sbSql.Append(strSql).Append(";");
                    }
                    else
                    {
                        nReturn += db.ExecuteNonQuery(sbSql.ToString());
                        sbSql.Remove(0, sbSql.Length);
                    }
                }
            }
            return(nReturn);
        }
Ejemplo n.º 2
0
 public static DataTable GetOneDataByID(EDatabase db, IQueryTable table, object id)
 {
     if (id != null)
     {
         return(db.Select(table).Where(table.IDColumn == id).ToDataTable());
     }
     return(null);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取总记录条数
        /// </summary>
        /// <param name="column">主键</param>
        /// <returns></returns>
        public static int GetTotalRecord(EDatabase db, IQueryTable table, WhereClip where, List <JoinTable> joinTables)
        {
            SelectSqlSection sql = db.Select(table, table.IDColumn.Count());

            if (joinTables != null && joinTables.Count > 0)
            {
                foreach (JoinTable joinTable in joinTables)
                {
                    joinTable.Join(sql);
                }
            }
            object obj = sql.Where(where).ToScalar();

            if (obj != null)
            {
                return(Convert.ToInt32(obj));
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 4
0
 public ModalAdapter(IQueryTable table, EDatabase db)
 {
     this._DB            = db;
     this._DB.QueryTable = table;
     this._tableName     = this._DB.QueryTable.GetTableName();
 }
Ejemplo n.º 5
0
 public SearchHelper(IQueryTable table, EDatabase db)
 {
     this._Table = table;
     this._DB    = db;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 获取总的数据条数
 /// </summary>
 /// <param name="DB"></param>
 /// <param name="column"></param>
 /// <returns></returns>
 public static int GetTotalRecord(EDatabase db, IQueryTable table, QueryColumn column, WhereClip where)
 {
     return(Convert.ToInt32(db.Select(table, column.Count()).Where(where).ToScalar()));
 }
Ejemplo n.º 7
0
        public static int DeleteByWhere(EDatabase db, IQueryTable table, WhereClip where, bool withTran)
        {
            DeleteSqlSection delSection = db.Delete(table).Where(where);

            return(withTran ? delSection.ExecuteWithTran() : delSection.Execute());
        }
Ejemplo n.º 8
0
 public static int DeleteByIDs(EDatabase db, IQueryTable table, string ids, bool withTran)
 {
     return(DeleteByWhere(db, table, table.IDColumn.In(ids.Split(',')), withTran));
 }
Ejemplo n.º 9
0
 public static int DeleteByIDs(EDatabase db, IQueryTable table, string ids)
 {
     return(DeleteByIDs(db, table, ids, false));
 }
Ejemplo n.º 10
0
 public static bool DeleteByID(EDatabase db, IQueryTable table, string id)
 {
     return(db.Delete(table).Where(table.IDColumn == id).Execute() == 1);
 }