private void Modify(DatabaseContext context) { var sql = @" UPDATE batch SET target_db = @target_db, loader_db = @loader_db, source_path = @source_path, file_suffix = @file_suffix, bulk_path = @bulk_path, binary = @binary, column_orders = @column_orders WHERE batch_id = @batch_id"; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { cmd.Parameters.Add("@batch_id", SqlDbType.Int).Value = batchID; AppendCreateModifyParameters(cmd); cmd.ExecuteNonQuery(); } }
public void CreateChunk(Chunk chunk, DatabaseContext context) { var sql = @" INSERT chunk (batch_id, chunk_id, prepare_start, prepare_end, load_start, load_end, merge_start, merge_end, cleanup_start, cleanup_end) VALUES (@batch_id, @chunk_id, @prepare_start, @prepare_end, @load_start, @load_end, @merge_start, @merge_end, @cleanup_start, @cleanup_end); "; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { AppendChunkCreateModifyParameters(chunk, cmd); cmd.ExecuteNonQuery(); } }
private void Create(DatabaseContext context) { var sql = @" INSERT batch (target_db, loader_db, source_path, file_suffix, bulk_path, binary, column_orders) VALUES (@target_db, @loader_db, @source_path, @file_suffix, @bulk_path, @binary, @column_orders); SELECT CAST(@@IDENTITY AS int)"; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { AppendCreateModifyParameters(cmd); var res = cmd.ExecuteScalar(); batchID = (int)res; } }
private void DeleteChunks(DatabaseContext context) { var sql = "DELETE chunk WHERE batch_id = @batch_id"; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { cmd.Parameters.Add("@batch_id", SqlDbType.Int).Value = batchID; cmd.ExecuteNonQuery(); } }
public void Save(DatabaseContext context) { if (batchID == 0) { Create(context); } else { Modify(context); } }
public void ModifyChunk(Chunk chunk, DatabaseContext context) { var sql = @" UPDATE chunk SET prepare_start = @prepare_start, prepare_end = @prepare_end, load_start = @load_start, load_end = @load_end, merge_start = @merge_start, merge_end = @merge_end, cleanup_start = @cleanup_end WHERE batch_id = @batch_id AND chunk_id = @chunk_id"; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { AppendChunkCreateModifyParameters(chunk, cmd); cmd.ExecuteNonQuery(); } }
public void LoadChunks(DatabaseContext context) { chunks.Clear(); var sql = "SELECT * FROM chunk WHERE batch_id = @batch_id"; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { cmd.Parameters.Add("@batch_id", SqlDbType.Int).Value = batchID; using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { chunks.Add(LoadChunkFromDataReader(dr)); } } } }
public void Load(DatabaseContext context) { var sql = @"SELECT * FROM batch WHERE batch_id = @batch_id"; using (var cmd = new SqlCommand(sql, context.Connection, context.Transaction)) { cmd.Parameters.Add("@batch_id", SqlDbType.Int).Value = batchID; using (var dr = cmd.ExecuteReader()) { dr.Read(); LoadFromDataReader(dr); } } }
public void CreateChunks(DatabaseContext context) { foreach (var c in chunks) { CreateChunk(c, context); } }