Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DbDataAdapter.cs
Go to the documentation of this file.
5
6namespace System.Data.Common;
7
9{
10 private struct BatchCommandInfo
11 {
12 internal int _commandIdentifier;
13
14 internal int _parameterCount;
15
16 internal DataRow _row;
17
19
21
22 internal int? _recordsAffected;
23
25 }
26
27 public const string DefaultSourceTableName = "Table";
28
29 internal static readonly object s_parameterValueNonNullValue = 0;
30
31 internal static readonly object s_parameterValueNullValue = 1;
32
34
36
38
40
42
44
45 [Browsable(false)]
48 {
49 get
50 {
52 }
53 set
54 {
55 _IDbDataAdapter.DeleteCommand = value;
56 }
57 }
58
59 IDbCommand? IDbDataAdapter.DeleteCommand
60 {
61 get
62 {
63 return _deleteCommand;
64 }
65 set
66 {
68 }
69 }
70
72 {
73 get
74 {
75 return _fillCommandBehavior | CommandBehavior.SequentialAccess;
76 }
77 set
78 {
79 _fillCommandBehavior = value | CommandBehavior.SequentialAccess;
80 }
81 }
82
83 [Browsable(false)]
86 {
87 get
88 {
90 }
91 set
92 {
93 _IDbDataAdapter.InsertCommand = value;
94 }
95 }
96
97 IDbCommand? IDbDataAdapter.InsertCommand
98 {
99 get
100 {
101 return _insertCommand;
102 }
103 set
104 {
106 }
107 }
108
109 [Browsable(false)]
112 {
113 get
114 {
116 }
117 set
118 {
119 _IDbDataAdapter.SelectCommand = value;
120 }
121 }
122
123 IDbCommand? IDbDataAdapter.SelectCommand
124 {
125 get
126 {
127 return _selectCommand;
128 }
129 set
130 {
132 }
133 }
134
135 [DefaultValue(1)]
136 public virtual int UpdateBatchSize
137 {
138 get
139 {
140 return 1;
141 }
142 set
143 {
144 if (1 != value)
145 {
146 throw ADP.NotSupported();
147 }
148 }
149 }
150
151 [Browsable(false)]
154 {
155 get
156 {
158 }
159 set
160 {
161 _IDbDataAdapter.UpdateCommand = value;
162 }
163 }
164
165 IDbCommand? IDbDataAdapter.UpdateCommand
166 {
167 get
168 {
169 return _updateCommand;
170 }
171 set
172 {
174 }
175 }
176
178 {
179 get
180 {
181 if (MissingMappingAction.Passthrough == base.MissingMappingAction)
182 {
183 return MissingMappingAction.Passthrough;
184 }
185 return MissingMappingAction.Error;
186 }
187 }
188
190 {
191 get
192 {
193 MissingSchemaAction missingSchemaAction = base.MissingSchemaAction;
195 {
196 return MissingSchemaAction.Ignore;
197 }
198 return MissingSchemaAction.Error;
199 }
200 }
201
202 protected DbDataAdapter()
203 {
204 }
205
206 protected DbDataAdapter(DbDataAdapter adapter)
207 : base(adapter)
208 {
209 CloneFrom(adapter);
210 }
211
212 protected virtual int AddToBatch(IDbCommand command)
213 {
214 throw ADP.NotSupported();
215 }
216
217 protected virtual void ClearBatch()
218 {
219 throw ADP.NotSupported();
220 }
221
223 {
225 dbDataAdapter.CloneFrom(this);
226 return dbDataAdapter;
227 }
228
230 {
231 IDbDataAdapter iDbDataAdapter = from._IDbDataAdapter;
232 _IDbDataAdapter.SelectCommand = CloneCommand(iDbDataAdapter.SelectCommand);
233 _IDbDataAdapter.InsertCommand = CloneCommand(iDbDataAdapter.InsertCommand);
234 _IDbDataAdapter.UpdateCommand = CloneCommand(iDbDataAdapter.UpdateCommand);
235 _IDbDataAdapter.DeleteCommand = CloneCommand(iDbDataAdapter.DeleteCommand);
236 }
237
239 {
240 return (IDbCommand)((command is ICloneable) ? ((ICloneable)command).Clone() : null);
241 }
242
247
252
253 protected override void Dispose(bool disposing)
254 {
255 if (disposing)
256 {
257 ((IDbDataAdapter)this).SelectCommand = null;
258 ((IDbDataAdapter)this).InsertCommand = null;
259 ((IDbDataAdapter)this).UpdateCommand = null;
260 ((IDbDataAdapter)this).DeleteCommand = null;
261 }
262 base.Dispose(disposing);
263 }
264
265 protected virtual int ExecuteBatch()
266 {
267 throw ADP.NotSupported();
268 }
269
270 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
272 {
273 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.FillSchema|API> {0}, dataTable, schemaType={1}", base.ObjectID, schemaType);
274 try
275 {
279 }
280 finally
281 {
282 DataCommonEventSource.Log.ExitScope(scopeId);
283 }
284 }
285
286 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
287 public override DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType)
288 {
289 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.FillSchema|API> {0}, dataSet, schemaType={1}", base.ObjectID, schemaType);
290 try
291 {
293 if (base.DesignMode && (selectCommand == null || selectCommand.Connection == null || string.IsNullOrEmpty(selectCommand.CommandText)))
294 {
295 return Array.Empty<DataTable>();
296 }
298 return FillSchema(dataSet, schemaType, selectCommand, "Table", fillCommandBehavior);
299 }
300 finally
301 {
302 DataCommonEventSource.Log.ExitScope(scopeId);
303 }
304 }
305
306 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
308 {
309 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.FillSchema|API> {0}, dataSet, schemaType={1}, srcTable={2}", base.ObjectID, (int)schemaType, srcTable);
310 try
311 {
315 }
316 finally
317 {
318 DataCommonEventSource.Log.ExitScope(scopeId);
319 }
320 }
321
322 [RequiresUnreferencedCode("IDataReader's (built from command) schema table types cannot be statically analyzed.")]
324 {
325 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.FillSchema|API> {0}, dataSet, schemaType, command, srcTable, behavior={1}", base.ObjectID, behavior);
326 try
327 {
328 if (dataSet == null)
329 {
330 throw ADP.ArgumentNull("dataSet");
331 }
332 if (SchemaType.Source != schemaType && SchemaType.Mapped != schemaType)
333 {
334 throw ADP.InvalidSchemaType(schemaType);
335 }
336 if (string.IsNullOrEmpty(srcTable))
337 {
338 throw ADP.FillSchemaRequiresSourceTableName("srcTable");
339 }
340 if (command == null)
341 {
342 throw ADP.MissingSelectCommand("FillSchema");
343 }
344 return (DataTable[])FillSchemaInternal(dataSet, null, schemaType, command, srcTable, behavior);
345 }
346 finally
347 {
348 DataCommonEventSource.Log.ExitScope(scopeId);
349 }
350 }
351
352 [RequiresUnreferencedCode("IDataReader's (built from command) schema table types cannot be statically analyzed.")]
354 {
355 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.FillSchema|API> {0}, dataTable, schemaType, command, behavior={1}", base.ObjectID, behavior);
356 try
357 {
358 if (dataTable == null)
359 {
360 throw ADP.ArgumentNull("dataTable");
361 }
362 if (SchemaType.Source != schemaType && SchemaType.Mapped != schemaType)
363 {
364 throw ADP.InvalidSchemaType(schemaType);
365 }
366 if (command == null)
367 {
368 throw ADP.MissingSelectCommand("FillSchema");
369 }
370 string text = dataTable.TableName;
371 int num = IndexOfDataSetTable(text);
372 if (-1 != num)
373 {
374 text = base.TableMappings[num].SourceTable;
375 }
376 return (DataTable)FillSchemaInternal(null, dataTable, schemaType, command, text, behavior | CommandBehavior.SingleResult);
377 }
378 finally
379 {
380 DataCommonEventSource.Log.ExitScope(scopeId);
381 }
382 }
383
384 [RequiresUnreferencedCode("IDataReader's (built from command) schema table types cannot be statically analyzed.")]
386 {
387 object result = null;
388 bool flag = command.Connection == null;
389 try
390 {
391 IDbConnection connection = GetConnection3(this, command, "FillSchema");
393 try
394 {
395 QuietOpen(connection, out originalState);
396 using IDataReader dataReader = command.ExecuteReader(behavior | CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
397 result = ((datatable == null) ? ((object)FillSchema(dataset, schemaType, srcTable, dataReader)) : ((object)FillSchema(datatable, schemaType, dataReader)));
398 }
399 finally
400 {
401 QuietClose(connection, originalState);
402 }
403 }
404 finally
405 {
406 if (flag)
407 {
408 command.Transaction = null;
409 command.Connection = null;
410 }
411 }
412 return result;
413 }
414
415 public override int Fill(DataSet dataSet)
416 {
417 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataSet", base.ObjectID);
418 try
419 {
422 return Fill(dataSet, 0, 0, "Table", selectCommand, fillCommandBehavior);
423 }
424 finally
425 {
426 DataCommonEventSource.Log.ExitScope(scopeId);
427 }
428 }
429
430 public int Fill(DataSet dataSet, string srcTable)
431 {
432 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataSet, srcTable='{1}'", base.ObjectID, srcTable);
433 try
434 {
438 }
439 finally
440 {
441 DataCommonEventSource.Log.ExitScope(scopeId);
442 }
443 }
444
445 public int Fill(DataSet dataSet, int startRecord, int maxRecords, string srcTable)
446 {
447 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataSet, startRecord={1}, maxRecords={2}, srcTable='{3}'", base.ObjectID, startRecord, maxRecords, srcTable);
448 try
449 {
453 }
454 finally
455 {
456 DataCommonEventSource.Log.ExitScope(scopeId);
457 }
458 }
459
461 {
462 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataSet, startRecord, maxRecords, srcTable, command, behavior={1}", base.ObjectID, behavior);
463 try
464 {
465 if (dataSet == null)
466 {
467 throw ADP.FillRequires("dataSet");
468 }
469 if (startRecord < 0)
470 {
471 throw ADP.InvalidStartRecord("startRecord", startRecord);
472 }
473 if (maxRecords < 0)
474 {
475 throw ADP.InvalidMaxRecords("maxRecords", maxRecords);
476 }
477 if (string.IsNullOrEmpty(srcTable))
478 {
479 throw ADP.FillRequiresSourceTableName("srcTable");
480 }
481 if (command == null)
482 {
483 throw ADP.MissingSelectCommand("Fill");
484 }
486 }
487 finally
488 {
489 DataCommonEventSource.Log.ExitScope(scopeId);
490 }
491 }
492
494 {
495 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataTable", base.ObjectID);
496 try
497 {
502 }
503 finally
504 {
505 DataCommonEventSource.Log.ExitScope(scopeId);
506 }
507 }
508
510 {
511 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, startRecord={1}, maxRecords={2}, dataTable[]", base.ObjectID, startRecord, maxRecords);
512 try
513 {
517 }
518 finally
519 {
520 DataCommonEventSource.Log.ExitScope(scopeId);
521 }
522 }
523
525 {
526 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataTable, command, behavior={1}", base.ObjectID, behavior);
527 try
528 {
530 return Fill(dataTables, 0, 0, command, behavior);
531 }
532 finally
533 {
534 DataCommonEventSource.Log.ExitScope(scopeId);
535 }
536 }
537
539 {
540 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Fill|API> {0}, dataTables[], startRecord, maxRecords, command, behavior={1}", base.ObjectID, behavior);
541 try
542 {
543 if (dataTables == null || dataTables.Length == 0 || dataTables[0] == null)
544 {
545 throw ADP.FillRequires("dataTable");
546 }
547 if (startRecord < 0)
548 {
549 throw ADP.InvalidStartRecord("startRecord", startRecord);
550 }
551 if (maxRecords < 0)
552 {
553 throw ADP.InvalidMaxRecords("maxRecords", maxRecords);
554 }
555 if (1 < dataTables.Length && (startRecord != 0 || maxRecords != 0))
556 {
558 }
559 if (command == null)
560 {
561 throw ADP.MissingSelectCommand("Fill");
562 }
563 if (1 == dataTables.Length)
564 {
565 behavior |= CommandBehavior.SingleResult;
566 }
568 }
569 finally
570 {
571 DataCommonEventSource.Log.ExitScope(scopeId);
572 }
573 }
574
576 {
577 int result = 0;
578 bool flag = command.Connection == null;
579 try
580 {
581 IDbConnection connection = GetConnection3(this, command, "Fill");
583 if (MissingSchemaAction.AddWithKey == base.MissingSchemaAction)
584 {
585 behavior |= CommandBehavior.KeyInfo;
586 }
587 try
588 {
589 QuietOpen(connection, out originalState);
590 behavior |= CommandBehavior.SequentialAccess;
591 IDataReader dataReader = null;
592 try
593 {
594 dataReader = command.ExecuteReader(behavior);
596 }
597 finally
598 {
599 dataReader?.Dispose();
600 }
601 }
602 finally
603 {
604 QuietClose(connection, originalState);
605 }
606 }
607 finally
608 {
609 if (flag)
610 {
611 command.Transaction = null;
612 command.Connection = null;
613 }
614 }
615 return result;
616 }
617
619 {
620 throw ADP.NotSupported();
621 }
622
624 {
625 recordsAffected = 1;
626 error = null;
627 return true;
628 }
629
632 {
633 IDataParameter[] array = null;
635 if (selectCommand != null)
636 {
637 IDataParameterCollection parameters = selectCommand.Parameters;
638 if (parameters != null)
639 {
640 array = new IDataParameter[parameters.Count];
641 parameters.CopyTo(array, 0);
642 }
643 }
644 if (array == null)
645 {
646 array = Array.Empty<IDataParameter>();
647 }
648 return array;
649 }
650
652 {
654 int num = IndexOfDataSetTable(dataTable.TableName);
655 if (-1 != num)
656 {
657 dataTableMapping = base.TableMappings[num];
658 }
659 if (dataTableMapping == null)
660 {
661 if (MissingMappingAction.Error == base.MissingMappingAction)
662 {
664 }
665 dataTableMapping = new DataTableMapping(dataTable.TableName, dataTable.TableName);
666 }
667 return dataTableMapping;
668 }
669
670 protected virtual void InitializeBatching()
671 {
672 throw ADP.NotSupported();
673 }
674
675 protected virtual void OnRowUpdated(RowUpdatedEventArgs value)
676 {
677 }
678
680 {
681 }
682
684 {
687 foreach (IDataParameter parameter in parameters)
688 {
689 if (parameter == null || (ParameterDirection.Input & parameter.Direction) == 0)
690 {
691 continue;
692 }
693 string sourceColumn = parameter.SourceColumn;
694 if (!string.IsNullOrEmpty(sourceColumn))
695 {
697 if (dataColumn != null)
698 {
700 parameter.Value = row[dataColumn, parameterSourceVersion];
701 }
702 else
703 {
704 parameter.Value = null;
705 }
706 if (parameter is DbParameter { SourceColumnNullMapping: not false })
707 {
709 }
710 }
711 }
712 }
713
715 {
716 if ((ParameterDirection.Output & parameter.Direction) == 0)
717 {
718 return;
719 }
720 object value = parameter.Value;
721 if (value == null)
722 {
723 return;
724 }
725 string sourceColumn = parameter.SourceColumn;
726 if (string.IsNullOrEmpty(sourceColumn))
727 {
728 return;
729 }
731 if (dataColumn == null)
732 {
733 return;
734 }
735 if (dataColumn.ReadOnly)
736 {
737 try
738 {
739 dataColumn.ReadOnly = false;
741 return;
742 }
743 finally
744 {
745 dataColumn.ReadOnly = true;
746 }
747 }
749 }
750
763
764 protected virtual void TerminateBatching()
765 {
766 throw ADP.NotSupported();
767 }
768
769 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
770 public override int Update(DataSet dataSet)
771 {
772 return Update(dataSet, "Table");
773 }
774
775 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
776 public int Update(DataRow[] dataRows)
777 {
778 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataRows[]", base.ObjectID);
779 try
780 {
781 int result = 0;
782 if (dataRows == null)
783 {
784 throw ADP.ArgumentNull("dataRows");
785 }
786 if (dataRows.Length != 0)
787 {
788 DataTable dataTable = null;
789 for (int i = 0; i < dataRows.Length; i++)
790 {
791 if (dataRows[i] != null && dataTable != dataRows[i].Table)
792 {
793 if (dataTable != null)
794 {
796 }
797 dataTable = dataRows[i].Table;
798 }
799 }
800 if (dataTable != null)
801 {
803 result = Update(dataRows, tableMapping);
804 }
805 }
806 return result;
807 }
808 finally
809 {
810 DataCommonEventSource.Log.ExitScope(scopeId);
811 }
812 }
813
814 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
816 {
817 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataTable", base.ObjectID);
818 try
819 {
820 if (dataTable == null)
821 {
822 throw ADP.UpdateRequiresDataTable("dataTable");
823 }
825 int num = IndexOfDataSetTable(dataTable.TableName);
826 if (-1 != num)
827 {
828 dataTableMapping = base.TableMappings[num];
829 }
830 if (dataTableMapping == null)
831 {
832 if (MissingMappingAction.Error == base.MissingMappingAction)
833 {
835 }
836 dataTableMapping = new DataTableMapping("Table", dataTable.TableName);
837 }
839 }
840 finally
841 {
842 DataCommonEventSource.Log.ExitScope(scopeId);
843 }
844 }
845
846 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
847 public int Update(DataSet dataSet, string srcTable)
848 {
849 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataSet, srcTable='{1}'", base.ObjectID, srcTable);
850 try
851 {
852 if (dataSet == null)
853 {
854 throw ADP.UpdateRequiresNonNullDataSet("dataSet");
855 }
856 if (string.IsNullOrEmpty(srcTable))
857 {
858 throw ADP.UpdateRequiresSourceTableName("srcTable");
859 }
860 int result = 0;
864 if (dataTableBySchemaAction != null)
865 {
867 }
868 else if (!HasTableMappings() || -1 == base.TableMappings.IndexOf(tableMappingBySchemaAction))
869 {
871 }
872 return result;
873 }
874 finally
875 {
876 DataCommonEventSource.Log.ExitScope(scopeId);
877 }
878 }
879
880 [RequiresUnreferencedCode("IDataReader's (built from adapter commands) schema table types cannot be statically analyzed.")]
882 {
883 long scopeId = DataCommonEventSource.Log.EnterScope("<comm.DbDataAdapter.Update|API> {0}, dataRows[], tableMapping", base.ObjectID);
884 try
885 {
886 int num = 0;
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 }
906 DataRow[] array4 = new DataRow[num2];
907 int num3 = 0;
908 try
909 {
910 try
911 {
912 if (1 != num2)
913 {
915 }
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 }
938 }
939 else if (rowState != DataRowState.Deleted)
940 {
941 if (rowState != DataRowState.Modified)
942 {
943 goto IL_0115;
944 }
947 }
948 else
949 {
952 }
954 try
955 {
956 dataRow.RowError = null;
957 if (dbCommand != null)
958 {
960 }
961 }
963 {
965 rowUpdatingEventArgs.Errors = ex;
966 rowUpdatingEventArgs.Status = UpdateStatus.ErrorsOccurred;
967 }
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 }
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 {
1038 }
1039 }
1040 else
1041 {
1043 }
1044 }
1046 {
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 {
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 }
1112 {
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 {
1158 DataRow[] array5 = array4;
1159 if (num3 < array4.Length)
1160 {
1161 array5 = new DataRow[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 }
1176 {
1178 rowUpdatedEventArgs2.Errors = ex5;
1179 rowUpdatedEventArgs2.Status = UpdateStatus.ErrorsOccurred;
1180 }
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 }
1215
1217 {
1218 try
1219 {
1221 rowUpdatedEvent.AdapterInit(recordsAffected);
1222 }
1223 catch (DbException ex)
1224 {
1226 rowUpdatedEvent.Errors = ex;
1227 rowUpdatedEvent.Status = UpdateStatus.ErrorsOccurred;
1228 }
1231 int num = 0;
1232 bool flag = false;
1233 List<DataRow> list = null;
1234 for (int i = 0; i < commandCount; i++)
1235 {
1238 if (GetBatchedRecordsAffected(batchCommandInfo._commandIdentifier, out int recordsAffected2, out batchCommands[i]._errors))
1239 {
1240 batchCommands[i]._recordsAffected = recordsAffected2;
1241 }
1242 if (batchCommands[i]._errors != null || !batchCommands[i]._recordsAffected.HasValue)
1243 {
1244 continue;
1245 }
1246 if (StatementType.Update == statementType || StatementType.Delete == statementType)
1247 {
1248 num++;
1249 if (recordsAffected2 == 0)
1250 {
1251 if (list == null)
1252 {
1253 list = new List<DataRow>();
1254 }
1255 batchCommands[i]._errors = ADP.UpdateConcurrencyViolation(batchCommands[i]._statementType, 0, 1, new DataRow[1] { rowUpdatedEvent.Rows[i] });
1256 flag = true;
1257 list.Add(rowUpdatedEvent.Rows[i]);
1258 }
1259 }
1260 if ((StatementType.Insert == statementType || StatementType.Update == statementType) && (UpdateRowSource.OutputParameters & batchCommandInfo._updatedRowSource) != 0 && recordsAffected2 != 0)
1261 {
1262 if (StatementType.Insert == statementType)
1263 {
1264 rowUpdatedEvent.Rows[i].AcceptChanges();
1265 }
1266 for (int j = 0; j < batchCommandInfo._parameterCount; j++)
1267 {
1270 }
1271 }
1272 }
1273 if (rowUpdatedEvent.Errors == null && rowUpdatedEvent.Status == UpdateStatus.Continue && 0 < num && (rowUpdatedEvent.RecordsAffected == 0 || flag))
1274 {
1275 DataRow[] array = ((list != null) ? list.ToArray() : rowUpdatedEvent.Rows);
1276 rowUpdatedEvent.Errors = ADP.UpdateConcurrencyViolation(StatementType.Batch, commandCount - array.Length, commandCount, array);
1277 rowUpdatedEvent.Status = UpdateStatus.ErrorsOccurred;
1278 }
1279 }
1280
1282 {
1283 if (connection != connections[(int)statementType])
1284 {
1286 connections[(int)statementType] = connection;
1288 QuietOpen(connection, out connectionStates[(int)statementType]);
1289 if (useSelectConnectionState && connections[0] == connection)
1290 {
1292 }
1293 }
1294 return connection.State;
1295 }
1296
1297 [RequiresUnreferencedCode("IDataReader (built from _IDbDataAdapter command) schema table rows DataTypes cannot be statically analyzed.")]
1299 {
1300 int result = 0;
1302 if (array != null && array.Length != 0)
1303 {
1304 result = Update(array, tableMapping);
1305 }
1306 return result;
1307 }
1308
1309 [RequiresUnreferencedCode("IDataReader (built from dataCommand) schema table rows DataTypes cannot be statically analyzed.")]
1311 {
1312 bool flag = true;
1313 UpdateRowSource updatedRowSource = dataCommand.UpdatedRowSource;
1314 if (StatementType.Delete == cmdIndex || (UpdateRowSource.FirstReturnedRecord & updatedRowSource) == 0)
1315 {
1316 int recordsAffected = dataCommand.ExecuteNonQuery();
1317 rowUpdatedEvent.AdapterInit(recordsAffected);
1318 }
1319 else if (StatementType.Insert == cmdIndex || StatementType.Update == cmdIndex)
1320 {
1321 using IDataReader dataReader = dataCommand.ExecuteReader(CommandBehavior.SequentialAccess);
1323 try
1324 {
1325 bool flag2 = false;
1326 do
1327 {
1328 if (0 < dataReaderContainer.FieldCount)
1329 {
1330 flag2 = true;
1331 break;
1332 }
1333 }
1334 while (dataReader.NextResult());
1335 if (flag2 && dataReader.RecordsAffected != 0)
1336 {
1337 SchemaMapping schemaMapping = new SchemaMapping(this, null, rowUpdatedEvent.Row.Table, dataReaderContainer, keyInfo: false, SchemaType.Mapped, rowUpdatedEvent.TableMapping.SourceTable, gettingData: true, null, null);
1338 if (schemaMapping.DataTable != null && schemaMapping.DataValues != null && dataReader.Read())
1339 {
1340 if (StatementType.Insert == cmdIndex && flag)
1341 {
1342 rowUpdatedEvent.Row.AcceptChanges();
1343 flag = false;
1344 }
1345 schemaMapping.ApplyToDataRow(rowUpdatedEvent.Row);
1346 }
1347 }
1348 }
1349 finally
1350 {
1351 dataReader.Close();
1352 int recordsAffected2 = dataReader.RecordsAffected;
1353 rowUpdatedEvent.AdapterInit(recordsAffected2);
1354 }
1355 }
1356 if ((StatementType.Insert == cmdIndex || StatementType.Update == cmdIndex) && (UpdateRowSource.OutputParameters & updatedRowSource) != 0 && rowUpdatedEvent.RecordsAffected != 0)
1357 {
1358 if (StatementType.Insert == cmdIndex && flag)
1359 {
1360 rowUpdatedEvent.Row.AcceptChanges();
1361 }
1362 ParameterOutput(dataCommand.Parameters, rowUpdatedEvent.Row, rowUpdatedEvent.TableMapping);
1363 }
1364 if (rowUpdatedEvent.Status == UpdateStatus.Continue && (uint)(cmdIndex - 2) <= 1u && rowUpdatedEvent.RecordsAffected == 0)
1365 {
1366 rowUpdatedEvent.Errors = ADP.UpdateConcurrencyViolation(cmdIndex, rowUpdatedEvent.RecordsAffected, 1, new DataRow[1] { rowUpdatedEvent.Row });
1367 rowUpdatedEvent.Status = UpdateStatus.ErrorsOccurred;
1368 }
1369 }
1370
1372 {
1373 int num = 0;
1374 switch (rowUpdatedEvent.Status)
1375 {
1376 case UpdateStatus.Continue:
1378 case UpdateStatus.ErrorsOccurred:
1380 case UpdateStatus.SkipCurrentRow:
1381 case UpdateStatus.SkipAllRemainingRows:
1383 default:
1385 }
1386 }
1387
1389 {
1390 int num = 0;
1391 bool acceptChangesDuringUpdate = base.AcceptChangesDuringUpdate;
1392 for (int i = 0; i < commandCount; i++)
1393 {
1396 if (batchCommandInfo._errors == null && batchCommandInfo._recordsAffected.HasValue && batchCommandInfo._recordsAffected.Value != 0)
1397 {
1398 if (acceptChangesDuringUpdate && ((DataRowState.Added | DataRowState.Deleted | DataRowState.Modified) & row.RowState) != 0)
1399 {
1400 row.AcceptChanges();
1401 }
1402 num++;
1403 }
1404 }
1405 return num;
1406 }
1407
1409 {
1410 Exception ex = rowUpdatedEvent.Errors;
1411 if (ex == null)
1412 {
1413 ex = (rowUpdatedEvent.Errors = ADP.RowUpdatedErrors());
1414 }
1415 int result = 0;
1416 bool flag = false;
1417 string message = ex.Message;
1418 for (int i = 0; i < commandCount; i++)
1419 {
1420 DataRow row = batchCommands[i]._row;
1421 Exception errors = batchCommands[i]._errors;
1422 if (errors != null)
1423 {
1424 string text = errors.Message;
1425 if (string.IsNullOrEmpty(text))
1426 {
1427 text = message;
1428 }
1429 row.RowError += text;
1430 flag = true;
1431 }
1432 }
1433 if (!flag)
1434 {
1435 for (int j = 0; j < commandCount; j++)
1436 {
1437 batchCommands[j]._row.RowError += message;
1438 }
1439 }
1440 else
1441 {
1443 }
1444 if (!base.ContinueUpdateOnError)
1445 {
1446 throw ex;
1447 }
1448 return result;
1449 }
1450
1452 {
1453 int num = 0;
1454 for (int i = 0; i < commandCount; i++)
1455 {
1456 DataRow row = batchCommands[i]._row;
1457 if (((DataRowState.Detached | DataRowState.Unchanged) & row.RowState) != 0)
1458 {
1459 num++;
1460 }
1461 }
1462 return num;
1463 }
1464
1466 {
1467 Exception ex = rowUpdatedEvent.Errors;
1468 if (ex == null)
1469 {
1470 ex = (rowUpdatedEvent.Errors = ADP.RowUpdatingErrors());
1471 }
1472 string message = ex.Message;
1473 dataRow.RowError += message;
1474 if (!base.ContinueUpdateOnError)
1475 {
1476 throw ex;
1477 }
1478 }
1479
1481 {
1483 if (dbCommand == null)
1484 {
1486 if (dbCommand == null)
1487 {
1489 if (dbCommand == null)
1490 {
1492 }
1493 }
1494 }
1496 if (dbCommand != null)
1497 {
1498 dbConnection = dbCommand.Connection;
1499 }
1500 if (dbConnection == null)
1501 {
1503 }
1504 return dbConnection;
1505 }
1506
1508 {
1509 IDbConnection connection = command.Connection;
1510 if (connection == null)
1511 {
1513 }
1514 return connection;
1515 }
1516
1518 {
1519 IDbConnection connection = command.Connection;
1520 if (connection == null)
1521 {
1523 }
1524 return connection;
1525 }
1526
1528 {
1529 switch (statementType)
1530 {
1531 case StatementType.Insert:
1532 return DataRowVersion.Current;
1533 case StatementType.Update:
1534 return parameter.SourceVersion;
1535 case StatementType.Delete:
1536 return DataRowVersion.Original;
1537 case StatementType.Select:
1538 case StatementType.Batch:
1540 default:
1542 }
1543 }
1544
1546 {
1547 if (connection != null && originalState == ConnectionState.Closed)
1548 {
1549 connection.Close();
1550 }
1551 }
1552
1554 {
1555 originalState = connection.State;
1556 if (originalState == ConnectionState.Closed)
1557 {
1558 connection.Open();
1559 }
1560 }
1561}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static ArgumentException UpdateMismatchRowTable(int i)
Definition ADP.cs:461
static ArgumentNullException ArgumentNull(string parameter)
Definition ADP.cs:699
static ArgumentOutOfRangeException InvalidSchemaType(SchemaType value)
Definition ADP.cs:144
static ArgumentOutOfRangeException InvalidDataRowState(DataRowState value)
Definition ADP.cs:119
static Exception UpdateConcurrencyViolation(StatementType statementType, int affected, int expected, DataRow[] dataRows)
Definition ADP.cs:435
static ArgumentOutOfRangeException InvalidStatementType(StatementType value)
Definition ADP.cs:149
static ArgumentNullException UpdateRequiresNonNullDataSet(string parameter)
Definition ADP.cs:415
static Exception FillSchemaRequiresSourceTableName(string parameter)
Definition ADP.cs:375
static InvalidOperationException MissingSelectCommand(string method)
Definition ADP.cs:184
static DataRow[] SelectAdapterRows(DataTable dataTable, bool sorted)
Definition ADP.cs:531
static void TraceExceptionForCapture(Exception e)
Definition ADP.cs:74
static InvalidOperationException ConnectionRequired_Res(string method)
Definition ADP.cs:353
static DataException RowUpdatedErrors()
Definition ADP.cs:466
static ArgumentOutOfRangeException InvalidUpdateStatus(UpdateStatus value)
Definition ADP.cs:154
static InvalidOperationException MissingTableMappingDestination(string dstTable)
Definition ADP.cs:228
static NotSupportedException NotSupported()
Definition ADP.cs:753
static InvalidOperationException UpdateOpenConnectionRequired(StatementType statementType, bool isRowUpdatingCommand, ConnectionState state)
Definition ADP.cs:358
static InvalidOperationException UpdateRequiresSourceTable(string defaultSrcTableName)
Definition ADP.cs:420
static Exception InvalidMaxRecords(string parameter, int max)
Definition ADP.cs:380
static DataException RowUpdatingErrors()
Definition ADP.cs:471
static Exception FillRequires(string parameter)
Definition ADP.cs:390
static ArgumentException UnwantedStatementType(StatementType statementType)
Definition ADP.cs:370
static InvalidOperationException UpdateConnectionRequired(StatementType statementType, bool isRowUpdatingCommand)
Definition ADP.cs:323
static ArgumentNullException UpdateRequiresDataTable(string parameter)
Definition ADP.cs:430
static InvalidOperationException UpdateRequiresCommand(StatementType statementType, bool isRowUpdatingCommand)
Definition ADP.cs:448
static Exception FillRequiresSourceTableName(string parameter)
Definition ADP.cs:395
static InvalidOperationException UpdateRequiresSourceTableName(string srcTable)
Definition ADP.cs:425
static bool IsCatchableExceptionType(Exception e)
Definition ADP.cs:790
static InvalidOperationException ResultsNotAllowedDuringBatch()
Definition ADP.cs:476
static bool IsNull(object value)
Definition ADP.cs:957
static InvalidOperationException OnlyOneTableForStartRecordOrMaxRecords()
Definition ADP.cs:410
static Exception InvalidStartRecord(string parameter, int start)
Definition ADP.cs:385
virtual bool ReturnProviderSpecificTypes
DataTableMapping GetTableMappingBySchemaAction(string sourceTableName, string dataSetTableName, MissingMappingAction mappingAction)
int IndexOfDataSetTable(string dataSetTable)
virtual DataAdapter CloneInternals()
void UpdateRowExecute(RowUpdatedEventArgs rowUpdatedEvent, IDbCommand dataCommand, StatementType cmdIndex)
virtual RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand? command, StatementType statementType, DataTableMapping tableMapping)
override IDataParameter[] GetFillParameters()
virtual void OnRowUpdated(RowUpdatedEventArgs value)
virtual ? DataTable FillSchema(DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior)
int Fill(DataSet dataSet, int startRecord, int maxRecords, string srcTable)
int Fill(DataTable dataTable)
static readonly object s_parameterValueNonNullValue
void ParameterOutput(IDataParameterCollection parameters, DataRow row, DataTableMapping mappings)
DataTableMapping GetTableMapping(DataTable dataTable)
int Update(DataSet dataSet, string srcTable)
static IDbConnection GetConnection3(DbDataAdapter adapter, IDbCommand command, string method)
virtual int Fill(DataTable[] dataTables, int startRecord, int maxRecords, IDbCommand command, CommandBehavior behavior)
DataTable? FillSchema(DataTable dataTable, SchemaType schemaType)
static void QuietOpen(IDbConnection connection, out ConnectionState originalState)
static IDbConnection GetConnection4(DbDataAdapter adapter, IDbCommand command, StatementType statementType, bool isCommandFromRowUpdating)
virtual IDataParameter GetBatchedParameter(int commandIdentifier, int parameterIndex)
MissingMappingAction UpdateMappingAction
virtual void OnRowUpdating(RowUpdatingEventArgs value)
ConnectionState UpdateConnectionOpen(IDbConnection connection, StatementType statementType, IDbConnection[] connections, ConnectionState[] connectionStates, bool useSelectConnectionState)
int UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
int UpdatedRowStatusContinue(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, int commandCount)
int Fill(int startRecord, int maxRecords, params DataTable[] dataTables)
static void QuietClose(IDbConnection connection, ConnectionState originalState)
virtual bool GetBatchedRecordsAffected(int commandIdentifier, out int recordsAffected, out Exception? error)
virtual int AddToBatch(IDbCommand command)
static readonly object s_parameterValueNullValue
virtual int Update(DataRow[] dataRows, DataTableMapping tableMapping)
int UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, int commandCount)
virtual int Fill(DataSet dataSet, int startRecord, int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior)
DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType, string srcTable)
override DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType)
MissingSchemaAction UpdateSchemaAction
override int Fill(DataSet dataSet)
int FillInternal(DataSet dataset, DataTable[] datatables, int startRecord, int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior)
virtual RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand? command, StatementType statementType, DataTableMapping tableMapping)
void UpdateBatchExecute(BatchCommandInfo[] batchCommands, int commandCount, RowUpdatedEventArgs rowUpdatedEvent)
int Update(DataRow[] dataRows)
static DataRowVersion GetParameterSourceVersion(StatementType statementType, IDataParameter parameter)
static IDbConnection GetConnection1(DbDataAdapter adapter)
virtual int Fill(DataTable dataTable, IDbCommand command, CommandBehavior behavior)
IDbCommand CloneCommand(IDbCommand command)
void ParameterOutput(IDataParameter parameter, DataRow row, DataTableMapping mappings, MissingMappingAction missingMapping, MissingSchemaAction missingSchema)
override void Dispose(bool disposing)
override int Update(DataSet dataSet)
void CloneFrom(DbDataAdapter from)
int Update(DataTable dataTable)
DbDataAdapter(DbDataAdapter adapter)
void ParameterInput(IDataParameterCollection parameters, StatementType typeIndex, DataRow row, DataTableMapping mappings)
int Fill(DataSet dataSet, string srcTable)
object FillSchemaInternal(DataSet dataset, DataTable datatable, SchemaType schemaType, IDbCommand command, string srcTable, CommandBehavior behavior)
void UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow)
virtual DataTable[] FillSchema(DataSet dataSet, SchemaType schemaType, IDbCommand command, string srcTable, CommandBehavior behavior)
int UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, int commandCount)
int UpdatedRowStatusSkip(BatchCommandInfo[] batchCommands, int commandCount)
static readonly DataCommonEventSource Log
static DataReaderContainer Create(IDataReader dataReader, bool returnProviderSpecificTypes)
virtual string Message
Definition Exception.cs:100
static byte Min(byte val1, byte val2)
Definition Math.cs:912
void CopyTo(Array array, int index)