private long WriteTableDataToDataFile(ITableDefinition tableDefinition, string dataFileSuffix) { long rowCounter = 0; using (DataFileTextWriter dataWriter = new DataFileTextWriter(Directory + tableDefinition.Name + "." + dataFileSuffix, UseCompression)) { string selectStmt = CreateSelectStatement(tableDefinition); IDataCursor cursor = _dbContext.PowerPlant.CreateDataCursor(); try { IDataReader reader = cursor.ExecuteReader(selectStmt, tableDefinition.HasBlobColumn); while (reader.Read()) { WriteRow(rowCounter, reader, tableDefinition, dataWriter); dataWriter.WriteLine(); if (rowCounter % 10000 == 0) { _logger.Write($"...... reached row {rowCounter} for {tableDefinition.Name} ......"); } rowCounter++; } } finally { cursor.Close(); } } return(rowCounter); }
private void WriteRow(long rowCounter, IDataReader reader, ITableDefinition tableDefinition, DataFileTextWriter dataWriter) { for (int i = 0; i < tableDefinition.Columns.Count; i++) { if (reader.IsDBNull(i)) { dataWriter.Write("NULL,"); continue; } if (tableDefinition.Columns[i].Type == ColumnTypeName.Blob || tableDefinition.Columns[i].Type == ColumnTypeName.OldBlob) { string rawFileName = $"i{rowCounter:D15}.raw"; dataWriter.Write(rawFileName); WriteBlobColumn(i, $@"{Directory}{tableDefinition.Name}\{rawFileName}", reader); } else { dataWriter.Write(tableDefinition.Columns[i].ToString(reader.GetValue(i))); } dataWriter.Write(","); } }