示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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;
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
 public void Save(DatabaseContext context)
 {
     if (batchID == 0)
     {
         Create(context);
     }
     else
     {
         Modify(context);
     }
 }
示例#6
0
        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();
            }
        }
示例#7
0
        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));
                    }
                }
            }
        }
示例#8
0
        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);
                }
            }
        }
示例#9
0
 public void CreateChunks(DatabaseContext context)
 {
     foreach (var c in chunks)
     {
         CreateChunk(c, context);
     }
 }