2007-07-22 Nagappan A <anagappan@novell.com>
[mono.git] / mcs / class / System.Data / System.Data.Common / DataContainer.cs
index de0d64bc598d2af8f12bf6c875a2908665455c17..0354c2801fb47d40fffd86ef7bb45b28a1934f6c 100644 (file)
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-using System;
-using System.Collections;
-
-namespace System.Data.Common
-{
-       internal abstract class AbstractDataContainer
-       {
-               #region Fields
-
-               BitArray _nullValues;
-               System.Type _type;
-               DataColumn _column;
-
-               #endregion //Fields
-
-               #region Properties
-
-               internal abstract object this[int index] {
-                       get;
-                       set;
-               }
-
-               internal virtual int Capacity {
-                       get { 
-                               return (_nullValues != null) ? _nullValues.Count : 0; 
-                       }
-                       set { 
-                               if (_nullValues == null) {
-                                       _nullValues = new BitArray(value);
-                               }
-                               else {
-                                       _nullValues.Length = value;
-                               }
-                       }
-               }
-
-               internal Type Type {
-                       get {
-                               return _type;
-                       }
-               }
-
-               protected DataColumn Column {
-                       get {
-                               return _column;
-                       }
-               }
-
-               #endregion //Properties
-
-               #region Methods
-
-               internal static AbstractDataContainer CreateInstance(Type type, DataColumn column)
-               {
-                       AbstractDataContainer container;
-                       switch (Type.GetTypeCode(type)) {
-                               case TypeCode.Int16 :
-                                       container = new Int16DataContainer();
-                                       break;
-                               case TypeCode.Int32 : 
-                                       container = new Int32DataContainer();
-                                       break;
-                               case TypeCode.Int64 :
-                                       container = new Int64DataContainer();
-                                       break;
-                               case TypeCode.String :
-                                       container = new StringDataContainer();
-                                       break;
-                               case TypeCode.Boolean:
-                                       container = new BitDataContainer();
-                                       break;
-                               case TypeCode.Byte :
-                                       container = new ByteDataContainer();
-                                       break;
-                               //case TypeCode.Char :
-                               case TypeCode.DateTime :
-                                       container = new DateTimeDataContainer();
-                                       break;
-                               //case TypeCode.Decimal :
-                               case TypeCode.Double :
-                                       container = new DoubleDataContainer();
-                                       break;
-                               //case TypeCode.SByte :
-                               case TypeCode.Single :
-                                       container = new SingleDataContainer();
-                                       break;
-                               //case TypeCode.UInt16 :
-                               //case TypeCode.UInt32 :
-                               //case TypeCode.UInt64 :
-                               default :
-                                       container = new ObjectDataContainer();
-                                       break;
-                       }
-                       container._type = type;
-                       container._column = column;
-                       return container;
-               }
-
-               internal bool IsNull(int index)
-               {
-                       return (_nullValues != null) ? _nullValues[index] : true;
-               }
-
-               internal void SetNullBit(int index,bool isNull)
-               {
-                       _nullValues[index] = isNull;
-               }
-
-               protected void SetNull(int index,bool isNull,bool isDbNull)
-               {
-                       SetNullBit(index,isDbNull);
-                       // this method must be called after setting the value into value array
-                       // otherwise the dafault value will be overriden
-                       if ( isNull ) {
-                               // set the value to default
-                               CopyValue(Column.Table.DefaultValuesRowIndex,index);
-                       }
-               }
-
-               internal void FillValues(int fromIndex)
-               {
-                       for(int i=0; i < Capacity; i++) {
-                               CopyValue(fromIndex,i);
-                               _nullValues[i] = _nullValues[fromIndex];
-                       }
-               }
-
-               internal virtual void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-               {
-                       _nullValues[toIndex] = fromContainer._nullValues[fromIndex];
-               }
-
-               internal virtual void CopyValue(int fromIndex, int toIndex)
-               {
-                       _nullValues[toIndex] = _nullValues[fromIndex];
-               }
-
-               internal virtual void SetItemFromDataRecord(int index, IDataRecord record, int field)
-               {
-                       bool isDbNull = record.IsDBNull(field);
-                       SetNull(index,false,isDbNull);
-               }
-
-               protected  bool CheckAndSetNull( int index, IDataRecord record, int field)
-               {
-                        bool isDbNull = record.IsDBNull(field);
-                        SetNull(index,false,isDbNull);
-                        return isDbNull;               
-               }
-
-               protected int CompareNulls(int index1, int index2)
-               {
-                       bool null1 = IsNull(index1);
-                       bool null2 = IsNull(index2);
-
-                       if ( null1 ^ null2 ) {
-                               return null1 ? -1 : 1;
-                       }
-                       else {
-                               return 0;
-                       }
-               }
-
-               internal abstract int CompareValues(int index1, int index2);
-
-               internal abstract long GetInt64(int index);
-
-               #endregion //Methods
-
-               sealed class Int16DataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       short[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       if (IsNull(index)) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,0);
-                                       }
-                                       else if( value is short ) {
-                                               SetValue(index,(short)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToInt16(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new short[value];
-                                       }
-                                       else {
-                                               short[] tmp = new short[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, short value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                       SetValue(index,record.GetInt16(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((Int16DataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               short s1 = _values[index1];
-                               short s2 = _values[index2];
-
-                               if ( s1 == 0 && s2 == 0 ) {
-                                       int cn = CompareNulls(index1, index2);
-                                       return cn;
-                               }
-
-                               bool b1 = IsNull(index1);
-                               bool b2 = IsNull(index2);
-                               
-                               if ( s1 == 0 && b1 ) {
-                                       return -1;
-                               }
-
-                               if ( s2 == 0 && b2 ) {
-                                       return 1;
-                               }
-
-                               if ( s1 <= s2 ) {
-                                       return ( s1 != s2 ) ? -1 : 0;
-                               }
-                               return 1;
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return (long) _values[index];
-                       }
-
-                       #endregion //Methods
-               }
-
-               sealed class Int32DataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       int[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       if (IsNull(index)) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,0);
-                                       }
-                                       else if( value is int ) {
-                                               SetValue(index,(int)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToInt32(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new int[value];
-                                       }
-                                       else {
-                                               int[] tmp = new int[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, int value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetInt32(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((Int32DataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               int i1 = _values[index1];
-                               int i2 = _values[index2];
-
-                               if ( i1 == 0 && i2 == 0 ) {
-                                       int cn = CompareNulls(index1, index2);
-                                       return cn;
-                               }
-
-                               bool b1 = IsNull(index1);
-                               bool b2 = IsNull(index2);
-                               
-                               if ( i1 == 0 && b1 ) {
-                                       return -1;
-                               }
-
-                               if ( i2 == 0 && b2 ) {
-                                       return 1;
-                               }
-
-                               if ( i1 <= i2 ) {
-                                       return ( i1 != i2 ) ? -1 : 0;
-                               }
-                               return 1;
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return (long) _values[index];
-                       }
-
-                       #endregion //Methods
-               }
-
-               sealed class Int64DataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       long[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       if (IsNull(index)) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,0);
-                                       }
-                                       else if( value is long ) {
-                                               SetValue(index,(long)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToInt64(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new long[value];
-                                       }
-                                       else {
-                                               long[] tmp = new long[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, long value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetInt64(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((Int64DataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               long l1 = _values[index1];
-                               long l2 = _values[index2];
-
-                               if ( l1 == 0 || l2 == 0 ) {
-                                       int cn = CompareNulls(index1, index2);
-                                       if (cn != 0) {
-                                               return cn;
-                                       }
-                               }
-
-                               if ( l1 <= l2 ) {
-                                       return ( l1 != l2 ) ? -1 : 0;
-                               }
-                               return 1;
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return _values[index];
-                       }
-
-                       #endregion //Methods
-               }
-
-               sealed class SingleDataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       float[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       if (IsNull(index)) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,0);
-                                       }
-                                       else if( value is float ) {
-                                               SetValue(index,(float)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToSingle(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new float[value];
-                                       }
-                                       else {
-                                               float[] tmp = new float[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, float value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetFloat(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((SingleDataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               float f1 = _values[index1];
-                               float f2 = _values[index2];
-
-                               if ( f1 == 0 || f2 == 0 ) {
-                                       int cn = CompareNulls(index1, index2);
-                                       if (cn != 0) {
-                                               return cn;
-                                       }
-                               }
-
-                               if ( f1 <= f2 ) {
-                                       return ( f1 != f2 ) ? -1 : 0;
-                               }
-                               return 1;
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return Convert.ToInt64(_values[index]);
-                       }
-
-                       #endregion //Methods
-               }
-
-               sealed class DoubleDataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       double[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       if (IsNull(index)) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,0);
-                                       }
-                                       else if( value is double ) {
-                                               SetValue(index,(double)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToDouble(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new double[value];
-                                       }
-                                       else {
-                                               double[] tmp = new double[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, double value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetDouble(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((DoubleDataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               double d1 = _values[index1];
-                               double d2 = _values[index2];
-
-                               if ( d1 == 0 || d2 == 0 ) {
-                                       int cn = CompareNulls(index1, index2);
-                                       if (cn != 0) {
-                                               return cn;
-                                       }
-                               }
-
-                               if ( d1 <= d2 ) {
-                                       return ( d1 != d2 ) ? -1 : 0;
-                               }
-                               return 1;
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return Convert.ToInt64(_values[index]);
-                       }
-
-                       #endregion //Methods
-               }
-
-               sealed class ByteDataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       byte[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       if (IsNull(index)) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,0);
-                                       }
-                                       else if( value is byte ) {
-                                               SetValue(index,(byte)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToByte(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new byte[value];
-                                       }
-                                       else {
-                                               byte[] tmp = new byte[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, byte value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetByte(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((ByteDataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               byte b1 = _values[index1];
-                               byte b2 = _values[index2];
-
-                               if ( b1 == 0 || b2 == 0 ) {
-                                       int cn = CompareNulls(index1, index2);
-                                       if (cn != 0) {
-                                               return cn;
-                                       }
-                               }
-
-                               if ( b1 <= b2 ) {
-                                       return ( b1 != b2 ) ? -1 : 0;
-                               }
-                               return 1;
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return (long) _values[index];
-                       }
-
-                       #endregion //Methods
-               }
-
-               sealed class BitDataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       bool[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       bool isNull = IsNull(index);
-                                       if (isNull) {
-                                               return DBNull.Value;
-                                       }
-                                       else {
-                                               return _values[index];
-                                       }
-                               }
-                               set {
-                                       bool isDbNull = (value ==  DBNull.Value);
-                                       if (value == null || isDbNull) {
-                                               SetValue(index,false);
-                                       }
-                                       else if( value is bool ) {
-                                               SetValue(index,(bool)value);
-                                       }
-                                       else {
-                                               SetValue(index,Convert.ToBoolean(value));
-                                       }
-                                       SetNull(index,value == null,isDbNull);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new bool[value];
-                                       }
-                                       else {
-                                               bool[] tmp = new bool[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       private void SetValue(int index, bool value)
-                       {
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetBoolean(field));
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((BitDataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               bool b1 = _values[index1];
-                               bool b2 = _values[index2];
-
-                               if ( b1 ^ b2 ) {
-                                       return b1 ? 1 : -1;
-                               }
-                               
-                               if ( b1 ) {
-                                       return 0;
-                               }
-
-                               return CompareNulls(index1, index2);    
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return Convert.ToInt64(_values[index]);
-                       }
-
-                       #endregion //Methods
-               }
-
-               class ObjectDataContainer : AbstractDataContainer
-               {
-                       #region Fields
-               
-                       object[] _values;
-
-                       #endregion //Fields
-
-                       #region Properties
-
-                       internal override object this[int index] {
-                               get {
-                                       return _values[index];
-                               }
-                               set {
-                                       SetValue(index,value);
-                                       SetNull(index,value == null,value == DBNull.Value);
-                               }
-                       }
-
-                       internal override int Capacity {
-                               set {
-                                       base.Capacity = value;
-                                       if (_values == null) {
-                                               _values = new object[value];
-                                       }
-                                       else {
-                                               object[] tmp = new object[value];
-                                               Array.Copy(_values,0,tmp,0,_values.Length);
-                                               _values = tmp;
-                                       }
-                               }
-                       }
-
-                       #endregion //Properties
-
-                       #region Methods
-                       
-                       protected virtual void SetValue(int index, object value)
-                       {
-                               if(value == null) {
-                                       value = Column.DefaultValue;
-                               }
-                               _values[index] = value;
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller metho
-                               SetValue(index,record.GetValue(field));
-                               base.SetItemFromDataRecord(index,record,field);
-                       }
-
-                       internal override void CopyValue(int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromIndex, toIndex);
-                               _values[toIndex] = _values[fromIndex];
-                       }
-
-                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)
-                       {
-                               base.CopyValue(fromContainer, fromIndex, toIndex);
-                               _values[toIndex] = ((ObjectDataContainer)fromContainer)._values[fromIndex];
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               object obj1 = _values[index1];
-                               object obj2 = _values[index2];
-                               if(obj1 == obj2) {
-                                       return 0;
-                               }
-                               else if (obj1 is IComparable) {
-                                       try {
-                                               return ((IComparable)obj1).CompareTo(obj2);
-                                       }
-                                       catch {
-                                               //just suppress
-                                       }
-
-                                       if (obj2 is IComparable) {
-                                               obj2 = Convert.ChangeType(obj2, Type.GetTypeCode(obj1.GetType()));
-                                               return ((IComparable)obj1).CompareTo(obj2);
-                                       }
-                               }
-
-                               return String.Compare(obj1.ToString(), obj2.ToString());
-                       }
-
-                       internal override long GetInt64(int index)
-                       {
-                               return Convert.ToInt64(_values[index]);
-                       }
-
-                       #endregion //Methods
-        
-               }
-
-               sealed class StringDataContainer : ObjectDataContainer
-               {
-                       #region Methods
-
-                       private void SetValue(int index, string value)
-                       {
-                               if (value != null && Column.MaxLength >= 0 && Column.MaxLength < value.Length ) {
-                                       throw new ArgumentException("Cannot set column '" + Column.ColumnName + "' to '" + value + "'. The value violates the MaxLength limit of this column.");
-                               }
-                               base.SetValue(index,value);
-                       }
-                       
-                       protected override void SetValue(int index, object value)
-                       {
-                               if ( value != null && value != DBNull.Value ) {
-                                       if ( value is string ) {
-                                               SetValue(index, (string) value);
-                                       }
-                                       else {
-                                               SetValue(index, Convert.ToString(value));
-                                       }
-                                       return;
-                               }
-
-                               base.SetValue(index, value);
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                               if (!CheckAndSetNull ( index, record,field))
-                                        SetValue(index,record.GetString(field));
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               bool isNull1 = IsNull(index1);
-                               bool isNull2 = IsNull(index2);
-
-                               if (isNull1) {
-                                       return isNull2 ? 0 : -1;
-                               }
-                               else {
-                                       if (isNull2) {
-                                               return 1;
-                                       }
-                               }
-                               return String.Compare((string)this[index1], (string)this[index2], !Column.Table.CaseSensitive);
-                       }
-
-                       #endregion //Methods 
-               }
-
-               sealed class DateTimeDataContainer : ObjectDataContainer
-               {
-                       #region Methods
-                       
-                       protected override void SetValue(int index, object value)
-                       {
-                               if ( value != null && value != DBNull.Value && !(value is DateTime)) {
-                                       value = Convert.ToDateTime(value);
-                               }
-
-                               base.SetValue(index,value);
-                       }
-
-                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)
-                       {
-                               // if exception thrown, it should be caught 
-                               // in the  caller method
-                                if (!CheckAndSetNull(index,record,field))
-                                        base.SetValue(index,record.GetDateTime(field));
-                       }
-
-                       internal override int CompareValues(int index1, int index2)
-                       {
-                               bool isNull1 = IsNull(index1);
-                               bool isNull2 = IsNull(index2);
-
-                               if (isNull1) {
-                                       return isNull2 ? 0 : -1;
-                               }
-                               else {
-                                       if (isNull2) {
-                                               return 1;
-                                       }
-                               }
-                               return DateTime.Compare((DateTime)this[index1], (DateTime)this[index2]);
-                       }
-
-                       #endregion //Methods 
-               }
-       }
-}
+\r
+//\r
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+using System;\r
+using System.Collections;\r
+\r
+namespace System.Data.Common\r
+{\r
+       internal abstract class AbstractDataContainer\r
+       {\r
+               #region Fields\r
+\r
+               BitArray _nullValues;\r
+               System.Type _type;\r
+               DataColumn _column;\r
+\r
+               #endregion //Fields\r
+\r
+               #region Properties\r
+\r
+               internal abstract object this[int index] {\r
+                       get;\r
+                       set;\r
+               }\r
+\r
+               internal virtual int Capacity {\r
+                       get { \r
+                               return (_nullValues != null) ? _nullValues.Count : 0; \r
+                       }\r
+                       set { \r
+                               if (_nullValues == null) {\r
+                                       _nullValues = new BitArray(value);\r
+                               }\r
+                               else {\r
+                                       _nullValues.Length = value;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               internal Type Type {\r
+                       get {\r
+                               return _type;\r
+                       }\r
+               }\r
+\r
+               protected DataColumn Column {\r
+                       get {\r
+                               return _column;\r
+                       }\r
+               }\r
+\r
+               #endregion //Properties\r
+\r
+               #region Methods\r
+\r
+               internal static AbstractDataContainer CreateInstance(Type type, DataColumn column)\r
+               {\r
+                       AbstractDataContainer container;\r
+                       switch (Type.GetTypeCode(type)) {\r
+                               case TypeCode.Int16 :\r
+                                       container = new Int16DataContainer();\r
+                                       break;\r
+                               case TypeCode.Int32 : \r
+                                       container = new Int32DataContainer();\r
+                                       break;\r
+                               case TypeCode.Int64 :\r
+                                       container = new Int64DataContainer();\r
+                                       break;\r
+                               case TypeCode.String :\r
+                                       container = new StringDataContainer();\r
+                                       break;\r
+                               case TypeCode.Boolean:\r
+                                       container = new BitDataContainer();\r
+                                       break;\r
+                               case TypeCode.Byte :\r
+                                       container = new ByteDataContainer();\r
+                                       break;\r
+                               case TypeCode.Char :\r
+                                       container = new CharDataContainer();\r
+                                       break;\r
+                               case TypeCode.Double :\r
+                                       container = new DoubleDataContainer();\r
+                                       break;\r
+                               case TypeCode.SByte :\r
+                                       container = new SByteDataContainer();\r
+                                       break;\r
+                               case TypeCode.Single :\r
+                                       container = new SingleDataContainer();\r
+                                       break;\r
+                               case TypeCode.UInt16 :\r
+                                       container = new UInt16DataContainer();\r
+                                       break;\r
+                               case TypeCode.UInt32 :\r
+                                       container = new UInt32DataContainer();\r
+                                       break;\r
+                               case TypeCode.UInt64 :\r
+                                       container = new UInt64DataContainer();\r
+                                       break;\r
+                               case TypeCode.DateTime :\r
+                                       container = new DateTimeDataContainer();\r
+                                       break;\r
+                               case TypeCode.Decimal :\r
+                                       container = new DecimalDataContainer();\r
+                                       break;\r
+                               default :\r
+                                       container = new ObjectDataContainer();\r
+                                       break;\r
+                       }\r
+                       container._type = type;\r
+                       container._column = column;\r
+                       return container;\r
+               }\r
+\r
+               internal bool IsNull(int index)\r
+               {\r
+                       return (_nullValues != null) ? _nullValues[index] : true;\r
+               }\r
+\r
+               internal void SetNullBit(int index,bool isNull)\r
+               {\r
+                       _nullValues[index] = isNull;\r
+               }\r
+\r
+               protected void SetNull(int index,bool isNull,bool isDbNull)\r
+               {\r
+                       SetNullBit(index,isDbNull);\r
+                       // this method must be called after setting the value into value array\r
+                       // otherwise the dafault value will be overriden\r
+                       if ( isNull ) {\r
+                               // set the value to default\r
+                               CopyValue(Column.Table.DefaultValuesRowIndex,index);\r
+                       }\r
+               }\r
+\r
+               internal void FillValues(int fromIndex)\r
+               {\r
+                       for(int i=0; i < Capacity; i++) {\r
+                               CopyValue(fromIndex,i);\r
+                               _nullValues[i] = _nullValues[fromIndex];\r
+                       }\r
+               }\r
+\r
+               internal virtual void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+               {\r
+                       _nullValues[toIndex] = fromContainer._nullValues[fromIndex];\r
+               }\r
+\r
+               internal virtual void CopyValue(int fromIndex, int toIndex)\r
+               {\r
+                       _nullValues[toIndex] = _nullValues[fromIndex];\r
+               }\r
+\r
+               internal abstract void SetItemFromDataRecord(int index, IDataRecord record, int field);\r
+\r
+               protected int CompareNulls(int index1, int index2)\r
+               {\r
+                       bool null1 = IsNull(index1);\r
+                       bool null2 = IsNull(index2);\r
+\r
+                       if ( null1 ^ null2 ) {\r
+                               return null1 ? -1 : 1;\r
+                       }\r
+                       else {\r
+                               return 0;\r
+                       }\r
+               }\r
+\r
+               internal abstract int CompareValues(int index1, int index2);\r
+\r
+               internal abstract long GetInt64(int index);\r
+\r
+               #endregion //Methods\r
+\r
+               sealed class Int16DataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       short[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is short ) {\r
+                                               SetValue(index,(short)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToInt16(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new short[value];\r
+                                       }\r
+                                       else {\r
+                                               short[] tmp = new short[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, short value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetInt16Safe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((Int16DataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               short s1 = _values[index1];\r
+                               short s2 = _values[index2];\r
+\r
+                               if ( s1 == 0 || s2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0)\r
+                                               return cn;\r
+                               }\r
+\r
+                               return s1 - s2;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return (long) _values[index];\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class Int32DataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       int[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is int ) {\r
+                                               SetValue(index,(int)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToInt32(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new int[value];\r
+                                       }\r
+                                       else {\r
+                                               int[] tmp = new int[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, int value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetInt32Safe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((Int32DataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               int i1 = _values[index1];\r
+                               int i2 = _values[index2];\r
+                               \r
+                               if (i1 == 0 || i2 == 0) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0)\r
+                                               return cn;\r
+                               }\r
+\r
+                               if ( i1 <= i2 ) {\r
+                                       return ( i1 == i2 ) ? 0 : -1;\r
+                               }\r
+                               return 1;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return (long) _values[index];\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class Int64DataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       long[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is long ) {\r
+                                               SetValue(index,(long)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToInt64(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new long[value];\r
+                                       }\r
+                                       else {\r
+                                               long[] tmp = new long[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, long value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetInt64Safe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((Int64DataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               long l1 = _values[index1];\r
+                               long l2 = _values[index2];\r
+\r
+                               if ( l1 == 0 || l2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) {\r
+                                               return cn;\r
+                                       }\r
+                               }\r
+\r
+                               if ( l1 <= l2 ) {\r
+                                       return ( l1 != l2 ) ? -1 : 0;\r
+                               }\r
+                               return 1;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return _values[index];\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class SingleDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       float[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is float ) {\r
+                                               SetValue(index,(float)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToSingle(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new float[value];\r
+                                       }\r
+                                       else {\r
+                                               float[] tmp = new float[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, float value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetFloatSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((SingleDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               float f1 = _values[index1];\r
+                               float f2 = _values[index2];\r
+\r
+                               if ( f1 == 0 || f2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) {\r
+                                               return cn;\r
+                                       }\r
+                               }\r
+\r
+                               if ( f1 <= f2 ) {\r
+                                       return ( f1 != f2 ) ? -1 : 0;\r
+                               }\r
+                               return 1;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class DoubleDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       double[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is double ) {\r
+                                               SetValue(index,(double)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToDouble(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new double[value];\r
+                                       }\r
+                                       else {\r
+                                               double[] tmp = new double[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, double value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetDoubleSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((DoubleDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               double d1 = _values[index1];\r
+                               double d2 = _values[index2];\r
+\r
+                               if ( d1 == 0 || d2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) {\r
+                                               return cn;\r
+                                       }\r
+                               }\r
+\r
+                               if ( d1 <= d2 ) {\r
+                                       return ( d1 != d2 ) ? -1 : 0;\r
+                               }\r
+                               return 1;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class ByteDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       byte[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is byte ) {\r
+                                               SetValue(index,(byte)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToByte(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new byte[value];\r
+                                       }\r
+                                       else {\r
+                                               byte[] tmp = new byte[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, byte value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetByteSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((ByteDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               byte b1 = _values[index1];\r
+                               byte b2 = _values[index2];\r
+\r
+                               if ( b1 == 0 || b2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) {\r
+                                               return cn;\r
+                                       }\r
+                               }\r
+\r
+                               return b1 - b2;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return (long) _values[index];\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class BitDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       bool[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       bool isNull = IsNull(index);\r
+                                       if (isNull) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,false);\r
+                                       }\r
+                                       else if( value is bool ) {\r
+                                               SetValue(index,(bool)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToBoolean(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new bool[value];\r
+                                       }\r
+                                       else {\r
+                                               bool[] tmp = new bool[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, bool value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetBooleanSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((BitDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               bool b1 = _values[index1];\r
+                               bool b2 = _values[index2];\r
+\r
+                               if ( b1 ^ b2 ) {\r
+                                       return b1 ? 1 : -1;\r
+                               }\r
+                               \r
+                               if ( b1 ) {\r
+                                       return 0;\r
+                               }\r
+\r
+                               return CompareNulls(index1, index2);    \r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               abstract class AbstractObjectDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       object[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) \r
+                                               return DBNull.Value;\r
+\r
+                                       return _values[index];\r
+                               }\r
+                               set {\r
+                                       SetValue(index,value);\r
+                                       SetNull(index,value == null,value == DBNull.Value);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new object[value];\r
+                                       }\r
+                                       else {\r
+                                               object[] tmp = new object[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       protected virtual void SetValue(int index, object value)\r
+                       {\r
+                               if(value == null) {\r
+                                       value = Column.DefaultValue;\r
+                               }\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((AbstractObjectDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               object obj1 = _values[index1];\r
+                               object obj2 = _values[index2];\r
+                               if(obj1 == obj2) \r
+                               {\r
+                                       return 0;\r
+                               }\r
+                               else\r
+                               {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) \r
+                                               return cn;\r
+\r
+                                       if (obj1 is IComparable) \r
+                                       {\r
+                                               try \r
+                                               {\r
+                                                       return ((IComparable)obj1).CompareTo(obj2);\r
+                                               }\r
+                                               catch \r
+                                               {\r
+                                                       //just suppress\r
+                                               }\r
+\r
+                                               if (obj2 is IComparable) \r
+                                               {\r
+                                                       obj2 = Convert.ChangeType(obj2, Type.GetTypeCode(obj1.GetType()));\r
+                                                       return ((IComparable)obj1).CompareTo(obj2);\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               return String.Compare(obj1.ToString(), obj2.ToString());\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+        \r
+               }\r
+\r
+               sealed class ObjectDataContainer : AbstractObjectDataContainer\r
+               {\r
+                       #region Methods\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught \r
+                               // in the  caller method\r
+                               SetValue(index,record.GetValue(field));\r
+                       }\r
+\r
+                       #endregion //Methods\r
+        \r
+               }\r
+\r
+               sealed class DateTimeDataContainer : AbstractObjectDataContainer\r
+               {\r
+                       #region Methods\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught \r
+                               // in the  caller method\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetDateTimeSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       protected override void SetValue(int index, object value)\r
+                       {\r
+                               if (value != null && value != DBNull.Value)\r
+                                       value = Convert.ToDateTime(value);\r
+                               base.SetValue(index, value);\r
+                       }\r
+                       #endregion //Methods\r
+        \r
+               }\r
+\r
+               sealed class DecimalDataContainer : AbstractObjectDataContainer\r
+               {\r
+                       #region Methods\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetDecimalSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       protected override void SetValue(int index, object value)\r
+                       {\r
+                               if (value != null && value != DBNull.Value)\r
+                                       value = Convert.ToDecimal(value);\r
+                               base.SetValue(index, value);\r
+                       }\r
+                       #endregion //Methods\r
+        \r
+               }\r
+\r
+               sealed class StringDataContainer : AbstractObjectDataContainer\r
+               {\r
+                       #region Methods\r
+\r
+                       private void SetValue(int index, string value)\r
+                       {\r
+                               if (value != null && Column.MaxLength >= 0 && Column.MaxLength < value.Length ) {\r
+                                       throw new ArgumentException("Cannot set column '" + Column.ColumnName + "' to '" + value + "'. The value violates the MaxLength limit of this column.");\r
+                               }\r
+                               base.SetValue(index,value);\r
+                       }\r
+                       \r
+                       protected override void SetValue(int index, object value)\r
+                       {\r
+                               if ( value != null && value != DBNull.Value ) {\r
+                                       if ( value is string ) {\r
+                                               SetValue(index, (string) value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index, Convert.ToString(value));\r
+                                       }\r
+                                       return;\r
+                               }\r
+\r
+                               base.SetValue(index, value);\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught \r
+                               // in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetStringSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               bool isNull1 = IsNull(index1);\r
+                               bool isNull2 = IsNull(index2);\r
+\r
+                               if (isNull1) {\r
+                                       return isNull2 ? 0 : -1;\r
+                               }\r
+                               else {\r
+                                       if (isNull2) {\r
+                                               return 1;\r
+                                       }\r
+                               }\r
+                               return String.Compare((string)this[index1], (string)this[index2], !Column.Table.CaseSensitive, Column.Table.Locale);\r
+                       }\r
+\r
+                       #endregion //Methods \r
+               }\r
+\r
+               sealed class CharDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       char[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,'\0');\r
+                                       }\r
+                                       else if( value is char ) {\r
+                                               SetValue(index,(char)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToChar(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new char[value];\r
+                                       }\r
+                                       else {\r
+                                               char[] tmp = new char[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, char value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,((ISafeDataRecord)record).GetCharSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((CharDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               char c1 = _values[index1];\r
+                               char c2 = _values[index2];\r
+\r
+                               if ( c1 == '\0' || c2 == '\0' ) \r
+                               {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) \r
+                                               return cn;\r
+                               }\r
+\r
+                               return c1 - c2;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class UInt16DataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       ushort[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is ushort ) {\r
+                                               SetValue(index,(ushort)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToUInt16(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new ushort[value];\r
+                                       }\r
+                                       else {\r
+                                               ushort[] tmp = new ushort[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, ushort value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,(ushort)((ISafeDataRecord)record).GetInt16Safe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((UInt16DataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               ushort s1 = _values[index1];\r
+                               ushort s2 = _values[index2];\r
+\r
+                               if ( s1 == 0 || s2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0)\r
+                                               return cn;\r
+                               }\r
+\r
+                               return s1 - s2;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class UInt32DataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       uint[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is uint ) {\r
+                                               SetValue(index,(uint)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToUInt32(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new uint[value];\r
+                                       }\r
+                                       else {\r
+                                               uint[] tmp = new uint[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, uint value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,(uint)((ISafeDataRecord)record).GetInt32Safe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((UInt32DataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               uint i1 = _values[index1];\r
+                               uint i2 = _values[index2];\r
+\r
+                               if ( i1 == 0 || i2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0)\r
+                                               return cn;\r
+                               }\r
+\r
+                               if ( i1 <= i2 ) {\r
+                                       return ( i1 != i2 ) ? -1 : 0;\r
+                               }\r
+                               return 1;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+               sealed class UInt64DataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       ulong[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is ulong ) {\r
+                                               SetValue(index,(ulong)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToUInt64(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new ulong[value];\r
+                                       }\r
+                                       else {\r
+                                               ulong[] tmp = new ulong[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, ulong value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,(ulong)((ISafeDataRecord)record).GetInt64Safe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((UInt64DataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               ulong l1 = _values[index1];\r
+                               ulong l2 = _values[index2];\r
+\r
+                               if ( l1 == 0 || l2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) {\r
+                                               return cn;\r
+                                       }\r
+                               }\r
+\r
+                               if ( l1 <= l2 ) {\r
+                                       return ( l1 != l2 ) ? -1 : 0;\r
+                               }\r
+                               return 1;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToInt64(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+\r
+               sealed class SByteDataContainer : AbstractDataContainer\r
+               {\r
+                       #region Fields\r
+               \r
+                       sbyte[] _values;\r
+\r
+                       #endregion //Fields\r
+\r
+                       #region Properties\r
+\r
+                       internal override object this[int index] {\r
+                               get {\r
+                                       if (IsNull(index)) {\r
+                                               return DBNull.Value;\r
+                                       }\r
+                                       else {\r
+                                               return _values[index];\r
+                                       }\r
+                               }\r
+                               set {\r
+                                       bool isDbNull = (value ==  DBNull.Value);\r
+                                       if (value == null || isDbNull) {\r
+                                               SetValue(index,0);\r
+                                       }\r
+                                       else if( value is sbyte ) {\r
+                                               SetValue(index,(sbyte)value);\r
+                                       }\r
+                                       else {\r
+                                               SetValue(index,Convert.ToSByte(value));\r
+                                       }\r
+                                       SetNull(index,value == null,isDbNull);\r
+                               }\r
+                       }\r
+\r
+                       internal override int Capacity {\r
+                               set {\r
+                                       base.Capacity = value;\r
+                                       if (_values == null) {\r
+                                               _values = new sbyte[value];\r
+                                       }\r
+                                       else {\r
+                                               sbyte[] tmp = new sbyte[value];\r
+                                               Array.Copy(_values,0,tmp,0,_values.Length);\r
+                                               _values = tmp;\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+                       #endregion //Properties\r
+\r
+                       #region Methods\r
+                       \r
+                       private void SetValue(int index, sbyte value)\r
+                       {\r
+                               _values[index] = value;\r
+                       }\r
+\r
+                       internal override void SetItemFromDataRecord(int index, IDataRecord record, int field)\r
+                       {\r
+                               bool isDbNull = record.IsDBNull(field);\r
+                               if (isDbNull) {\r
+                                       SetNull(index,false,isDbNull);\r
+                                       return;\r
+                               }\r
+\r
+                               // if exception thrown, it should be caught in the  caller method\r
+                               if (record is ISafeDataRecord) {\r
+                                       SetValue(index,(sbyte)((ISafeDataRecord)record).GetByteSafe(field));\r
+                               }\r
+                               else {\r
+                                       this[index] = record.GetValue(field);\r
+                               }\r
+                       }\r
+\r
+                       internal override void CopyValue(int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromIndex, toIndex);\r
+                               _values[toIndex] = _values[fromIndex];\r
+                       }\r
+\r
+                       internal override void CopyValue(AbstractDataContainer fromContainer, int fromIndex, int toIndex)\r
+                       {\r
+                               base.CopyValue(fromContainer, fromIndex, toIndex);\r
+                               _values[toIndex] = ((SByteDataContainer)fromContainer)._values[fromIndex];\r
+                       }\r
+\r
+                       internal override int CompareValues(int index1, int index2)\r
+                       {\r
+                               sbyte b1 = _values[index1];\r
+                               sbyte b2 = _values[index2];\r
+\r
+                               if ( b1 == 0 || b2 == 0 ) {\r
+                                       int cn = CompareNulls(index1, index2);\r
+                                       if (cn != 0) {\r
+                                               return cn;\r
+                                       }\r
+                               }\r
+\r
+                               return b1 - b2;\r
+                       }\r
+\r
+                       internal override long GetInt64(int index)\r
+                       {\r
+                               return Convert.ToSByte(_values[index]);\r
+                       }\r
+\r
+                       #endregion //Methods\r
+               }\r
+\r
+       }\r
+}\r