Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Update() [2/5]

virtual int System.Data.Common.DbDataAdapter.Update ( DataRow[] dataRows,
DataTableMapping tableMapping )
inlineprotectedvirtual

Definition at line 881 of file DbDataAdapter.cs.

882 {
883 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataRows[], tableMapping", base.ObjectID);
884 try
885 {
886 int num = 0;
887 IDbConnection[] array = new IDbConnection[5];
889 bool useSelectConnectionState = false;
891 if (selectCommand != null)
892 {
893 array[0] = selectCommand.Connection;
894 if (array[0] != null)
895 {
896 array2[0] = array[0].State;
898 }
899 }
900 int num2 = Math.Min(UpdateBatchSize, dataRows.Length);
901 if (num2 < 1)
902 {
903 num2 = dataRows.Length;
904 }
905 BatchCommandInfo[] array3 = new BatchCommandInfo[num2];
906 DataRow[] array4 = new DataRow[num2];
907 int num3 = 0;
908 try
909 {
910 try
911 {
912 if (1 != num2)
913 {
915 }
916 StatementType statementType = StatementType.Select;
917 IDbCommand dbCommand = null;
918 foreach (DataRow dataRow in dataRows)
919 {
920 if (dataRow == null)
921 {
922 continue;
923 }
924 bool flag = false;
925 DataRowState rowState = dataRow.RowState;
926 if (rowState <= DataRowState.Added)
927 {
928 if ((uint)(rowState - 1) <= 1u)
929 {
930 continue;
931 }
932 if (rowState != DataRowState.Added)
933 {
934 goto IL_0115;
935 }
936 statementType = StatementType.Insert;
938 }
939 else if (rowState != DataRowState.Deleted)
940 {
941 if (rowState != DataRowState.Modified)
942 {
943 goto IL_0115;
944 }
945 statementType = StatementType.Update;
947 }
948 else
949 {
950 statementType = StatementType.Delete;
952 }
954 try
955 {
956 dataRow.RowError = null;
957 if (dbCommand != null)
958 {
960 }
961 }
962 catch (Exception ex) when (ADP.IsCatchableExceptionType(ex))
963 {
964 ADP.TraceExceptionForCapture(ex);
965 rowUpdatingEventArgs.Errors = ex;
966 rowUpdatingEventArgs.Status = UpdateStatus.ErrorsOccurred;
967 }
969 IDbCommand command = rowUpdatingEventArgs.Command;
970 flag = dbCommand != command;
972 command = null;
973 UpdateStatus status = rowUpdatingEventArgs.Status;
974 if (status != 0)
975 {
976 if (UpdateStatus.ErrorsOccurred == status)
977 {
979 continue;
980 }
981 if (UpdateStatus.SkipCurrentRow == status)
982 {
983 if (DataRowState.Unchanged == dataRow.RowState)
984 {
985 num++;
986 }
987 continue;
988 }
989 if (UpdateStatus.SkipAllRemainingRows == status)
990 {
991 if (DataRowState.Unchanged == dataRow.RowState)
992 {
993 num++;
994 }
995 break;
996 }
997 throw ADP.InvalidUpdateStatus(status);
998 }
1000 RowUpdatedEventArgs rowUpdatedEventArgs = null;
1001 if (1 == num2)
1002 {
1003 if (dbCommand != null)
1004 {
1005 array3[0]._commandIdentifier = 0;
1006 array3[0]._parameterCount = dbCommand.Parameters.Count;
1007 array3[0]._statementType = statementType;
1008 array3[0]._updatedRowSource = dbCommand.UpdatedRowSource;
1009 }
1010 array3[0]._row = dataRow;
1011 array4[0] = dataRow;
1012 num3 = 1;
1013 }
1014 else
1015 {
1016 Exception ex2 = null;
1017 try
1018 {
1019 if (dbCommand != null)
1020 {
1021 if ((UpdateRowSource.FirstReturnedRecord & dbCommand.UpdatedRowSource) == 0)
1022 {
1023 array3[num3]._commandIdentifier = AddToBatch(dbCommand);
1024 array3[num3]._parameterCount = dbCommand.Parameters.Count;
1025 array3[num3]._row = dataRow;
1026 array3[num3]._statementType = statementType;
1027 array3[num3]._updatedRowSource = dbCommand.UpdatedRowSource;
1028 array4[num3] = dataRow;
1029 num3++;
1030 if (num3 < num2)
1031 {
1032 continue;
1033 }
1034 }
1035 else
1036 {
1037 ex2 = ADP.ResultsNotAllowedDuringBatch();
1038 }
1039 }
1040 else
1041 {
1042 ex2 = ADP.UpdateRequiresCommand(statementType, flag);
1043 }
1044 }
1045 catch (Exception ex3) when (ADP.IsCatchableExceptionType(ex3))
1046 {
1047 ADP.TraceExceptionForCapture(ex3);
1048 ex2 = ex3;
1049 }
1050 if (ex2 != null)
1051 {
1053 rowUpdatedEventArgs.Errors = ex2;
1054 rowUpdatedEventArgs.Status = UpdateStatus.ErrorsOccurred;
1056 if (ex2 != rowUpdatedEventArgs.Errors)
1057 {
1058 for (int j = 0; j < array3.Length; j++)
1059 {
1060 array3[j]._errors = null;
1061 }
1062 }
1064 if (UpdateStatus.SkipAllRemainingRows == rowUpdatedEventArgs.Status)
1065 {
1066 break;
1067 }
1068 continue;
1069 }
1070 }
1072 try
1073 {
1074 if (1 != num2)
1075 {
1076 IDbConnection connection = GetConnection1(this);
1078 rowUpdatedEventArgs.AdapterInit(array4);
1079 if (ConnectionState.Open == connectionState)
1080 {
1082 }
1083 else
1084 {
1085 rowUpdatedEventArgs.Errors = ADP.UpdateOpenConnectionRequired(StatementType.Batch, isRowUpdatingCommand: false, connectionState);
1086 rowUpdatedEventArgs.Status = UpdateStatus.ErrorsOccurred;
1087 }
1088 }
1089 else if (dbCommand != null)
1090 {
1091 IDbConnection connection2 = GetConnection4(this, dbCommand, statementType, flag);
1094 {
1096 array3[0]._recordsAffected = rowUpdatedEventArgs.RecordsAffected;
1097 array3[0]._errors = null;
1098 }
1099 else
1100 {
1101 rowUpdatedEventArgs.Errors = ADP.UpdateOpenConnectionRequired(statementType, flag, connectionState2);
1102 rowUpdatedEventArgs.Status = UpdateStatus.ErrorsOccurred;
1103 }
1104 }
1105 else
1106 {
1107 rowUpdatedEventArgs.Errors = ADP.UpdateRequiresCommand(statementType, flag);
1108 rowUpdatedEventArgs.Status = UpdateStatus.ErrorsOccurred;
1109 }
1110 }
1111 catch (Exception ex4) when (ADP.IsCatchableExceptionType(ex4))
1112 {
1113 ADP.TraceExceptionForCapture(ex4);
1114 rowUpdatedEventArgs.Errors = ex4;
1115 rowUpdatedEventArgs.Status = UpdateStatus.ErrorsOccurred;
1116 }
1117 bool flag2 = UpdateStatus.ErrorsOccurred == rowUpdatedEventArgs.Status;
1118 Exception errors = rowUpdatedEventArgs.Errors;
1120 if (errors != rowUpdatedEventArgs.Errors)
1121 {
1122 for (int k = 0; k < array3.Length; k++)
1123 {
1124 array3[k]._errors = null;
1125 }
1126 }
1128 if (UpdateStatus.SkipAllRemainingRows == rowUpdatedEventArgs.Status)
1129 {
1130 if (flag2 && 1 != num2)
1131 {
1132 ClearBatch();
1133 num3 = 0;
1134 }
1135 break;
1136 }
1137 if (1 != num2)
1138 {
1139 ClearBatch();
1140 num3 = 0;
1141 }
1142 for (int l = 0; l < array3.Length; l++)
1143 {
1144 array3[l] = default(BatchCommandInfo);
1145 }
1146 num3 = 0;
1147 continue;
1148 IL_0115:
1149 throw ADP.InvalidDataRowState(dataRow.RowState);
1150 }
1151 if (1 != num2 && 0 < num3)
1152 {
1154 try
1155 {
1156 IDbConnection connection3 = GetConnection1(this);
1158 DataRow[] array5 = array4;
1159 if (num3 < array4.Length)
1160 {
1161 array5 = new DataRow[num3];
1162 Array.Copy(array4, array5, num3);
1163 }
1164 rowUpdatedEventArgs2.AdapterInit(array5);
1166 {
1168 }
1169 else
1170 {
1171 rowUpdatedEventArgs2.Errors = ADP.UpdateOpenConnectionRequired(StatementType.Batch, isRowUpdatingCommand: false, connectionState3);
1172 rowUpdatedEventArgs2.Status = UpdateStatus.ErrorsOccurred;
1173 }
1174 }
1175 catch (Exception ex5) when (ADP.IsCatchableExceptionType(ex5))
1176 {
1177 ADP.TraceExceptionForCapture(ex5);
1178 rowUpdatedEventArgs2.Errors = ex5;
1179 rowUpdatedEventArgs2.Status = UpdateStatus.ErrorsOccurred;
1180 }
1181 Exception errors2 = rowUpdatedEventArgs2.Errors;
1183 if (errors2 != rowUpdatedEventArgs2.Errors)
1184 {
1185 for (int m = 0; m < array3.Length; m++)
1186 {
1187 array3[m]._errors = null;
1188 }
1189 }
1191 }
1192 }
1193 finally
1194 {
1195 if (1 != num2)
1196 {
1198 }
1199 }
1200 }
1201 finally
1202 {
1203 for (int n = 0; n < array.Length; n++)
1204 {
1206 }
1207 }
1208 return num;
1209 }
1210 finally
1211 {
1212 DataCommonEventSource.Log.ExitScope(scopeId);
1213 }
1214 }
void UpdateRowExecute(RowUpdatedEventArgs rowUpdatedEvent, IDbCommand dataCommand, StatementType cmdIndex)
virtual RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand? command, StatementType statementType, DataTableMapping tableMapping)
virtual void OnRowUpdated(RowUpdatedEventArgs value)
static IDbConnection GetConnection4(DbDataAdapter adapter, IDbCommand command, StatementType statementType, bool isCommandFromRowUpdating)
virtual void OnRowUpdating(RowUpdatingEventArgs value)
ConnectionState UpdateConnectionOpen(IDbConnection connection, StatementType statementType, IDbConnection[] connections, ConnectionState[] connectionStates, bool useSelectConnectionState)
static void QuietClose(IDbConnection connection, ConnectionState originalState)
virtual int AddToBatch(IDbCommand command)
virtual RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand? command, StatementType statementType, DataTableMapping tableMapping)
void UpdateBatchExecute(BatchCommandInfo[] batchCommands, int commandCount, RowUpdatedEventArgs rowUpdatedEvent)
static IDbConnection GetConnection1(DbDataAdapter adapter)
void ParameterInput(IDataParameterCollection parameters, StatementType typeIndex, DataRow row, DataTableMapping mappings)
void UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow)
int UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, int commandCount)

References System.Data.Common.DbDataAdapter._IDbDataAdapter, System.Data.Common.DbDataAdapter.AddToBatch(), System.array, System.Data.Common.DbDataAdapter.ClearBatch(), System.Array.Copy(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Data.Common.DbDataAdapter.CreateRowUpdatedEvent(), System.Data.Common.DbDataAdapter.CreateRowUpdatingEvent(), System.Data.IDbDataAdapter.DeleteCommand, System.Data.Common.DbDataAdapter.GetConnection1(), System.Data.Common.DbDataAdapter.GetConnection4(), System.Data.Common.DbDataAdapter.InitializeBatching(), System.Data.IDbDataAdapter.InsertCommand, System.Data.Common.ADP.InvalidDataRowState(), System.Data.Common.ADP.InvalidUpdateStatus(), System.Data.Common.ADP.IsCatchableExceptionType(), System.Data.DataCommonEventSource.Log, System.Math.Min(), System.Data.Common.DbDataAdapter.OnRowUpdated(), System.Data.Common.DbDataAdapter.OnRowUpdating(), System.Data.Common.DbDataAdapter.ParameterInput(), System.Data.Common.DbDataAdapter.QuietClose(), System.Data.Common.ADP.ResultsNotAllowedDuringBatch(), System.Data.IDbDataAdapter.SelectCommand, System.Data.Common.DbDataAdapter.TerminateBatching(), System.Data.Common.ADP.TraceExceptionForCapture(), System.Data.Common.DbDataAdapter.UpdateBatchExecute(), System.Data.Common.DbDataAdapter.UpdateBatchSize, System.Data.IDbDataAdapter.UpdateCommand, System.Data.Common.DbDataAdapter.UpdateConnectionOpen(), System.Data.Common.DbDataAdapter.UpdatedRowStatus(), System.Data.Common.ADP.UpdateOpenConnectionRequired(), System.Data.Common.ADP.UpdateRequiresCommand(), System.Data.Common.DbDataAdapter.UpdateRowExecute(), and System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors().