public virtual void FillTable(ITableStructure table, IDataQueue queue, TableCopyOptions opts) { var colnames = from c in queue.GetRowFormat.Columns select c.ColumnName; bool autoinc = queue.GetRowFormat.FindAutoIncrementColumn() != null; if (autoinc) { m_dmp.AllowIdentityInsert(table.FullName, true); } try { while (!queue.IsEof) { IBedRecord row = queue.GetRecord(); m_dmp.PutCmd("^insert ^into %f (%,i) ^values (%,v)", table, colnames, row); } } finally { queue.CloseReading(); } if (autoinc) { m_dmp.AllowIdentityInsert(table.FullName, false); } }
protected void GenerateFillTable(ITableStructure tbl, ISqlDumper dmp) { var autocol = tbl.FindAutoIncrementColumn(); if (autocol != null) { dmp.AllowIdentityInsert(tbl.FullName, true); } var colnames = from c in tbl.Columns select c.ColumnName; dmp.PutCmd("^insert ^into %f (%,i) ^select %,i ^from %s.%f", tbl.FullName, colnames, colnames, SourceDb, tbl.FullName); if (autocol != null) { dmp.AllowIdentityInsert(tbl.FullName, false); } }
public override void GenSql(ISqlDumper dmp) { dmp.AllowIdentityInsert(TableName, AllowIdentityInsert); }
private void InsertTableData(TableInfo table) { if (!_options.TableOptions.Insert) { return; } ColumnInfo autoinc = table.FindAutoIncrementColumn(); if (autoinc != null && !_options.TableOptions.SkipAutoincrementColumn) { _dmp.AllowIdentityInsert(table.FullName, true); } var colIndexes = new List <int>(); for (int i = 0; i < table.ColumnCount; i++) { colIndexes.Add(i); } var colNames = table.Columns.Select(x => x.Name).ToList(); if (_options.TableOptions.SkipAutoincrementColumn && autoinc != null) { int index = table.Columns.IndexOf(autoinc); colIndexes.RemoveAt(index); colNames.RemoveAt(index); } var colIndexesArray = colIndexes.ToArray(); using (var reader = CreateTableReader(table, out var cmd)) { try { int processedRows = 0; while (reader.Read()) { if (IsFull || _isCanceled) { cmd.Cancel(); return; } LogMessage($"Exported {processedRows} rows from {table.Name}"); if (_options.TableOptions.OmitNulls) { var values = reader.GetValuesByCols(colIndexesArray).ToList(); var colNamesCopy = new List <string>(colNames); for (int i = values.Count - 1; i >= 0; i--) { if (values[i] == null) { values.RemoveAt(i); colNamesCopy.RemoveAt(i); } } _dmp.Put("^insert ^into %f (%,i) ^values (%,v);&n", table.FullName, colNamesCopy, values); } else { _dmp.Put("^insert ^into %f (%,i) ^values (%,v);&n", table.FullName, colNames, reader.GetValuesByCols(colIndexesArray)); } if (_sqlo.CurrentCommandLength > MaxBatchInsertSize) { _dmp.EndCommand(); } processedRows++; } } finally { _cancelable?.RemoveCancelMethod(cmd); } } if (autoinc != null && !_options.TableOptions.SkipAutoincrementColumn) { _dmp.AllowIdentityInsert(table.FullName, false); } }