[Repository] 增加清空資料表 函式
This commit is contained in:
		
							parent
							
								
									ba03adc2b5
								
							
						
					
					
						commit
						560ec58908
					
				@ -888,5 +888,41 @@ namespace Repository.BaseRepository.Implement
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion AddOneReturnId
 | 
			
		||||
 | 
			
		||||
        #region TruncateTable (清空資料表)
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 清空資料表資料
 | 
			
		||||
        /// TRUNCATE TABLE {tableName}
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="table_name"></param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public virtual async Task TruncateTable(string table_name)
 | 
			
		||||
        {
 | 
			
		||||
            using (IDbConnection conn = GetDbConnection())
 | 
			
		||||
            {
 | 
			
		||||
                conn.Open();
 | 
			
		||||
                using (var trans = conn.BeginTransaction())
 | 
			
		||||
                {
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        var sql = $"TRUNCATE TABLE {table_name}";
 | 
			
		||||
                        await conn.ExecuteAsync(sql, null, trans);
 | 
			
		||||
 | 
			
		||||
                        trans.Commit();
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (Exception exception)
 | 
			
		||||
                    {
 | 
			
		||||
                        trans.Rollback();
 | 
			
		||||
                        throw exception;
 | 
			
		||||
                    }
 | 
			
		||||
                    finally
 | 
			
		||||
                    {
 | 
			
		||||
                        conn.Close();
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        #endregion TruncateTable
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -181,5 +181,12 @@ namespace Repository.BaseRepository.Interface
 | 
			
		||||
        /// <returns>
 | 
			
		||||
        /// </returns>
 | 
			
		||||
        Task<int> AddOneByCustomTableReturnId(Dictionary<string, object> dict, string Table_name, bool returnId = true);
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 清空table資料
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="table_name">資料表名稱</param>
 | 
			
		||||
        /// <returns>
 | 
			
		||||
        /// </returns>
 | 
			
		||||
        Task TruncateTable(string table_name);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user