public void ConvertValue(IBedValueReader reader, TypeStorage dsttype, IBedValueWriter writer) { var srctype = reader.GetFieldType(); if (srctype == dsttype) { // no conversion needed writer.ReadFrom(reader); return; } if (srctype.IsNumber() && dsttype.IsNumber()) { if (dsttype.IsInteger()) { writer.SetIntegerValue(dsttype, reader.GetIntegerValue()); } else { writer.SetRealValue(dsttype, reader.GetRealValue()); } return; } if (srctype.IsDateRelated() && dsttype.IsDateRelated()) { writer.SetDateTimeValue(dsttype, reader.GetDateTimeValue()); return; } if (srctype == TypeStorage.Boolean && dsttype.IsNumber()) { bool val = reader.GetBoolean(); writer.SetIntegerValue(dsttype, val ? 1 : 0); return; } if (srctype.IsNumber() && dsttype == TypeStorage.Boolean) { long val = reader.GetIntegerValue(); writer.SetBoolean(val != 0); return; } if (srctype == TypeStorage.String) { // parse m_parser.ParseValue(reader.GetString(), dsttype, writer); return; } if (dsttype == TypeStorage.String) { // format m_formatter.ReadFrom(reader); writer.SetString(m_formatter.GetText()); return; } { // most generic case - format and than parse m_formatter.ReadFrom(reader); m_parser.ParseValue(m_formatter.GetText(), dsttype, writer); return; } }
public void GetData(IBedValueWriter writer) { if (m_row == null) { return; } m_row.ReadValue(m_colindex); writer.ReadFrom(m_row); }
public void AdaptValue(IBedValueReader reader, DbTypeBase type, IBedValueWriter writer, IBedValueConvertor converter, ILogger logger) { if (reader.GetFieldType() == TypeStorage.Null) { m_holder.SetNull(); } else { converter.ConvertValue(reader, type.DefaultStorage, m_holder); ApplyTypeRestrictions(m_holder, type, logger); } writer.ReadFrom(m_holder); }
public void GetData(IBedValueWriter writer) { writer.ReadFrom(m_data); }
public static void ReadFrom(this IBedValueWriter writer, object value) { if (value == null || value == DBNull.Value) { writer.SetNull(); return; } var valreader = value as IBedValueReader; if (valreader != null) { writer.ReadFrom(valreader); return; } Type type = value.GetType(); switch (Type.GetTypeCode(type)) { case TypeCode.Boolean: writer.SetBoolean((bool)value); break; case TypeCode.Byte: writer.SetByte((byte)value); break; case TypeCode.Int16: writer.SetInt16((short)value); break; case TypeCode.Int32: writer.SetInt32((int)value); break; case TypeCode.Int64: writer.SetInt64((long)value); break; case TypeCode.SByte: writer.SetSByte((sbyte)value); break; case TypeCode.UInt16: writer.SetUInt16((ushort)value); break; case TypeCode.UInt32: writer.SetUInt32((uint)value); break; case TypeCode.UInt64: writer.SetUInt64((ulong)value); break; case TypeCode.DateTime: writer.SetDateTime((DateTime)value); break; case TypeCode.Decimal: writer.SetDecimal((decimal)value); break; case TypeCode.Single: writer.SetFloat((float)value); break; case TypeCode.Double: writer.SetDouble((double)value); break; case TypeCode.String: writer.SetString((string)value); break; default: if (type == typeof(Guid)) { writer.SetGuid((Guid)value); } else if (type == typeof(byte[])) { writer.SetByteArray((byte[])value); } else if (type == typeof(DateTimeEx)) { writer.SetDateTimeEx((DateTimeEx)value); } else if (type == typeof(DateEx)) { writer.SetDateEx((DateEx)value); } else if (type == typeof(TimeEx)) { writer.SetTimeEx((TimeEx)value); } else { writer.SetString(value.ToString()); } break; } }
public static void ReadFrom(this IBedValueWriter writer, IDataRecord record, int index) { if (record.IsDBNull(index)) { writer.SetNull(); return; } Type type = record.GetFieldType(index); try { switch (Type.GetTypeCode(type)) { case TypeCode.Boolean: writer.SetBoolean(record.GetBoolean(index)); break; case TypeCode.Byte: writer.SetByte(record.GetByte(index)); break; case TypeCode.Int16: writer.SetInt16(record.GetInt16(index)); break; case TypeCode.Int32: writer.SetInt32(record.GetInt32(index)); break; case TypeCode.Int64: writer.SetInt64(record.GetInt64(index)); break; case TypeCode.SByte: unchecked { writer.SetSByte((sbyte)record.GetByte(index)); } break; case TypeCode.UInt16: unchecked { writer.SetUInt16((ushort)record.GetInt16(index)); } break; case TypeCode.UInt32: unchecked { writer.SetUInt32((uint)record.GetInt32(index)); } break; case TypeCode.UInt64: unchecked { writer.SetUInt64((ulong)record.GetInt64(index)); } break; case TypeCode.DateTime: writer.SetDateTime(record.GetDateTime(index)); break; case TypeCode.Decimal: writer.SetDecimal(record.GetDecimal(index)); break; case TypeCode.Single: writer.SetFloat(record.GetFloat(index)); break; case TypeCode.Double: writer.SetDouble(record.GetDouble(index)); break; case TypeCode.String: writer.SetString(record.GetString(index)); break; default: if (type == typeof(Guid)) { writer.SetGuid(record.GetGuid(index)); } else if (type == typeof(byte[])) { writer.SetByteArray((byte[])record.GetValue(index)); } else { writer.SetString(record.GetValue(index).ToString()); } break; } } catch { try { object val = record[index]; // try to read from boxed value (not very effective) writer.ReadFrom(val); } catch { try { writer.SetString(record.GetString(index)); } catch (Exception err) { // add information to exception try { err.Data["data_type"] = record.GetFieldType(index).FullName; } catch (Exception err2) { err.Data["data_type"] = err2.ToString(); } try { err.Data["data_isnull"] = record.IsDBNull(index).ToString(); } catch (Exception err2) { err.Data["data_isnull"] = err2.ToString(); } throw; } } } }