private void SetIdentityInsert(ICsvTable csvTable, StringBuilder builder, string value) { if (csvTable.HasIdentity) { builder.AppendFormat(SetIdentityInsertFormatString, csvTable.Name, value); } }
private void GenerateInserts(ICsvTable csvTable, string file) { string columnNames = null; using (var fp = File.OpenRead(file)){ var data = new StreamReader(fp).ReadLine(); columnNames = (data ?? string.Empty) .Split(',') .Select(x => string.Format("[{0}]", x)) .Aggregate((x, y) => string.Format("{0},{1}", x, y)); } csvTable.Write(string.Format(INSERT_HEADER_FORMAT, _headerEscapingStrategy.Escape(csvTable.Name), file, columnNames)); }
private void GenerateInserts(ICsvTable csvTable) { string insertHeader = string.Format(InsertHeaderFormat, _headerEscapingStrategy.Escape(csvTable.Name), String.Join(",", _headerEscapingStrategy.Escape(csvTable.GetColumnNames()))); var builder = new StringBuilder(); StartFile(csvTable, builder, insertHeader); int i = 0; string separator = string.Empty; while (csvTable.ReadNextRow()) { if (i != 0 && i%_numberOfRowsPerInsert == 0) { EndFile(csvTable, builder); StartFile(csvTable, builder, insertHeader); separator = string.Empty; } InsertRow(csvTable, builder, separator); separator = ","; i++; } if (i != 0) EndFile(csvTable, builder); }
public void Convert(ICsvTable csvTable, string file) { GenerateInserts(csvTable, file); }
private void EndFile(ICsvTable csvTable, StringBuilder builder) { TurnOffIdentityInsert(csvTable, builder); csvTable.Write(builder.ToString()); builder.Clear(); }
public void Convert(ICsvTable csvTable) { GenerateInserts(csvTable); }
private void TurnOnIdentityInsert(ICsvTable csvTable, StringBuilder builder) { SetIdentityInsert(csvTable, builder, On); }
private void StartFile(ICsvTable csvTable, StringBuilder builder, string insertHeader) { TurnOnIdentityInsert(csvTable, builder); builder.Append(insertHeader); }
private void InsertRow(ICsvTable csvTable, StringBuilder builder, string separator) { string insertValues = String.Join(",", _valueEscapingStrategy.Escape(csvTable.GetValues())); builder.AppendFormat(InsertFormat, separator, insertValues); }