Exemplo n.º 1
0
        protected override void DoBulkInsert(ITableData data)
        {
            data.Definition.EnsureColumns(this, true);

            var TN = new ObjectNameDescriptor(data.Definition.Name, ConnectionManagerType.Postgres);
            var quotedDestColumns = data.Definition.ColumnsSynchronized.Names().Select(col => TN.QB + col + TN.QE);

            using (var writer = DbConnection.BeginBinaryImport($@"
COPY {TN.QuotatedFullName} ({string.Join(", ", quotedDestColumns)})
FROM STDIN (FORMAT BINARY)"))
            {
                foreach (var row in data.EnumerateRowsAndConvertValuesToNETDataType())
                {
                    writer.StartRow();
                    foreach (var column in row)
                    {
                        if (column.value != null)
                        {
                            writer.Write(column.value, column.column.InternalDataType.ToLower());
                        }
                        else
                        {
                            writer.WriteNull();
                        }
                    }
                }
                writer.Complete();
            }
        }