using System;
using System.Collections;
using System.Reflection;
+#if !FULL_AOT_RUNTIME
using System.Reflection.Emit;
+#endif
namespace System.Data.Common
{
DataColumn _column;
// implementing class protocol
- protected abstract object GetValue (int index);
+ protected internal abstract object GetValue (int index);
internal abstract long GetInt64 (int index);
// used to set the array value to something neutral when the corresponding item is null (in the database sense)
get { return IsNull (index) ? DBNull.Value : GetValue (index); }
set {
if (value == null) {
- CopyValue (Column.Table.DefaultValuesRowIndex, index);
+ // Table might not have a default values row to copy from
+ if (Column.Table.DefaultValuesRowIndex == -1) {
+ ZeroOut (index);
+ null_values [index] = true;
+ } else {
+ CopyValue (Column.Table.DefaultValuesRowIndex, index);
+ }
return;
}
{
object obj;
TypeCode tc;
-
+
+ if (value == null)
+ return null;
+
if (_type.IsInstanceOfType (value)) {
return value;
} else if ((tc = Type.GetTypeCode (_type)) == TypeCode.String) {
case TypeCode.UInt64:
return (Convert.ToUInt64 (value));
case TypeCode.DateTime:
+ if (value == DBNull.Value)
+ return DBNull.Value;
return (Convert.ToDateTime (value));
case TypeCode.Decimal:
return (Convert.ToDecimal (value));
default:
- throw new InvalidCastException ();
+ throw new InvalidCastException (string.Format ("Cannot convert from {0} to {1}", value.GetType ().FullName, _type.FullName));
}
} else if ((obj = GetExplicitValue (value)) != null) {
return (obj);
sealed class BitDataContainer : DataContainer {
BitArray _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((BitDataContainer) from)._values [from_index];
+ _values [to_index] = (bool) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class CharDataContainer : DataContainer {
char [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((CharDataContainer) from)._values [from_index];
+ _values [to_index] = (char) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class ByteDataContainer : DataContainer {
byte [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((ByteDataContainer) from)._values [from_index];
+ _values [to_index] = (byte) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class SByteDataContainer : DataContainer {
sbyte [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((SByteDataContainer) from)._values [from_index];
+ _values [to_index] = (sbyte) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class Int16DataContainer : DataContainer {
short [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((Int16DataContainer) from)._values [from_index];
+ _values [to_index] = (short) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class UInt16DataContainer : DataContainer {
ushort [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((UInt16DataContainer) from)._values [from_index];
+ _values [to_index] = (ushort) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class Int32DataContainer : DataContainer {
int [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((Int32DataContainer) from)._values [from_index];
+ _values [to_index] = (int) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class UInt32DataContainer : DataContainer {
uint [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((UInt32DataContainer) from)._values [from_index];
+ _values [to_index] = (uint) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class Int64DataContainer : DataContainer {
long [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((Int64DataContainer) from)._values [from_index];
+ _values [to_index] = (long) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class UInt64DataContainer : DataContainer {
ulong [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((UInt64DataContainer) from)._values [from_index];
+ _values [to_index] = (ulong) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class SingleDataContainer : DataContainer {
float [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((SingleDataContainer) from)._values [from_index];
+ _values [to_index] = (float) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
sealed class DoubleDataContainer : DataContainer {
double [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((DoubleDataContainer) from)._values [from_index];
+ _values [to_index] = (double) GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)
class ObjectDataContainer : DataContainer {
object [] _values;
- protected override object GetValue (int index)
+ protected internal override object GetValue (int index)
{
return _values [index];
}
protected override void DoCopyValue (DataContainer from, int from_index, int to_index)
{
- _values [to_index] = ((ObjectDataContainer) from)._values [from_index];
+ _values [to_index] = GetContainerData (from.GetValue (from_index));
}
protected override int DoCompareValues (int index1, int index2)