3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
5 // Permission is hereby granted, free of charge, to any person obtaining
\r
6 // a copy of this software and associated documentation files (the
\r
7 // "Software"), to deal in the Software without restriction, including
\r
8 // without limitation the rights to use, copy, modify, merge, publish,
\r
9 // distribute, sublicense, and/or sell copies of the Software, and to
\r
10 // permit persons to whom the Software is furnished to do so, subject to
\r
11 // the following conditions:
\r
13 // The above copyright notice and this permission notice shall be
\r
14 // included in all copies or substantial portions of the Software.
\r
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
25 using System.Collections;
\r
27 namespace System.Data.Common
\r
29 internal abstract class AbstractDataContainer
\r
33 BitArray _nullValues;
\r
41 internal abstract object this[int index] {
\r
46 internal virtual int Capacity {
\r
48 return (_nullValues != null) ? _nullValues.Count : 0;
\r
51 if (_nullValues == null) {
\r
52 _nullValues = new BitArray(value);
\r
55 _nullValues.Length = value;
\r
60 internal Type Type {
\r
66 protected DataColumn Column {
\r
72 #endregion //Properties
\r
76 internal static AbstractDataContainer CreateInstance(Type type, DataColumn column)
\r
78 AbstractDataContainer container;
\r
79 switch (Type.GetTypeCode(type)) {
\r
80 case TypeCode.Int16 :
\r
81 container = new Int16DataContainer();
\r
83 case TypeCode.Int32 :
\r
84 container = new Int32DataContainer();
\r
86 case TypeCode.Int64 :
\r
87 container = new Int64DataContainer();
\r
89 case TypeCode.String :
\r
90 container = new StringDataContainer();
\r
92 case TypeCode.Boolean:
\r
93 container = new BitDataContainer();
\r
95 case TypeCode.Byte :
\r
96 container = new ByteDataContainer();
\r
98 case TypeCode.Char :
\r
99 container = new CharDataContainer();
\r
101 case TypeCode.Double :
\r
102 container = new DoubleDataContainer();
\r
104 case TypeCode.SByte :
\r
105 container = new SByteDataContainer();
\r
107 case TypeCode.Single :
\r
108 container = new SingleDataContainer();
\r
110 case TypeCode.UInt16 :
\r
111 container = new UInt16DataContainer();
\r
113 case TypeCode.UInt32 :
\r
114 container = new UInt32DataContainer();
\r
116 case TypeCode.UInt64 :
\r
117 container = new UInt64DataContainer();
\r
119 case TypeCode.DateTime :
\r
120 container = new DateTimeDataContainer();
\r
122 case TypeCode.Decimal :
\r
123 container = new DecimalDataContainer();
\r
126 container = new ObjectDataContainer();
\r
129 container._type = type;
\r
130 container._column = column;
\r
134 internal bool IsNull(int index)
\r
136 return (_nullValues != null) ? _nullValues[index] : true;
\r
139 internal void SetNullBit(int index,bool isNull)
\r
141 _nullValues[index] = isNull;
\r
144 protected void SetNull(int index,bool isNull,bool isDbNull)
\r
146 SetNullBit(index,isDbNull);
\r
147 // this method must be called after setting the value into value array
\r
148 // otherwise the dafault value will be overriden
\r
150 // set the value to default
\r
151 CopyValue(Column.Table.DefaultValuesRowIndex,index);
\r
155 internal void FillValues(int fromIndex)
\r
157 for(int i=0; i < Capacity; i++) {
\r
158 CopyValue(fromIndex,i);
\r
159 _nullValues[i] = _nullValues[fromIndex];
\r
163 internal virtual void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
165 _nullValues[toIndex] = fromContainer._nullValues[fromIndex];
\r
168 internal virtual void CopyValue(int fromIndex, int toIndex)
\r
170 _nullValues[toIndex] = _nullValues[fromIndex];
\r
173 internal abstract void SetItemFromDataRecord(int index, IDataRecord record, int field);
\r
175 protected int CompareNulls(int index1, int index2)
\r
177 bool null1 = IsNull(index1);
\r
178 bool null2 = IsNull(index2);
\r
180 if ( null1 ^ null2 ) {
\r
181 return null1 ? -1 : 1;
\r
188 internal abstract int CompareValues(int index1, int index2);
\r
190 internal abstract long GetInt64(int index);
\r
192 #endregion //Methods
\r
194 sealed class Int16DataContainer : AbstractDataContainer
\r
200 #endregion //Fields
\r
204 internal override object this[int index] {
\r
206 if (IsNull(index)) {
\r
207 return DBNull.Value;
\r
210 return _values[index];
\r
214 bool isDbNull = (value == DBNull.Value);
\r
215 if (value == null || isDbNull) {
\r
218 else if( value is short ) {
\r
219 SetValue(index,(short)value);
\r
222 SetValue(index,Convert.ToInt16(value));
\r
224 SetNull(index,value == null,isDbNull);
\r
228 internal override int Capacity {
\r
230 base.Capacity = value;
\r
231 if (_values == null) {
\r
232 _values = new short[value];
\r
235 short[] tmp = new short[value];
\r
236 Array.Copy(_values,0,tmp,0,_values.Length);
\r
242 #endregion //Properties
\r
246 private void SetValue(int index, short value)
\r
248 _values[index] = value;
\r
251 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
253 bool isDbNull = record.IsDBNull(field);
\r
255 SetNull(index,false,isDbNull);
\r
259 // if exception thrown, it should be caught in the caller method
\r
260 if (record is ISafeDataRecord) {
\r
261 SetValue(index,((ISafeDataRecord)record).GetInt16Safe(field));
\r
264 this[index] = record.GetValue(field);
\r
268 internal override void CopyValue(int fromIndex, int toIndex)
\r
270 base.CopyValue(fromIndex, toIndex);
\r
271 _values[toIndex] = _values[fromIndex];
\r
274 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
276 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
277 _values[toIndex] = ((Int16DataContainer)fromContainer)._values[fromIndex];
\r
280 internal override int CompareValues(int index1, int index2)
\r
282 short s1 = _values[index1];
\r
283 short s2 = _values[index2];
\r
285 if ( s1 == 0 || s2 == 0 ) {
\r
286 int cn = CompareNulls(index1, index2);
\r
294 internal override long GetInt64(int index)
\r
296 return (long) _values[index];
\r
299 #endregion //Methods
\r
302 sealed class Int32DataContainer : AbstractDataContainer
\r
308 #endregion //Fields
\r
312 internal override object this[int index] {
\r
314 if (IsNull(index)) {
\r
315 return DBNull.Value;
\r
318 return _values[index];
\r
322 bool isDbNull = (value == DBNull.Value);
\r
323 if (value == null || isDbNull) {
\r
326 else if( value is int ) {
\r
327 SetValue(index,(int)value);
\r
330 SetValue(index,Convert.ToInt32(value));
\r
332 SetNull(index,value == null,isDbNull);
\r
336 internal override int Capacity {
\r
338 base.Capacity = value;
\r
339 if (_values == null) {
\r
340 _values = new int[value];
\r
343 int[] tmp = new int[value];
\r
344 Array.Copy(_values,0,tmp,0,_values.Length);
\r
350 #endregion //Properties
\r
354 private void SetValue(int index, int value)
\r
356 _values[index] = value;
\r
359 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
361 bool isDbNull = record.IsDBNull(field);
\r
363 SetNull(index,false,isDbNull);
\r
367 // if exception thrown, it should be caught in the caller method
\r
368 if (record is ISafeDataRecord) {
\r
369 SetValue(index,((ISafeDataRecord)record).GetInt32Safe(field));
\r
372 this[index] = record.GetValue(field);
\r
376 internal override void CopyValue(int fromIndex, int toIndex)
\r
378 base.CopyValue(fromIndex, toIndex);
\r
379 _values[toIndex] = _values[fromIndex];
\r
382 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
384 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
385 _values[toIndex] = ((Int32DataContainer)fromContainer)._values[fromIndex];
\r
388 internal override int CompareValues(int index1, int index2)
\r
390 int i1 = _values[index1];
\r
391 int i2 = _values[index2];
\r
393 if (i1 == 0 || i2 == 0) {
\r
394 int cn = CompareNulls(index1, index2);
\r
400 return ( i1 == i2 ) ? 0 : -1;
\r
405 internal override long GetInt64(int index)
\r
407 return (long) _values[index];
\r
410 #endregion //Methods
\r
413 sealed class Int64DataContainer : AbstractDataContainer
\r
419 #endregion //Fields
\r
423 internal override object this[int index] {
\r
425 if (IsNull(index)) {
\r
426 return DBNull.Value;
\r
429 return _values[index];
\r
433 bool isDbNull = (value == DBNull.Value);
\r
434 if (value == null || isDbNull) {
\r
437 else if( value is long ) {
\r
438 SetValue(index,(long)value);
\r
441 SetValue(index,Convert.ToInt64(value));
\r
443 SetNull(index,value == null,isDbNull);
\r
447 internal override int Capacity {
\r
449 base.Capacity = value;
\r
450 if (_values == null) {
\r
451 _values = new long[value];
\r
454 long[] tmp = new long[value];
\r
455 Array.Copy(_values,0,tmp,0,_values.Length);
\r
461 #endregion //Properties
\r
465 private void SetValue(int index, long value)
\r
467 _values[index] = value;
\r
470 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
472 bool isDbNull = record.IsDBNull(field);
\r
474 SetNull(index,false,isDbNull);
\r
478 // if exception thrown, it should be caught in the caller method
\r
479 if (record is ISafeDataRecord) {
\r
480 SetValue(index,((ISafeDataRecord)record).GetInt64Safe(field));
\r
483 this[index] = record.GetValue(field);
\r
487 internal override void CopyValue(int fromIndex, int toIndex)
\r
489 base.CopyValue(fromIndex, toIndex);
\r
490 _values[toIndex] = _values[fromIndex];
\r
493 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
495 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
496 _values[toIndex] = ((Int64DataContainer)fromContainer)._values[fromIndex];
\r
499 internal override int CompareValues(int index1, int index2)
\r
501 long l1 = _values[index1];
\r
502 long l2 = _values[index2];
\r
504 if ( l1 == 0 || l2 == 0 ) {
\r
505 int cn = CompareNulls(index1, index2);
\r
512 return ( l1 != l2 ) ? -1 : 0;
\r
517 internal override long GetInt64(int index)
\r
519 return _values[index];
\r
522 #endregion //Methods
\r
525 sealed class SingleDataContainer : AbstractDataContainer
\r
531 #endregion //Fields
\r
535 internal override object this[int index] {
\r
537 if (IsNull(index)) {
\r
538 return DBNull.Value;
\r
541 return _values[index];
\r
545 bool isDbNull = (value == DBNull.Value);
\r
546 if (value == null || isDbNull) {
\r
549 else if( value is float ) {
\r
550 SetValue(index,(float)value);
\r
553 SetValue(index,Convert.ToSingle(value));
\r
555 SetNull(index,value == null,isDbNull);
\r
559 internal override int Capacity {
\r
561 base.Capacity = value;
\r
562 if (_values == null) {
\r
563 _values = new float[value];
\r
566 float[] tmp = new float[value];
\r
567 Array.Copy(_values,0,tmp,0,_values.Length);
\r
573 #endregion //Properties
\r
577 private void SetValue(int index, float value)
\r
579 _values[index] = value;
\r
582 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
584 bool isDbNull = record.IsDBNull(field);
\r
586 SetNull(index,false,isDbNull);
\r
590 // if exception thrown, it should be caught in the caller method
\r
591 if (record is ISafeDataRecord) {
\r
592 SetValue(index,((ISafeDataRecord)record).GetFloatSafe(field));
\r
595 this[index] = record.GetValue(field);
\r
599 internal override void CopyValue(int fromIndex, int toIndex)
\r
601 base.CopyValue(fromIndex, toIndex);
\r
602 _values[toIndex] = _values[fromIndex];
\r
605 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
607 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
608 _values[toIndex] = ((SingleDataContainer)fromContainer)._values[fromIndex];
\r
611 internal override int CompareValues(int index1, int index2)
\r
613 float f1 = _values[index1];
\r
614 float f2 = _values[index2];
\r
616 if ( f1 == 0 || f2 == 0 ) {
\r
617 int cn = CompareNulls(index1, index2);
\r
624 return ( f1 != f2 ) ? -1 : 0;
\r
629 internal override long GetInt64(int index)
\r
631 return Convert.ToInt64(_values[index]);
\r
634 #endregion //Methods
\r
637 sealed class DoubleDataContainer : AbstractDataContainer
\r
643 #endregion //Fields
\r
647 internal override object this[int index] {
\r
649 if (IsNull(index)) {
\r
650 return DBNull.Value;
\r
653 return _values[index];
\r
657 bool isDbNull = (value == DBNull.Value);
\r
658 if (value == null || isDbNull) {
\r
661 else if( value is double ) {
\r
662 SetValue(index,(double)value);
\r
665 SetValue(index,Convert.ToDouble(value));
\r
667 SetNull(index,value == null,isDbNull);
\r
671 internal override int Capacity {
\r
673 base.Capacity = value;
\r
674 if (_values == null) {
\r
675 _values = new double[value];
\r
678 double[] tmp = new double[value];
\r
679 Array.Copy(_values,0,tmp,0,_values.Length);
\r
685 #endregion //Properties
\r
689 private void SetValue(int index, double value)
\r
691 _values[index] = value;
\r
694 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
696 bool isDbNull = record.IsDBNull(field);
\r
698 SetNull(index,false,isDbNull);
\r
702 // if exception thrown, it should be caught in the caller method
\r
703 if (record is ISafeDataRecord) {
\r
704 SetValue(index,((ISafeDataRecord)record).GetDoubleSafe(field));
\r
707 this[index] = record.GetValue(field);
\r
711 internal override void CopyValue(int fromIndex, int toIndex)
\r
713 base.CopyValue(fromIndex, toIndex);
\r
714 _values[toIndex] = _values[fromIndex];
\r
717 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
719 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
720 _values[toIndex] = ((DoubleDataContainer)fromContainer)._values[fromIndex];
\r
723 internal override int CompareValues(int index1, int index2)
\r
725 double d1 = _values[index1];
\r
726 double d2 = _values[index2];
\r
728 if ( d1 == 0 || d2 == 0 ) {
\r
729 int cn = CompareNulls(index1, index2);
\r
736 return ( d1 != d2 ) ? -1 : 0;
\r
741 internal override long GetInt64(int index)
\r
743 return Convert.ToInt64(_values[index]);
\r
746 #endregion //Methods
\r
749 sealed class ByteDataContainer : AbstractDataContainer
\r
755 #endregion //Fields
\r
759 internal override object this[int index] {
\r
761 if (IsNull(index)) {
\r
762 return DBNull.Value;
\r
765 return _values[index];
\r
769 bool isDbNull = (value == DBNull.Value);
\r
770 if (value == null || isDbNull) {
\r
773 else if( value is byte ) {
\r
774 SetValue(index,(byte)value);
\r
777 SetValue(index,Convert.ToByte(value));
\r
779 SetNull(index,value == null,isDbNull);
\r
783 internal override int Capacity {
\r
785 base.Capacity = value;
\r
786 if (_values == null) {
\r
787 _values = new byte[value];
\r
790 byte[] tmp = new byte[value];
\r
791 Array.Copy(_values,0,tmp,0,_values.Length);
\r
797 #endregion //Properties
\r
801 private void SetValue(int index, byte value)
\r
803 _values[index] = value;
\r
806 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
808 bool isDbNull = record.IsDBNull(field);
\r
810 SetNull(index,false,isDbNull);
\r
814 // if exception thrown, it should be caught in the caller method
\r
815 if (record is ISafeDataRecord) {
\r
816 SetValue(index,((ISafeDataRecord)record).GetByteSafe(field));
\r
819 this[index] = record.GetValue(field);
\r
823 internal override void CopyValue(int fromIndex, int toIndex)
\r
825 base.CopyValue(fromIndex, toIndex);
\r
826 _values[toIndex] = _values[fromIndex];
\r
829 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
831 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
832 _values[toIndex] = ((ByteDataContainer)fromContainer)._values[fromIndex];
\r
835 internal override int CompareValues(int index1, int index2)
\r
837 byte b1 = _values[index1];
\r
838 byte b2 = _values[index2];
\r
840 if ( b1 == 0 || b2 == 0 ) {
\r
841 int cn = CompareNulls(index1, index2);
\r
850 internal override long GetInt64(int index)
\r
852 return (long) _values[index];
\r
855 #endregion //Methods
\r
858 sealed class BitDataContainer : AbstractDataContainer
\r
864 #endregion //Fields
\r
868 internal override object this[int index] {
\r
870 bool isNull = IsNull(index);
\r
872 return DBNull.Value;
\r
875 return _values[index];
\r
879 bool isDbNull = (value == DBNull.Value);
\r
880 if (value == null || isDbNull) {
\r
881 SetValue(index,false);
\r
883 else if( value is bool ) {
\r
884 SetValue(index,(bool)value);
\r
887 SetValue(index,Convert.ToBoolean(value));
\r
889 SetNull(index,value == null,isDbNull);
\r
893 internal override int Capacity {
\r
895 base.Capacity = value;
\r
896 if (_values == null) {
\r
897 _values = new bool[value];
\r
900 bool[] tmp = new bool[value];
\r
901 Array.Copy(_values,0,tmp,0,_values.Length);
\r
907 #endregion //Properties
\r
911 private void SetValue(int index, bool value)
\r
913 _values[index] = value;
\r
916 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
918 bool isDbNull = record.IsDBNull(field);
\r
920 SetNull(index,false,isDbNull);
\r
924 // if exception thrown, it should be caught in the caller method
\r
925 if (record is ISafeDataRecord) {
\r
926 SetValue(index,((ISafeDataRecord)record).GetBooleanSafe(field));
\r
929 this[index] = record.GetValue(field);
\r
933 internal override void CopyValue(int fromIndex, int toIndex)
\r
935 base.CopyValue(fromIndex, toIndex);
\r
936 _values[toIndex] = _values[fromIndex];
\r
939 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
941 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
942 _values[toIndex] = ((BitDataContainer)fromContainer)._values[fromIndex];
\r
945 internal override int CompareValues(int index1, int index2)
\r
947 bool b1 = _values[index1];
\r
948 bool b2 = _values[index2];
\r
951 return b1 ? 1 : -1;
\r
958 return CompareNulls(index1, index2);
\r
961 internal override long GetInt64(int index)
\r
963 return Convert.ToInt64(_values[index]);
\r
966 #endregion //Methods
\r
969 abstract class AbstractObjectDataContainer : AbstractDataContainer
\r
975 #endregion //Fields
\r
979 internal override object this[int index] {
\r
981 if (IsNull(index))
\r
982 return DBNull.Value;
\r
984 return _values[index];
\r
987 SetValue(index,value);
\r
988 SetNull(index,value == null,value == DBNull.Value);
\r
992 internal override int Capacity {
\r
994 base.Capacity = value;
\r
995 if (_values == null) {
\r
996 _values = new object[value];
\r
999 object[] tmp = new object[value];
\r
1000 Array.Copy(_values,0,tmp,0,_values.Length);
\r
1006 #endregion //Properties
\r
1010 protected virtual void SetValue(int index, object value)
\r
1012 if(value == null) {
\r
1013 value = Column.DefaultValue;
\r
1015 _values[index] = value;
\r
1018 internal override void CopyValue(int fromIndex, int toIndex)
\r
1020 base.CopyValue(fromIndex, toIndex);
\r
1021 _values[toIndex] = _values[fromIndex];
\r
1024 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
1026 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
1027 _values[toIndex] = ((AbstractObjectDataContainer)fromContainer)._values[fromIndex];
\r
1030 internal override int CompareValues(int index1, int index2)
\r
1032 object obj1 = _values[index1];
\r
1033 object obj2 = _values[index2];
\r
1040 int cn = CompareNulls(index1, index2);
\r
1044 if (obj1 is IComparable)
\r
1048 return ((IComparable)obj1).CompareTo(obj2);
\r
1055 if (obj2 is IComparable)
\r
1057 obj2 = Convert.ChangeType(obj2, Type.GetTypeCode(obj1.GetType()));
\r
1058 return ((IComparable)obj1).CompareTo(obj2);
\r
1063 return String.Compare(obj1.ToString(), obj2.ToString());
\r
1066 internal override long GetInt64(int index)
\r
1068 return Convert.ToInt64(_values[index]);
\r
1071 #endregion //Methods
\r
1075 sealed class ObjectDataContainer : AbstractObjectDataContainer
\r
1078 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1080 bool isDbNull = record.IsDBNull(field);
\r
1082 SetNull(index,false,isDbNull);
\r
1086 // if exception thrown, it should be caught
\r
1087 // in the caller method
\r
1088 SetValue(index,record.GetValue(field));
\r
1091 #endregion //Methods
\r
1095 sealed class DateTimeDataContainer : AbstractObjectDataContainer
\r
1098 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1100 bool isDbNull = record.IsDBNull(field);
\r
1102 SetNull(index,false,isDbNull);
\r
1106 // if exception thrown, it should be caught
\r
1107 // in the caller method
\r
1108 // if exception thrown, it should be caught in the caller method
\r
1109 if (record is ISafeDataRecord) {
\r
1110 SetValue(index,((ISafeDataRecord)record).GetDateTimeSafe(field));
\r
1113 this[index] = record.GetValue(field);
\r
1117 protected override void SetValue(int index, object value)
\r
1119 if (value != null && value != DBNull.Value)
\r
1120 value = Convert.ToDateTime(value);
\r
1121 base.SetValue(index, value);
\r
1123 #endregion //Methods
\r
1127 sealed class DecimalDataContainer : AbstractObjectDataContainer
\r
1130 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1132 bool isDbNull = record.IsDBNull(field);
\r
1134 SetNull(index,false,isDbNull);
\r
1138 // if exception thrown, it should be caught in the caller method
\r
1139 if (record is ISafeDataRecord) {
\r
1140 SetValue(index,((ISafeDataRecord)record).GetDecimalSafe(field));
\r
1143 this[index] = record.GetValue(field);
\r
1147 protected override void SetValue(int index, object value)
\r
1149 if (value != null && value != DBNull.Value)
\r
1150 value = Convert.ToDecimal(value);
\r
1151 base.SetValue(index, value);
\r
1153 #endregion //Methods
\r
1157 sealed class StringDataContainer : AbstractObjectDataContainer
\r
1161 private void SetValue(int index, string value)
\r
1163 if (value != null && Column.MaxLength >= 0 && Column.MaxLength < value.Length ) {
\r
1164 throw new ArgumentException("Cannot set column '" + Column.ColumnName + "' to '" + value + "'. The value violates the MaxLength limit of this column.");
\r
1166 base.SetValue(index,value);
\r
1169 protected override void SetValue(int index, object value)
\r
1171 if ( value != null && value != DBNull.Value ) {
\r
1172 if ( value is string ) {
\r
1173 SetValue(index, (string) value);
\r
1176 SetValue(index, Convert.ToString(value));
\r
1181 base.SetValue(index, value);
\r
1184 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1186 bool isDbNull = record.IsDBNull(field);
\r
1188 SetNull(index,false,isDbNull);
\r
1192 // if exception thrown, it should be caught
\r
1193 // in the caller method
\r
1194 if (record is ISafeDataRecord) {
\r
1195 SetValue(index,((ISafeDataRecord)record).GetStringSafe(field));
\r
1198 this[index] = record.GetValue(field);
\r
1202 internal override int CompareValues(int index1, int index2)
\r
1204 bool isNull1 = IsNull(index1);
\r
1205 bool isNull2 = IsNull(index2);
\r
1208 return isNull2 ? 0 : -1;
\r
1215 return String.Compare((string)this[index1], (string)this[index2], !Column.Table.CaseSensitive);
\r
1218 #endregion //Methods
\r
1221 sealed class CharDataContainer : AbstractDataContainer
\r
1227 #endregion //Fields
\r
1229 #region Properties
\r
1231 internal override object this[int index] {
\r
1233 if (IsNull(index)) {
\r
1234 return DBNull.Value;
\r
1237 return _values[index];
\r
1241 bool isDbNull = (value == DBNull.Value);
\r
1242 if (value == null || isDbNull) {
\r
1243 SetValue(index,'\0');
\r
1245 else if( value is char ) {
\r
1246 SetValue(index,(char)value);
\r
1249 SetValue(index,Convert.ToChar(value));
\r
1251 SetNull(index,value == null,isDbNull);
\r
1255 internal override int Capacity {
\r
1257 base.Capacity = value;
\r
1258 if (_values == null) {
\r
1259 _values = new char[value];
\r
1262 char[] tmp = new char[value];
\r
1263 Array.Copy(_values,0,tmp,0,_values.Length);
\r
1269 #endregion //Properties
\r
1273 private void SetValue(int index, char value)
\r
1275 _values[index] = value;
\r
1278 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1280 bool isDbNull = record.IsDBNull(field);
\r
1282 SetNull(index,false,isDbNull);
\r
1286 // if exception thrown, it should be caught in the caller method
\r
1287 if (record is ISafeDataRecord) {
\r
1288 SetValue(index,((ISafeDataRecord)record).GetCharSafe(field));
\r
1291 this[index] = record.GetValue(field);
\r
1295 internal override void CopyValue(int fromIndex, int toIndex)
\r
1297 base.CopyValue(fromIndex, toIndex);
\r
1298 _values[toIndex] = _values[fromIndex];
\r
1301 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
1303 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
1304 _values[toIndex] = ((CharDataContainer)fromContainer)._values[fromIndex];
\r
1307 internal override int CompareValues(int index1, int index2)
\r
1309 char c1 = _values[index1];
\r
1310 char c2 = _values[index2];
\r
1312 if ( c1 == '\0' || c2 == '\0' )
\r
1314 int cn = CompareNulls(index1, index2);
\r
1322 internal override long GetInt64(int index)
\r
1324 return Convert.ToInt64(_values[index]);
\r
1327 #endregion //Methods
\r
1330 sealed class UInt16DataContainer : AbstractDataContainer
\r
1336 #endregion //Fields
\r
1338 #region Properties
\r
1340 internal override object this[int index] {
\r
1342 if (IsNull(index)) {
\r
1343 return DBNull.Value;
\r
1346 return _values[index];
\r
1350 bool isDbNull = (value == DBNull.Value);
\r
1351 if (value == null || isDbNull) {
\r
1352 SetValue(index,0);
\r
1354 else if( value is ushort ) {
\r
1355 SetValue(index,(ushort)value);
\r
1358 SetValue(index,Convert.ToUInt16(value));
\r
1360 SetNull(index,value == null,isDbNull);
\r
1364 internal override int Capacity {
\r
1366 base.Capacity = value;
\r
1367 if (_values == null) {
\r
1368 _values = new ushort[value];
\r
1371 ushort[] tmp = new ushort[value];
\r
1372 Array.Copy(_values,0,tmp,0,_values.Length);
\r
1378 #endregion //Properties
\r
1382 private void SetValue(int index, ushort value)
\r
1384 _values[index] = value;
\r
1387 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1389 bool isDbNull = record.IsDBNull(field);
\r
1391 SetNull(index,false,isDbNull);
\r
1395 // if exception thrown, it should be caught in the caller method
\r
1396 if (record is ISafeDataRecord) {
\r
1397 SetValue(index,(ushort)((ISafeDataRecord)record).GetInt16Safe(field));
\r
1400 this[index] = record.GetValue(field);
\r
1404 internal override void CopyValue(int fromIndex, int toIndex)
\r
1406 base.CopyValue(fromIndex, toIndex);
\r
1407 _values[toIndex] = _values[fromIndex];
\r
1410 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
1412 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
1413 _values[toIndex] = ((UInt16DataContainer)fromContainer)._values[fromIndex];
\r
1416 internal override int CompareValues(int index1, int index2)
\r
1418 ushort s1 = _values[index1];
\r
1419 ushort s2 = _values[index2];
\r
1421 if ( s1 == 0 || s2 == 0 ) {
\r
1422 int cn = CompareNulls(index1, index2);
\r
1430 internal override long GetInt64(int index)
\r
1432 return Convert.ToInt64(_values[index]);
\r
1435 #endregion //Methods
\r
1438 sealed class UInt32DataContainer : AbstractDataContainer
\r
1444 #endregion //Fields
\r
1446 #region Properties
\r
1448 internal override object this[int index] {
\r
1450 if (IsNull(index)) {
\r
1451 return DBNull.Value;
\r
1454 return _values[index];
\r
1458 bool isDbNull = (value == DBNull.Value);
\r
1459 if (value == null || isDbNull) {
\r
1460 SetValue(index,0);
\r
1462 else if( value is uint ) {
\r
1463 SetValue(index,(uint)value);
\r
1466 SetValue(index,Convert.ToUInt32(value));
\r
1468 SetNull(index,value == null,isDbNull);
\r
1472 internal override int Capacity {
\r
1474 base.Capacity = value;
\r
1475 if (_values == null) {
\r
1476 _values = new uint[value];
\r
1479 uint[] tmp = new uint[value];
\r
1480 Array.Copy(_values,0,tmp,0,_values.Length);
\r
1486 #endregion //Properties
\r
1490 private void SetValue(int index, uint value)
\r
1492 _values[index] = value;
\r
1495 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1497 bool isDbNull = record.IsDBNull(field);
\r
1499 SetNull(index,false,isDbNull);
\r
1503 // if exception thrown, it should be caught in the caller method
\r
1504 if (record is ISafeDataRecord) {
\r
1505 SetValue(index,(uint)((ISafeDataRecord)record).GetInt32Safe(field));
\r
1508 this[index] = record.GetValue(field);
\r
1512 internal override void CopyValue(int fromIndex, int toIndex)
\r
1514 base.CopyValue(fromIndex, toIndex);
\r
1515 _values[toIndex] = _values[fromIndex];
\r
1518 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
1520 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
1521 _values[toIndex] = ((UInt32DataContainer)fromContainer)._values[fromIndex];
\r
1524 internal override int CompareValues(int index1, int index2)
\r
1526 uint i1 = _values[index1];
\r
1527 uint i2 = _values[index2];
\r
1529 if ( i1 == 0 || i2 == 0 ) {
\r
1530 int cn = CompareNulls(index1, index2);
\r
1536 return ( i1 != i2 ) ? -1 : 0;
\r
1541 internal override long GetInt64(int index)
\r
1543 return Convert.ToInt64(_values[index]);
\r
1546 #endregion //Methods
\r
1549 sealed class UInt64DataContainer : AbstractDataContainer
\r
1555 #endregion //Fields
\r
1557 #region Properties
\r
1559 internal override object this[int index] {
\r
1561 if (IsNull(index)) {
\r
1562 return DBNull.Value;
\r
1565 return _values[index];
\r
1569 bool isDbNull = (value == DBNull.Value);
\r
1570 if (value == null || isDbNull) {
\r
1571 SetValue(index,0);
\r
1573 else if( value is ulong ) {
\r
1574 SetValue(index,(ulong)value);
\r
1577 SetValue(index,Convert.ToUInt64(value));
\r
1579 SetNull(index,value == null,isDbNull);
\r
1583 internal override int Capacity {
\r
1585 base.Capacity = value;
\r
1586 if (_values == null) {
\r
1587 _values = new ulong[value];
\r
1590 ulong[] tmp = new ulong[value];
\r
1591 Array.Copy(_values,0,tmp,0,_values.Length);
\r
1597 #endregion //Properties
\r
1601 private void SetValue(int index, ulong value)
\r
1603 _values[index] = value;
\r
1606 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1608 bool isDbNull = record.IsDBNull(field);
\r
1610 SetNull(index,false,isDbNull);
\r
1614 // if exception thrown, it should be caught in the caller method
\r
1615 if (record is ISafeDataRecord) {
\r
1616 SetValue(index,(ulong)((ISafeDataRecord)record).GetInt64Safe(field));
\r
1619 this[index] = record.GetValue(field);
\r
1623 internal override void CopyValue(int fromIndex, int toIndex)
\r
1625 base.CopyValue(fromIndex, toIndex);
\r
1626 _values[toIndex] = _values[fromIndex];
\r
1629 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
1631 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
1632 _values[toIndex] = ((UInt64DataContainer)fromContainer)._values[fromIndex];
\r
1635 internal override int CompareValues(int index1, int index2)
\r
1637 ulong l1 = _values[index1];
\r
1638 ulong l2 = _values[index2];
\r
1640 if ( l1 == 0 || l2 == 0 ) {
\r
1641 int cn = CompareNulls(index1, index2);
\r
1648 return ( l1 != l2 ) ? -1 : 0;
\r
1653 internal override long GetInt64(int index)
\r
1655 return Convert.ToInt64(_values[index]);
\r
1658 #endregion //Methods
\r
1662 sealed class SByteDataContainer : AbstractDataContainer
\r
1668 #endregion //Fields
\r
1670 #region Properties
\r
1672 internal override object this[int index] {
\r
1674 if (IsNull(index)) {
\r
1675 return DBNull.Value;
\r
1678 return _values[index];
\r
1682 bool isDbNull = (value == DBNull.Value);
\r
1683 if (value == null || isDbNull) {
\r
1684 SetValue(index,0);
\r
1686 else if( value is sbyte ) {
\r
1687 SetValue(index,(sbyte)value);
\r
1690 SetValue(index,Convert.ToSByte(value));
\r
1692 SetNull(index,value == null,isDbNull);
\r
1696 internal override int Capacity {
\r
1698 base.Capacity = value;
\r
1699 if (_values == null) {
\r
1700 _values = new sbyte[value];
\r
1703 sbyte[] tmp = new sbyte[value];
\r
1704 Array.Copy(_values,0,tmp,0,_values.Length);
\r
1710 #endregion //Properties
\r
1714 private void SetValue(int index, sbyte value)
\r
1716 _values[index] = value;
\r
1719 internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
\r
1721 bool isDbNull = record.IsDBNull(field);
\r
1723 SetNull(index,false,isDbNull);
\r
1727 // if exception thrown, it should be caught in the caller method
\r
1728 if (record is ISafeDataRecord) {
\r
1729 SetValue(index,(sbyte)((ISafeDataRecord)record).GetByteSafe(field));
\r
1732 this[index] = record.GetValue(field);
\r
1736 internal override void CopyValue(int fromIndex, int toIndex)
\r
1738 base.CopyValue(fromIndex, toIndex);
\r
1739 _values[toIndex] = _values[fromIndex];
\r
1742 internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
\r
1744 base.CopyValue(fromContainer, fromIndex, toIndex);
\r
1745 _values[toIndex] = ((SByteDataContainer)fromContainer)._values[fromIndex];
\r
1748 internal override int CompareValues(int index1, int index2)
\r
1750 sbyte b1 = _values[index1];
\r
1751 sbyte b2 = _values[index2];
\r
1753 if ( b1 == 0 || b2 == 0 ) {
\r
1754 int cn = CompareNulls(index1, index2);
\r
1763 internal override long GetInt64(int index)
\r
1765 return Convert.ToSByte(_values[index]);
\r
1768 #endregion //Methods
\r