/// <summary> /// Saves Blob to file -> returns Blob pointer -> generates script insert for blobs as PK|BlobPointer to keep track /// After migrating data for a table (which contains Blob), will need this data to set Blob pointer /// </summary> /// <param name="blobMappings">The BLOB mappings.</param> /// <returns></returns> private bool HandleBlobFields(List <FieldMappingDefinition> blobMappings, out string blobScript) { Console.WriteLine("Handling Blob for " + _definition.SourceTable.Name); blobScript = ""; string insertScript = string.Format(SqlScriptTemplates.INSERT, "[TempDatabase].dbo.[BlobPointers]", "([PKValue], [BlobFieldName], [BlobPointer])"); StringBuilder valuesScriptBuilder = new StringBuilder(); blobMappings.ForEach(m => { var blobs = _sourceDatabase.GetBlobs(_definition.SourceTable.Name, m.SourceField.Name); blobs.ForEach(b => { byte[] data = b.Value; string blobPointer = BlobConverter.ConvertToFile(m.BlobCategory, m.BlobCategory, data); valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}','{2}')", b.Key, m.SourceField.Name, blobPointer) + ","); }); }); if (valuesScriptBuilder.Length == 0) { return(false); } string valuesScript = valuesScriptBuilder.ToString().Trim(','); blobScript = insertScript + Environment.NewLine + string.Format(SqlScriptTemplates.INSERT_VALUES, valuesScript); return(true); }