BulkWriters.cs (1982271B)
1 // This code was generated via a CLI app that used the source code in BulkWriterBaseCase.cs as a template. 2 // To improve compilation performance, the code uses very little 'whitespace' beyond what is necessary and contains no documentation, warning suppressions, or comments. 3 using Microsoft.Data.SqlClient; 4 using Serde.Bin.Ser; 5 using Std; 6 using Std.Iter; 7 using Std.Maybe; 8 using Std.Num; 9 using Std.Result; 10 using System; 11 using System.Data; 12 using System.Diagnostics; 13 using static SQLServer.Helpers; 14 using System.Runtime.InteropServices; 15 #pragma warning disable CA1005, CA1045, CA1051, CA1062, CA1066, CA1815, CA2100, CA2231, IDE0032 16 namespace SQLServer { 17 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 18 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 19 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 20 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 21 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 22 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 23 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 24 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 25 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 26 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 27 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 28 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 29 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 30 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 31 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 32 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 33 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 34 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 35 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 36 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 37 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 38 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 39 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 40 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 41 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 42 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 43 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 44 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 45 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 46 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 47 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 48 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 49 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 50 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 51 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 52 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 53 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 54 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 55 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 56 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 57 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 58 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 59 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 60 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 61 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 62 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 63 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 64 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 65 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 66 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 67 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 68 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 69 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 70 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 71 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 72 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 73 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 74 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 75 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 76 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 77 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 78 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 79 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 80 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 81 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 82 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 83 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 84 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 85 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 86 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 87 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 88 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 89 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 90 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 91 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 92 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 93 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 94 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 95 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 96 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 97 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 98 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 99 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 100 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 101 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 102 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 103 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 104 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 105 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 106 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 107 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 108 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 109 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 110 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 111 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 112 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 113 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 114 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 115 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 116 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 117 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 118 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 119 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 120 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 121 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 122 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 123 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 124 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 125 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 126 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 127 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 128 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 129 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 130 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 131 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 132 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 133 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 134 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 135 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 136 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 137 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 138 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType where T122:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),122=>new(typeof(T122)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 139 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType where T122:struct,IDataType where T123:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),122=>new(typeof(T122)),123=>new(typeof(T123)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 140 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType where T122:struct,IDataType where T123:struct,IDataType where T124:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),122=>new(typeof(T122)),123=>new(typeof(T123)),124=>new(typeof(T124)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 141 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType where T122:struct,IDataType where T123:struct,IDataType where T124:struct,IDataType where T125:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),122=>new(typeof(T122)),123=>new(typeof(T123)),124=>new(typeof(T124)),125=>new(typeof(T125)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 142 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType where T122:struct,IDataType where T123:struct,IDataType where T124:struct,IDataType where T125:struct,IDataType where T126:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),122=>new(typeof(T122)),123=>new(typeof(T123)),124=>new(typeof(T124)),125=>new(typeof(T125)),126=>new(typeof(T126)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 143 [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode,Pack= 0)]public struct BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>:IBulkWriter where T0:struct,IDataType where T1:struct,IDataType where T2:struct,IDataType where T3:struct,IDataType where T4:struct,IDataType where T5:struct,IDataType where T6:struct,IDataType where T7:struct,IDataType where T8:struct,IDataType where T9:struct,IDataType where T10:struct,IDataType where T11:struct,IDataType where T12:struct,IDataType where T13:struct,IDataType where T14:struct,IDataType where T15:struct,IDataType where T16:struct,IDataType where T17:struct,IDataType where T18:struct,IDataType where T19:struct,IDataType where T20:struct,IDataType where T21:struct,IDataType where T22:struct,IDataType where T23:struct,IDataType where T24:struct,IDataType where T25:struct,IDataType where T26:struct,IDataType where T27:struct,IDataType where T28:struct,IDataType where T29:struct,IDataType where T30:struct,IDataType where T31:struct,IDataType where T32:struct,IDataType where T33:struct,IDataType where T34:struct,IDataType where T35:struct,IDataType where T36:struct,IDataType where T37:struct,IDataType where T38:struct,IDataType where T39:struct,IDataType where T40:struct,IDataType where T41:struct,IDataType where T42:struct,IDataType where T43:struct,IDataType where T44:struct,IDataType where T45:struct,IDataType where T46:struct,IDataType where T47:struct,IDataType where T48:struct,IDataType where T49:struct,IDataType where T50:struct,IDataType where T51:struct,IDataType where T52:struct,IDataType where T53:struct,IDataType where T54:struct,IDataType where T55:struct,IDataType where T56:struct,IDataType where T57:struct,IDataType where T58:struct,IDataType where T59:struct,IDataType where T60:struct,IDataType where T61:struct,IDataType where T62:struct,IDataType where T63:struct,IDataType where T64:struct,IDataType where T65:struct,IDataType where T66:struct,IDataType where T67:struct,IDataType where T68:struct,IDataType where T69:struct,IDataType where T70:struct,IDataType where T71:struct,IDataType where T72:struct,IDataType where T73:struct,IDataType where T74:struct,IDataType where T75:struct,IDataType where T76:struct,IDataType where T77:struct,IDataType where T78:struct,IDataType where T79:struct,IDataType where T80:struct,IDataType where T81:struct,IDataType where T82:struct,IDataType where T83:struct,IDataType where T84:struct,IDataType where T85:struct,IDataType where T86:struct,IDataType where T87:struct,IDataType where T88:struct,IDataType where T89:struct,IDataType where T90:struct,IDataType where T91:struct,IDataType where T92:struct,IDataType where T93:struct,IDataType where T94:struct,IDataType where T95:struct,IDataType where T96:struct,IDataType where T97:struct,IDataType where T98:struct,IDataType where T99:struct,IDataType where T100:struct,IDataType where T101:struct,IDataType where T102:struct,IDataType where T103:struct,IDataType where T104:struct,IDataType where T105:struct,IDataType where T106:struct,IDataType where T107:struct,IDataType where T108:struct,IDataType where T109:struct,IDataType where T110:struct,IDataType where T111:struct,IDataType where T112:struct,IDataType where T113:struct,IDataType where T114:struct,IDataType where T115:struct,IDataType where T116:struct,IDataType where T117:struct,IDataType where T118:struct,IDataType where T119:struct,IDataType where T120:struct,IDataType where T121:struct,IDataType where T122:struct,IDataType where T123:struct,IDataType where T124:struct,IDataType where T125:struct,IDataType where T126:struct,IDataType where T127:struct,IDataType{public BulkWriter()=>throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");BulkWriter(UserTable table,Maybe<ErrorTable>errTable,Prod<ulong,double>maxErrorsAllowed,string processName,string userName,bool encrypted,bool encryptedMod)=>(Destination,ErrTable,MaxErrorsAllowed,_currentErrorCount,_currentProcessedCount,_processName,_userName,_containsEncryptedColumn,_mustBeAllowEncryptedValueModifications)=(table,errTable,maxErrorsAllowed,ulong.MinValue,ulong.MinValue,processName,userName,encrypted,encryptedMod);public readonly Maybe<ErrorTable>ErrTable;public readonly UserTable Destination;public readonly Prod<ulong,double>MaxErrorsAllowed;ulong _currentErrorCount;ulong _currentProcessedCount;readonly string _processName;readonly string _userName;readonly bool _containsEncryptedColumn;readonly bool _mustBeAllowEncryptedValueModifications;readonly Maybe<ErrorTable>IBulkWriter.ErrTable=>ErrTable;readonly UserTable IBulkWriter.Destination=>Destination;readonly Prod<ulong,double>IBulkWriter.MaxErrorsAllowed=>MaxErrorsAllowed;public readonly ulong CurrentSuccessfullyProcessedCount=>_currentProcessedCount-_currentErrorCount;public readonly ulong CurrentErrorCount=>_currentErrorCount;public readonly ulong CurrentProcessedCount=>_currentProcessedCount;public readonly double CurrentErrorRatio=>(double)_currentErrorCount/_currentProcessedCount;public readonly bool IsInError=>_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1;public static Result<BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>,BulkWriterCreateError>New(in UserTable table,Prod<ulong,double>maxErrorsAllowed,in Maybe<ErrorTable>errTable,string processName,string userName){if(table.Schema.Database.IsReadOnly){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.DatabaseIsReadOnly,new StackTrace(1,true)));}else if(double.IsNaN(maxErrorsAllowed.Item1)||double.IsNegative(maxErrorsAllowed.Item1)||maxErrorsAllowed.Item1>1.0d){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.InvalidErrorRatio,new StackTrace(1,true)));}else if(processName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.ProcessNameLengthExceeds128,new StackTrace(1,true)));}else if(userName.Length>128){return new(new BulkWriterCreateError(BulkWriterCreateError.Tag.UserNameLengthExceeds128,new StackTrace(1,true)));}else{var counter=ushort.MinValue;var match=TypeMatch(Std.Iter.Functions.FromFn(()=>counter++switch{0=>new(typeof(T0)),1=>new(typeof(T1)),2=>new(typeof(T2)),3=>new(typeof(T3)),4=>new(typeof(T4)),5=>new(typeof(T5)),6=>new(typeof(T6)),7=>new(typeof(T7)),8=>new(typeof(T8)),9=>new(typeof(T9)),10=>new(typeof(T10)),11=>new(typeof(T11)),12=>new(typeof(T12)),13=>new(typeof(T13)),14=>new(typeof(T14)),15=>new(typeof(T15)),16=>new(typeof(T16)),17=>new(typeof(T17)),18=>new(typeof(T18)),19=>new(typeof(T19)),20=>new(typeof(T20)),21=>new(typeof(T21)),22=>new(typeof(T22)),23=>new(typeof(T23)),24=>new(typeof(T24)),25=>new(typeof(T25)),26=>new(typeof(T26)),27=>new(typeof(T27)),28=>new(typeof(T28)),29=>new(typeof(T29)),30=>new(typeof(T30)),31=>new(typeof(T31)),32=>new(typeof(T32)),33=>new(typeof(T33)),34=>new(typeof(T34)),35=>new(typeof(T35)),36=>new(typeof(T36)),37=>new(typeof(T37)),38=>new(typeof(T38)),39=>new(typeof(T39)),40=>new(typeof(T40)),41=>new(typeof(T41)),42=>new(typeof(T42)),43=>new(typeof(T43)),44=>new(typeof(T44)),45=>new(typeof(T45)),46=>new(typeof(T46)),47=>new(typeof(T47)),48=>new(typeof(T48)),49=>new(typeof(T49)),50=>new(typeof(T50)),51=>new(typeof(T51)),52=>new(typeof(T52)),53=>new(typeof(T53)),54=>new(typeof(T54)),55=>new(typeof(T55)),56=>new(typeof(T56)),57=>new(typeof(T57)),58=>new(typeof(T58)),59=>new(typeof(T59)),60=>new(typeof(T60)),61=>new(typeof(T61)),62=>new(typeof(T62)),63=>new(typeof(T63)),64=>new(typeof(T64)),65=>new(typeof(T65)),66=>new(typeof(T66)),67=>new(typeof(T67)),68=>new(typeof(T68)),69=>new(typeof(T69)),70=>new(typeof(T70)),71=>new(typeof(T71)),72=>new(typeof(T72)),73=>new(typeof(T73)),74=>new(typeof(T74)),75=>new(typeof(T75)),76=>new(typeof(T76)),77=>new(typeof(T77)),78=>new(typeof(T78)),79=>new(typeof(T79)),80=>new(typeof(T80)),81=>new(typeof(T81)),82=>new(typeof(T82)),83=>new(typeof(T83)),84=>new(typeof(T84)),85=>new(typeof(T85)),86=>new(typeof(T86)),87=>new(typeof(T87)),88=>new(typeof(T88)),89=>new(typeof(T89)),90=>new(typeof(T90)),91=>new(typeof(T91)),92=>new(typeof(T92)),93=>new(typeof(T93)),94=>new(typeof(T94)),95=>new(typeof(T95)),96=>new(typeof(T96)),97=>new(typeof(T97)),98=>new(typeof(T98)),99=>new(typeof(T99)),100=>new(typeof(T100)),101=>new(typeof(T101)),102=>new(typeof(T102)),103=>new(typeof(T103)),104=>new(typeof(T104)),105=>new(typeof(T105)),106=>new(typeof(T106)),107=>new(typeof(T107)),108=>new(typeof(T108)),109=>new(typeof(T109)),110=>new(typeof(T110)),111=>new(typeof(T111)),112=>new(typeof(T112)),113=>new(typeof(T113)),114=>new(typeof(T114)),115=>new(typeof(T115)),116=>new(typeof(T116)),117=>new(typeof(T117)),118=>new(typeof(T118)),119=>new(typeof(T119)),120=>new(typeof(T120)),121=>new(typeof(T121)),122=>new(typeof(T122)),123=>new(typeof(T123)),124=>new(typeof(T124)),125=>new(typeof(T125)),126=>new(typeof(T126)),127=>new(typeof(T127)),_=>Maybe<Type>.None()}),in table);return match.IsSome?match.Unwrap()?new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>(table,errTable,maxErrorsAllowed,processName,userName,table.ContainsEncryptedColumn(),false)):new(new BulkWriterCreateError(BulkWriterCreateError.Tag.TypeMismatch,new StackTrace(1,true))):new(new BulkWriter<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>(table,errTable,maxErrorsAllowed,processName,userName,true,true));}}public override readonly bool Equals(object?_)=>false;public override readonly int GetHashCode()=>0;readonly void IBulkWriter.Sealed(){}public override readonly string ToString()=>string.Empty;public Result<Unit,WriteError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SessionOptions options)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{var allowEncryptMod=false;if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){allowEncryptMod=true;}else{return new(new WriteError(WriteError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteError(WriteError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}using var con=Functions.CreateOpenedConnection(in Destination.Schema.Database,options,!allowEncryptMod&&_containsEncryptedColumn,Maybe<Uri>.None());if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){using var txn=con.BeginTransaction(IsolationLevel.Serializable);using (SqlCommand qry=new($"SET IDENTITY_INSERT [{Destination.Schema.Name.Value}].[{Destination.Name}] ON;",con,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=60,CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){_=qry.ExecuteNonQuery();}txn.Commit();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,null,(options&SessionOptions.NUMERIC_ROUNDABORT_OFF)!=SessionOptions.NUMERIC_ROUNDABORT_OFF,new StackTrace(1,true).ToString()).MapErr(_writeTxnErrToWriteErr);}public Result<Unit,WriteErrorOrTransactionError>Write<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlTransaction txn)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(txn.Connection.State!=ConnectionState.Open){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionIsNotOpen,new StackTrace(1,true)));}else if(!string.Equals(txn.Connection.DataSource,$"tcp:{Destination.Schema.Database.Server.IntoString()}",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionServerMismatch,new StackTrace(1,true)));}else{if((writeOptions&WriteOptions.AllowEncryptedValueModifications)==WriteOptions.AllowEncryptedValueModifications){if(_containsEncryptedColumn){if(!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.SqlConnectionViolatesAllowEncryptedValueModifications,new StackTrace(1,true)));}}else{return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableExpectedToContainEncryptedDataButDoesNot,new StackTrace(1,true)));}}else if(_mustBeAllowEncryptedValueModifications){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.TableColumnMismatchOrWriteOptionsMustContainAllowEncryptedValueModifications,new StackTrace(1,true)));}else if(_containsEncryptedColumn&&!txn.Connection.ConnectionString.Contains("Column Encryption Setting=enabled",StringComparison.Ordinal)){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.ContainsEncryptedColumnsButConnectionDoesNotHandleEncryptedColumns,new StackTrace(1,true)));}if((writeOptions&WriteOptions.KeepIdentity)==WriteOptions.KeepIdentity&&Destination.ContainsIDENTITYColumn()){bool numericRoundAbort;using (SqlCommand qry=new($@"SET IDENTITY_INSERT [{Destination.Schema.Database.Name.Value}].[{Destination.Schema.Name.Value}].[{Destination.Name}] ON;SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}var tableCopy=Destination;return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString()).MapOrElse((err)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};_=qry.ExecuteNonQuery();return new Result<Unit,WriteErrorOrTransactionError>(err);},(x)=>{using SqlCommand qry=new($"SET IDENTITY_INSERT [{tableCopy.Schema.Database.Name.Value}].[{tableCopy.Schema.Name.Value}].[{tableCopy.Name}] OFF;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true};var unused=qry.ExecuteNonQuery();return new(x);});}else{bool numericRoundAbort;using (SqlCommand qry=new($@"SELECT CASE (@@OPTIONS & 8192) WHEN 8192 THEN CONVERT(bit,1) ELSE CONVERT(bit,0) END AS fblnNumericRoundabort;",txn.Connection,txn,SqlCommandColumnEncryptionSetting.Disabled){CommandTimeout=timeout.MapOr(0,_nzUshortToInt),CommandType=CommandType.Text,EnableOptimizedParameterBinding=true}){numericRoundAbort=(bool)qry.ExecuteScalar();}return WriteInternal<TRowIter,TRow,TProd,TErr>(ref iter,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,txn.Connection,txn,numericRoundAbort,new StackTrace(1,true).ToString());}}}Result<Unit,WriteErrorOrTransactionError>WriteInternal<TRowIter,TRow,TProd,TErr>(ref TRowIter iter,WriteOptions writeOptions,Maybe<NonZeroUshort>batchSize,Maybe<NonZeroUshort>timeout,bool enableStreaming,bool isSortedAccordingToClusteredIndex,SqlConnection con,SqlTransaction?txn,bool numericRoundAbort,string stackTrace)where TErr:notnull,IBulkRowError where TProd:notnull,IBinSerializable,IProduct<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>where TRow:notnull,ISum<TProd,TErr>where TRowIter:notnull,IFusedIterator<TRow>{if(_currentErrorCount>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1){return new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true)));}using var blk=CreateBulkCopy(in Destination,writeOptions,batchSize,timeout,enableStreaming,isSortedAccordingToClusteredIndex,con,txn);using IterDataReader<TRowIter,TRow,TProd,TErr,T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127>rdr=new(ErrTable,Destination,MaxErrorsAllowed,_currentProcessedCount,_currentErrorCount,iter,_processName,_userName,numericRoundAbort,stackTrace);blk.WriteToServer(rdr);_currentProcessedCount=rdr.CurrentProcessedCount;return (_currentErrorCount=rdr.CurrentErrorCount)>MaxErrorsAllowed.Item0&&CurrentErrorRatio>MaxErrorsAllowed.Item1?new(new WriteErrorOrTransactionError(WriteErrorOrTransactionError.Tag.MaxErrorsExceeded,new StackTrace(1,true))):new(new Unit());}} 144 }