Ejemplo n.º 1
0
 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));
        }
Ejemplo n.º 3
0
        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);
 }
Ejemplo n.º 5
0
 private void EndFile(ICsvTable csvTable, StringBuilder builder)
 {
     TurnOffIdentityInsert(csvTable, builder);
     csvTable.Write(builder.ToString());
     builder.Clear();
 }
Ejemplo n.º 6
0
 public void Convert(ICsvTable csvTable)
 {
     GenerateInserts(csvTable);
 }
Ejemplo n.º 7
0
 private void TurnOnIdentityInsert(ICsvTable csvTable, StringBuilder builder)
 {
     SetIdentityInsert(csvTable, builder, On);
 }
Ejemplo n.º 8
0
 private void StartFile(ICsvTable csvTable, StringBuilder builder, string insertHeader)
 {
     TurnOnIdentityInsert(csvTable, builder);
     builder.Append(insertHeader);
 }
Ejemplo n.º 9
0
 private void InsertRow(ICsvTable csvTable, StringBuilder builder, string separator)
 {
     string insertValues = String.Join(",", _valueEscapingStrategy.Escape(csvTable.GetValues()));
     builder.AppendFormat(InsertFormat, separator, insertValues);
 }